chore(review): 1106 Service Worker·호스팅 조치 브랜치를 합친다

This commit is contained in:
DongHyeonka
2026-11-06 07:02:34 +09:00
5 changed files with 81 additions and 11 deletions
@@ -611,10 +611,11 @@ Service Worker를 별도 선택한 조합에서만 추가. 워커의 fetch 가
`skipWaiting()`하고, 활성화 때 `registration.unregister()`한다. fetch handler가
없어서 그동안의 요청은 모두 네트워크로 간다. 다음 load부터는 제어받지 않는다.
브라우저 확인: `tests/e2e/service-worker-recovery.spec.ts`.
- 이 경로가 동작하려면 `service-worker.js`를 `Cache-Control: no-cache`로 서빙해야
한다. 워커를 싣는 빌드(`ACTIVE`·`REMOVE_REGISTRATION`)에서는
`verify:hosting-headers` live 모드가 `/service-worker.js`를 요청해 이 헤더를
확인하고, 다르면 FAIL이다(`config/hosting/cache-policy.json` `serviceWorker`,
- 이 경로가 동작하려면 `service-worker.js`를 `Cache-Control: no-cache`로, redirect
없이 서빙해야 한다. 브라우저는 워커 스크립트의 redirect를 같은 origin 안이라도
거절한다. 워커를 싣는 빌드(`ACTIVE`·`REMOVE_REGISTRATION`)에서는
`verify:hosting-headers` live 모드가 `/service-worker.js`를 요청해 이 헤더와
redirect를 확인하고, 다르면 FAIL이다(`config/hosting/cache-policy.json` `serviceWorker`,
`scripts/verify-hosting-headers.ts`). fixture 모드는 선언끼리만 대조하므로
`UNVERIFIED`다. 하위 경로 base URL은 live probe가 아직 받지 않는다
(`scripts/lib/hosting-probe.ts` `classifyLiveHostingBaseUrl`, 리뷰 0929/13-06).
+6 -3
View File
@@ -71,9 +71,12 @@ It also requests `appRoute` (`/__probe/deep-link`, a path no build has a file
for): the host must answer 200 with the same `index.html` (the same entry
script) and the HTML headers, so a host without the SPA fallback fails
(review 1101/13-04). When the build ships a worker it requests
`/service-worker.js` and expects `no-cache`. The surfaces and their headers are
declared in `config/hosting/cache-policy.json`. For each cacheable extension the
release has under `assets/` (`.css`, `.js`, `.woff2` and the rest of
`/service-worker.js` and expects `no-cache` and no redirect at all, not even
one inside the origin: browsers fetch the worker script with redirect mode
`error`, so registration, every update check and the `REMOVE_REGISTRATION`
kill switch fail behind one (review 1106/06-01). The surfaces and their
headers are declared in `config/hosting/cache-policy.json`. For each cacheable
extension the release has under `assets/` (`.css`, `.js`, `.woff2` and the rest of
`CACHEABLE_ASSET_CONTENT_TYPES`) it requests the first such file and expects
exactly that type (`hashedAsset.css` and so on). The worker's install refuses
the whole release when one precached asset has another type, while a page
+17
View File
@@ -125,6 +125,12 @@ export function releaseIdentity(manifest: string | null): ReleaseIdentity | null
*
* 1103/13-02. The host must negotiate a declared protocol (HTTP/2): the
* template splits its initial chunks on that premise.
*
* 1106/06-01. The worker script alone must also answer without any redirect.
* Browsers fetch it with redirect mode "error" (the Service Worker Update
* algorithm), so a same-origin redirect breaks registration, every update
* check and the REMOVE_REGISTRATION kill switch, although the followed answer
* is a 200 with the right headers. Pages may still follow a redirect.
*/
export async function probeLiveRelease(
base: URL,
@@ -156,6 +162,17 @@ export async function probeLiveRelease(
passed: finalOrigin === base.origin,
},
);
if (surface === "serviceWorker") {
const redirected = response.redirected || response.type === "opaqueredirect";
results.push({
surface,
header: "redirect",
expected: false,
observed: redirected,
...(redirected ? { reason: "browsers refuse a redirected worker script" } : {}),
passed: !redirected,
});
}
responses[surface] = Object.fromEntries(
[...response.headers.entries()].map(([name, value]) => [name.toLowerCase(), value]),
);
+49
View File
@@ -448,6 +448,55 @@ describe("live hosting probe (1105/06-02)", () => {
expect.objectContaining({ surface: "releaseManifest", header: "build-id", passed: true }),
);
});
// 1106/06-01. Browsers fetch the worker script with redirect mode "error",
// so a same-origin redirect breaks registration, every update check and the
// REMOVE_REGISTRATION kill switch, while the followed answer is a 200 with
// the right headers. A page may still follow such a redirect.
it("fails a worker script the host answers only after a same-origin redirect", async () => {
const served: Record<string, readonly [string, string]> = {
"/": [INDEX, "text/html"],
"/release-manifest.json": [JSON.stringify(IDENTITY), "application/json"],
"/service-worker.js": ["", "text/javascript"],
"/assets/index-A1.js": ["", "text/javascript"],
"/assets/index-C3.css": ["", "text/css"],
};
// Each path in `redirected` is answered after a redirect to `/v2/...` on the same origin.
const failing = async (redirected: readonly string[]) => {
const { results } = await probeLiveHosting(
base,
{ ...PATHS, serviceWorker: "/service-worker.js" },
CANDIDATE,
DIST_FILES,
{
fetcher: async (url) => {
const entry = served[url.pathname];
const response = new Response(entry?.[0] ?? "Not Found", {
status: entry ? 200 : 404,
headers: entry ? { "content-type": entry[1] } : {},
});
const moved = redirected.includes(url.pathname);
Object.defineProperty(response, "url", {
value: moved ? new URL(`/v2${url.pathname}`, url).href : url.href,
});
Object.defineProperty(response, "redirected", { value: moved });
return response;
},
},
);
return results.filter((result) => !result.passed);
};
expect(await failing([])).toEqual([]);
expect(await failing(["/", "/service-worker.js"])).toEqual([
expect.objectContaining({
surface: "serviceWorker",
header: "redirect",
observed: true,
reason: expect.stringContaining("redirect"),
}),
]);
});
});
// 1101/13-01. FE-GATE-019 checks the promoted candidate it downloaded, not a
+4 -4
View File
@@ -2007,6 +2007,9 @@ describe("SW-01 the activation marker read is bounded in bytes", () => {
// 1101/10-07. The read deadline is the runtime's own 5 s constant. The
// clock is faked, so the test passes the deadline instead of waiting it
// out; without a deadline the activation never settles and this fails.
// 1106/06-02. This fixture has one cache, the current one, so activation
// reads one marker and waits for one deadline. The clock advances exactly
// 5 s once: a longer deadline, even by 1 ms, leaves it unsettled here.
vi.useFakeTimers();
try {
let cancels = 0;
@@ -2026,10 +2029,7 @@ describe("SW-01 the activation marker read is bounded in bytes", () => {
.finally(() => {
settled = true;
});
// One read deadline per marker probe.
for (let probe = 0; probe < 4 && !settled; probe += 1) {
await vi.advanceTimersByTimeAsync(5_000);
}
await vi.advanceTimersByTimeAsync(5_000);
expect(settled).toBe(true);
await expect(activation).resolves.toBeTypeOf("number");