From b5c7128bdae5e401df11c3640f75f04241020862 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 20:57:19 +0900 Subject: [PATCH] =?UTF-8?q?test(storage):=20Web=20Storage=EC=9D=98=20Firef?= =?UTF-8?q?ox=20quota=20=EC=9D=B4=EB=A6=84=EA=B3=BC=20=EB=A7=8C=EB=A3=8C?= =?UTF-8?q?=20=EA=B2=BD=EA=B3=84=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 문제: 2026-11-01 05-06에서 남은 두 분기를 테스트가 잡지 못한다. 이번 리뷰에서도 두 변이가 Web Storage 관련 테스트 3파일 49건을 통과했다. - W4: quota 판정 목록에서 Firefox의 NS_ERROR_DOM_QUOTA_REACHED를 빼도 테스트가 통과한다. 빠지면 Firefox의 quota 실패가 memory fallback 없이 STORAGE_UNAVAILABLE이 된다. - W8: 만료 비교 `<=`를 `<`로 바꿔도 통과한다. 만료 시각과 같은 순간에 값을 돌려준다. 고른 방법: 각 분기에 실패하는 테스트 하나씩. 저장소 test double에 Firefox 이름으로 던지는 모드를 더했고, 만료 경계는 expiresAt 100·101을 now 100에서 읽는다. 위험·한계: 테스트만 바꾼다. codec을 직접 부르는 테스트는 여전히 없다. 검증: W4·W8 변이를 하나씩 넣고 storage-registry·runtime-adapters· browser-storage-policy 테스트를 돌렸다. 둘 다 새 테스트가 실패했고, 원래 코드에서 storage-registry 26건 통과. check:types:test, eslint 통과. Refs: docs/reviews/2026-11-03-maturity-review/05-adapters-storage-kernel.md 1101/05-06 --- tests/unit/storage-registry.test.ts | 57 ++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/tests/unit/storage-registry.test.ts b/tests/unit/storage-registry.test.ts index 7259492e..44e03db1 100644 --- a/tests/unit/storage-registry.test.ts +++ b/tests/unit/storage-registry.test.ts @@ -11,7 +11,7 @@ import { type StorageKeyInput, } from "../../src/contracts/storage-keys.ts"; -type StorageFailureMode = "none" | "quota" | "security"; +type StorageFailureMode = "none" | "quota" | "firefox-quota" | "security"; function createStorage(options: { initial?: Readonly>; @@ -54,6 +54,10 @@ function throwFor(mode: StorageFailureMode): void { if (mode === "quota") { throw new DOMException("private quota detail", "QuotaExceededError"); } + if (mode === "firefox-quota") { + // Older Firefox names the quota error this way, with code 1014. + throw new DOMException("private quota detail", "NS_ERROR_DOM_QUOTA_REACHED"); + } if (mode === "security") { throw new DOMException("private security detail", "SecurityError"); } @@ -278,6 +282,22 @@ describe("storage registry", () => { ); }); + // 2026-11-01 05-06. The second quota name was in the adapter's list but no + // test sent it, so dropping it went unseen. + it("falls back to memory on Firefox's quota error name too", () => { + const { storage: localStorage } = createStorage({ + writeFailure: "firefox-quota", + }); + const adapter = createBrowserStorageAdapter({ localStorage }); + + expect(adapter.write("COLOR_SCHEME", "dark")).toMatchObject({ + ok: false, + fallback: "memory", + error: { kind: "STORAGE_QUOTA_EXCEEDED" }, + }); + expect(adapter.read("COLOR_SCHEME")).toEqual({ ok: true, value: "dark" }); + }); + it("discards data from a previous schema version", () => { const { storage: localStorage, values, removeItem } = createStorage({ initial: { @@ -396,6 +416,41 @@ describe("storage registry", () => { expect(removeItem).toHaveBeenCalledWith(expiring.physicalKey); }); + // 2026-11-01 05-06. A record is expired at its expiry instant, not after it. + it.each([ + [100, undefined], + [101, "private-expiring"], + ])("reads a record expiring at %i at time 100 as %s", (expiresAt, value) => { + const expiring = defineStorageKey({ + logicalName: "EXPIRING_PREFERENCE", + scope: "preference", + name: "expiring", + backend: "localStorage", + classification: "public-preference", + schemaVersion: 1, + valueCodec: "opaque-string-v1", + ttl: 10, + migration: "discard", + quotaFallback: "memory", + }); + const { storage } = createStorage({ + initial: { + [expiring.physicalKey]: serializedEnvelope("private-expiring", { + expiresAt, + }), + }, + }); + const adapter = createBrowserStorageAdapter({ + localStorage: storage, + now: () => 100, + resolveDefinition: definitionResolver({ + EXPIRING_PREFERENCE: expiring, + }), + }); + + expect(adapter.read("EXPIRING_PREFERENCE")).toEqual({ ok: true, value }); + }); + it("prioritizes a failed-write memory envelope over stale persistent data and expires it", () => { let timestamp = 100; const expiring = defineStorageKey({