diff --git a/src/features/feature-adapter-contribution.ts b/src/features/feature-adapter-contribution.ts index 77a9874d..2d80c22d 100644 --- a/src/features/feature-adapter-contribution.ts +++ b/src/features/feature-adapter-contribution.ts @@ -144,7 +144,14 @@ function invokeContribution< contribution: FeatureAdapterContribution, context: FeaturePlatformCapabilities, ) { - return contribution.createInput(context); + // 1103/09-08. Only the declared capabilities reach the factory, at run time + // as in the type: the host builds every capability (and every product one) + // for every feature, so handing it the whole context let a cast reach a + // capability `needs` never named. + const selected = Object.freeze( + Object.fromEntries(contribution.needs.map((need) => [need, context[need]])), + ) as FeatureCapabilitySelection; + return contribution.createInput(selected); } /** diff --git a/tests/contract/reusable-capability/feature-adapter-composition.test.ts b/tests/contract/reusable-capability/feature-adapter-composition.test.ts index 8eeaaeb0..c800940d 100644 --- a/tests/contract/reusable-capability/feature-adapter-composition.test.ts +++ b/tests/contract/reusable-capability/feature-adapter-composition.test.ts @@ -163,6 +163,36 @@ describe("feature adapter composition", () => { ).toEqual({}); }); + it("hands a contribution only the capabilities it names in needs (1103/09-08)", () => { + // The host builds every capability for every feature. `needs` is the + // feature's whole dependency list only if the factory cannot reach the + // rest at run time too, not just through its static type. + const received: string[][] = []; + const telemetryOnly = defineFeatureAdapterContribution({ + featureId: "test-http-feature", + needs: ["telemetry"] as const, + createInput(context) { + received.push(Object.keys(context)); + expect(Object.isFrozen(context)).toBe(true); + return Object.freeze({ + featureId: "test-http-feature" as const, + input: Object.freeze({ ping: async () => "pong" as const }), + }); + }, + }); + const telemetry = Object.freeze({ emit: () => {} }) as unknown as Parameters< + typeof composeFeatureAdapterInputs + >[2]["telemetry"]; + + composeFeatureAdapterInputs( + Object.freeze([telemetryOnly] as const), + Object.freeze(["test-http-feature"]), + Object.freeze({ http, telemetry }), + ); + + expect(received).toEqual([["telemetry"]]); + }); + it("rejects an input installed under another feature's id (Q-6.9-6)", () => { const wrongId = defineFeatureAdapterContribution({ featureId: "test-http-feature",