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}\\.`)); + }); });