From 0a74bd42b049b9370fc19df42a306aca5dd01aa8 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 20:59:25 +0900 Subject: [PATCH] =?UTF-8?q?test(browser-files):=20handoff=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20lease=20=EB=B0=98=ED=99=98=EA=B3=BC=20=EB=82=A8?= =?UTF-8?q?=EC=9D=80=20=EB=B3=B4=ED=98=B8=20=EA=B7=9C=EC=B9=99=203?= =?UTF-8?q?=EA=B0=9C=EB=A5=BC=20=EA=B3=A0=EC=A0=95=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 이번 리뷰에서도 아래 browser-files 변이가 관련 unit 파일을 모두 통과했다. - M10(0929/02-05): bounded download의 catch에서 lease?.release()를 지운다. handoff가 던지면 만든 blob URL이 runtime dispose까지 남는다. - N27(1101/02-04 ③): 같은 파일을 다시 inspect할 때 이전 receipt를 무효화하지 않는다. 다른 정책으로 검사한 옛 receipt로 preview가 열린다. - N29(1101/02-04 ①): object URL lease의 합계 바이트 상한을 지운다. 기존 테스트는 개수 상한이 먼저 막아 바이트 상한을 보지 못했다. - N30(1101/02-04 ⑥): browser-managed handoff의 fragment 거절을 지운다. 고른 방법: 규칙마다 실패하는 테스트 하나. N29는 개수 여유가 있을 때도 바이트가 막는 경우를 기존 상한 테스트 끝에 더했고, N30은 target 규칙 표에 fragment href 한 줄을 더했다. 위험·한계: 테스트만 바꾼다. 1101/02-04의 나머지(N26·N26b는 다음 커밋, N38 host storageArea, N39 조회 keys() 재확인)는 이 커밋에 없다. 검증: 네 변이를 하나씩 넣고 browser-files 단위 5파일 + tests/recipes를 돌렸다. 모두 새 테스트(또는 늘린 행)가 실패했고 되돌린 뒤 통과. 원래 코드에서 두 파일 47건 통과. check:types:test, eslint 통과. Refs: docs/reviews/2026-11-03-maturity-review/02-adapters-browser-files-cache.md 0929/02-05, 1101/02-04 --- tests/unit/browser-file-content.test.ts | 77 ++++++++++++++++++++++++ tests/unit/browser-file-download.test.ts | 35 +++++++++++ 2 files changed, 112 insertions(+) diff --git a/tests/unit/browser-file-content.test.ts b/tests/unit/browser-file-content.test.ts index b44ef84a..fde5dcbf 100644 --- a/tests/unit/browser-file-content.test.ts +++ b/tests/unit/browser-file-content.test.ts @@ -981,6 +981,83 @@ describe("browser file content policy", () => { ).toThrowError(DOMException); lease.release(); expect(leases.aggregateLeaseByteLength).toBe(0); + + // 2026-11-01 02-04 (N29). A free slot does not lift the byte cap. + const byBytes = new ObjectUrlLeaseRegistry( + { + createObjectURL: () => `blob:bytes-${urlSequence++}`, + revokeObjectURL() {}, + }, + { + hardMaxActiveLeases: 2, + hardMaxSingleLeaseBytes: 4, + hardMaxAggregateLeaseBytes: 6, + }, + ); + const held = byBytes.create(new Blob([new Uint8Array(4)])); + expect(() => + byBytes.create(new Blob([new Uint8Array(3)])), + ).toThrowError(DOMException); + expect(byBytes.activeLeaseCount).toBe(1); + held.release(); + expect(() => + byBytes.create(new Blob([new Uint8Array(3)])), + ).not.toThrow(); + }); + + // 2026-11-01 02-04 (N27). Inspecting again replaces the receipt: the file + // may have been checked against a different policy, so the old one ends. + it("ends the previous receipt when the same file is inspected again", async () => { + const policies = pngPolicies(); + const vault = new BrowserFileVault({ policies }); + const captured = vault.captureFiles( + [ + new File( + [new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])], + "again.png", + { type: "image/png", lastModified: 1 }, + ), + ], + pngSelectionPolicy, + ); + if (!captured.ok || !captured.value[0]) throw new Error("capture"); + const ref = captured.value[0].ref; + const receiptOf = async () => { + const inspected = await vault.inspect({ + ref, + policy: pngPolicy, + signal: new AbortController().signal, + }); + if (!inspected.ok || !inspected.value.verificationReceipt) { + throw new Error("inspect"); + } + return inspected.value.verificationReceipt; + }; + const first = await receiptOf(); + const second = await receiptOf(); + expect(vault.activeVerificationCount).toBe(1); + const preview = new BrowserTransientPreview({ + files: vault, + policies, + leases: new ObjectUrlLeaseRegistry({ + createObjectURL: () => "blob:again", + revokeObjectURL() {}, + }), + hardMaxPreviewBytes: 10, + }); + const create = (verificationReceipt: FileVerificationReceipt) => + preview.create({ + ref, + verificationReceipt, + policy: pngPolicy, + signal: new AbortController().signal, + }); + + expect(await create(first)).toMatchObject({ + ok: false, + error: { code: "POLICY_REJECTED" }, + }); + expect(await create(second)).toMatchObject({ ok: true }); }); it("converts native stream exceptions to closed chunk failures", async () => { diff --git a/tests/unit/browser-file-download.test.ts b/tests/unit/browser-file-download.test.ts index 4521d7e7..40effd97 100644 --- a/tests/unit/browser-file-download.test.ts +++ b/tests/unit/browser-file-download.test.ts @@ -293,9 +293,11 @@ describe("browser download delivery", () => { it("rejects cross-origin or query-bearing browser-managed targets", async () => { // 02-08. Each href breaks one rule, so neither check hides the other. + // 2026-11-01 02-04 (N30): a fragment is refused on its own too. for (const href of [ "https://evil.example/downloads/a", "/downloads/a?token=secret", + "/downloads/a#token=secret", ]) { const handoff = vi.fn(); const adapter = createDownloadDeliveryAdapter({ @@ -767,6 +769,39 @@ describe("browser download delivery", () => { expect(revoked).toEqual(["blob:download-1"]); }); + // [0929] 02-05. A handoff that throws hands nothing to the browser, so the + // lease made for it is revoked at once instead of waiting for dispose. + it("revokes the lease of a handoff that throws", async () => { + const revoked: string[] = []; + const leases = new ObjectUrlLeaseRegistry({ + createObjectURL: () => "blob:download-failed", + revokeObjectURL: (url) => revoked.push(url), + }); + const adapter = createDownloadDeliveryAdapter({ + ...HARD_LIMITS, + policies, + host: { + handoff() { + throw new DOMException("blocked", "NotAllowedError"); + }, + }, + browserManagedCapabilities: capabilityResolver(), + objectUrls: leases, + userActivation: { isActive: true }, + }); + + expect( + await adapter.deliver( + deliveryInput( + { kind: "GENERATED", bytes: byteSource([new Uint8Array([1, 2])]) }, + "BOUNDED_OBJECT_URL", + ), + ), + ).toMatchObject({ ok: false }); + expect(leases.activeLeaseCount).toBe(0); + expect(revoked).toEqual(["blob:download-failed"]); + }); + it("revokes only its own leases on dispose when the registry is shared (2026-11-01 02-01)", async () => { const revoked: string[] = []; let urlSequence = 0;