fix(features): 기능 어댑터 기여에 needs에 적은 capability만 넘긴다 (1103/09-08)

문제
조립 루트 주석과 생성 뼈대 주석은 "기능은 needs에 적은 capability만 받는다"고
했지만, invokeContribution은 context 전체를 넘겼다. needs: ["telemetry"] 기여가
["telemetry","http"]를 받았다(E6). 제품 capability도 모든 기능에 갔다. 타입이
막고 있어 cast가 있어야 생기지만, 그러면 needs가 실제 의존을 다 말하지 않는다.

고른 방법
invokeContribution이 needs의 키만 골라 새 frozen 객체로 넘긴다. 주석을 "타입만
그렇다"로 고치는 대안은 생성 뼈대 주석(scripts/create-feature.ts)까지 모든
기능에 퍼진 설명을 바꿔야 해서 버렸다. 이제 두 주석이 실행과 맞는다.

위험·한계
needs에 적지 않은 capability를 cast로 쓰던 다운스트림 기능은 그 값이
undefined가 된다. repo 안에는 그런 기능이 없다.

검증
- RED: feature-adapter-composition.test.ts에 E6 행(받은 키가 ["telemetry"])을
  더했고 수정 전 실패.
- tests/contract/reusable-capability, tests/features, runtime-adapters 계열,
  product-composition-fixture → 27 files / 178 tests 통과.
- check:types, eslint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/09-app-core.md 09-08
This commit is contained in:
DongHyeonka
2026-11-04 20:22:58 +09:00
parent f98d0c3663
commit e7d63586b6
2 changed files with 38 additions and 1 deletions
+8 -1
View File
@@ -144,7 +144,14 @@ function invokeContribution<
contribution: FeatureAdapterContribution<FeatureId, Needs>,
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<Needs>;
return contribution.createInput(selected);
}
/**
@@ -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<readonly [typeof telemetryOnly]>
>[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",