test(http): MAX_RETRY_ATTEMPTS 전달과 signal listener 정리를 고정한다
문제
V2를 지울 때(048f490) 같이 지운 테스트 둘이 V3 동작도 지키고 있었다.
- 운영 설정 MAX_RETRY_ATTEMPTS가 실행기에 닿는지. V3는
runtime-adapters.ts에서 넘긴다. 값을 상수 2로 바꾼 변이 H53이 15파일
143건을 통과했다. 장애 때 재시도를 끄는 손잡이가 조용히 사라질 수 있다
(REQUEST_TIMEOUT_MS는 실제로 한 번 그렇게 버려졌다).
- 호출자·scope signal에 단 abort listener를 지우는지. 호출자 쪽 제거를 지운
H56은 머지 게이트 테스트를 모두 통과했고, scope 쪽(H57)은 nightly
tier의 long-session 테스트 하나만 잡았다.
고른 방법
- tests/features/reference-feature/reference-runtime-composition.test.ts:
실제 createRuntimeAdapters에 MAX_RETRY_ATTEMPTS 0·1을 주고, 재시도
예산 2인 참조 목록 조회가 503에 1회·2회 나가는지 센다(Math.random 0으로
backoff 대기 없음). 설치된 기능의 HTTP가 있어야 조립 루트 경로를 탈 수
있어 참조 기능 테스트에 두었다. test:reference-feature는 머지 게이트다.
- tests/unit/http-execution-v3.test.ts: 응답으로 끝날 때와 호출자 abort로
끝날 때, 호출자·scope signal에 더한 abort listener가 같은 함수로 모두
지워지는지 센다.
위험·한계
- ①은 참조 기능에 기댄다. 샘플을 지운 제품에서는 이 테스트도 같이
빠진다. 조립 루트를 기능 없이 부를 수단이 없어서다.
- 10-04 ③(realtime snapshot의 GET 조건)은 다른 작업 몫이다.
검증
- 변이 H53·H56·H57을 하나씩 넣으면 새 테스트가 실패하고, 되돌리면 통과한다.
- 두 파일 76건 통과. check:types:test, eslint 통과.
Refs: docs/reviews/2026-11-03-maturity-review/10-tests-fast-layers.md 10-04
This commit is contained in:
@@ -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<Readonly<{ url: string; headers: Headers }>> = [];
|
||||
const fetcher = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
|
||||
@@ -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<Uint8Array>({
|
||||
pull(controller) {
|
||||
|
||||
Reference in New Issue
Block a user