chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the generator-built feature index with its app, bounded-context and feature declarations, the src/platform kernel and scale tooling, the 2026-09-24 src review fixes, and the 2026-09-25 maturity review round with its CHANGELOG [보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them merged with product changes; 127 are not carried. Product identity is unchanged: name, version 0.1.0, routes, design and the TechLog domain. Three decisions worth naming. TechLog stays composed directly, as the last two syncs recorded; its directory carries a NOT_INSTALLED marker that says so, and every installed-* composer takes the template's projection with TechLog added on top. The reference sample is no longer installed: the template now installs a feature only through feature-module.ts and context-routes.ts, which load the screens this product deleted, so its three operations, six schemas and one topic leave the registries, recorded as registry change evidence. And AppRouter mounts the platform and TechLog routes only; the template's bounded-context route gateway waits for a generator-installed feature. Required fixes: readSubject on the BFF session owner (without it every HTTP Studio session would close as integration-failed), zod through the facade in nine TechLog files, noUnusedLocals, and public/config.json written out to match the local profile. Derived baselines were recomputed after reproducing both sides' values: CI contract 101 commands / 106 references / 141 artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime config schema baseline equals the schema at8210d48. Verified here: types, lint, architecture, adapter inventory, CI contract, i18n, design system, diagnostics, browser security, dev release manifest, TechLog contract and build pass; 220 component, 155 integration, 15 contract, 418 TechLog, 43 reference-feature, 18 recipe and 46 release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at8210d48first and unchanged: check:registries (byte-identical), test:runtime-schema, verify:documentation. Brought by the template and escalated rather than suppressed: check:request-fanout on TechLog's cursor pagination, check:remediation-ledger (fails upstream too), the shared-chunk hash test, and the registry-dependent sample removal and second-feature tests. Playwright suites were not run. Full record, the five open questions and the follow-ups in docs/operations/template-sync-2026-09-29.md. (cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createContractHttpExecutor } from "../../src/adapters/http/http-execution-v3.ts";
|
||||
import {
|
||||
createFeatureHttpBinding,
|
||||
defineFeatureHttpOperation,
|
||||
} from "../../src/adapters/http/feature-http-binding.ts";
|
||||
import {
|
||||
createContractHttpExecutor,
|
||||
type HttpExecutionObservation,
|
||||
} from "../../src/adapters/http/http-execution-v3.ts";
|
||||
import { mappingSuccess } from "../../src/contracts/boundary-mapper.ts";
|
||||
import type { InstalledHttpContract } from "../../src/contracts/external-contract-runtime.ts";
|
||||
import {
|
||||
createExecutionContext,
|
||||
type ExecutionContext,
|
||||
} from "../../src/platform/execution/execution-context.ts";
|
||||
import {
|
||||
TEST_CREATE_HTTP_CONTRACT,
|
||||
TEST_LIST_HTTP_CONTRACT,
|
||||
@@ -137,6 +149,32 @@ describe("runtime request deadline ceiling", () => {
|
||||
});
|
||||
|
||||
describe("descriptor-driven HTTP execution lifetime", () => {
|
||||
it("tells a missing credential apart from a server 401", async () => {
|
||||
const refusedFetcher = vi.fn();
|
||||
const refused = await createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 0,
|
||||
attachCredentials: () => ({ kind: "UNAUTHENTICATED" }),
|
||||
fetcher: refusedFetcher,
|
||||
}).execute(installed, { limit: 20 }, { routeId: ROUTE_ID, scope });
|
||||
const rejected = await createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 0,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher: async () => new Response(null, { status: 401 }),
|
||||
}).execute(installed, { limit: 20 }, { routeId: ROUTE_ID, scope });
|
||||
|
||||
// Only the server's answer carries response metadata; the composition
|
||||
// root reports just that one to the session owner.
|
||||
expect(refusedFetcher).not.toHaveBeenCalled();
|
||||
expect(refused).toEqual({ kind: "UNAUTHENTICATED", effect: "NOT_APPLICABLE" });
|
||||
expect(rejected).toMatchObject({
|
||||
kind: "UNAUTHENTICATED",
|
||||
effect: "NOT_APPLICABLE",
|
||||
metadata: { status: 401 },
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes a read-side 429 to the non-applicable effect vocabulary", async () => {
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
@@ -751,3 +789,528 @@ describe("descriptor-driven HTTP execution lifetime", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* R-3.3. A gateway 5xx/408 with an HTML, empty or broken body is a server
|
||||
* outage. It must keep its status and stay retryable instead of surfacing as a
|
||||
* "contact support" contract breach.
|
||||
*/
|
||||
describe("gateway failures without a usable problem body", () => {
|
||||
it.each([
|
||||
[502, "text/html", "<html>Bad Gateway</html>"],
|
||||
[503, "application/json", ""],
|
||||
[504, "application/json", "{"],
|
||||
[408, "text/plain", "timeout"],
|
||||
])(
|
||||
"ends a %i response as a retryable server failure with its status",
|
||||
async (status, contentType, body) => {
|
||||
const fetcher = vi.fn(
|
||||
async () =>
|
||||
new Response(body, { status, headers: { "content-type": contentType } }),
|
||||
);
|
||||
const observations: HttpExecutionObservation[] = [];
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 1,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher,
|
||||
sleep: async () => {},
|
||||
observe: (observation) => void observations.push(observation),
|
||||
});
|
||||
const list = defineFeatureHttpOperation({
|
||||
contract: TEST_LIST_HTTP_CONTRACT,
|
||||
routeId: ROUTE_ID,
|
||||
mapSuccess: (value) => mappingSuccess(value),
|
||||
});
|
||||
const binding = createFeatureHttpBinding(
|
||||
{
|
||||
execute: (contract, input, context) =>
|
||||
executor.execute(contract, input, { ...context, scope }),
|
||||
},
|
||||
{ [list.operationId]: list },
|
||||
);
|
||||
|
||||
const result = await binding.execute(list.operationId, { limit: 20 });
|
||||
|
||||
expect(fetcher).toHaveBeenCalledTimes(2);
|
||||
expect(observations.at(-1)?.status).toBe(status);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
kind: "SERVER_FAILURE",
|
||||
httpStatus: status,
|
||||
retryable: true,
|
||||
action: "retry",
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Q-6.3-6. Every wait the lifetime signal can end reports its owner the same
|
||||
* way: the caller cancels, the deadline times out, and a scope fence ends as a
|
||||
* scope abort — a transport abort before response headers, the stale-generation
|
||||
* violation after them. A fence during a retry backoff used to read as TIMEOUT.
|
||||
*/
|
||||
describe("terminal owner classification at every wait", () => {
|
||||
const phases = [
|
||||
"credentials",
|
||||
"lease",
|
||||
"dispatch",
|
||||
"transport backoff",
|
||||
"admission",
|
||||
"retry backoff",
|
||||
] as const;
|
||||
type Phase = (typeof phases)[number];
|
||||
type Owner = "CALLER" | "SCOPE_FENCE" | "DEADLINE";
|
||||
|
||||
const hang = () => new Promise<never>(() => {});
|
||||
|
||||
async function endWaitAt(phase: Phase, owner: Owner) {
|
||||
const caller = new AbortController();
|
||||
const fence = new AbortController();
|
||||
const fencedScope = Object.freeze({
|
||||
...scope,
|
||||
signal: fence.signal,
|
||||
isCurrent: () => !fence.signal.aborted,
|
||||
});
|
||||
let reached = false;
|
||||
const reach = () => {
|
||||
reached = true;
|
||||
};
|
||||
let execution: ExecutionContext | undefined;
|
||||
if (phase === "lease") {
|
||||
execution = createExecutionContext({
|
||||
interactionId: "held-lease",
|
||||
deadlineMs: 10_000,
|
||||
traffic: {
|
||||
maxPhysicalRequests: 4,
|
||||
maxRetries: 2,
|
||||
maxConcurrentRequests: 1,
|
||||
maxQueuedRequests: 1,
|
||||
},
|
||||
});
|
||||
await execution.traffic.concurrency.acquire(new AbortController().signal);
|
||||
}
|
||||
const observations: HttpExecutionObservation[] = [];
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 2,
|
||||
attachCredentials: () =>
|
||||
phase === "credentials"
|
||||
? (reach(), hang())
|
||||
: { kind: "READY", headers: {} },
|
||||
fetcher: vi.fn(async () => {
|
||||
switch (phase) {
|
||||
case "transport backoff":
|
||||
throw new TypeError("network down");
|
||||
case "admission":
|
||||
return new Response(
|
||||
new ReadableStream<Uint8Array>({
|
||||
pull: () => (reach(), hang()),
|
||||
}),
|
||||
{ status: 200, headers: { "content-type": "application/json" } },
|
||||
);
|
||||
case "retry backoff":
|
||||
return Response.json(
|
||||
{ type: "about:blank", title: "temporary", status: 503 },
|
||||
{ status: 503 },
|
||||
);
|
||||
default:
|
||||
reach();
|
||||
return hang();
|
||||
}
|
||||
}),
|
||||
sleep: () => (reach(), hang()),
|
||||
random: () => 0,
|
||||
observe: (observation) => void observations.push(observation),
|
||||
});
|
||||
|
||||
const pending = executor.execute(
|
||||
operation({ deadlineMs: owner === "DEADLINE" ? 30 : 10_000 }),
|
||||
{ limit: 20 },
|
||||
{
|
||||
routeId: ROUTE_ID,
|
||||
scope: fencedScope,
|
||||
signal: caller.signal,
|
||||
...(execution === undefined ? {} : { execution }),
|
||||
},
|
||||
);
|
||||
if (owner !== "DEADLINE") {
|
||||
await vi.waitFor(() =>
|
||||
expect(reached || execution?.traffic.concurrency.queued === 1).toBe(
|
||||
true,
|
||||
),
|
||||
);
|
||||
(owner === "CALLER" ? caller : fence).abort();
|
||||
}
|
||||
const outcome = await pending;
|
||||
return {
|
||||
outcome,
|
||||
cancellationOwner: observations.at(-1)?.cancellationOwner,
|
||||
};
|
||||
}
|
||||
|
||||
it.each(phases)(
|
||||
"cancels at the %s wait when the caller aborts",
|
||||
async (phase) => {
|
||||
await expect(endWaitAt(phase, "CALLER")).resolves.toMatchObject({
|
||||
outcome: { kind: "CANCELLED", effect: "NOT_STARTED" },
|
||||
cancellationOwner: "CALLER",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(phases)(
|
||||
"times out at the %s wait when the deadline fires",
|
||||
async (phase) => {
|
||||
await expect(endWaitAt(phase, "DEADLINE")).resolves.toMatchObject({
|
||||
outcome: { kind: "TRANSPORT_FAILURE", failure: { kind: "TIMEOUT" } },
|
||||
cancellationOwner: "DEADLINE",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(phases)(
|
||||
"ends the %s wait as a scope abort when the scope is fenced",
|
||||
async (phase) => {
|
||||
await expect(endWaitAt(phase, "SCOPE_FENCE")).resolves.toMatchObject({
|
||||
outcome:
|
||||
phase === "admission"
|
||||
? {
|
||||
kind: "CONTRACT_VIOLATION",
|
||||
violation: { kind: "SCOPE_FENCED" },
|
||||
}
|
||||
: {
|
||||
kind: "TRANSPORT_FAILURE",
|
||||
failure: { kind: "ABORTED_BY_SCOPE" },
|
||||
},
|
||||
cancellationOwner: "SCOPE_FENCE",
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* 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
|
||||
* `x-correlation-id` as `requestId`.
|
||||
*/
|
||||
describe("request correlation", () => {
|
||||
it("sends one request id per logical execution, shared by its retries", async () => {
|
||||
const sent: (string | null)[] = [];
|
||||
const fetcher = vi.fn<typeof fetch>(async (_input, init) => {
|
||||
sent.push(new Headers(init?.headers).get("x-correlation-id"));
|
||||
return sent.length === 1
|
||||
? new Response(null, { status: 503 })
|
||||
: Response.json([{ id: "a", name: "A" }]);
|
||||
});
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 2,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher,
|
||||
sleep: async () => {},
|
||||
random: () => 0,
|
||||
});
|
||||
const retried = {
|
||||
...installed,
|
||||
frontend: { ...installed.frontend, retryBudget: 1 as const },
|
||||
};
|
||||
|
||||
await executor.execute(retried, { limit: 20 }, { routeId: ROUTE_ID, scope });
|
||||
await executor.execute(retried, { limit: 20 }, { routeId: ROUTE_ID, scope });
|
||||
|
||||
expect(sent).toHaveLength(3);
|
||||
expect(sent[0]).toMatch(/^[A-Za-z0-9._:-]{1,128}$/u);
|
||||
expect(sent[1]).toBe(sent[0]);
|
||||
expect(sent[2]).not.toBe(sent[0]);
|
||||
});
|
||||
|
||||
it("still sends the request when no request id can be made", async () => {
|
||||
const fetcher = vi.fn<typeof fetch>(async () =>
|
||||
Response.json([{ id: "a", name: "A" }]),
|
||||
);
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 0,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher,
|
||||
createRequestId: () => {
|
||||
throw new TypeError("randomUUID needs a secure context");
|
||||
},
|
||||
});
|
||||
|
||||
const outcome = await executor.execute(installed, { limit: 20 }, {
|
||||
routeId: ROUTE_ID,
|
||||
scope,
|
||||
});
|
||||
|
||||
expect(outcome.kind).toBe("SUCCESS");
|
||||
expect(
|
||||
new Headers(fetcher.mock.calls[0]?.[1]?.headers).get("x-correlation-id"),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a problem", 400, { type: "about:blank", title: "rejected", status: 400 }],
|
||||
["an unauthenticated answer", 401, null],
|
||||
["a forbidden answer", 403, null],
|
||||
["a rate limit", 429, null],
|
||||
["a gateway outage", 504, null],
|
||||
] as const)("carries the server correlation id on %s", async (_label, status, body) => {
|
||||
const observations: HttpExecutionObservation[] = [];
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 0,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher: vi.fn(async () =>
|
||||
body === null
|
||||
? new Response(null, {
|
||||
status,
|
||||
headers: { "x-correlation-id": "server-ref-42" },
|
||||
})
|
||||
: Response.json(body, {
|
||||
status,
|
||||
headers: { "x-correlation-id": "server-ref-42" },
|
||||
}),
|
||||
),
|
||||
observe: (observation) => observations.push(observation),
|
||||
});
|
||||
const list = defineFeatureHttpOperation({
|
||||
contract: TEST_LIST_HTTP_CONTRACT,
|
||||
routeId: ROUTE_ID,
|
||||
mapSuccess: (value) => mappingSuccess(value),
|
||||
});
|
||||
const binding = createFeatureHttpBinding(
|
||||
{
|
||||
execute: (contract, input, context) =>
|
||||
executor.execute(contract, input, { ...context, scope }),
|
||||
},
|
||||
{ [list.operationId]: list },
|
||||
);
|
||||
|
||||
const result = await binding.execute(list.operationId, { limit: 20 });
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { requestId: "server-ref-42" },
|
||||
});
|
||||
expect(observations.at(-1)?.correlationId).toBe("server-ref-42");
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* D-2 (03-02). 401, 403 and 429 are admitted before any problem body is read.
|
||||
* The package may classify them by status; without a classifier, or when it
|
||||
* misbehaves, a dispatched command stays MAYBE_APPLIED.
|
||||
*/
|
||||
describe("command status classification", () => {
|
||||
function withStatusClassifier(
|
||||
classifyStatus: ((status: 401 | 403 | 429) => unknown) | undefined,
|
||||
): InstalledHttpContract<unknown, unknown, unknown> {
|
||||
return {
|
||||
...createInstalled,
|
||||
contract: {
|
||||
...createInstalled.contract,
|
||||
commandEffect: {
|
||||
...createInstalled.contract.commandEffect!,
|
||||
...(classifyStatus === undefined ? {} : { classifyStatus }),
|
||||
} as NonNullable<typeof createInstalled.contract.commandEffect>,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function effectFor(
|
||||
status: number,
|
||||
contract: InstalledHttpContract<unknown, unknown, unknown>,
|
||||
) {
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 0,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher: vi.fn(async () => new Response(null, { status })),
|
||||
});
|
||||
const outcome = await executor.execute(
|
||||
contract,
|
||||
{ name: "created" },
|
||||
{ routeId: ROUTE_ID, scope, intent: mutationIntent() },
|
||||
);
|
||||
return { kind: outcome.kind, effect: outcome.effect };
|
||||
}
|
||||
|
||||
it.each([
|
||||
[401, "UNAUTHENTICATED"],
|
||||
[403, "FORBIDDEN"],
|
||||
[429, "RATE_LIMITED"],
|
||||
] as const)("uses the package classifier for %i", async (status, kind) => {
|
||||
const classifyStatus = vi.fn(() => "NOT_APPLIED");
|
||||
await expect(
|
||||
effectFor(status, withStatusClassifier(classifyStatus)),
|
||||
).resolves.toEqual({ kind, effect: "NOT_APPLIED" });
|
||||
expect(classifyStatus).toHaveBeenCalledWith(status);
|
||||
});
|
||||
|
||||
const throwingClassifier = (): unknown => {
|
||||
throw new Error("package defect");
|
||||
};
|
||||
const unknownAnswer = (): unknown => "APPLIED_CONFIRMED";
|
||||
|
||||
it.each([
|
||||
["no classifier", undefined],
|
||||
["a throwing classifier", throwingClassifier],
|
||||
["an unknown answer", unknownAnswer],
|
||||
] as const)("keeps MAYBE_APPLIED for %s", async (_label, classifyStatus) => {
|
||||
for (const status of [401, 403, 429]) {
|
||||
await expect(
|
||||
effectFor(status, withStatusClassifier(classifyStatus)),
|
||||
).resolves.toMatchObject({ effect: "MAYBE_APPLIED" });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Q-6.3-7. A retried command's final effect joins what earlier attempts already
|
||||
* established, and an answer that says the command may already be applied is
|
||||
* not replayed.
|
||||
*/
|
||||
describe("command effect across retries", () => {
|
||||
const idempotentCommand: InstalledHttpContract<unknown, unknown, unknown> = {
|
||||
...createInstalled,
|
||||
contract: {
|
||||
...createInstalled.contract,
|
||||
retrySemantics: "IDEMPOTENT" as const,
|
||||
},
|
||||
frontend: { ...createInstalled.frontend, retryBudget: 1 as const },
|
||||
};
|
||||
|
||||
async function runThenReject(first: () => Promise<Response>) {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementationOnce(first)
|
||||
.mockImplementation(async () =>
|
||||
// The fixture classifier reads a 400 problem as NOT_APPLIED.
|
||||
Response.json(
|
||||
{ type: "about:blank", title: "rejected", status: 400 },
|
||||
{ status: 400 },
|
||||
),
|
||||
);
|
||||
const executor = createContractHttpExecutor({
|
||||
baseUrl: "https://api.example/",
|
||||
maxRetryAttempts: 1,
|
||||
attachCredentials: () => ({ kind: "READY", headers: {} }),
|
||||
fetcher,
|
||||
sleep: async () => {},
|
||||
random: () => 0,
|
||||
});
|
||||
const outcome = await executor.execute(
|
||||
idempotentCommand,
|
||||
{ name: "created" },
|
||||
{
|
||||
routeId: ROUTE_ID,
|
||||
scope,
|
||||
intent: mutationIntent({ idempotencyKey: null }),
|
||||
},
|
||||
);
|
||||
return { outcome, attempts: fetcher.mock.calls.length };
|
||||
}
|
||||
|
||||
it("keeps MAYBE_APPLIED when the retry after a lost response is rejected", async () => {
|
||||
await expect(
|
||||
runThenReject(async () => {
|
||||
throw new TypeError("connection reset");
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
attempts: 2,
|
||||
outcome: { kind: "PROBLEM", effect: "MAYBE_APPLIED" },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps MAYBE_APPLIED when the retry after a rate limit is rejected", async () => {
|
||||
await expect(
|
||||
runThenReject(async () => new Response(null, { status: 429 })),
|
||||
).resolves.toMatchObject({
|
||||
attempts: 2,
|
||||
outcome: { kind: "PROBLEM", effect: "MAYBE_APPLIED" },
|
||||
});
|
||||
});
|
||||
|
||||
it("does not replay a command whose gateway failure may already be applied", async () => {
|
||||
await expect(
|
||||
runThenReject(async () => new Response("", { status: 504 })),
|
||||
).resolves.toMatchObject({
|
||||
attempts: 1,
|
||||
outcome: {
|
||||
kind: "CONTRACT_VIOLATION",
|
||||
metadata: { status: 504 },
|
||||
effect: "MAYBE_APPLIED",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user