frontend-quality-gates / merge / static checks (pull_request) Successful in 1m17s
frontend-quality-gates / merge / tests (pull_request) Successful in 11m53s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m36s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
문제: SW를 켠 제품이 새 버전 안내·reload 안내를 붙이려면 템플릿 파일을 고쳐야 한다(1103/09-05). 설치에 실패한 갱신(redundant)과 실패한 주기 검사는 아무 기록도 남기지 않는다(0925/06-05). build.assetsDir를 바꾸면 사전 캐시가 조용히 빈다(0925/06-08). 릴리스마다 바뀌지 않은 자산까지 no-store로 다시 받는다(1101/06-05). 쓰지 않는 protocol kind 셋과 reload guard 상수, void 참조, 손으로 쓴 protocol 버전 1, web-push의 fence 검사 두 벌이 남았다(1101/06-03, R1~R3). 고른 방법: - ProductServiceWorkerWiring에 onUpdateWaiting(activate)· onReloadRequired()를 더한다(추가만). create-runtime-composition이 worker 시작 전에 host 이벤트를 구독해 부르고, 던지면 버린다. page controller는 시작 때 이미 기다리던 갱신도 onUpdateWaiting 구독자에게 알린다. - page controller가 update_install REDUNDANT, update_check FAILED를 observe로 낸다. - 사전 캐시 생성기와 SW 설치가 빈 asset 목록을 거절하고, 시험이 vite.config.ts의 build.assetsDir와 BUILD_ASSET_DIRECTORY를 대조한다 (vite.config.ts는 그룹 C가 고치는 파일이라 건드리지 않았다). - 설치가 이전 릴리스 캐시의 같은 URL을 digest로 다시 확인해 복사하고, 없거나 맞지 않을 때만 받는다. - PAGE_HELLO·WORKER_HELLO_ACK·UPDATE_READY, reloadGuard*· retainedPreviousCaches를 지운다. sync 알림은 createServiceWorkerMessage로 만든다. fence 검사는 push-association-fence-store.ts 하나다. 버린 대안: 활성화 화면을 presentation 슬롯으로 열기 — 화면 문구와 흐름은 제품 것이라 조합 계약의 함수 칸이 작다. 위험·한계: 지운 kind는 보내는 곳이 없었다. 다른 빌드의 worker가 보내도 UNKNOWN_KIND로 관측만 된다. 재사용은 이전 캐시를 읽는 비용이 들고, 읽기 실패는 다운로드로 돌아간다. 검증: desktop check:types·lint·check:architecture· check:adapter-inventory rc=0, SW 시험 묶음 통과 (/tmp/claude-gates/r9b-pr1-quick). merge 단계는 PR 본문. Refs: 1103/09-05, 0925/06-05, 0925/06-08, 1101/06-03, 1101/06-05, 1101/R1, 1101/R2, 1101/R3
240 lines
8.5 KiB
TypeScript
240 lines
8.5 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { createServiceWorkerPageController } from "../../src/adapters/service-worker/index.ts";
|
|
import { installStaticAssets } from "../../src/adapters/service-worker/service-worker-static-assets.ts";
|
|
import {
|
|
SERVICE_WORKER_BOUNDS,
|
|
SERVICE_WORKER_SCRIPT_PATH,
|
|
} from "../../src/contracts/service-worker.ts";
|
|
|
|
/**
|
|
* 0925/06-05. An update that failed to install (the new worker went
|
|
* `redundant`) and a periodic update check that failed left no record: the
|
|
* page stayed on its build and nothing said why.
|
|
*
|
|
* 1103/09-05. An update already waiting when the page registered was reported
|
|
* only as the start outcome, so a product notice subscribed to
|
|
* `onUpdateWaiting` never heard of it.
|
|
*/
|
|
|
|
const ORIGIN = "https://app.example";
|
|
|
|
class FakeWorker extends EventTarget {
|
|
readonly scriptURL = `${ORIGIN}/${SERVICE_WORKER_SCRIPT_PATH}`;
|
|
constructor(public state: ServiceWorkerState) {
|
|
super();
|
|
}
|
|
postMessage(): void {}
|
|
move(state: ServiceWorkerState): void {
|
|
this.state = state;
|
|
this.dispatchEvent(new Event("statechange"));
|
|
}
|
|
}
|
|
|
|
function browser(options: Readonly<{ waiting?: boolean; update?: () => Promise<void> }> = {}) {
|
|
const registration = Object.assign(new EventTarget(), {
|
|
scope: `${ORIGIN}/`,
|
|
installing: null as FakeWorker | null,
|
|
waiting: options.waiting ? new FakeWorker("installed") : null,
|
|
active: new FakeWorker("activated"),
|
|
update: vi.fn(options.update ?? (async () => {})),
|
|
});
|
|
const container = {
|
|
controller: registration.active,
|
|
register: vi.fn(async () => registration),
|
|
addEventListener() {},
|
|
removeEventListener() {},
|
|
};
|
|
return { registration, container };
|
|
}
|
|
|
|
function controllerFor(container: unknown) {
|
|
const observed: Array<Readonly<{ event: string; outcome: string }>> = [];
|
|
const controller = createServiceWorkerPageController({
|
|
selection: { mode: "ACTIVE", scriptPath: SERVICE_WORKER_SCRIPT_PATH, handlers: [] },
|
|
disabledCleanup: false,
|
|
routerBasePath: "/",
|
|
origin: ORIGIN,
|
|
buildId: "page-build",
|
|
container: container as ServiceWorkerContainer,
|
|
observe: (observation) => observed.push(observation),
|
|
});
|
|
return { controller, observed };
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
describe("0925/06-05 update failures are observed", () => {
|
|
it("records an update whose install failed", async () => {
|
|
const { registration, container } = browser();
|
|
const { controller, observed } = controllerFor(container);
|
|
await controller.start();
|
|
|
|
const update = new FakeWorker("installing");
|
|
registration.installing = update;
|
|
registration.dispatchEvent(new Event("updatefound"));
|
|
update.move("redundant");
|
|
|
|
expect(observed).toContainEqual({ event: "update_install", outcome: "REDUNDANT" });
|
|
await controller.stop();
|
|
});
|
|
|
|
it("records a periodic update check that failed", async () => {
|
|
vi.useFakeTimers();
|
|
const { container } = browser({
|
|
update: async () => {
|
|
throw new TypeError("network");
|
|
},
|
|
});
|
|
const { controller, observed } = controllerFor(container);
|
|
await controller.start();
|
|
|
|
await vi.advanceTimersByTimeAsync(SERVICE_WORKER_BOUNDS.updateCheckIntervalMs);
|
|
|
|
expect(observed).toContainEqual({ event: "update_check", outcome: "FAILED" });
|
|
await controller.stop();
|
|
});
|
|
|
|
it("records nothing for an update that installed", async () => {
|
|
const { registration, container } = browser();
|
|
const { controller, observed } = controllerFor(container);
|
|
const waiting = vi.fn();
|
|
controller.onUpdateWaiting?.(waiting);
|
|
await controller.start();
|
|
|
|
const update = new FakeWorker("installing");
|
|
registration.installing = update;
|
|
registration.dispatchEvent(new Event("updatefound"));
|
|
registration.waiting = update;
|
|
update.move("installed");
|
|
|
|
expect(waiting).toHaveBeenCalledOnce();
|
|
expect(observed.some(({ event }) => event.startsWith("update_"))).toBe(false);
|
|
await controller.stop();
|
|
});
|
|
});
|
|
|
|
describe("1103/09-05 an update waiting at start reaches onUpdateWaiting", () => {
|
|
it("tells the listener once, with the UPDATE_WAITING start outcome", async () => {
|
|
const { container } = browser({ waiting: true });
|
|
const { controller } = controllerFor(container);
|
|
const waiting = vi.fn();
|
|
controller.onUpdateWaiting?.(waiting);
|
|
|
|
await expect(controller.start()).resolves.toEqual({ kind: "UPDATE_WAITING" });
|
|
|
|
expect(waiting).toHaveBeenCalledOnce();
|
|
await controller.stop();
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 1101/06-05. Every release downloaded the whole asset set again with
|
|
* `no-store`, even the files whose content-hashed names it shared with the
|
|
* release before. A verified copy in an earlier release's cache is reused;
|
|
* the download stays for a file that is new, missing or no longer matches.
|
|
*/
|
|
describe("1101/06-05 an earlier release's verified asset is reused", () => {
|
|
const CURRENT = `ca-static-v1-${"a".repeat(16)}`;
|
|
const PREVIOUS = `ca-static-v1-${"c".repeat(16)}`;
|
|
const kept = new TextEncoder().encode("kept");
|
|
const fresh = new TextEncoder().encode("fresh");
|
|
/** A fake digest: one hex digit per content. */
|
|
const DIGESTS: Readonly<Record<string, string>> = { kept: "1", fresh: "2", tamp: "3" };
|
|
const digestOf = (bytes: Uint8Array) =>
|
|
`sha256:${(DIGESTS[new TextDecoder().decode(bytes)] ?? "f").repeat(64)}`;
|
|
const asset = (name: string, bytes: Uint8Array) => ({
|
|
url: `${ORIGIN}/assets/${name}`,
|
|
sha256: digestOf(bytes) as `sha256:${string}`,
|
|
bytes: bytes.byteLength,
|
|
contentType: "text/javascript",
|
|
});
|
|
const manifest = {
|
|
schemaVersion: 1 as const,
|
|
buildId: "worker-build",
|
|
releaseId: "release-2",
|
|
setDigest: `sha256:${"a".repeat(64)}` as const,
|
|
assets: [asset("kept", kept), asset("fresh", fresh)],
|
|
};
|
|
|
|
async function install(
|
|
previous: Readonly<Record<string, Uint8Array>>,
|
|
previousContentType = "text/javascript",
|
|
) {
|
|
const put = vi.fn(async () => {});
|
|
const previousCache = {
|
|
match: vi.fn(async (url: string) => {
|
|
const bytes = previous[url];
|
|
return bytes
|
|
? new Response(bytes.slice(), { headers: { "content-type": previousContentType } })
|
|
: undefined;
|
|
}),
|
|
};
|
|
const fetcher = vi.fn(async (input: RequestInfo | URL) => {
|
|
const bytes = String(input).endsWith("kept") ? kept : fresh;
|
|
return new Response(bytes.slice(), { headers: { "content-type": "text/javascript" } });
|
|
});
|
|
const result = await installStaticAssets(manifest, {
|
|
caches: {
|
|
open: vi.fn(async (name: string) =>
|
|
(name === PREVIOUS ? previousCache : { put }) as unknown as Cache,
|
|
),
|
|
delete: vi.fn(async () => true),
|
|
keys: vi.fn(async () => [PREVIOUS]),
|
|
},
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
digest: vi.fn(async (bytes: Uint8Array) => digestOf(bytes)),
|
|
});
|
|
return { result, fetched: fetcher.mock.calls.map(([input]) => String(input)), put };
|
|
}
|
|
|
|
it("copies the unchanged file and downloads only the new one", async () => {
|
|
const { result, fetched, put } = await install({ [`${ORIGIN}/assets/kept`]: kept });
|
|
|
|
expect(result).toEqual({ kind: "INSTALLED", cacheName: CURRENT, assets: 2 });
|
|
expect(fetched).toEqual([`${ORIGIN}/assets/fresh`]);
|
|
expect(put).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("downloads a file whose earlier copy was stored with another content type", async () => {
|
|
const { fetched } = await install({ [`${ORIGIN}/assets/kept`]: kept }, "text/css");
|
|
|
|
expect(fetched.sort()).toEqual([`${ORIGIN}/assets/fresh`, `${ORIGIN}/assets/kept`]);
|
|
});
|
|
|
|
it("downloads a file whose earlier copy no longer matches its digest", async () => {
|
|
const { result, fetched } = await install({
|
|
[`${ORIGIN}/assets/kept`]: new TextEncoder().encode("tamp"),
|
|
});
|
|
|
|
expect(result).toMatchObject({ kind: "INSTALLED" });
|
|
expect(fetched.sort()).toEqual([`${ORIGIN}/assets/fresh`, `${ORIGIN}/assets/kept`]);
|
|
});
|
|
});
|
|
|
|
describe("0925/06-08 an empty asset manifest is refused", () => {
|
|
it("does not install a worker that would serve nothing", async () => {
|
|
const fetcher = vi.fn();
|
|
|
|
await expect(
|
|
installStaticAssets(
|
|
{
|
|
schemaVersion: 1,
|
|
buildId: "worker-build",
|
|
releaseId: "release-2",
|
|
setDigest: `sha256:${"a".repeat(64)}`,
|
|
assets: [],
|
|
},
|
|
{
|
|
caches: { open: vi.fn(), delete: vi.fn(async () => true) },
|
|
fetcher: fetcher as unknown as typeof fetch,
|
|
digest: vi.fn(),
|
|
},
|
|
),
|
|
).resolves.toEqual({ kind: "REJECTED", code: "MANIFEST_INVALID" });
|
|
expect(fetcher).not.toHaveBeenCalled();
|
|
});
|
|
});
|