From c842bac0d54f1d984a6617ff3e476f6a74538f52 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:23:25 +0900 Subject: [PATCH] =?UTF-8?q?test(http):=20=EC=98=A4=EB=9E=98=EB=90=9C=20sco?= =?UTF-8?q?pe=EC=9D=98=20=EC=84=B1=EA=B3=B5=20=EC=9D=91=EB=8B=B5=EC=9D=84?= =?UTF-8?q?=20=EB=B2=84=EB=A6=AC=EB=8A=94=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=EB=A5=BC=20=EA=B3=A0=EC=A0=95=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 §10.8의 마지막 검사(src/adapters/http/http-execution-v3.ts:1493-1499, 검증을 통과한 성공 응답이라도 scope가 이미 현재가 아니면 SCOPE_FENCED) 를 false로 바꿔도 네 라운드째 모든 테스트가 통과한다(변이 L01). 지금 scope fence 테스트는 scope signal도 abort해서, abort 경로가 먼저 답하고 이 검사까지 오지 않는다. 고른 방법과 버린 대안 - tests/unit/http-execution-v3.test.ts에 경우 둘(조회·명령)을 더한다. fetch 안에서 scope의 isCurrent만 false로 바꾸고 signal은 abort하지 않는다. JSON 성공 경로에서 dispatch 뒤 scope를 보는 곳은 이 검사 하나라서, 검사를 지우면 SUCCESS가 나와 테스트가 실패한다. - 기대값: CONTRACT_VIOLATION/SCOPE_FENCED, 조회는 NOT_APPLICABLE, 명령은 MAYBE_APPLIED(보냈으니 적용됐을 수 있다). - 기존 abort 테스트를 바꾸는 안은 버렸다. 그 테스트는 abort가 먼저 이기는 경로를 지킨다. 위험·한계 - 테스트만 더했다. 실행기 코드는 그대로다. 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/http-execution-v3.test.ts - 변이 L01(:1494 조건을 false로)을 넣으면 "discards a valid read/command success that arrives after its scope stopped being current" 2건이 실패해야 한다. Refs: 0929/10-04 --- tests/unit/http-execution-v3.test.ts | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/unit/http-execution-v3.test.ts b/tests/unit/http-execution-v3.test.ts index e9b1ec8b..ee085b00 100644 --- a/tests/unit/http-execution-v3.test.ts +++ b/tests/unit/http-execution-v3.test.ts @@ -571,6 +571,54 @@ describe("descriptor-driven HTTP execution lifetime", () => { }); }); + // 0929/10-04. §10.8's last check: a valid success body for a scope that went + // stale while the request was out is discarded. The scope here only stops + // being current; its signal never aborts, so no earlier cancellation path + // answers first (the test above aborts it and never reaches this check). + it.each([ + ["read", "NOT_APPLICABLE"], + ["command", "MAYBE_APPLIED"], + ] as const)( + "discards a valid %s success that arrives after its scope stopped being current", + async (kind, effect) => { + let current = true; + const staleScope = Object.freeze({ + ...scope, + signal: new AbortController().signal, + isCurrent: () => current, + }); + const executor = createContractHttpExecutor({ + baseUrl: "https://api.example/", + maxRetryAttempts: 0, + attachCredentials: () => ({ kind: "READY", headers: {} }), + fetcher: vi.fn(async () => { + current = false; + return kind === "read" + ? Response.json([{ id: "a", name: "A" }]) + : Response.json({ id: "created", name: "Created" }, { status: 201 }); + }), + }); + + const outcome = + kind === "read" + ? await executor.execute(installed, { limit: 20 }, { + routeId: ROUTE_ID, + scope: staleScope, + }) + : await executor.execute(createInstalled, { name: "created" }, { + routeId: ROUTE_ID, + scope: staleScope, + intent: mutationIntent({ intentId: "intent-3", idempotencyKey: "key-3" }), + }); + + expect(outcome).toMatchObject({ + kind: "CONTRACT_VIOLATION", + violation: { kind: "SCOPE_FENCED" }, + effect, + }); + }, + ); + it("keeps a dispatched command MAYBE_APPLIED when a retry-time fence lands between scope checks", async () => { // Attempt 1 dispatches an idempotent command and receives 429. The retry // sleep resolves, the loop-entry scope check is still current, and only the