From 2a78169c58d79e4e5a50c54acbb41ed5bdb3c427 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 6 Nov 2026 05:17:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix(hosting):=20live=20probe=EA=B0=80=20red?= =?UTF-8?q?irect=EB=90=9C=20=EC=9B=8C=EC=BB=A4=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=EB=A5=BC=20=EA=B1=B0=EC=A0=88=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 워커를 싣는 빌드에서 live probe는 `/service-worker.js`를 기본 fetcher `redirect: "follow"`로 받고, 최종 응답의 status와 origin만 본다 (`scripts/lib/hosting-probe.ts` `probeLiveRelease`). 같은 origin 안 redirect 뒤에 200·`no-cache`·JS MIME이 오면 FE-GATE-019가 PASS다. 브라우저는 워커 스크립트를 redirect mode "error"로 받는다(Service Worker Update 알고리즘). 그런 호스트에서는 첫 등록, update 검사, `REMOVE_REGISTRATION` kill switch가 모두 실패한다. 고른 방법과 버린 대안 - `serviceWorker` surface에만 `redirect` 행을 더한다. `response.redirected`이거나 `opaqueredirect`이면 FAIL이다. 자산 probe(1105/06-02)와 같은 판정식이라 fetcher가 redirect를 따라가든 manual이든 잡는다. 3xx 응답은 지금처럼 `http-status` 행이 FAIL로 본다. - redirect가 없으면 이 행은 PASS로 남는다. 산출물에 이 검사를 했다는 기록이 된다. - 버린 대안: 모든 surface에서 redirect를 FAIL로 보기(리뷰 (b)). `index`·`appRoute`의 정상 redirect(끝 슬래시 정규화 등)까지 막는다. 문서에만 적기(리뷰 (c))는 게이트가 그대로 PASS다. - 운영 문서 두 곳에 "redirect 없이"를 적었다. release-cache-rollback.md의 live probe 설명과 browser-file-storage-recovery.md의 kill switch 전제다. 위험·한계 - 워커 스크립트를 redirect하던 호스트는 이제 FE-GATE-019에서 FAIL이다. 그런 호스트에서는 지금도 워커가 동작하지 않는다. - 브라우저 거절은 명세와 Chromium 오류 문구에 기댄 것이다. redirect하는 호스트로 실제 등록을 돌려 보지 않았고, live 모드도 실제 호스트로 돌리지 않았다(리뷰 §5 미검증 그대로). 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/hosting-probe.test.ts - RED: "live hosting probe (1105/06-02) > fails a worker script the host answers only after a same-origin redirect"가 실패한다. 옛 probe에는 redirect 행이 없어 실패 행이 비어 있다. - 함께: check:types, lint, verify:documentation Refs: 1106/06-01 --- .../browser-file-storage-recovery.md | 9 ++-- docs/operations/release-cache-rollback.md | 9 ++-- scripts/lib/hosting-probe.ts | 17 +++++++ tests/unit/hosting-probe.test.ts | 49 +++++++++++++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/docs/operations/browser-file-storage-recovery.md b/docs/operations/browser-file-storage-recovery.md index dd758100..5815615d 100644 --- a/docs/operations/browser-file-storage-recovery.md +++ b/docs/operations/browser-file-storage-recovery.md @@ -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). diff --git a/docs/operations/release-cache-rollback.md b/docs/operations/release-cache-rollback.md index b6211a37..5d782079 100644 --- a/docs/operations/release-cache-rollback.md +++ b/docs/operations/release-cache-rollback.md @@ -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 diff --git a/scripts/lib/hosting-probe.ts b/scripts/lib/hosting-probe.ts index 82e90fd5..02a997b5 100644 --- a/scripts/lib/hosting-probe.ts +++ b/scripts/lib/hosting-probe.ts @@ -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]), ); diff --git a/tests/unit/hosting-probe.test.ts b/tests/unit/hosting-probe.test.ts index de9f2d3c..0d980b33 100644 --- a/tests/unit/hosting-probe.test.ts +++ b/tests/unit/hosting-probe.test.ts @@ -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 = { + "/": [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 From 1f4b929fbe26b9f433ec3e02b4ee658c0cdcb12e Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 6 Nov 2026 05:18:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test(service-worker):=20marker=20=EC=9D=BD?= =?UTF-8?q?=EA=B8=B0=20=EC=83=81=ED=95=9C=20test=EA=B0=80=205=EC=B4=88?= =?UTF-8?q?=EB=B3=B4=EB=8B=A4=20=EA=B8=B4=20=EC=83=81=ED=95=9C=EC=9D=84=20?= =?UTF-8?q?=EC=9E=A1=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 "bounds a stream that never produces a chunk"는 가짜 시계를 5초씩 최대 4번 넘긴 뒤 활성화가 끝났는지 본다(`ce191be`, 1101/10-07). 그래서 marker 읽기 상한(`ACTIVATION_MARKER_READ_DEADLINE_MS`, 5초)을 20초까지 올려도 통과한다. 실제 시계로 기다리던 수정 전 test는 10초 test 제한에서 실패했다. 상한을 15초로 올린 리뷰 변이 06-R3에서 64건이 모두 통과했다. 고른 방법과 버린 대안 - 반복을 지우고 `advanceTimersByTimeAsync(5_000)`를 한 번만 부른다(리뷰 (가)). 이 fixture는 캐시가 현재 캐시 하나라 marker를 한 번만 읽는다 (`highestMarkedCache`는 현재 캐시를 건너뛴다). 상한이 1 ms만 길어도 활성화가 끝나지 않아 `settled` 단언이 실패한다. 수정 전 test(10초 이상만 검출)보다 강하다. 가짜 시계는 그대로라 실제 대기는 돌아오지 않는다. `cancels >= 1` 단언도 그대로다. - 버린 대안: 상수를 `SERVICE_WORKER_BOUNDS`로 옮기고 그 값만큼 넘기기 (리뷰 (나)). test가 상수를 따라가므로 계약 모듈에서 값을 15초로 올리면 그대로 통과한다. 약점이 자리만 옮긴다. 계약 모듈 변경이라 워커·페이지 두 realm 검사도 다시 돌아야 하고, 리뷰 변이 06-R3도 이 커밋에 그대로 적용되지 않는다. - 숫자 5_000이 test에 한 번 더 적힌다. 이 test가 지키는 값이 그것이라 일부러 둔다. 위험·한계 - fixture가 marker를 여러 번 읽게 바뀌면 이 test가 실패한다. 그때는 읽는 횟수만큼 정확히 넘긴다(리뷰 재검토 조건). - 상한을 줄이는 변경은 잡지 않는다. 수정 전 test도 잡지 않았다. - 한 번의 tick으로 끝나려면 deadline timer가 tick 전에 걸려 있어야 한다. `onActivate()`부터 `setTimeout`까지는 바로 끝나는 async mock뿐이고, `advanceTimersByTimeAsync`는 시계를 넘기기 전에 실제 macrotask 하나를 양보한다(fake-timers `tickAsync`). 코드로 본 판단이고 이 커밋으로는 아직 돌리지 않았다. 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/service-worker-runtime.test.ts - 테스트만 바꾼 커밋이라 RED는 없다. 대신 변이 둘에서 이 test가 실패해야 한다: 리뷰 06-R3(상한 15_000), 완료 기준 변이(상한 5_001). - 무변이에서는 64건이 통과한다. Refs: 1106/06-02 --- tests/unit/service-worker-runtime.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/service-worker-runtime.test.ts b/tests/unit/service-worker-runtime.test.ts index 930496cc..a88e9a57 100644 --- a/tests/unit/service-worker-runtime.test.ts +++ b/tests/unit/service-worker-runtime.test.ts @@ -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");