diff --git a/tests/features/reference-feature/reference-runtime-composition.test.ts b/tests/features/reference-feature/reference-runtime-composition.test.ts index 4c4d0540..16ccec03 100644 --- a/tests/features/reference-feature/reference-runtime-composition.test.ts +++ b/tests/features/reference-feature/reference-runtime-composition.test.ts @@ -160,6 +160,49 @@ describe("reference feature runtime composition", () => { adapters.infrastructure.dispose(); }); + // 1103/10-04 ①. MAX_RETRY_ATTEMPTS is the operator's dial over every + // contract's retry budget (the list declares 2). Zero must stop retries. + it.each([ + [0, 1], + [1, 2], + ])("honours MAX_RETRY_ATTEMPTS %i: a retryable list read goes out %i time(s)", async (maxRetryAttempts, sends) => { + const fetcher = vi.fn(async (_input: RequestInfo | URL) => + Response.json( + { type: "about:blank", title: "temporary", status: 503 }, + { status: 503 }, + ), + ); + // No backoff wait: the jitter is the random draw times a ceiling. + const random = vi.spyOn(Math, "random").mockReturnValue(0); + try { + const adapters = await createRuntimeAdapters({ + runtime: { + ...runtime, + config: { ...runtime.config, MAX_RETRY_ATTEMPTS: maxRetryAttempts }, + }, + release, + host: {}, + fetcher, + }); + await adapters.outputPorts.session.beginSignIn(); + await vi.waitFor(() => + expect(adapters.infrastructure.serverStateScope.getPhase()).toBe("READY"), + ); + + await expect( + (await referenceInput(adapters)).listResources({ limit: 20 }), + ).resolves.toMatchObject({ ok: false, error: { kind: "SERVER_FAILURE" } }); + expect( + fetcher.mock.calls.filter(([url]) => + String(url).includes("/api/reference-resources"), + ), + ).toHaveLength(sends); + adapters.infrastructure.dispose(); + } finally { + random.mockRestore(); + } + }); + it("keeps private command intent identity out of URLs and diagnostics", async () => { const requests: Array> = []; const fetcher = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => { diff --git a/tests/unit/http-execution-v3.test.ts b/tests/unit/http-execution-v3.test.ts index 4f240ce1..06757200 100644 --- a/tests/unit/http-execution-v3.test.ts +++ b/tests/unit/http-execution-v3.test.ts @@ -761,6 +761,48 @@ describe("descriptor-driven HTTP execution lifetime", () => { await expect(result).resolves.toMatchObject({ kind: "CANCELLED" }); }); + // 1103/10-04 ②. A signal is shared by many requests (a screen, a session + // scope). Every abort listener an execution adds to the caller's and the + // scope's signal is removed when it ends, however it ends. + it.each(["an answer", "a caller abort"] as const)( + "removes the listeners it added to the caller and scope signals after %s", + async (ending) => { + const caller = new AbortController(); + const scopeLifetime = new AbortController(); + const watched = [caller.signal, scopeLifetime.signal].map((signal) => ({ + add: vi.spyOn(signal, "addEventListener"), + remove: vi.spyOn(signal, "removeEventListener"), + })); + const executor = createContractHttpExecutor({ + baseUrl: "https://api.example/", + maxRetryAttempts: 0, + attachCredentials: () => ({ kind: "READY", headers: {} }), + fetcher: vi.fn(async () => Response.json([])), + }); + + const result = executor.execute(installed, { limit: 20 }, { + routeId: ROUTE_ID, + scope: { ...scope, signal: scopeLifetime.signal }, + signal: caller.signal, + }); + if (ending === "a caller abort") caller.abort(); + + await expect(result).resolves.toMatchObject({ + kind: ending === "an answer" ? "SUCCESS" : "CANCELLED", + }); + for (const { add, remove } of watched) { + const added = add.mock.calls + .filter(([type]) => type === "abort") + .map(([, listener]) => listener); + const removed = remove.mock.calls + .filter(([type]) => type === "abort") + .map(([, listener]) => listener); + expect(added).toHaveLength(1); + expect(removed).toEqual(added); + } + }, + ); + it("treats an unreadable forbidden-body probe as a transport failure", async () => { const body = new ReadableStream({ pull(controller) {