diff --git a/tests/unit/product-extension-typecheck.test.ts b/tests/unit/product-extension-typecheck.test.ts index c1cf4e04..c12f3b0b 100644 --- a/tests/unit/product-extension-typecheck.test.ts +++ b/tests/unit/product-extension-typecheck.test.ts @@ -1,4 +1,5 @@ import { spawnSync } from "node:child_process"; +import { existsSync } from "node:fs"; import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; @@ -23,21 +24,29 @@ import { REMOVAL_FIXTURE_COPY_TARGETS } from "../../scripts/lib/removal-fixture. * own tests must not have to spell out. * * Only product-owned files and the feature's own directory are written. + * + * The probe's names (`typecheck-probe-*`) are reserved for it: they are not + * the manual's example names, which a product may well use (1103 X2 #1). The + * capability type is appended to the product's own declaration, which a + * TypeScript interface merges, so a product that already declares + * capabilities keeps them. */ -/** Filled into the shipped `product-capabilities.ts`, the rest kept. */ -const PRODUCT_CAPABILITY_TYPES = `export interface ProductFeaturePlatformCapabilities { - readonly noticeSettings: Readonly<{ pageSize(): number }>; -}`; +/** Appended to the product's own `product-capabilities.ts`. */ +const PRODUCT_CAPABILITY_TYPES = ` +export interface ProductFeaturePlatformCapabilities { + readonly typecheckProbeSettings: Readonly<{ pageSize(): number }>; +} +`; const PRODUCT_CONTRACTS = `import { z } from "./zod.ts"; /** Product-owned. Filled by the 1103/09-02 typecheck fixture. */ export const PRODUCT_RUNTIME_CONFIG_FIELDS = Object.freeze({ - NOTICE_PAGE_SIZE: z.int().min(1).max(100).default(20), + TYPECHECK_PROBE_PAGE_SIZE: z.int().min(1).max(100).default(20), }); export const PRODUCT_ENV_REGISTRY = Object.freeze({ - NOTICE_PAGE_SIZE: { + TYPECHECK_PROBE_PAGE_SIZE: { phase: "runtime", classification: "public", required: false, @@ -63,18 +72,18 @@ export function composeProductSessionOwner( } export function composeProduct(context: ProductCompositionContext) { - const pageSize = context.config.NOTICE_PAGE_SIZE; + const pageSize = context.config.TYPECHECK_PROBE_PAGE_SIZE; return { capabilities: { - noticeSettings: Object.freeze({ pageSize: () => pageSize }), + typecheckProbeSettings: Object.freeze({ pageSize: () => pageSize }), }, credentialProviders: {}, } satisfies ProductComposition; } `; -const FEATURE_ID = "notice-feature"; -const CONTEXT_ID = "notice-context"; +const FEATURE_ID = "typecheck-probe-feature"; +const CONTEXT_ID = "typecheck-probe-context"; const FEATURE_MODULE = `import { defineFeatureModule } from "../feature-module.ts"; @@ -99,8 +108,8 @@ export const FEATURE_MODULE = defineFeatureModule({ // Both locales: with the sample features removed (test:sample-removal) // this is the only catalog the message key types come from. messages: { - "ko-KR": { "notice.title": "공지" }, - "en-US": { "notice.title": "Notice" }, + "ko-KR": { "typecheckProbe.title": "타입 검사 탐침" }, + "en-US": { "typecheckProbe.title": "Typecheck probe" }, }, loadRuntime: async () => (await import("./feature-runtime.ts")).FEATURE_RUNTIME, } as const); @@ -109,11 +118,11 @@ export const FEATURE_MODULE = defineFeatureModule({ const FEATURE_RUNTIME = `import { defineFeatureAdapterContribution } from "../feature-adapter-contribution.ts"; import { defineFeatureRuntime } from "../feature-module.ts"; -type NoticeFeatureInput = Readonly<{ pageSize(): number }>; +type TypecheckProbeInput = Readonly<{ pageSize(): number }>; declare module "../../application/ports/in/application-api.ts" { interface ApplicationFeatureInputs { - "${FEATURE_ID}": NoticeFeatureInput; + "${FEATURE_ID}": TypecheckProbeInput; } } @@ -123,11 +132,11 @@ export const FEATURE_RUNTIME = defineFeatureRuntime({ adapters: [ defineFeatureAdapterContribution({ featureId: "${FEATURE_ID}", - needs: ["noticeSettings"] as const, - createInput: ({ noticeSettings }) => + needs: ["typecheckProbeSettings"] as const, + createInput: ({ typecheckProbeSettings }) => Object.freeze({ featureId: "${FEATURE_ID}", - input: Object.freeze({ pageSize: () => noticeSettings.pageSize() }), + input: Object.freeze({ pageSize: () => typecheckProbeSettings.pageSize() }), }), }), ], @@ -142,7 +151,7 @@ export const FEATURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze([]); const CONTEXT_MODULE = `export const CONTEXT_MODULE_ID = "${CONTEXT_ID}"; export const CONTEXT_APP_ID = "template-app"; -export const CONTEXT_ROUTE_PATH = "notice/*"; +export const CONTEXT_ROUTE_PATH = "typecheck-probe/*"; export const CONTEXT_MAX_FEATURES = 1; `; @@ -156,8 +165,12 @@ describe("1103/09-02 a product filled through its own files typechecks", () => { it("passes the app, node and test programs", async () => { const root = await mkdtemp(path.join(tmpdir(), "product-extension-typecheck-")); roots.push(root); - // The repository's one copy-target list for a fixture copy. + // The repository's one copy-target list for a fixture copy. A removal + // drill runs this test in a copy that has already lost some of them + // (test:optional-recipe-removal deletes recipes/). + expect(existsSync(path.resolve("src/features", FEATURE_ID)), FEATURE_ID).toBe(false); for (const entry of REMOVAL_FIXTURE_COPY_TARGETS) { + if (!existsSync(path.resolve(entry))) continue; await cp(path.resolve(entry), path.join(root, entry), { recursive: true, filter: (source) => !source.includes(`${path.sep}.generated`), @@ -165,10 +178,8 @@ describe("1103/09-02 a product filled through its own files typechecks", () => { } await linkFixtureNodeModules(root); const shipped = await readFile(path.resolve("src/features/product-capabilities.ts"), "utf8"); - const emptyTypes = "export interface ProductFeaturePlatformCapabilities {}"; - expect(shipped.split(emptyTypes)).toHaveLength(2); const files: Readonly> = { - "src/features/product-capabilities.ts": shipped.replace(emptyTypes, PRODUCT_CAPABILITY_TYPES), + "src/features/product-capabilities.ts": `${shipped}${PRODUCT_CAPABILITY_TYPES}`, "src/contracts/product-contracts.ts": PRODUCT_CONTRACTS, "src/bootstrap/product-composition.ts": PRODUCT_COMPOSITION, [`src/contexts/${CONTEXT_ID}/context-module.ts`]: CONTEXT_MODULE,