test(browser-files): 손상 데이터·로그아웃 경로의 보호 규칙 5개를 고정한다
문제: 2026-11-03 리뷰 변이 중 아래 5개가 관련 unit 파일을 모두 통과했다. 규칙을 고치는 사람은 테스트가 통과해도 손상·로그아웃 보호가 남았는지 알 수 없다. - L6 cleanupOwned()가 읽을 수 없는 pointer를 "pointer 없음"으로 보고 지금 서비스 중인 release까지 지운다. - L7 stage가 손상된 marker를 고치지 않고 실패한다. REHYDRATE 안내가 기대는 회복 경로다. - L4 preview가 파일 resolve 뒤 #disposed를 다시 보지 않는다. - L5 vault resolveFile이 load 뒤 #disposed를 다시 보지 않는다. - L1 vault dispose()가 File 참조 Map을 비우지 않는다. L4·L5는 lease registry가 dispose 뒤에도 lease를 내주기 때문에 소비자 쪽 검사가 유일한 방어선이다. 고른 방법: 규칙마다 실패하는 테스트 하나를 더한다. 리뷰가 L5에 제안한 readRange()는 slice 읽기 뒤에 #disposed를 한 번 더 보므로 L5를 잡지 못한다. 그래서 resolve 직후 소스를 돌려주는 openSource()로 고정했다. 위험·한계: 테스트만 바꾼다. 동작 변경 없음. 검증: 5개 변이를 하나씩 넣고 browser-files 단위 5파일 + tests/recipes, cache 단위 3파일 + tests/recipes를 돌렸다. L1·L4·L5·L6·L7 모두 새 테스트 하나씩이 실패했고(되돌린 뒤 통과), 원래 코드에서 두 파일 34건 통과. check:types:test, 바꾼 파일 eslint 통과. Refs: docs/reviews/2026-11-03-maturity-review/02-adapters-browser-files-cache.md 02-03
This commit is contained in:
@@ -646,6 +646,75 @@ describe("browser file content policy", () => {
|
||||
expect(vault.retainedByteLength).toBe(0);
|
||||
});
|
||||
|
||||
// 2026-11-03 02-03. Logout disposes the runtime while a call is in flight.
|
||||
// The lease registry still hands out leases after dispose, so each
|
||||
// consumer's own re-check is the only thing that keeps a URL from outliving
|
||||
// the session.
|
||||
it("creates no object URL for a preview whose runtime is disposed while it resolves", async () => {
|
||||
let urlSequence = 0;
|
||||
const leases = new ObjectUrlLeaseRegistry({
|
||||
createObjectURL: () => `blob:disposed-${urlSequence++}`,
|
||||
revokeObjectURL() {},
|
||||
});
|
||||
const { preview, request } = await verifiedPngPreview(leases);
|
||||
|
||||
const pending = preview.create(request(new AbortController().signal));
|
||||
preview.dispose();
|
||||
|
||||
expect(await pending).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "UNAVAILABLE", operation: "PREVIEW" },
|
||||
});
|
||||
expect(urlSequence).toBe(0);
|
||||
expect(leases.activeLeaseCount).toBe(0);
|
||||
});
|
||||
|
||||
it("opens no byte source for a file whose vault is disposed while it loads", async () => {
|
||||
const vault = new BrowserFileVault({ policies: pngPolicies() });
|
||||
const captured = vault.captureFiles(
|
||||
[
|
||||
new File([new Uint8Array([0x89, 0x50, 0x4e, 0x47])], "a.png", {
|
||||
type: "image/png",
|
||||
lastModified: 1,
|
||||
}),
|
||||
],
|
||||
pngSelectionPolicy,
|
||||
);
|
||||
if (!captured.ok || !captured.value[0]) throw new Error("capture");
|
||||
|
||||
const pending = vault.openSource({
|
||||
ref: captured.value[0].ref,
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
vault.dispose();
|
||||
|
||||
expect(await pending).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "UNAVAILABLE", operation: "FILE_READ" },
|
||||
});
|
||||
});
|
||||
|
||||
it("lets go of every selected File on dispose", () => {
|
||||
const vault = new BrowserFileVault({ policies: pngPolicies() });
|
||||
expect(
|
||||
vault.captureFiles(
|
||||
[
|
||||
new File([new Uint8Array([0x89, 0x50, 0x4e, 0x47])], "a.png", {
|
||||
type: "image/png",
|
||||
lastModified: 1,
|
||||
}),
|
||||
],
|
||||
pngSelectionPolicy,
|
||||
),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(vault.activeReferenceCount).toBe(1);
|
||||
|
||||
vault.dispose();
|
||||
|
||||
expect(vault.activeReferenceCount).toBe(0);
|
||||
expect(vault.retainedByteLength).toBe(0);
|
||||
});
|
||||
|
||||
it("returns ABORTED without a lease when the caller aborts right after create() (02-01)", async () => {
|
||||
const revoked: string[] = [];
|
||||
let urlSequence = 0;
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { PublicCacheAsset } from "../../src/application/ports/browser-file-
|
||||
import {
|
||||
activePointerRequest,
|
||||
controlCacheName,
|
||||
markerRequest,
|
||||
} from "../../src/adapters/cache-storage/public-cache-codec.ts";
|
||||
import {
|
||||
createDefaultPublicCachePolicy,
|
||||
@@ -526,6 +527,63 @@ describe("public cache pointer after a policy change or damage (0929/02-01)", ()
|
||||
control.match = realMatch;
|
||||
});
|
||||
|
||||
it("does not clean up on a damaged pointer, which may name the release being served (2026-11-03 02-03)", async () => {
|
||||
const cacheStorage = new MemoryCacheStorage();
|
||||
const policy = policyRetaining(1);
|
||||
const adapter = adapterFor(cacheStorage, policy);
|
||||
expect(await deploy(adapter, "r1", policy)).toMatchObject({ ok: true });
|
||||
expect(await deploy(adapter, "r2", policy)).toMatchObject({ ok: true });
|
||||
const control = await cacheStorage.open(controlCacheName(policy));
|
||||
await control.put(
|
||||
activePointerRequest(policy),
|
||||
new Response('{"schemaVersion":1,"releaseRegis', {
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
);
|
||||
const before = (await cacheStorage.keys()).sort();
|
||||
|
||||
expect(await adapter.admin.cleanupOwned()).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "CORRUPT_DATA", operation: "CACHE_DELETE" },
|
||||
});
|
||||
expect((await cacheStorage.keys()).sort()).toEqual(before);
|
||||
});
|
||||
|
||||
it("repairs a damaged release marker by staging the same manifest again (2026-11-03 02-03)", async () => {
|
||||
const cacheStorage = new MemoryCacheStorage();
|
||||
const policy = policyRetaining(1);
|
||||
const adapter = adapterFor(cacheStorage, policy);
|
||||
expect(await deploy(adapter, "r1", policy)).toMatchObject({ ok: true });
|
||||
const releaseName = (await cacheStorage.keys()).find((name) =>
|
||||
name.includes("release:r1:"),
|
||||
);
|
||||
if (!releaseName) throw new Error("release cache missing");
|
||||
const release = await cacheStorage.open(releaseName);
|
||||
await release.put(
|
||||
markerRequest(policy),
|
||||
new Response('{"schemaVersion":1,"verif', {
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
);
|
||||
// REHYDRATE: the damaged candidate cannot be activated as it is ...
|
||||
const manifest = await manifestOf("r1", policy);
|
||||
expect(
|
||||
await adapter.admin.activateRelease(
|
||||
manifest.releaseRegistryId,
|
||||
manifest.manifestDigestHex,
|
||||
),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "CORRUPT_DATA", recovery: "REHYDRATE" },
|
||||
});
|
||||
|
||||
// ... and staging it again is the recovery that hint promises.
|
||||
expect(await deploy(adapter, "r1", policy)).toMatchObject({ ok: true });
|
||||
expect(
|
||||
await adapter.responses.matchActiveExact({ absoluteUrl: assetUrl("r1") }),
|
||||
).toMatchObject({ ok: true, value: expect.anything() });
|
||||
});
|
||||
|
||||
it("still stops activation when the pointer read fails transiently", async () => {
|
||||
const cacheStorage = new MemoryCacheStorage();
|
||||
const policy = policyRetaining(1);
|
||||
|
||||
Reference in New Issue
Block a user