fix(service-worker): let the app subscribe to reload-required and update-waiting (R-6.3)

Tabs that did not request an activation only observe()d
ACTIVATED_RELOAD_REQUIRED, and the host contract had no way to tell the
app. Worse, the worker targeted that broadcast at the requester's build,
so a tab on another build dropped it as TARGET_BUILD_MISMATCH. A waiting
worker produced by the periodic registration.update() was never reported
either.

- ServiceWorkerRuntimeHost gains optional onReloadRequired/onUpdateWaiting
  (additive; existing host implementations still type-check).
- The page controller notifies reload subscribers when an expected worker
  source sends ACTIVATED_RELOAD_REQUIRED, and watches `updatefound` +
  `statechange` to announce an update that reached `installed` while an
  active worker exists (a first install is never announced). Listeners
  are removed on stop(); a throwing subscriber is isolated.
- Worker post-commit/reject notifications are untargeted; the requester
  still pairs by nonce.
- Test fixtures: registration and workers are now EventTarget-backed.

RED before fix (listener called 0 times):
- announces an update that finished installing as waiting (R-6.3)
- page ↔ worker activation seam > tells a tab that did not ask that a
  reload is required (R-6.3)
Gates: check:architecture, check:types:{app,test,service-worker}, lint,
test:component pass. test:unit passes except the pre-existing
removal-fixture.test.ts case that needs generated release evidence
under artifacts/ (absent in a fresh worktree; unrelated to this diff).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:28:38 +09:00
co-authored by Claude Opus 5.5
parent 47832fbe65
commit fb8a3b5e1d
4 changed files with 172 additions and 27 deletions
+11
View File
@@ -149,4 +149,15 @@ export interface ServiceWorkerRuntimeHost {
requestActivation(): Promise<ServiceWorkerActivationOutcome>;
resetOwnedCaches(): Promise<ServiceWorkerResetOutcome>;
stop(): Promise<void>;
/**
* R-6.3. A new worker was activated (by any tab), so this page runs under a
* worker of another build and should reload. Every tab is told, including
* the one that asked. Returns the unsubscribe function.
*/
onReloadRequired?(listener: () => void): () => void;
/**
* R-6.3. An update finished installing and waits for `requestActivation()`.
* Returns the unsubscribe function.
*/
onUpdateWaiting?(listener: () => void): () => void;
}