From 76de74a0faeb1d5a8d031945b0e3d937ac791baf Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:19:39 +0900 Subject: [PATCH] fix(features): withhold feature inputs switched off by FEATURE_OVERRIDES (Q-6.9-5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createRuntimeAdapters computed activeFeatureIds and then composed feature inputs for every installed feature, so a feature disabled by the kill switch still got its API from application.features.get(); only the router honoured the switch. createInstalledFeatureInputs now takes the active ids (optional; the default stays "every installed feature" for callers without runtime config) and the runtime passes them. Verified: tests/unit/runtime-adapters.test.ts — disabled feature has no features.has/get (RED before: has() was true); every installed feature still resolves when nothing is switched off. All gates pass except the known tests/unit/removal-fixture.test.ts (artifacts/ absent). Co-Authored-By: Claude Opus 5.5 --- src/bootstrap/runtime-adapters.ts | 4 +- src/features/installed-feature-adapters.ts | 11 ++++- tests/unit/runtime-adapters.test.ts | 48 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/runtime-adapters.ts b/src/bootstrap/runtime-adapters.ts index 91e73ce6..2025e0ed 100644 --- a/src/bootstrap/runtime-adapters.ts +++ b/src/bootstrap/runtime-adapters.ts @@ -561,7 +561,9 @@ export async function createRuntimeAdapters( http: contractOperations, telemetry: featureTelemetry, }); - const featureInputs = createInstalledFeatureInputs(featureCapabilities); + const featureInputs = createInstalledFeatureInputs(featureCapabilities, [ + ...activeFeatureIds, + ]); return Object.freeze({ outputPorts: Object.freeze({ diff --git a/src/features/installed-feature-adapters.ts b/src/features/installed-feature-adapters.ts index 165f38ec..fbea274b 100644 --- a/src/features/installed-feature-adapters.ts +++ b/src/features/installed-feature-adapters.ts @@ -16,13 +16,22 @@ type InstalledFeatureCapabilityContext = ContributionsCapabilityContext< /** * Adapter installation is a projection of feature-owned descriptors. Adding a * feature changes its descriptor and the generated index, not this composer. + * + * Q-6.9-5. The runtime composer passes `activeFeatureIds` (installed minus + * `FEATURE_OVERRIDES`). A feature switched off there gets no input, so + * `application.features.get()` cannot hand out its API; the router was the + * only place that honoured the switch before. The default (every installed + * feature) is for callers that have no runtime configuration. */ export function createInstalledFeatureInputs( context: InstalledFeatureCapabilityContext, + activeFeatureIds: readonly string[] = INSTALLED_PRODUCT_FEATURE_MODULES.map( + (module) => module.id, + ), ): InstalledFeatureInputs { return composeFeatureAdapterInputs( INSTALLED_FEATURE_ADAPTER_CONTRIBUTIONS, - INSTALLED_PRODUCT_FEATURE_MODULES.map((module) => module.id), + activeFeatureIds, context, ); } diff --git a/tests/unit/runtime-adapters.test.ts b/tests/unit/runtime-adapters.test.ts index 0ffaeefb..2553a34c 100644 --- a/tests/unit/runtime-adapters.test.ts +++ b/tests/unit/runtime-adapters.test.ts @@ -5,6 +5,9 @@ import { createRuntimeHttpClient, } from "../../src/bootstrap/runtime-adapters.ts"; import { createBrowserMutationIntentFactory } from "../../src/adapters/platform/browser-mutation-intent-factory.ts"; +import { createApplication } from "../../src/application/create-application.ts"; +import type { ApplicationFeatureId } from "../../src/application/ports/in/application-api.ts"; +import { INSTALLED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts"; import { TEST_HTTP_CONTRACT } from "../helpers/http-contract-fixture.ts"; type Runtime = Parameters[0]["runtime"]; @@ -278,6 +281,51 @@ describe("runtime adapter composition", () => { expect(serviceWorker?.active).toBe(0); }); + it("gives a feature switched off by FEATURE_OVERRIDES no application API (Q-6.9-5)", async () => { + const [disabledId, ...activeIds] = INSTALLED_PRODUCT_FEATURE_IDS; + const adapters = await createRuntimeAdapters({ + runtime: { + ...runtime, + config: { + ...runtime.config, + FEATURE_OVERRIDES: { [disabledId!]: "DISABLED" }, + }, + }, + release, + host: {}, + }); + const application = createApplication( + adapters.outputPorts, + adapters.featureInputs, + ); + + expect(adapters.outputPorts.productFeatures.isActive(disabledId!)).toBe(false); + expect(application.features.has(disabledId!)).toBe(false); + expect(() => + application.features.get(disabledId as ApplicationFeatureId), + ).toThrow(/not installed/u); + for (const featureId of activeIds) { + expect(application.features.has(featureId)).toBe(true); + } + adapters.infrastructure.dispose(); + }); + + it("still resolves every installed feature API when nothing is switched off", async () => { + const adapters = await createRuntimeAdapters({ runtime, release, host: {} }); + const application = createApplication( + adapters.outputPorts, + adapters.featureInputs, + ); + + for (const featureId of INSTALLED_PRODUCT_FEATURE_IDS) { + expect(application.features.has(featureId)).toBe(true); + expect( + application.features.get(featureId as ApplicationFeatureId), + ).toBeDefined(); + } + adapters.infrastructure.dispose(); + }); + it("states contract identity as a digest for a V2 release manifest", async () => { const adapters = await createRuntimeAdapters({ runtime, release, host: {} });