test(http): cover KEYED retries with budget left through the V3 executor (10-03)
Every KEYED fixture had retryBudget 0, so passing "SAFE" instead of the contract's retry semantics (M1b) survived. Two executor tests now pin that a KEYED send retries only before dispatch, with the same key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e14c6131be
commit
e62b020ad6
@@ -992,6 +992,71 @@ describe("terminal owner classification at every wait", () => {
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* 10-03. The executor, not only the pure rule, must read the contract's retry
|
||||
* semantics: a KEYED command with budget left retries a send that never left,
|
||||
* and never replays one that was dispatched.
|
||||
*/
|
||||
describe("KEYED retry budget through the executor", () => {
|
||||
const keyedWithBudget: InstalledHttpContract<unknown, unknown, unknown> = {
|
||||
...createInstalled,
|
||||
frontend: { ...createInstalled.frontend, retryBudget: 2 as const },
|
||||
};
|
||||
|
||||
function keyedExecutor(fetcher: typeof fetch) {
|
||||
return createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 2,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher,
|
||||
sleep: async () => {},
|
||||
random: () => 0,
|
||||
});
|
||||
}
|
||||
|
||||
it("retries a KEYED send that failed before dispatch, with the same key", async () => {
|
||||
const keys: (string | null)[] = [];
|
||||
const fetcher = vi.fn<typeof fetch>((_input, init) => {
|
||||
keys.push(new Headers(init?.headers).get("idempotency-key"));
|
||||
if (keys.length === 1) throw new TypeError("fetch refused to start");
|
||||
return Promise.resolve(
|
||||
Response.json({ id: "created", name: "created" }, { status: 201 }),
|
||||
);
|
||||
});
|
||||
|
||||
const outcome = await keyedExecutor(fetcher).execute(
|
||||
keyedWithBudget,
|
||||
{ name: "created" },
|
||||
{ routeId: ROUTE_ID, scope, intent: mutationIntent() },
|
||||
);
|
||||
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(keys).toEqual(["key-1", "key-1"]);
|
||||
expect(outcome).toMatchObject({
|
||||
kind: "SUCCESS",
|
||||
effect: "APPLIED_CONFIRMED",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not replay a dispatched KEYED send even with budget left", async () => {
|
||||
const fetcher = vi.fn<typeof fetch>(async () => {
|
||||
throw new TypeError("connection reset");
|
||||
});
|
||||
|
||||
const outcome = await keyedExecutor(fetcher).execute(
|
||||
keyedWithBudget,
|
||||
{ name: "created" },
|
||||
{ routeId: ROUTE_ID, scope, intent: mutationIntent() },
|
||||
);
|
||||
|
||||
expect(fetcher).toHaveBeenCalledOnce();
|
||||
expect(outcome).toMatchObject({
|
||||
kind: "TRANSPORT_FAILURE",
|
||||
effect: "MAYBE_APPLIED",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 03-03. A support reference must reach the server log: every logical
|
||||
* execution sends one request id, and a failure carries the server's echoed
|
||||
|
||||
Reference in New Issue
Block a user