import { activeProductFeatureIds, resolveProductFeatures, type ProductFeatureState, } from "../../src/contracts/product-features.ts"; import type { ProductFeaturesPort } from "../../src/application/ports/product-features-port.ts"; import { COMPILED_PRODUCT_FEATURE_IDS, INSTALLED_PRODUCT_FEATURE_IDS, } from "../../src/features/installed-product-manifest.ts"; import type { RuntimeCapabilityId, RuntimeCapabilityStatus, } from "../../src/contracts/runtime-capabilities.ts"; import type { RuntimeCapabilitiesPort } from "../../src/application/ports/runtime-capabilities-port.ts"; const CAPABILITY_IDS = Object.freeze([ "REALTIME", "WEB_WORKER", "SERVICE_WORKER", "OFFLINE_COMMANDS", ] as const); /** * A capability port whose snapshot is fixed by the test rather than by the * repository's installed selection, so a suite asserting presentation behaviour * does not change meaning when a capability is later installed. */ export function createRuntimeCapabilitiesStub( overrides: Readonly>>> = {}, ): RuntimeCapabilitiesPort { const snapshot = Object.freeze( CAPABILITY_IDS.map((capabilityId) => Object.freeze({ capabilityId, selected: 0, active: 0, override: "DEFAULT" as const, ...overrides[capabilityId], }), ), ); return Object.freeze({ getSnapshot: () => snapshot }); } /** * A product-feature port that reports the real manifest with nothing disabled. * Tests that care about the switch build their own; the rest only need the * boundary to be complete. */ export function createProductFeaturesStub( overrides: Readonly> = {}, ): ProductFeaturesPort { const snapshot = resolveProductFeatures( COMPILED_PRODUCT_FEATURE_IDS, INSTALLED_PRODUCT_FEATURE_IDS, Object.fromEntries( Object.entries(overrides) .filter(([, state]) => state === "DISABLED_BY_CONFIG") .map(([featureId]) => [featureId, "DISABLED" as const]), ), ); const active = new Set(activeProductFeatureIds(snapshot)); return Object.freeze({ getSnapshot: () => snapshot, isActive: (featureId: string) => active.has(featureId), }); }