From ad0e83c8672f9b87601bdd3546400732ad8ef7ff Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 25 Sep 2026 23:10:19 +0900 Subject: [PATCH] fix(features): make feature add and removal work from the feature directory (09-07, 14-03) A feature directory without feature-module.ts vanished silently, registry consumers listed only the sample's directories, and the removal gate only knew the sample. The generator now fails unless a NOT_INSTALLED marker says so (D-10), consumer directories are globs over every feature, and the removal script takes --feature=. starter-experience.md documents the current ownership declarations and the files a new feature touches. Co-Authored-By: Claude Opus 5.5 --- config/contracts/registry-governance.json | 8 +- docs/architecture/starter-experience.md | 96 ++++++-- package.json | 2 +- scripts/check-registries.ts | 27 ++- scripts/generate-product-feature-index.ts | 25 +- scripts/test-sample-removal.ts | 214 ++++++++++++------ src/apps/template-app/app-module.ts | 3 +- .../reference-context/context-module.ts | 3 +- .../local-draft-feature/NOT_INSTALLED | 6 + src/features/reference-feature/README.md | 3 +- .../generate-product-feature-index.test.ts | 19 ++ tests/unit/feature-removal-argument.test.ts | 20 ++ 12 files changed, 327 insertions(+), 99 deletions(-) create mode 100644 src/features/local-draft-feature/NOT_INSTALLED create mode 100644 tests/unit/feature-removal-argument.test.ts diff --git a/config/contracts/registry-governance.json b/config/contracts/registry-governance.json index a19036d4..6de373e2 100644 --- a/config/contracts/registry-governance.json +++ b/config/contracts/registry-governance.json @@ -193,8 +193,8 @@ ], "consumerIdentityField": "operationId", "consumerDirectories": [ - "src/features/reference-feature/adapters", - "src/features/reference-feature/application" + "src/features/*/adapters", + "src/features/*/application" ], "breakingFields": [ "method", @@ -234,8 +234,8 @@ "consumerIdentityField": "schemaId", "consumerDirectories": [ "src/presentation/routes", - "src/features/reference-feature/presentation", - "src/features/reference-feature/contracts" + "src/features/*/presentation", + "src/features/*/contracts" ], "breakingFields": ["schemaId", "boundary", "runtime"] }, diff --git a/docs/architecture/starter-experience.md b/docs/architecture/starter-experience.md index ab757891..020c17ec 100644 --- a/docs/architecture/starter-experience.md +++ b/docs/architecture/starter-experience.md @@ -26,14 +26,10 @@ remain stable in the shell. ## Registered routes -| ID | Path | Access | Surface | -| --- | --- | --- | --- | -| `APP_HOME` | `/` | public | readiness dashboard | -| `EXAMPLES_UI` | `/examples/ui` | public | interactive primitives and tokens | -| `EXAMPLES_STATES` | `/examples/states` | public | async and access state matrix | -| `EXAMPLES_AUTH` | `/examples/auth` | public | session integration controls | -| `REFERENCE_RESOURCE_LIST` | `/examples/reference-resources` | session-required | removable vertical slice | -| `NOT_FOUND` | `*` | public | safe navigation recovery | +The route list is `ROUTE_REGISTRY` (`src/features/installed-feature-contracts.ts`): +the platform routes of `src/contracts/routes.ts` plus the routes of every +installed feature. The platform overview page (`/examples/platform`) shows the +composed list at runtime, so this document does not keep a copy of it. Navigation labels and order come from `ROUTE_REGISTRY`; the sidebar does not maintain a second route list. The client access decision never claims to be @@ -69,25 +65,81 @@ safe default. The `demo` adapter reports one fixed demo user as its subject. ## Extending the starter -The steps below describe the current extension path. New platform work should follow +New platform work should follow [routing, page templates, and reusable patterns](./routing-pages-and-patterns.md) and the [TypeScript, state, and data-flow target](./typescript-state-and-data-flow.md) rather than adding another independent route or data-loading convention. -1. Add a serializable contribution under the feature ownership boundary and - install it through `src/features/installed-feature-contracts.ts`. -2. Add the lazy component and route codecs through - `src/features/installed-feature-runtimes.tsx`. -3. Compose feature application inputs and outbound gateways only through - `src/features/installed-feature-adapters.ts`. -4. Use the semantic tokens, UI primitives, and state surfaces before adding a - project-specific variant. -5. Add component behavior, all-engine E2E, automated axe, and signed manual - route evidence. -6. Run `test:sample-removal` to prove the generic starter typechecks, passes - architecture/registry/tests/coverage/source-evidence/home smoke, and builds - without the complete reference feature. +### Ownership declarations + +Features, contexts and apps are discovered by +`scripts/generate-product-feature-index.ts`. Each boundary declares only its +parent, as exported string or integer literals the generator reads: + +| File | Exports | +| --- | --- | +| `src/apps//app-module.ts` | `APP_MODULE_ID`, `APP_MAX_CONTEXTS` | +| `src/contexts//context-module.ts` | `CONTEXT_MODULE_ID`, `CONTEXT_APP_ID`, `CONTEXT_ROUTE_PATH`, `CONTEXT_MAX_FEATURES` | +| `src/features//feature-module.ts` | `FEATURE_MODULE_ID`, `FEATURE_CONTEXT_ID`, `FEATURE_MODULE` | +| `src/features//context-routes.ts` | `FEATURE_CONTEXT_ROUTES` | + +The generator writes `src/.generated/` (git-ignored): the feature index the +installed catalogs import, the context index the router loads lazily, and the +selected app. Every build and check script runs it first; run it yourself with +`corepack pnpm generate:feature-index`. It fails, naming the file, when: + +- a directory under `src/features/` has no `feature-module.ts` and no + `NOT_INSTALLED` marker file (`src/features/local-draft-feature/NOT_INSTALLED` + is the one intentional example); +- a feature names an undeclared context, or a context an undeclared app; +- a context or app exceeds its declared budget; +- `VITE_PRODUCT_FEATURES` names a feature the app does not declare. The + variable narrows the installed set here, before anything is compiled. + +### Adding a feature + +1. Create `src/features//feature-module.ts`. Build `FEATURE_MODULE` + with `defineFeatureModule` (`src/features/feature-module.ts`): the feature's + contract (routes, route runtime contracts, API operations, invalidation, + schemas, runtime schemas, mappers), its adapter contributions + (`defineFeatureAdapterContribution`, with `needs` naming the platform + capabilities it receives), its runtime descriptor (route codecs), its message + catalogs and its contract contributions. + `src/features/reference-feature/feature-module.ts` is the complete example. +2. Create `src/features//context-routes.ts` exporting + `FEATURE_CONTEXT_ROUTES`. Page components are imported lazily here; the + owning context loads this file only when its route root is visited + (`src/features/reference-feature/context-routes.ts`). +3. Name the owning context in `FEATURE_CONTEXT_ID`. Use an existing context or + add `src/contexts//context-module.ts` owned by the app. +4. If the feature has application input, augment `ApplicationFeatureInputs` + from the feature (`src/features/local-draft-feature/application/local-draft-api.ts`). +5. Run `corepack pnpm check:architecture`, `corepack pnpm check:types`, + `corepack pnpm check:registries` and the tests. `tests/unit/two-feature-install-typecheck.test.ts` + keeps the installed catalogs compiling with more than one feature. +6. Run `corepack pnpm test:sample-removal -- --feature=` to prove + the product still builds and passes its gates without the feature. + +Files outside the feature directory: + +| File | Change | +| --- | --- | +| `src/.generated/*` | regenerated automatically | +| `src/contexts//context-module.ts` | only when the feature needs a new context | +| `config/runtime/.json` | optional `FEATURE_OVERRIDES` entry to switch the feature off | +| `src/bootstrap/runtime-adapters.ts` | only when `needs` includes `indexedDb`: add the capability, built as in `recipes/frontend-capabilities/indexeddb-feature-capability.ts` | + +The central catalogs (`src/features/installed-*.ts`) and the registry +governance file do not change: consumer directories there are globs over every +feature (`src/features/*/adapters`, `config/contracts/registry-governance.json`). + +### Before shipping + +- Use the semantic tokens, UI primitives, and state surfaces before adding a + project-specific variant. +- Add component behavior, all-engine E2E, automated axe, and signed manual + route evidence. Theme preference is the public `COLOR_SCHEME` storage contract. Authentication tokens and other secrets remain forbidden storage keys. diff --git a/package.json b/package.json index 08384a87..2558dad7 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "check:test-evidence:fixture": "node scripts/check-test-evidence.ts --source-root tests/fixtures/test-evidence/forbidden --artifact artifacts/quality/test-evidence-fixture.json", "test:a11y": "node scripts/generate-product-feature-index.ts && playwright test --grep @a11y && node scripts/write-a11y-report.ts", "review:a11y-manual": "node scripts/generate-product-feature-index.ts && node scripts/verify-a11y-manual.ts", - "test:sample-removal": "node scripts/test-sample-removal.ts", + "test:sample-removal": "node scripts/generate-product-feature-index.ts && node scripts/test-sample-removal.ts", "test:optional-recipe-removal": "node scripts/test-optional-recipe-removal.ts", "test:browser-file-storage-removal": "node scripts/test-browser-file-storage-runtime-removal.ts", "test:realtime-removal": "node scripts/test-realtime-runtime-removal.ts", diff --git a/scripts/check-registries.ts b/scripts/check-registries.ts index 9c458640..3bec84f5 100644 --- a/scripts/check-registries.ts +++ b/scripts/check-registries.ts @@ -330,6 +330,27 @@ function projectSnapshotRows( }); } +/** + * 09-07. `src/features/*\/adapters` names that directory in every feature, so + * adding a feature does not mean adding it to this governance file. + */ +async function expandDirectoryPattern(pattern: string): Promise { + const star = pattern.split("/").indexOf("*"); + if (star === -1) return [pattern]; + const segments = pattern.split("/"); + const parent = segments.slice(0, star).join("/"); + const rest = segments.slice(star + 1).join("/"); + const entries = await readdir(parent, { withFileTypes: true }).catch(() => []); + const expanded = await Promise.all( + entries + .filter((entry) => entry.isDirectory()) + .map((entry) => + expandDirectoryPattern(path.join(parent, entry.name, rest)), + ), + ); + return expanded.flat(); +} + async function filesBelow(directory: string): Promise { try { const entries = await readdir(directory, { withFileTypes: true }); @@ -548,7 +569,11 @@ for (const specification of governance.registries) { if (specification.consumerIdentityField) { const consumerFiles = ( await Promise.all( - (specification.consumerDirectories ?? []).map(filesBelow), + (await Promise.all( + (specification.consumerDirectories ?? []).map(expandDirectoryPattern), + )) + .flat() + .map(filesBelow), ) ).flat(); const sourcePath = sourcesByRegistry.get(specification.registryId); diff --git a/scripts/generate-product-feature-index.ts b/scripts/generate-product-feature-index.ts index 3b7aaf2f..e5ebdac9 100644 --- a/scripts/generate-product-feature-index.ts +++ b/scripts/generate-product-feature-index.ts @@ -105,7 +105,8 @@ export function renderContextIndex(entries: readonly FeatureIndexEntry[]): strin } /** - * Spec §3.2 / §5. Ownership declarations the generator reads. Each boundary + * Ownership declarations the generator reads, documented in + * docs/architecture/starter-experience.md ("Ownership declarations"). Each boundary * declares only its parent: * * src/apps//app-module.ts APP_MODULE_ID, APP_MAX_CONTEXTS @@ -258,9 +259,17 @@ function requiredInteger(source: string, name: string, file: string): number { return parsed; } +/** + * 09-07 (D-10). A feature directory must declare itself or say it is not + * installed. A missing or misspelt `feature-module.ts` used to drop the + * feature from the product without a word. + */ +export const NOT_INSTALLED_MARKER = "NOT_INSTALLED"; + async function readDeclarations( directory: string, fileName: string, + requiredUnless?: string, ): Promise[]> { const found: { directory: string; file: string; source: string }[] = []; let items; @@ -275,7 +284,13 @@ async function readDeclarations( try { found.push({ directory: item.name, file, source: await readFile(file, "utf8") }); } catch { - continue; + if (requiredUnless === undefined) continue; + const marker = await readFile(resolve(directory, item.name, requiredUnless)) + .then(() => true, () => false); + if (marker) continue; + throw new Error( + `src/features/${item.name} has no ${fileName}; add one or mark the directory with ${requiredUnless}`, + ); } } return found; @@ -318,7 +333,11 @@ export async function createFileSystemDeclarationSource( } const featuresByContext = new Map(); const featureIds = new Set(); - for (const declaration of await readDeclarations(resolve(root, "src/features"), "feature-module.ts")) { + for (const declaration of await readDeclarations( + resolve(root, "src/features"), + "feature-module.ts", + NOT_INSTALLED_MARKER, + )) { const feature: FeatureDeclaration = { id: requiredLiteral(declaration.source, "FEATURE_MODULE_ID", declaration.file), contextId: requiredLiteral(declaration.source, "FEATURE_CONTEXT_ID", declaration.file), diff --git a/scripts/test-sample-removal.ts b/scripts/test-sample-removal.ts index 732601ae..fd5d5f4a 100644 --- a/scripts/test-sample-removal.ts +++ b/scripts/test-sample-removal.ts @@ -2,12 +2,15 @@ import { access, mkdir, mkdtemp, + readdir, readFile, rm, writeFile, } from "node:fs/promises"; import path from "node:path"; +import { ROUTE_FEATURE_OWNER } from "../src/features/installed-feature-contracts.ts"; +import { createFileSystemDeclarationSource } from "./generate-product-feature-index.ts"; import { isProductionModulePath } from "./lib/risk-coverage.ts"; import { filesBelow, @@ -19,14 +22,130 @@ import { runRemovalFixturePnpm, } from "./lib/removal-fixture.ts"; +/** + * 09-07 (D-10). Removes one installed feature, `--feature=` (default: the + * reference sample), from a copy of the repository and proves the rest still + * typechecks, tests, covers and builds. Every feature loses its directory, its + * tests/features directory, its context when no other feature is left in it, + * its runtime-profile override and its central policy rows. The sample also + * owns the extra paths and scripts listed in SAMPLE_EXTRAS. + */ +const featureId = + process.argv.find((argument) => argument.startsWith("--feature=")) + ?.slice("--feature=".length) ?? "reference-feature"; + +type FeatureExtras = Readonly<{ + paths: readonly string[]; + ciScripts: readonly string[]; + evidencePathFragments: readonly string[]; + residue: RegExp; +}>; + +const SAMPLE_EXTRAS: Readonly> = Object.freeze({ + "reference-feature": Object.freeze({ + paths: [ + "tests/integration/http-scenario-catalog.test.ts", + "tests/component/product-feature-switch.test.tsx", + "tests/e2e/reference-form.spec.ts", + "tests/e2e/reference-route.spec.ts", + "tests/mocks", + "tests/fixtures/typecheck/invalid-feature-input.ts", + "tests/fixtures/typecheck/invalid-reference-operation.ts", + "tests/fixtures/typecheck/invalid-http-operation-input.ts", + "tests/fixtures/typecheck/invalid-http-wire-mapper.ts", + "tests/fixtures/typecheck/invalid-http-operation-id.ts", + "tests/fixtures/typecheck/invalid-http-route-id.ts", + "tests/fixtures/typecheck/invalid-feature-contribution-input.ts", + "tests/fixtures/typecheck/invalid-feature-capability-selection.ts", + "tests/fixtures/typecheck/tsconfig.feature-input.json", + "tests/fixtures/typecheck/tsconfig.reference-operation.json", + "tests/fixtures/typecheck/tsconfig.http-operation-input.json", + "tests/fixtures/typecheck/tsconfig.http-wire-mapper.json", + "tests/fixtures/typecheck/tsconfig.http-operation-id.json", + "tests/fixtures/typecheck/tsconfig.http-route-id.json", + "tests/fixtures/typecheck/tsconfig.feature-contribution-input.json", + "tests/fixtures/typecheck/tsconfig.feature-capability-selection.json", + ], + ciScripts: [ + "check:types:fixture:feature-input", + "check:types:fixture:reference-operation", + "check:types:fixture:http-operation-input", + "check:types:fixture:http-wire-mapper", + "check:types:fixture:http-operation-id", + "check:types:fixture:http-route-id", + "check:types:fixture:feature-contribution-input", + "check:types:fixture:feature-capability-selection", + "test:http-scenario-evidence", + "test:reference-feature", + ], + evidencePathFragments: [ + "reference-feature.xml", + "http-scenario-executions", + "http-scenario-evidence", + ], + residue: /REFERENCE_RESOURCE|reference-feature|reference-resource/i, + }), +}); + +function escapeRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); +} + +async function locateFeature(id: string) { + const source = await createFileSystemDeclarationSource(process.cwd()); + for (const appId of source.appIds()) { + for (const context of source.contextsOf(appId)) { + const features = source.featuresOf(context.id); + const feature = features.find((candidate) => candidate.id === id); + if (!feature) continue; + let contextDirectory: string | null = null; + for (const entry of await readdir("src/contexts", { withFileTypes: true })) { + if (!entry.isDirectory()) continue; + const declaration = await readFile( + path.join("src/contexts", entry.name, "context-module.ts"), + "utf8", + ).catch(() => ""); + if ( + new RegExp(`CONTEXT_MODULE_ID\\s*=\\s*["']${escapeRegExp(context.id)}["']`, "u") + .test(declaration) + ) { + contextDirectory = `src/contexts/${entry.name}`; + } + } + return Object.freeze({ + directory: feature.directory, + // The context goes with its last feature. + contextDirectory: features.length === 1 ? contextDirectory : null, + }); + } + } + throw new Error(`No installed feature declares FEATURE_MODULE_ID "${id}"`); +} + +const located = await locateFeature(featureId); +const extras: FeatureExtras = SAMPLE_EXTRAS[featureId] ?? Object.freeze({ + paths: [], + ciScripts: [], + evidencePathFragments: [], + residue: new RegExp( + `${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`, + "i", + ), +}); +// Captured from this repository before the copy loses them. +const featureRouteIds = Object.entries(ROUTE_FEATURE_OWNER) + .filter(([, owner]) => owner === featureId) + .map(([routeId]) => routeId); + const fixtureParent = path.resolve(".tmp"); await mkdir(fixtureParent, { recursive: true }); const fixtureRoot = await mkdtemp( - path.join(fixtureParent, "reference-feature-removal-"), + path.join(fixtureParent, `${featureId}-removal-`), ); const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath"); -const featureSource = "src/features/reference-feature"; -const featureTests = "tests/features/reference-feature"; +const featureSource = `src/features/${located.directory}`; +const featureTests = `tests/features/${located.directory}`; +const isSample = featureId in SAMPLE_EXTRAS; /** * Platform tests that must survive the sample feature's removal. Asserting they * are still present is what stops the removal fixture from "passing" by having @@ -41,29 +160,10 @@ const commonTestPaths = [ const featureOwnedPaths = [ featureSource, featureTests, - // The sample's bounded-context declaration; the template app stays. - "src/contexts/reference-context", - "tests/integration/http-scenario-catalog.test.ts", - "tests/component/product-feature-switch.test.tsx", - "tests/e2e/reference-form.spec.ts", - "tests/e2e/reference-route.spec.ts", - "tests/mocks", - "tests/fixtures/typecheck/invalid-feature-input.ts", - "tests/fixtures/typecheck/invalid-reference-operation.ts", - "tests/fixtures/typecheck/invalid-http-operation-input.ts", - "tests/fixtures/typecheck/invalid-http-wire-mapper.ts", - "tests/fixtures/typecheck/invalid-http-operation-id.ts", - "tests/fixtures/typecheck/invalid-http-route-id.ts", - "tests/fixtures/typecheck/invalid-feature-contribution-input.ts", - "tests/fixtures/typecheck/invalid-feature-capability-selection.ts", - "tests/fixtures/typecheck/tsconfig.feature-input.json", - "tests/fixtures/typecheck/tsconfig.reference-operation.json", - "tests/fixtures/typecheck/tsconfig.http-operation-input.json", - "tests/fixtures/typecheck/tsconfig.http-wire-mapper.json", - "tests/fixtures/typecheck/tsconfig.http-operation-id.json", - "tests/fixtures/typecheck/tsconfig.http-route-id.json", - "tests/fixtures/typecheck/tsconfig.feature-contribution-input.json", - "tests/fixtures/typecheck/tsconfig.feature-capability-selection.json", + // The feature's bounded-context declaration when it was the last feature in + // it; the template app stays. + ...(located.contextDirectory === null ? [] : [located.contextDirectory]), + ...extras.paths, ]; type CoveragePolicy = { @@ -152,7 +252,7 @@ try { FEATURE_OVERRIDES?: Record; }; if (runtimeConfig.FEATURE_OVERRIDES) { - delete runtimeConfig.FEATURE_OVERRIDES["reference-feature"]; + delete runtimeConfig.FEATURE_OVERRIDES[featureId]; } await writeFile( profilePath, @@ -164,6 +264,7 @@ try { (modulePolicy) => !modulePolicy.path?.startsWith(`${featureSource}/`), ); if ( + isSample && retainedCriticalModules.length === coveragePolicy.criticalModules.length ) { throw new Error("Reference feature coverage policy is not registered"); @@ -202,12 +303,12 @@ try { } evidencePolicy[policyKey] = contributions.filter((candidate: unknown) => { const contribution = candidate as EvidenceContribution; - const retained = contribution.owner !== "reference-feature"; + const retained = contribution.owner !== featureId; if (!retained) removedEvidenceContributions += 1; return retained; }); } - if (removedEvidenceContributions === 0) { + if (isSample && removedEvidenceContributions === 0) { throw new Error("Reference feature test evidence policy is not registered"); } await writeFile( @@ -230,7 +331,7 @@ try { consumers: registry.consumers.filter( (candidate: unknown) => { const consumer = candidate as GovernanceConsumer; - return !consumer.path?.includes("features/reference-feature"); + return !consumer.path?.includes(featureSource); }, ), } @@ -240,7 +341,7 @@ try { consumerDirectories: registry.consumerDirectories.filter( (directory: unknown) => typeof directory !== "string" || - !directory.includes("features/reference-feature"), + !directory.includes(featureSource), ), } : {}), @@ -251,41 +352,28 @@ try { `${JSON.stringify(removalGovernance, null, 2)}\n`, ); - const removedCiScripts = new Set([ - "check:types:fixture:feature-input", - "check:types:fixture:reference-operation", - "check:types:fixture:http-operation-input", - "check:types:fixture:http-wire-mapper", - "check:types:fixture:http-operation-id", - "check:types:fixture:http-route-id", - "check:types:fixture:feature-contribution-input", - "check:types:fixture:feature-capability-selection", - "test:http-scenario-evidence", - "test:reference-feature", - ]); + const removedCiScripts = new Set(extras.ciScripts); const fixturePackagePath = path.join(fixtureRoot, "package.json"); const fixturePackage = JSON.parse(await readFile(fixturePackagePath, "utf8")) as { scripts: Record; }; pruneScriptOrchestration(fixturePackage.scripts, "test:all", removedCiScripts); - delete fixturePackage.scripts["check:http-scenario-evidence"]; - delete fixturePackage.scripts["check:http-scenario-evidence:fixture"]; + if (isSample) { + delete fixturePackage.scripts["check:http-scenario-evidence"]; + delete fixturePackage.scripts["check:http-scenario-evidence:fixture"]; + } await writeFile(fixturePackagePath, `${JSON.stringify(fixturePackage, null, 2)}\n`); await pruneRemovalFixtureCiContract({ root: fixtureRoot, removedScripts: removedCiScripts, - removedEvidencePathFragments: [ - "reference-feature.xml", - "http-scenario-executions", - "http-scenario-evidence", - ], + removedEvidencePathFragments: extras.evidencePathFragments, }); // D-13: removing the sample is a breaking registry change. The fixture // records the new registry baseline the way a downstream project does, and // the canonical check:registries then runs against it. if (!runRemovalFixturePnpm(fixtureRoot, pnpmCli, "update:registry-baseline", [], { REGISTRY_BASELINE_OWNER: "removal-fixture", - REGISTRY_BASELINE_REASON: "reference feature removed", + REGISTRY_BASELINE_REASON: `${featureId} removed`, })) { throw new Error("Registry baseline failed to update after sample removal"); } @@ -296,11 +384,7 @@ try { for (const file of await filesBelow(path.join(fixtureRoot, root))) { const relative = path.relative(fixtureRoot, file); const content = await readFile(file, "utf8"); - if ( - /REFERENCE_RESOURCE|reference-feature|reference-resource/i.test( - `${relative}\n${content}`, - ) - ) { + if (extras.residue.test(`${relative}\n${content}`)) { residue.push(relative); } } @@ -347,9 +431,7 @@ try { for (const file of await filesBelow(path.join(fixtureRoot, "dist"))) { if (!/\.(?:js|css|html|json)$/.test(file)) continue; const content = await readFile(file, "utf8"); - if ( - /REFERENCE_RESOURCE|reference-feature|reference-resource/i.test(content) - ) { + if (extras.residue.test(content)) { builtResidue.push(path.relative(fixtureRoot, file)); } } @@ -360,8 +442,8 @@ try { `file://${fixtureRoot}/scripts/`, ).href}?removed=${Date.now()}` ) as { ROUTE_REGISTRY: Readonly> }; - const routeIds = Object.keys(routeCatalog.ROUTE_REGISTRY); - const routeAbsent = routeIds.every((routeId) => !routeId.startsWith("REFERENCE_")); + const routeIds = new Set(Object.keys(routeCatalog.ROUTE_REGISTRY)); + const routeAbsent = featureRouteIds.every((routeId) => !routeIds.has(routeId)); checks.push(["route-absent", routeAbsent]); checks.push(["fixture-id-residue", residue.length === 0]); checks.push(["built-fixture-id-residue", builtResidue.length === 0]); @@ -369,9 +451,11 @@ try { const passed = checks.every(([, result]) => result); await mkdir("artifacts/tests", { recursive: true }); await writeFile( - "artifacts/tests/sample-removal.xml", + isSample + ? "artifacts/tests/sample-removal.xml" + : `artifacts/tests/feature-removal-${featureId}.xml`, `\n` + - `` + + `` + checks .map( ([name, result]) => @@ -385,12 +469,12 @@ try { .filter(([, result]) => !result) .map(([name]) => name); process.stderr.write( - `Reference feature removal failed: ${failures.join(", ")}; residue: ${[...residue, ...builtResidue].join(", ")}\n`, + `${featureId} removal failed: ${failures.join(", ")}; residue: ${[...residue, ...builtResidue].join(", ")}\n`, ); process.exitCode = 1; } else { process.stdout.write( - `Reference feature removal: PASS (${checks.length} checks, no fixture IDs)\n`, + `${featureId} removal: PASS (${checks.length} checks, no fixture IDs)\n`, ); } } finally { diff --git a/src/apps/template-app/app-module.ts b/src/apps/template-app/app-module.ts index 0b10e621..c26eb78d 100644 --- a/src/apps/template-app/app-module.ts +++ b/src/apps/template-app/app-module.ts @@ -1,5 +1,6 @@ /** - * Spec §5.3. Ownership declaration of the template deployable app. The + * Ownership declaration of the template deployable app + * (docs/architecture/starter-experience.md, "Ownership declarations"). The * generator reads these literals; contexts name this id as their owner. */ export const APP_MODULE_ID = "template-app"; diff --git a/src/contexts/reference-context/context-module.ts b/src/contexts/reference-context/context-module.ts index bba3c41d..11c6996b 100644 --- a/src/contexts/reference-context/context-module.ts +++ b/src/contexts/reference-context/context-module.ts @@ -1,5 +1,6 @@ /** - * Spec §5.2. Ownership declaration of the reference bounded context: the app + * Ownership declaration of the reference bounded context (the rules are in + * docs/architecture/starter-experience.md, "Ownership declarations"): the app * that owns it, its route root, and its direct-feature budget. Features name * this id as their owner. */ diff --git a/src/features/local-draft-feature/NOT_INSTALLED b/src/features/local-draft-feature/NOT_INSTALLED new file mode 100644 index 00000000..1c481d10 --- /dev/null +++ b/src/features/local-draft-feature/NOT_INSTALLED @@ -0,0 +1,6 @@ +local-draft is an architecture sample for the indexedDb feature capability, not +a product feature. It has no feature-module.ts on purpose, so the index +generator (scripts/generate-product-feature-index.ts) leaves it out; its +composition is exercised by tests/contract/reusable-capability and +recipes/frontend-capabilities/indexeddb-feature-capability.ts. To install it, +add feature-module.ts and context-routes.ts and delete this file. diff --git a/src/features/reference-feature/README.md b/src/features/reference-feature/README.md index cc34c8d6..8c07b364 100644 --- a/src/features/reference-feature/README.md +++ b/src/features/reference-feature/README.md @@ -45,7 +45,8 @@ route codec과 URL builder는 `src/presentation/routes/route-codecs.ts`, route t feature가 실제 contribution을 소유한다. - contract: `reference-feature-contract.ts` -- component/codec: `REFERENCE_FEATURE_RUNTIME_CONTRIBUTION` +- route codec: `REFERENCE_FEATURE_RUNTIME_DESCRIPTOR` (`feature-module.ts`가 설치) +- page component: `REFERENCE_FEATURE_ROUTE_RUNTIME` (`context-routes.ts`가 lazy로 적재) - bootstrap input: `REFERENCE_FEATURE_ADAPTER_CONTRIBUTION` 중앙 파일인 `installed-feature-contracts.ts`, diff --git a/tests/scripts/generate-product-feature-index.test.ts b/tests/scripts/generate-product-feature-index.test.ts index 181cb8a7..1f1bcfd4 100644 --- a/tests/scripts/generate-product-feature-index.test.ts +++ b/tests/scripts/generate-product-feature-index.test.ts @@ -134,6 +134,25 @@ describe("app-scoped selection from ownership declarations", () => { await expect(generateAppIndexes(overContexts, "a")).rejects.toThrow(/App a context cardinality 2 exceeds budget 1/); }); + it("refuses a feature directory without a declaration or NOT_INSTALLED marker (09-07)", async () => { + const files = { + "src/apps/a/app-module.ts": app("a"), + "src/contexts/c/context-module.ts": context("c", "a"), + "src/features/f/feature-module.ts": feature("f", "c"), + // A misspelt declaration file used to drop the feature without a word. + "src/features/typo/feature-modul.ts": feature("typo", "c"), + }; + await expect(generateAppIndexes(await repo(files), "a")).rejects.toThrow( + /src\/features\/typo has no feature-module\.ts/u, + ); + const marked = await repo({ + ...files, + "src/features/typo/NOT_INSTALLED": "Composed only by tests.\n", + }); + const selected = await generateAppIndexes(marked, "a"); + expect(selected.entries.map((entry) => entry.id)).toEqual(["f"]); + }); + it("skips contexts without features and never imports another app's features", async () => { const root = await repo({ "src/apps/a/app-module.ts": app("a"), diff --git a/tests/unit/feature-removal-argument.test.ts b/tests/unit/feature-removal-argument.test.ts new file mode 100644 index 00000000..b5db92dc --- /dev/null +++ b/tests/unit/feature-removal-argument.test.ts @@ -0,0 +1,20 @@ +import { spawnSync } from "node:child_process"; + +import { describe, expect, it } from "vitest"; + +// 09-07 (D-10). The removal gate takes the feature to remove as an argument +// instead of hard-coding the sample; an id no feature declares stops it before +// any fixture is built. +describe("feature removal argument", () => { + it("refuses a feature id that no installed feature declares", () => { + const run = spawnSync( + process.execPath, + ["scripts/test-sample-removal.ts", "--feature=missing-feature"], + { encoding: "utf8" }, + ); + expect(run.status).not.toBe(0); + expect(run.stderr).toMatch( + /No installed feature declares FEATURE_MODULE_ID "missing-feature"/u, + ); + }); +});