From cfdb0b2f42b95e09f6c1a5a6aafd5298cf02a0ca Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 11:42:22 +0900 Subject: [PATCH] =?UTF-8?q?test(platform):=20traffic=20=EC=83=81=ED=95=9C?= =?UTF-8?q?=C2=B7JSON=20=EA=B5=AC=EC=A1=B0=20=EC=98=88=EC=82=B0=EC=9D=98?= =?UTF-8?q?=20=EA=B2=BD=EA=B3=84=EC=99=80=20=EC=B7=A8=EC=86=8C=EB=90=9C=20?= =?UTF-8?q?owner=20signal=EC=9D=84=20=EC=8B=9C=ED=97=98=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: retry·동시성 상한, 이미 취소된 owner signal, JSON 구조 예산의 경계값을 시험이 보지 않는다. traffic-budget.ts의 maxRetries· maxConcurrentRequests 상한을 1_000으로 올리거나 상한 비교 `>`를 `>=`로 바꿔도, execution-context.ts가 이미 취소된 signal을 무시해도, bounded-json.ts의 노드·문자열·깊이·배열·객체 폭 비교를 `>=`로 바꾸거나 key 길이 검사를 지워도 test:platform과 http-execution-v3 시험이 모두 통과한다. 고른 방법: 시험만 더한다. traffic 거절 표에 maxRetries=17· maxConcurrentRequests=17을 넣고, 상한값 넷(64·16·16·256)을 받아들이는 시험을 둔다. 값은 리터럴로 쓴다. 이미 취소된 owner signal로 만든 interaction은 처음부터 취소돼 있다. JSON 구조는 상한과 같은 값은 통과, 하나 넘는 값은 거절하는 쌍을 노드·깊이·문자열·key 길이마다 둔다. 배열·객체 폭은 컨테이너 자신이 노드라 maxItems개 자식이면 노드 수가 먼저 넘으므로 「같은 값 통과」가 없다. 그래서 detail로 어느 검사가 걸렸는지 본다(같은 값 → 노드 수, 하나 넘음 → 폭 검사). 버린 안: 상한 상수를 import해 대조한다. 상수를 올리면 시험 숫자도 따라 바뀌어 잡지 못한다. 위험·한계: 폭 시험은 detail 문구의 한 낱말(nodes·array·object)에 묶인다. 문구를 바꾸면 이 시험도 고쳐야 한다. src/platform의 상한 값과 로직은 바꾸지 않았다. 검증: desktop `scripts/verify.sh exec`. 고치기 전 시험에 변이 10개를 하나씩 넣고 tests/platform·tests/architecture·http-execution-v3를 돌리면 모두 통과(368 passed). 새 시험에 같은 변이를 넣으면 변이마다 새 시험 하나가 실패(1 failed | 39 passed). 원본에서는 40 passed. Refs: REV-FE-0032 --- .../execution/execution-context.test.ts | 13 ++++ tests/platform/traffic/traffic-budget.test.ts | 14 ++++ .../platform/validation/bounded-json.test.ts | 72 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/tests/platform/execution/execution-context.test.ts b/tests/platform/execution/execution-context.test.ts index c0e611de..8ef7ef1b 100644 --- a/tests/platform/execution/execution-context.test.ts +++ b/tests/platform/execution/execution-context.test.ts @@ -69,6 +69,19 @@ describe("createExecutionContext", () => { expect(direct.cancellation.signal.aborted).toBe(true); }); + it("starts cancelled when the owner signal is already aborted", () => { + const owner = new AbortController(); + owner.abort(); + const context = createExecutionContext({ + interactionId: "interaction-8", + deadlineMs: 1_000, + traffic: TRAFFIC, + signal: owner.signal, + }); + + expect(context.cancellation.signal.aborted).toBe(true); + }); + it("detaches from a long-lived owner signal when the interaction completes (Q-6.9-7)", () => { const owner = new AbortController(); const remove = vi.spyOn(owner.signal, "removeEventListener"); diff --git a/tests/platform/traffic/traffic-budget.test.ts b/tests/platform/traffic/traffic-budget.test.ts index 699b3767..568939eb 100644 --- a/tests/platform/traffic/traffic-budget.test.ts +++ b/tests/platform/traffic/traffic-budget.test.ts @@ -50,10 +50,24 @@ describe("createTrafficRuntime", () => { ["maxConcurrentRequests", 0], ["maxQueuedRequests", Number.NaN], ["maxPhysicalRequests", 65], + ["maxRetries", 17], + ["maxConcurrentRequests", 17], ["maxQueuedRequests", 257], ] as const)("rejects %s=%s", (key, value) => { expect(() => defineTrafficBudget({ ...POLICY, [key]: value })).toThrow( new RegExp(key), ); }); + + it("accepts every hard ceiling itself", () => { + // Literal values on purpose: a test that imports the ceilings would follow + // a raised constant instead of catching it. + const atCeiling = { + maxPhysicalRequests: 64, + maxRetries: 16, + maxConcurrentRequests: 16, + maxQueuedRequests: 256, + }; + expect(defineTrafficBudget(atCeiling)).toEqual(atCeiling); + }); }); diff --git a/tests/platform/validation/bounded-json.test.ts b/tests/platform/validation/bounded-json.test.ts index ad9e1062..79f1502e 100644 --- a/tests/platform/validation/bounded-json.test.ts +++ b/tests/platform/validation/bounded-json.test.ts @@ -101,6 +101,78 @@ describe("validateJsonStructure", () => { }); }); +describe("checkJsonStructure at and one above each ceiling", () => { + it("counts total nodes up to maxItems", () => { + // Short arrays keep the length guard out of the way: only the node count can fire. + const budget = { ...BUDGET, maxItems: 5 }; + expect(checkJsonStructure([[1], [2]], budget)).toEqual({ ok: true, nodes: 5 }); + expect(checkJsonStructure([[1], [2, 3]], budget)).toMatchObject({ + ok: false, + violation: "too-many-items", + detail: expect.stringMatching(/nodes/), + }); + }); + + it("allows nesting up to maxDepth", () => { + const budget = { ...BUDGET, maxDepth: 3 }; + expect(checkJsonStructure([[[1]]], budget)).toMatchObject({ ok: true }); + expect(checkJsonStructure([[[[1]]]], budget)).toMatchObject({ + ok: false, + violation: "too-deep", + }); + }); + + it("allows string values up to maxStringLength", () => { + const budget = { ...BUDGET, maxStringLength: 4 }; + expect(checkJsonStructure(["abcd"], budget)).toMatchObject({ ok: true }); + expect(checkJsonStructure(["abcde"], budget)).toMatchObject({ + ok: false, + violation: "string-too-long", + }); + }); + + it("allows object keys up to maxStringLength", () => { + const budget = { ...BUDGET, maxStringLength: 4 }; + expect(checkJsonStructure({ abcd: 1 }, budget)).toMatchObject({ ok: true }); + expect(checkJsonStructure({ abcde: 1 }, budget)).toEqual({ + ok: false, + violation: "string-too-long", + detail: "object key too long", + }); + }); + + // A container is itself a node, so one with exactly maxItems children always + // trips the node count. The width guards must fire only above the ceiling, + // before the children are walked; `detail` tells the two apart. + it("leaves an array of exactly maxItems to the node count", () => { + const budget = { ...BUDGET, maxItems: 3 }; + expect(checkJsonStructure([1, 2, 3], budget)).toMatchObject({ + ok: false, + violation: "too-many-items", + detail: expect.stringMatching(/nodes/), + }); + expect(checkJsonStructure([1, 2, 3, 4], budget)).toMatchObject({ + ok: false, + violation: "too-many-items", + detail: expect.stringMatching(/array/), + }); + }); + + it("leaves an object of exactly maxItems keys to the node count", () => { + const budget = { ...BUDGET, maxItems: 3 }; + expect(checkJsonStructure({ a: 1, b: 2, c: 3 }, budget)).toMatchObject({ + ok: false, + violation: "too-many-items", + detail: expect.stringMatching(/nodes/), + }); + expect(checkJsonStructure({ a: 1, b: 2, c: 3, d: 4 }, budget)).toMatchObject({ + ok: false, + violation: "too-many-items", + detail: expect.stringMatching(/object/), + }); + }); +}); + describe("response structure budget in the V3 executor", () => { const TEST_QUERY = TEST_LIST_HTTP_CONTRACT as InstalledHttpContract< unknown, -- 2.54.0