From 48a4074e3a42cafaeeb0afe6a3338a082318fd92 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sun, 1 Nov 2026 22:49:20 +0900 Subject: [PATCH] =?UTF-8?q?fix(bootstrap):=20=EC=8B=9C=EC=9E=91=ED=95=A0?= =?UTF-8?q?=20=EB=9F=B0=ED=83=80=EC=9E=84=EC=9D=B4=20=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20capability=EB=A5=BC=20=EC=A1=B0=EB=A6=BD?= =?UTF-8?q?=20=EB=95=8C=20=EA=B1=B0=EC=A0=88=ED=95=9C=EB=8B=A4=20(09-07)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 선택 파일은 "Adding an entry here is what installs a capability"라고 적지만 optional host가 실제로 시작하는 것은 Service Worker뿐이다. realtime·webWorkers·offlineCommands에 항목을 넣으면 아무것도 시작되지 않고 health는 UNAVAILABLE로 남는데, 플랫폼 개요가 읽는 스냅샷은 그 선택을 active로 세어 "활성 (1)"을 보인다. 경고도 실패도 없다. 고른 방법: - `createOptionalRuntimeHost`가 시작 수단이 없는 capability(realtime, webWorkers, offlineCommands)가 선택돼 있으면 그 이름을 모두 담아 throw한다. 런타임 설정으로 끈 선택은 resolve 단계에서 빠지므로 막지 않는다. host는 부트 조립에서 만들어지므로 부트 실패 화면으로 드러난다. - 선택 파일 주석을 "Service Worker만 여기서 설치된다. 나머지는 composition에 런타임을 먼저 연결해야 한다"로 고쳤다. 버린 대안: 주석만 고치기. 스냅샷이 계속 active로 세고, 선택한 제품은 여전히 아무 신호도 받지 못한다. 위험·한계: - 런타임을 연결하는 제품은 host의 시작 순서와 이 검사를 함께 바꿔야 한다(09-02 확장 지점과 같은 자리). 검사 주석에 적었다. - health 계산의 세 capability `UNAVAILABLE` 분기는 이제 닿지 않지만, 런타임을 연결할 때 쓸 자리라 남겼다. - 리뷰 09-05(선택 파일에서 템플릿 상태 설명 분리)는 하지 않았다. - 초기 JS +127 B gzip(202,995 → 203,122 B, 여유 1,678 B). 검증: - RED: tests/unit/optional-runtime-host.test.ts의 새 테스트 3건(capability별 하나)이 "expected [Function] to throw an error"로 실패. - GREEN: 같은 파일 9건 통과. - 회귀: tests/unit(pnpm을 띄우는 5개 제외) 1,933건, tests/integration (프로세스를 띄우는 3개 제외) 131건, tests/{component,platform, architecture,features,contract} 570건 통과. 그중 app-build-input.test.ts 1건이 부하 25에서 10초 시간 초과로 실패했고, heavy lock 아래 단독 재실행에서 4건 통과. tsc app·test 통과. 바꾼 파일 eslint 통과. --- src/bootstrap/optional-runtime-host.ts | 15 ++++++++++ .../installed-runtime-capabilities.ts | 10 +++++-- tests/unit/optional-runtime-host.test.ts | 28 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/optional-runtime-host.ts b/src/bootstrap/optional-runtime-host.ts index 21714859..fac1945a 100644 --- a/src/bootstrap/optional-runtime-host.ts +++ b/src/bootstrap/optional-runtime-host.ts @@ -48,6 +48,21 @@ export function createOptionalRuntimeHost( input: OptionalRuntimeHostInput, ): OptionalRuntimeHost { const { capabilities } = input; + // 09-07. Only the Service Worker has a runtime here. A selection nothing + // starts would stay UNAVAILABLE while the capability snapshot counts it as + // active, so composition refuses it. Wiring a runtime in means changing + // this check together with the start order below. + const unstartable = [ + capabilities.realtime.length > 0 && "realtime", + capabilities.webWorkers.length > 0 && "webWorkers", + capabilities.offlineCommands !== null && "offlineCommands", + ].filter((name): name is string => typeof name === "string"); + if (unstartable.length > 0) { + throw new TypeError( + `Selected optional capabilities have no runtime to start them: ${unstartable.join(", ")}. ` + + "Connect a runtime in src/bootstrap/optional-runtime-host.ts or remove the selection from src/features/installed-runtime-capabilities.ts.", + ); + } const serviceWorker = Object.hasOwn(input, "serviceWorkerHost") ? (input.serviceWorkerHost ?? null) diff --git a/src/features/installed-runtime-capabilities.ts b/src/features/installed-runtime-capabilities.ts index 822fa31b..8e8d4d70 100644 --- a/src/features/installed-runtime-capabilities.ts +++ b/src/features/installed-runtime-capabilities.ts @@ -15,9 +15,13 @@ import { /** * §3.5. Static optional capability selection SSOT. * - * Adding an entry here is what installs a capability. Runtime Config can only - * disable what this file already selected, and no dynamic import path is ever - * built from a configuration string. + * Runtime Config can only disable what this file already selected, and no + * dynamic import path is ever built from a configuration string. + * + * Only the Service Worker is installed by an entry here alone. Realtime, Web + * Workers and offline commands have no runtime in the composition yet: a + * selection without one makes `createOptionalRuntimeHost` refuse to compose + * (09-07). Connect the runtime there first. * * Current template state, matching the §25 stop conditions: * diff --git a/tests/unit/optional-runtime-host.test.ts b/tests/unit/optional-runtime-host.test.ts index 7087c022..d8883e0c 100644 --- a/tests/unit/optional-runtime-host.test.ts +++ b/tests/unit/optional-runtime-host.test.ts @@ -145,4 +145,32 @@ describe("optional runtime host", () => { await runtime.stop(); }, ); + + // 09-07. Only the Service Worker has a runtime this host starts. A selection + // nothing starts used to boot quietly while the platform overview counted + // it as active. The host only reads whether something is selected, so the + // selections below are placeholders, not valid contributions. + it.each([ + { + capability: "realtime", + selected: { realtime: Object.freeze([{}]) as unknown as ResolvedRuntimeCapabilities["realtime"] }, + }, + { + capability: "webWorkers", + selected: { webWorkers: Object.freeze([{}]) as unknown as ResolvedRuntimeCapabilities["webWorkers"] }, + }, + { + capability: "offlineCommands", + selected: { offlineCommands: {} as unknown as ResolvedRuntimeCapabilities["offlineCommands"] }, + }, + ])("refuses a selected $capability it has no runtime to start", ({ capability, selected }) => { + expect(() => + createOptionalRuntimeHost({ + capabilities: { ...capabilities, ...selected }, + routerBasePath: "/", + buildId: "build-1", + serviceWorkerHost: null, + }), + ).toThrow(new RegExp(`no runtime to start them: ${capability}\\.`)); + }); });