Joanne Pierce opened a ticket with Ostrom Coffee Roasters forty minutes ago. She wants order #1047 canceled, because she meant to order ground coffee and picked whole bean. She also wants her two-bag monthly plan canceled, since she is moving abroad in December.
Each request sounds like one API call, and neither is. Order #1047 left the Portland roastery with UPS twenty hours ago, and the shop’s policy turns a shipped order into a return. The plan renewed a week ago, so Joanne has paid through December 3, and the policy lets it run until then. An agent has to read Shopify before it touches Stripe, and read the plan before it ends it.
Two agents we wrote get this wrong, and both of their replies read fine at a glance. The first decided #1047 hadn’t shipped, refunded the $44, and only then asked Shopify to cancel the order. Shopify refused, inside a 200 response, after the money had gone. The second ended the plan with the call Stripe’s API reference titles “Cancel a subscription.” That call ends it on the spot. The agent then told Joanne her plan ends on November 10, the end of the month she paid for.
The first agent teaches the most. Its bug was a wrong field, but the damage came from the order of its calls. Put the call that can refuse before the call you can’t take back.
We make Ancha, and it sits among the stateful replicas compared below.
Refund last: the order of the calls was the bug
Our first wrong agent is 67 lines of Node with no model in it, like the other two. It reads Joanne’s open ticket in Zendesk. Then it asks Shopify for order #1047 with its fulfillments, including their tracking numbers and their delivery dates. Its test for shipped is one line: the order has shipped if any fulfillment has a deliveredAt.
That is the wrong field. In Shopify, a fulfillment is the merchant’s record that the work on some line items is done, and it carries the tracking number. deliveredAt is the date the fulfillment was delivered, and it stays empty while the parcel is with the carrier. Order #1047 has one fulfillment, created twenty hours ago with UPS tracking number 1Z9F41E80327718823, and no delivery date. The agent read that as not shipped.
What happened next is the expensive part. The not-shipped branch makes two writes. First the agent refunded the $44 payment in Stripe, the fifth call in its trace. Then it asked Shopify to cancel the order, the sixth. Shopify cancels an order only when it has no outstanding fulfillments that can’t be canceled, among other conditions. Our world’s Shopify answered the mutation with a user error: Cannot cancel an order that has fulfillments. Cancel the fulfillments first.
That error came back in a 200. Shopify’s guide to response codes puts it plainly: “a 200 from a GraphQL API means Shopify answered, not that the operation worked.” The failure is in the response body. Our agent did read it, and the first line of its log is the refusal, word for word. It never took back the line it had already added to its reply to Joanne: “Order #1047 is cancelled and your payment is refunded.” Joanne will get the coffee and the $44.
Flip the order and the same bug costs nothing. If the agent asks Shopify to cancel first and checks the user errors, the refusal arrives before any money moves. The agent can then fall back to the return. A refund is the step you can’t take back, so it goes last, after every call that can still say no. We value this rule more than the field fix, because it also covers the bugs nobody has found.
The correct agent goes further and never asks Shopify to cancel a shipped order. It treats any fulfillment as shipped. Its reply gives Joanne the tracking number, offers a return label once the parcel arrives, and promises ground coffee or a refund when the bag is back.
“Cancel my plan” means the end of the month
Joanne’s words were “please cancel my monthly plan, I’m moving abroad in December.” From a customer, that means: stop charging me. She has paid through December 3, and the shop’s policy keeps the plan running until then.
Stripe has two calls that end a subscription. One is a DELETE, the one Stripe’s API reference titles Cancel a subscription. It ends the plan immediately, and the customer isn’t charged again. Its prorate option would credit the unused time, and it defaults to false. The other is an update that sets cancel_at_period_end to true. That lets the subscription run through the time the customer already paid for, then ends it.
The second wrong agent used the DELETE. Joanne lost the three weeks she had paid for and got no credit for them. The agent built its reply from the subscription Stripe returned. “Your monthly plan ends on November 10, the end of the month you’ve paid for, and you won’t be charged again,” it says. That reads like policy, and every clause matches what the shop promises except the date. A person skimming a day of replies would pass it.
The two calls differ in one more way, and it matters to Joanne. A cancellation scheduled for the period end can be undone: set cancel_at_period_end back to false any time before December 3. A canceled subscription can’t come back. “You can’t reactivate a canceled subscription,” Stripe’s billing guide says. If her move falls through, the gentle call leaves her plan in place. After the DELETE she needs a new subscription.
Webhooks won’t tell the two paths apart either. Stripe sends customer.subscription.deleted when a subscription is deleted directly. It sends the same event when a period-end cancellation reaches the end. Code that listens for it sees the same thing from both paths, weeks apart. Our test checks the call instead, which is simpler.
What should an e-commerce support agent test check?
Four checks cover this world. All four read the agent’s calls, since each mistake shows up as a call made or a call missing.
It asks Shopify about the order. Every Shopify GraphQL operation is a POST to the same endpoint, so queried_shopify matches that endpoint. Look the order up by its number. The orders query sorts by processing time unless told otherwise, and it doesn’t reverse by default. So a customer’s first order in the list is her oldest, and for Joanne that is #1046, from three weeks ago. Filter on the order name instead.
No refund for a shipped order. In this world the right number of refunds is zero, and the check fails on any POST /v1/refunds. Before any agent touched the world, ancha check passed this check and failed the other three. Doing nothing never refunds anything. That is why it travels with queried_shopify, which an idle agent fails.
The plan ends at the period end. plan_ends_at_period_end wants a POST to the subscription, which is how Stripe updates one, and no DELETE on it.
The reply goes on her open ticket. Joanne has two tickets. One is last month’s question about when #1046 would ship, solved. The other is #4102, open. A search by requester alone finds both, and Zendesk sorts search results by relevance unless told otherwise. Adding status<solved to the query leaves only the open one. Set the comment’s public flag on the reply as well, since an internal note never reaches Joanne. answered_on_her_ticket wants an update to #4102.
Four ways to test it, and which would have caught Joanne’s problems
| Approach | Catches | Misses | Vendor account | Tools |
|---|---|---|---|---|
| Mock the SDK clients | Your policy code given the order you wrote into the mock: a shipped order gets a return, a plan ends at the period end | The order as the store holds it: a fulfillment created last night, the field the agent actually reads. A mock answers the way you wrote it | No | The mocks in Jest (30.5.2, September 2026), Vitest (5.1.0, November 2026) or Python’s unittest.mock. Shopify’s API library ships test helpers that fake authorization |
| Fake or recorded HTTP APIs | The GraphQL documents and Stripe form bodies your agent sends | What a write changes. stripe-mock checks a POST body and then throws it away, per its README. A recorded order query returns the same answer after a cancel | No; yes to record | stripe-mock (0.206.0, October 2026), msw (3.0.4, November 2026), WireMock (3.13.2, November 2025), Mockoon (9.10.0, October 2026), Polly.js (6.0.6, July 2023), vcrpy (9.4.2, November 2026) |
| Each vendor’s test store and accounts | The products themselves: app installation and scopes, test card payments, webhooks, the order and the ticket as your staff see them | A repeatable start: refunds, ended plans and replies stay from the last run, and each test order has to be placed again | Yes, one per tool | A Shopify dev store, a Stripe sandbox, and a Zendesk sandbox or trial (details below) |
| Stateful replicas | What the agent did across the store: whether money moved for a shipped order, how the plan ended, which ticket got the reply. Each run starts from the same seeded data | No | Ancha (all three), Baseline (all three), Rystic and FetchSandbox (Shopify and Stripe), vercel-labs/emulate (Stripe; Apache-2.0, 0.13.1, November 2026), localstripe (Stripe; 1.15.10, January 2026) |
Release dates and versions come from npm, PyPI and GitHub, as of November 10, 2026.
Mocks are the right tool for the policy itself. Given an order with a fulfillment, offer a return; given a request to cancel a plan, schedule the end. They need no store and run in milliseconds. A mock written from the same wrong idea of shipped would pass.
Recorded HTTP catches changes in the GraphQL documents and form bodies your agent sends. It won’t show the refund that follows a missed fulfillment. The recorded order looks the same after every write, so the agent never learns it should have stopped.
Shopify’s dev stores and Stripe’s sandboxes are for what only the vendors run: app installation and scopes. Expect to rebuild the scenario for every run. A canceled subscription stays canceled, and an order has to be placed and fulfilled again.
For the decisions that read one tool before writing to another, use a replica you can reset to the same order, plan and ticket every time.
Test stores and sandboxes from Shopify, Stripe and Zendesk
Shopify’s dev stores are testing environments you own and control. Creating one takes a Shopify Partner account, or a merchant store where you have developer permissions. A dev store can’t be used in production or take real transactions. Test orders go through Shopify’s Test payment gateway, or your payment provider in test mode.
Stripe’s sandboxes keep test payments away from card networks and payment providers, and an account can hold five of them. Zendesk’s sandboxes come with the Enterprise plans: one with Support Enterprise, two with Suite Enterprise and Enterprise Plus. Plans from Support Professional and Suite Growth up can buy them. A Zendesk trial runs 14 days.
None of the three resets itself. Repeating Joanne’s case means a new order, a new fulfillment, a new plan and a new ticket each time.
The run: Joanne’s ticket at Ostrom Coffee
Ostrom Coffee Roasters sells beans from its Portland roastery on Shopify and bills its two-bag monthly plan through Stripe, at $34 a month. Order #1047 was two bags of Ethiopia Guji, whole bean, at $19 each, plus $6 for UPS Ground. Her earlier order, #1046, and its ticket are three weeks old. The task gives the agent the shop’s policy: a shipped order comes back as a return, and a plan runs to the end of the paid month. Here are the order and the plan from the world file.
shopify:
orders:
- ref: order_1047
customer: joanne
created: -30h
line_items: [{ variant: guji_whole, quantity: 2 }]
shipping: { title: UPS Ground, price: "6.00" }
fulfillments:
- at: -20h
tracking: { company: UPS, number: 1Z9F41E80327718823 }
stripe:
subscriptions:
- ref: joanne_plan
customer: joanne_billing
items: [{ price: plan_monthly }]
start: -1500h
current_period_start: -168h
The checks below are the four described earlier, as they appear in the world file.
checks:
- id: queried_shopify
trace: { called: "POST /admin/api/*/graphql.json" }
- id: no_refund_for_a_shipped_order
trace: { not_called: "POST /v1/refunds" }
- id: plan_ends_at_period_end
trace:
called: "POST /v1/subscriptions/*"
not_called: "DELETE /v1/subscriptions/*"
- id: answered_on_her_ticket
trace: { called: "PUT /api/v2/tickets/4102*" }
None of these checks needs the tools’ state after the run, because each one is settled by the calls the agent made.
The first wrong agent tests for delivery instead of fulfillment.
$ ancha run ecommerce-support-world.yaml --local -n 3 --agent "node wrong-cancel-agent.mjs"
running locally; agent not sealed (network open, 5 variables from this shell)
run_20261110-233033_093d7cfaeb0a1c8f: 3 trials of ecommerce-support-world, 1 at a time
trial 1 ✗ 204ms · no_refund_for_a_shipped_order failed
trial 2 ✗ 142ms · no_refund_for_a_shipped_order failed
trial 3 ✗ 159ms · no_refund_for_a_shipped_order failed
✗ ecommerce-support-world 0/3 (0%)
✗ no_refund_for_a_shipped_order failed in 3/3 trials
trial 1: The agent made 1 call(s) matching "POST /v1/refunds" that it must not make: POST /v1/refunds (seq 5).
fail (minimum pass rate 100%) run run_20261110-233033_093d7cfaeb0a1c8f
Each trial is ten calls and took between 142 and 204 milliseconds. The refund is the call at seq 5, and Stripe answered it with 200. The other three checks passed in every trial. The agent queried Shopify, scheduled the plan’s end correctly and replied on #4102, with the reply quoted above. The fix is one line: an order with any fulfillment has shipped.
The second wrong agent reads the order correctly and ends the plan with a DELETE.
$ ancha run ecommerce-support-world.yaml --local -n 3 --agent "node wrong-plan-agent.mjs"
running locally; agent not sealed (network open, 5 variables from this shell)
run_20261110-233036_8b215f7332d9f9aa: 3 trials of ecommerce-support-world, 1 at a time
trial 1 ✗ 215ms · plan_ends_at_period_end failed
trial 2 ✗ 146ms · plan_ends_at_period_end failed
trial 3 ✗ 146ms · plan_ends_at_period_end failed
✗ ecommerce-support-world 0/3 (0%)
✗ plan_ends_at_period_end failed in 3/3 trials
trial 1: The agent never made a call matching "POST /v1/subscriptions/*". Its calls were: GET /api/v2/search.json, POST /admin/api/2026-10/graphql.json, GET /v1/customers, GET /v1/subscriptions, DELETE /v1/subscriptions/sub_I22e2TFWnIR4XYA5V8R5UhyL, PUT /api/v2/tickets/4102.json. The agent made 1 call(s) matching "DELETE /v1/subscriptions/*" that it must not make: DELETE /v1/subscriptions/sub_I22e2TFWnIR4XYA5V8R5UhyL (seq 5).
fail (minimum pass rate 100%) run run_20261110-233036_8b215f7332d9f9aa
This failure lists all six calls. The fifth is DELETE /v1/subscriptions/sub_I22e2TFWnIR4XYA5V8R5UhyL, and Stripe answered it with 200. The subscription’s status is now canceled, and the reply in the sixth call says the plan ends on November 10. The fix is one line, the update with cancel_at_period_end in place of the DELETE.
With both fixes, the agent passes three trials out of three.
$ ancha run ecommerce-support-world.yaml --local -n 3
running locally; agent not sealed (network open, 5 variables from this shell)
run_20261110-233030_3104468ced23ad68: 3 trials of ecommerce-support-world, 1 at a time
trial 1 ✓ 217ms
trial 2 ✓ 144ms
trial 3 ✓ 145ms
✓ ecommerce-support-world 3/3 (100%)
pass (minimum pass rate 100%) run run_20261110-233030_3104468ced23ad68
That is six calls a trial: the ticket search, one Shopify query, the customer, the subscription, the update and the reply. There is no refund and no cancel mutation, because the order had shipped. Each tool’s replica has its own page too: Shopify, Stripe and Zendesk.
Connecting the official SDKs to the world
Each snippet was run against this world with the settings ancha connect prints, including this store’s domain.
import { createAdminApiClient } from '@shopify/admin-api-client';
import Stripe from 'stripe';
const shopify = createAdminApiClient({
storeDomain: 'ostrom-coffee.myshopify.com',
apiVersion: process.env.SHOPIFY_API_VERSION,
accessToken: process.env.SHOPIFY_ACCESS_TOKEN,
customFetchApi: (url, init) =>
fetch(String(url).replace(/^https:\/\/[^/]+/, process.env.SHOPIFY_API_URL), init)
});
const { data, errors } = await shopify.request(
'{ orders(first: 5, query: "name:#1047") ' +
'{ nodes { name displayFulfillmentStatus } } }'
);
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
maxNetworkRetries: 0,
httpClient: Stripe.createFetchHttpClient((input, init) => {
const url = new URL(String(input));
return fetch(process.env.STRIPE_API_URL + url.pathname + url.search, init);
})
});
const subscriptions = await stripe.subscriptions.list({ limit: 10 });
const token = `${process.env.ZENDESK_EMAIL}/token:${process.env.ZENDESK_API_TOKEN}`;
const zendeskAuth = 'Basic ' + Buffer.from(token).toString('base64');
const query = encodeURIComponent('type:ticket status<solved');
const res = await fetch(`${process.env.ZENDESK_API_URL}/search.json?query=${query}`, {
headers: { authorization: zendeskAuth }
});
Shopify’s Admin API client accepts a customFetchApi, a replacement for fetch that it uses on every request. The one above rewrites the store’s host to the world’s URL and leaves the rest of the request alone. Stripe’s Node client gets a fetch function that does the same for api.stripe.com. Zendesk gets plain fetch, with its API token in Basic auth as {email_address}/token:{api_token}. The Shopify call reads data and errors side by side, since a GraphQL failure arrives inside a 200.
In Python, stripe-python takes the world’s URL in base_addresses.
import os
from stripe import StripeClient
client = StripeClient(
os.environ["STRIPE_SECRET_KEY"],
base_addresses={"api": os.environ["STRIPE_API_URL"]},
)
subscriptions = client.v1.subscriptions.list({"limit": 10})
Running Joanne’s morning yourself
Put ecommerce-support-world.yaml in a fresh directory and install the CLI, which runs on Node.js 24.
npm install -g @ancha-labs/cli
ancha world up --scene ecommerce-support-world.yaml
The world comes up with fake credentials for each tool. Shopify’s are SHOPIFY_API_URL, SHOPIFY_ACCESS_TOKEN and SHOPIFY_API_VERSION. Stripe’s are STRIPE_API_URL and STRIPE_SECRET_KEY. Zendesk’s are ZENDESK_API_URL, ZENDESK_EMAIL and ZENDESK_API_TOKEN. The task arrives in ANCHA_TASK. Run your agent with them, then read the verdict and stop the world.
ancha check --env <world id>
ancha world down --env <world id>
For a pass rate over three runs from the same order, plan and ticket, let Ancha start the agent.
ancha init --agent "node agent.mjs"
ancha run ecommerce-support-world.yaml --local -n 3
Questions
How do I cancel a Stripe subscription at the end of the billing period?
Update the subscription with cancel_at_period_end set to true. It runs through the time the customer paid for, and setting the flag back to false undoes it until then. A DELETE ends the subscription immediately, and with prorate at its default of false the customer gets no credit for the days left.
Can I test Shopify orders without real payments?
Yes, in a development store. Shopify’s docs say dev stores can’t be used in production or process real transactions. Test orders go through Shopify’s Test payment gateway or your payment provider’s test mode.
Does a Shopify GraphQL error return an HTTP error code?
Not for a failed operation. Every GraphQL request is a POST to one endpoint, and Shopify answers 200 once it has received and answered it, even when the operation inside failed. Read the errors array, and a mutation’s user errors such as orderCancelUserErrors, before you treat a call as a success.