fix(cache-storage): stage 재검증 실패를 CACHE_STAGE로 기록한다 (02-03)
문제: 이미 stage된 release를 다시 stage하면 후보를 재검증한다. 재검증 함수 verifyReleaseCandidate는 활성화와 같이 쓰는 함수라 실패 Result의 operation을 CACHE_ACTIVATE로 만든다. 활성화 경로는 rebaseFailure로 바꾸지만 stage의 재사용 경로는 그대로 돌려준다. Cache API가 재검증 중 일시 오류를 내면 stage 결과와 관측이 모두 CACHE_ACTIVATE가 된다. 운영자는 "활성화 실패"로 읽고, error.operation 으로 분기하는 호출자는 잘못된 경로를 탄다. 고른 방법: stage 재사용 경로도 활성화 경로처럼 rebaseFailure(..., "CACHE_STAGE")로 돌려준다. 한 줄이다. 버린 대안: verifyReleaseCandidate가 operation을 인자로 받게 하는 안. 호출부 세 곳(stage, activate, inspect)을 모두 바꾸고, inspect는 실패를 밖으로 내지 않아 이득이 없다. 리뷰가 함께 적은 readAndValidateResponse의 CACHE_STAGE 고정은 두 소비 경로가 이미 rebase하거나 결과를 내보내지 않아 겉으로 드러나는 결함이 없으므로 건드리지 않았다. 위험·한계: 동작(실패를 성공으로 바꾸지 않음, 후보를 지우지 않음)은 그대로다. 바뀌는 것은 실패의 operation 값뿐이다. service-worker-pwa 레시피 번들 9,662 → 9,665 / 10,000 gzip bytes. 검증: - RED(수정 전): public-response-cache-repair.test.ts 새 1건이 operation "CACHE_ACTIVATE"(기대 "CACHE_STAGE")로 실패. - GREEN: public-response-cache 단위 3파일 37건 통과. - 회귀: tsc app·test·service-worker 통과. 바꾼 파일 eslint 통과. check-optional-recipes(source) PASS. Refs: docs/reviews/2026-11-01-maturity-review/02-adapters-browser-files-cache.md
This commit is contained in:
@@ -491,8 +491,10 @@ export function createPublicResponseCacheAdapter(
|
||||
}
|
||||
if (verified.kind === "UNKNOWN") {
|
||||
// Abort or an unreadable candidate is never stage success and
|
||||
// never silently deletes an owned candidate.
|
||||
return verified.failure;
|
||||
// never silently deletes an owned candidate. 2026-11-01
|
||||
// 02-03: the verdict is shared with activation, so the
|
||||
// failure is re-labelled as this stage call's own.
|
||||
return rebaseFailure(verified.failure.error, "CACHE_STAGE");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ import {
|
||||
* yet earned the right to delete what still works.
|
||||
*/
|
||||
describe("public response cache repair is failure-atomic", () => {
|
||||
async function stagedRelease(releaseRegistryId: string) {
|
||||
async function stagedRelease(
|
||||
releaseRegistryId: string,
|
||||
observer?: (event: unknown) => void,
|
||||
) {
|
||||
const policy = createDefaultPublicCachePolicy(
|
||||
"https://assets.example.test",
|
||||
);
|
||||
@@ -55,6 +58,7 @@ describe("public response cache repair is failure-atomic", () => {
|
||||
crypto: globalThis.crypto,
|
||||
mutationLock: immediateLock,
|
||||
policy,
|
||||
...(observer ? { observer } : {}),
|
||||
fetcher: async (request: Request) => {
|
||||
fetchLog.push(request.url);
|
||||
if (failFrom !== null && request.url === failFrom) {
|
||||
@@ -127,6 +131,40 @@ describe("public response cache repair is failure-atomic", () => {
|
||||
).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
it("reports a failed re-verification of a staged candidate as CACHE_STAGE (2026-11-01 02-03)", async () => {
|
||||
const observations: Readonly<{ outcome?: string }>[] = [];
|
||||
const release = await stagedRelease("reverify-unreadable", (event) =>
|
||||
observations.push(event as Readonly<{ outcome?: string }>),
|
||||
);
|
||||
const cache = release.cacheStorage.caches.get(release.cacheName)!;
|
||||
const realMatch = cache.match.bind(cache);
|
||||
const assetUrls = new Set(release.assets.map((asset) => asset.absoluteUrl));
|
||||
cache.match = async (request: RequestInfo | URL) => {
|
||||
const url =
|
||||
request instanceof Request ? request.url : String(request);
|
||||
if (assetUrls.has(url)) {
|
||||
throw new DOMException("Storage is busy", "InvalidStateError");
|
||||
}
|
||||
return await realMatch(request);
|
||||
};
|
||||
observations.length = 0;
|
||||
|
||||
const restaged = await release.adapter.admin.stageRelease(release.manifest);
|
||||
|
||||
expect(restaged).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "UNAVAILABLE", operation: "CACHE_STAGE" },
|
||||
});
|
||||
expect(
|
||||
observations.filter(({ outcome }) => outcome === "FAILED"),
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
operation: "CACHE_STAGE",
|
||||
failureCode: "UNAVAILABLE",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps every healthy asset when one repair fetch fails", async () => {
|
||||
const release = await stagedRelease("partial-repair");
|
||||
const cache = release.cacheStorage.caches.get(release.cacheName)!;
|
||||
|
||||
Reference in New Issue
Block a user