From d31c7d6b18762974eb713460a7f423dd3e77e66d Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:16:46 +0900 Subject: [PATCH] =?UTF-8?q?fix(recipes):=20=EC=84=B8=EC=85=98=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=A0=88=EC=8B=9C=ED=94=BC=EA=B0=80=20=EB=A7=A4?= =?UTF-8?q?=EB=89=B4=EC=96=BC=EA=B3=BC=20=EA=B0=99=EC=9D=80=20capability?= =?UTF-8?q?=20=ED=83=80=EC=9E=85=20=EC=9C=84=EC=B9=98=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EB=A6=AC=ED=82=A8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 세션 레시피 주석이 "`FeaturePlatformCapabilities`를 `files: SessionBrowserFiles`로 보강한다"고 적는다. 매뉴얼 (`docs/manual/03-outside-feature-folder.md`)은 그 타입을 `src/features/product-capabilities.ts`의 `ProductFeaturePlatformCapabilities`에 적으라고 하고, `declare module` 보강은 `check:types:node`가 키를 보지 못한다고 막는다. 주석대로 하면 앱 typecheck는 통과하고 node typecheck에서 키를 잃는다. 또 레시피 테스트는 `capabilities: {}`로 조립하고 `files.current()`를 레시피 객체에서 직접 불러서, capability가 기능 쪽으로 넘어가는 절반이 깨져도 통과한다. 고른 방법: - 주석이 `ProductFeaturePlatformCapabilities`에 적는 예와 매뉴얼 경로를 보이고, `declare module` 보강은 쓰지 말라고 적는다. - 레시피 테스트가 `capabilities: { files }`를 돌려주고, 템플릿이 설치된 기능의 loader에 넘기는 capability 객체(`createInstalledFeatureLoaders`의 첫 인자)를 기록한다. 테스트의 모든 파일 동작(선택, 읽기, download, 계정 전환 뒤 새 runtime)을 그 객체의 `files.current()`로 돈다. 같은 mock 방식은 `tests/recipes/session-owners-runtime.test.ts`가 이미 쓴다. 버린 대안: `files`를 `needs`에 적은 가짜 기능을 생성 index에 끼워 넣기. `ProductFeaturePlatformCapabilities`가 비어 있는 템플릿에서는 타입을 우회해야 하고, `needs`로 고르는 부분은 1103/09-08 테스트가 이미 잡는다. 위험·한계: 검사는 loader가 받는 capability 객체까지다. 기능 factory가 `needs`로 골라 받는 마지막 단계는 기존 테스트에 맡긴다. 동작 코드는 바뀌지 않는다(주석과 테스트만). 검증: desktop batch에서 확인 - node scripts/run-vitest.ts run tests/recipes/browser-file-session-capability.test.ts - 변이: 테스트 mock의 `capabilities`에서 `files`를 빼거나, `src/bootstrap/runtime-adapters.ts`의 `...product.capabilities`를 지우면 "Features did not receive the files capability"로 실패해야 한다. Refs: 1105/02-03 --- .../browser-file-session-capability.ts | 13 +++++- .../browser-file-session-capability.test.ts | 41 ++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/recipes/frontend-capabilities/browser-file-session-capability.ts b/recipes/frontend-capabilities/browser-file-session-capability.ts index 04d95996..66c84b71 100644 --- a/recipes/frontend-capabilities/browser-file-session-capability.ts +++ b/recipes/frontend-capabilities/browser-file-session-capability.ts @@ -20,8 +20,17 @@ export type SessionBrowserFiles = Readonly<{ * * file-transfer is an opt-in recipe (`productionComposition: false`), so the * template does not build this. A product that installs a feature using it - * augments `FeaturePlatformCapabilities` with `files: SessionBrowserFiles` and - * returns both halves from `src/bootstrap/product-composition.ts`: + * types the capability in `src/features/product-capabilities.ts`, as + * `docs/manual/03-outside-feature-folder.md` says: + * + * export interface ProductFeaturePlatformCapabilities { + * readonly files: SessionBrowserFiles; + * } + * + * not with a `declare module` augmentation of `FeaturePlatformCapabilities`, + * whose key `check:types:node` does not see (1105/02-03). The feature lists + * `files` in `needs`, and the product returns both halves from + * `src/bootstrap/product-composition.ts`: * * const browserFiles = createSessionBrowserFileCapability(() => * createBrowserFileRuntime({ input, policies, limits, download }), diff --git a/tests/recipes/browser-file-session-capability.test.ts b/tests/recipes/browser-file-session-capability.test.ts index 1be69edd..568d0f14 100644 --- a/tests/recipes/browser-file-session-capability.test.ts +++ b/tests/recipes/browser-file-session-capability.test.ts @@ -9,7 +9,10 @@ import { type BrowserFilePolicyProfile, } from "../../src/adapters/browser-files/index.ts"; import { createRuntimeAdapters } from "../../src/bootstrap/runtime-adapters.ts"; -import { createSessionBrowserFileCapability } from "../../recipes/frontend-capabilities/browser-file-session-capability.ts"; +import { + createSessionBrowserFileCapability, + type SessionBrowserFiles, +} from "../../recipes/frontend-capabilities/browser-file-session-capability.ts"; import { testRuntimeConfig } from "../helpers/runtime-config.ts"; /** @@ -17,7 +20,9 @@ import { testRuntimeConfig } from "../helpers/runtime-config.ts"; * filling only its own `product-composition.ts`: the recipe capability goes to * features, its scope participant to the template. The real * `createRuntimeAdapters` runs; only the product-owned file is replaced, with - * what a product would write in it. + * what a product would write in it. 1105/02-03. The test drives the runtime + * through the capability the template hands the feature loaders, so dropping + * `files` from the composition's `capabilities` fails it. */ const selectPolicy = browserFilePolicyReference("session-file", "select-text"); @@ -57,6 +62,8 @@ const fixture = vi.hoisted(() => ({ files: undefined as | ReturnType["files"] | undefined, + /** What the template hands the installed features' loaders. */ + featureCapabilities: undefined as Readonly> | undefined, inputs: [] as HTMLInputElement[], handoffs: 0, owner: undefined as @@ -139,19 +146,37 @@ vi.mock("../../src/bootstrap/product-composition.ts", () => ({ ); fixture.files = browserFiles.files; return { - capabilities: {}, + capabilities: { files: browserFiles.files }, credentialProviders: {}, scopeParticipants: [browserFiles.scopeParticipant], }; }, })); +/** Records the capabilities features receive; the loaders run unchanged. */ +vi.mock("../../src/features/installed-feature-adapters.ts", async (importOriginal) => { + const original = + await importOriginal(); + return { + ...original, + createInstalledFeatureLoaders( + ...args: Parameters + ) { + fixture.featureCapabilities = args[0] as unknown as Readonly< + Record + >; + return original.createInstalledFeatureLoaders(...args); + }, + }; +}); + let current: Awaited> | undefined; afterEach(() => { current?.infrastructure.dispose(); current = undefined; for (const input of fixture.inputs.splice(0)) input.remove(); fixture.files = undefined; + fixture.featureCapabilities = undefined; fixture.handoffs = 0; }); @@ -202,9 +227,15 @@ async function compose() { }, host: {}, }); - const files = fixture.files; const owner = fixture.owner; - if (!files || !owner) throw new Error("The product composition did not run"); + if (!fixture.files || !owner) { + throw new Error("The product composition did not run"); + } + // What a feature that lists `files` in `needs` is given. + const files = fixture.featureCapabilities?.files as + | SessionBrowserFiles + | undefined; + if (!files) throw new Error("Features did not receive the files capability"); return { adapters: current, files, owner }; }