fix(bootstrap): report a Service Worker that did not start through telemetry (06-05)

An ACTIVE worker whose install failed left a trace only in health(), which
nothing reads. The optional host now emits service-worker.start.failed on the
application telemetry port, and the recipe doc lists what else to wire.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-26 00:26:54 +09:00
co-authored by Claude Opus 5.5
parent 9f2305a562
commit cd47516592
6 changed files with 103 additions and 3 deletions
+58
View File
@@ -87,4 +87,62 @@ describe("optional runtime host", () => {
expect(runtime.health().serviceWorker).toBe("DISABLED");
expect(runtime.browserLifecycle()).toBeNull();
});
// 06-05. An ACTIVE selection whose worker install fails must be visible to
// operators, not only in `health()`, which nothing reads.
it.each([
{
outcome: { kind: "FAILED", code: "INSTALL_FAILED" } as const,
events: [
[
"service-worker.start.failed",
{ error_kind: "INSTALL_FAILED", build_id: "build-1" },
],
],
},
{
outcome: { kind: "INCOMPATIBLE" } as const,
events: [
[
"service-worker.start.failed",
{ error_kind: "INCOMPATIBLE", build_id: "build-1" },
],
],
},
{ outcome: { kind: "ACTIVE", buildId: "build-1" } as const, events: [] },
{ outcome: { kind: "RELOAD_TO_ENABLE" } as const, events: [] },
])(
"records $outcome.kind as $events.length telemetry event(s)",
async ({ outcome, events }) => {
const emit = vi.fn();
const runtime = createOptionalRuntimeHost({
capabilities: {
...capabilities,
serviceWorker: {
mode: "ACTIVE",
scriptPath: "service-worker.js",
handlers: ["PWA_STATIC_ASSETS"],
},
},
routerBasePath: "/",
buildId: "build-1",
serviceWorkerHost: {
start: vi.fn(async (): Promise<ServiceWorkerStartOutcome> => outcome),
requestActivation: vi.fn(),
resetOwnedCaches: vi.fn(),
stop: vi.fn(async () => {}),
},
browserLifecycleHost: {
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
},
telemetry: { emit },
});
await runtime.startAfterMount();
expect(emit.mock.calls).toEqual(events);
await runtime.stop();
},
);
});