test(http): 오래된 scope의 성공 응답을 버리는 마지막 검사를 고정한다
문제 §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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user