diff --git a/config/contracts/registry-change-evidence.json b/config/contracts/registry-change-evidence.json index f7e2ab0c..4e03d4ed 100644 --- a/config/contracts/registry-change-evidence.json +++ b/config/contracts/registry-change-evidence.json @@ -27,6 +27,27 @@ "compatibilityWindow": "No storage or wire format changes: deployed tabs keep exchanging the same raw pulse on the same key.", "rollback": "Revert together with FE-REG-STORAGE:CACHE_INVALIDATION_PULSE:backend:field-changed.", "owner": "frontend-platform" + }, + { + "changeId": "FE-REG-ROUTE:$contract:allowedValues:contract-field-changed", + "after": { + "access": ["public", "session-required"], + "errorSurface": ["feature-boundary", "not-found", "route-boundary"] + }, + "versionBump": "0929/07-03: FE-REG-ROUTE stops listing paramsSchema, searchSchema and loadingSurface values. A feature route with its own schema or loading surface no longer needs a governance edit.", + "migration": "None for existing routes: every value the lists held is still valid. paramsSchema and searchSchema stay checked against FE-REG-SCHEMA by references; loadingSurface is checked by fieldPatterns. A downstream that added its own values to these lists drops them at the next template sync.", + "compatibilityWindow": "No runtime change: the lists were read only by check:registries. access and errorSurface keep their closed lists.", + "rollback": "Restore the three lists in config/contracts/registry-governance.json, then drop this entry and its fieldPatterns sibling.", + "owner": "frontend-platform" + }, + { + "changeId": "FE-REG-ROUTE:$contract:fieldPatterns:contract-field-added", + "after": { "loadingSurface": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$" }, + "versionBump": "0929/07-03: FE-REG-ROUTE checks loadingSurface for a kebab-case name instead of a closed list. The value is only the data-surface attribute of the route loading element.", + "migration": "None: every installed loading surface is already kebab-case.", + "compatibilityWindow": "No runtime change: only check:registries reads the pattern.", + "rollback": "Revert together with FE-REG-ROUTE:$contract:allowedValues:contract-field-changed.", + "owner": "frontend-platform" } ] } diff --git a/config/contracts/registry-governance.json b/config/contracts/registry-governance.json index 24f4404a..80846b6b 100644 --- a/config/contracts/registry-governance.json +++ b/config/contracts/registry-governance.json @@ -41,23 +41,15 @@ "uniqueFields": ["routeId", "path", "chunkId"], "allowedValues": { "access": ["public", "session-required"], - "paramsSchema": [null, "NotFoundSplat", "ReferenceResourceParams"], - "searchSchema": [null, "ReferenceResourceListQuery"], - "loadingSurface": [ - "app-shell", - "example-page", - "reference-resource-list", - "reference-resource-detail", - "reference-resource-form", - "reference-resource-status", - "none" - ], "errorSurface": [ "route-boundary", "feature-boundary", "not-found" ] }, + "fieldPatterns": { + "loadingSurface": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$" + }, "references": [ { "field": "routeId", diff --git a/docs/architecture/starter-experience.md b/docs/architecture/starter-experience.md index f45c76f7..6db25faa 100644 --- a/docs/architecture/starter-experience.md +++ b/docs/architecture/starter-experience.md @@ -172,6 +172,12 @@ Files outside the feature directory: 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`). +A route's params/search schema ids are checked against the schemas the feature +registers, and its `loadingSurface` only has to be a kebab-case name, so a +route with its own schema and loading surface needs no governance edit either. +`tests/unit/second-api-feature-registries.test.ts` adds such a feature (an API +operation and a route with its own search schema and loading surface) to a copy +of the repository and runs `check:registries` on it. ### Before shipping diff --git a/scripts/check-registries.ts b/scripts/check-registries.ts index 5725e58e..347000d3 100644 --- a/scripts/check-registries.ts +++ b/scripts/check-registries.ts @@ -50,6 +50,8 @@ type RegistrySpecification = Readonly<{ uniqueFieldSets?: readonly (readonly string[])[]; snapshotProjection?: RegistrySnapshotProjection; allowedValues?: Readonly>; + /** Field name to an anchored regular expression its string value matches. */ + fieldPatterns?: Readonly>; references?: readonly RegistryReference[]; breakingFields?: readonly string[]; consumers?: readonly RegistryConsumer[]; @@ -470,6 +472,23 @@ for (const specification of governance.registries) { } } + // 0929/07-03. A name no code branches on is checked for its form, not + // listed, so a feature adds its own value without editing governance. + for (const [field, pattern] of Object.entries( + specification.fieldPatterns ?? {}, + )) { + const expression = new RegExp(pattern, "u"); + for (const [rowName, row] of Object.entries(registryRows)) { + if (!row || typeof row !== "object" || Array.isArray(row)) continue; + const value = lookupField(row, field).value; + if (typeof value !== "string" || !expression.test(value)) { + failures.push( + `${specification.registryId}.${rowName}.${field} value ${String(value)} does not match ${pattern}`, + ); + } + } + } + const contract = Object.freeze({ requiredFields: specification.requiredFields, fieldTypes: specification.fieldTypes ?? {}, @@ -478,6 +497,9 @@ for (const specification of governance.registries) { references: specification.references ?? [], keyField: specification.keyField ?? null, breakingFields: specification.breakingFields ?? [], + ...(specification.fieldPatterns + ? { fieldPatterns: specification.fieldPatterns } + : {}), ...(specification.rowsPath ? { rowsPath: specification.rowsPath } : {}), diff --git a/tests/fixtures/registry/routes/governance.json b/tests/fixtures/registry/routes/governance.json index 0b9d5721..3f6ba48c 100644 --- a/tests/fixtures/registry/routes/governance.json +++ b/tests/fixtures/registry/routes/governance.json @@ -20,10 +20,12 @@ "allowedValues": { "paramsSchema": [null], "searchSchema": [null], - "loadingSurface": ["app-shell"], "errorSurface": ["route-boundary"], "chunkId": ["route-home"] }, + "fieldPatterns": { + "loadingSurface": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$" + }, "references": [ { "field": "routeId", diff --git a/tests/fixtures/registry/routes/invalid-routes.ts b/tests/fixtures/registry/routes/invalid-routes.ts index 83741227..6429d2d5 100644 --- a/tests/fixtures/registry/routes/invalid-routes.ts +++ b/tests/fixtures/registry/routes/invalid-routes.ts @@ -4,7 +4,7 @@ export const INVALID_ROUTES = { path: "/duplicate", paramsSchema: "UnknownParams", searchSchema: "UnknownSearch", - loadingSurface: "unknown-loading", + loadingSurface: "Unknown loading", errorSurface: "unknown-error", chunkId: "unknown-chunk", }, diff --git a/tests/unit/registry-governance.test.ts b/tests/unit/registry-governance.test.ts index f5fbf295..5efa4949 100644 --- a/tests/unit/registry-governance.test.ts +++ b/tests/unit/registry-governance.test.ts @@ -432,4 +432,35 @@ describe("registry governance manifest", () => { await rm(directory, { recursive: true, force: true }); } }); + + // 0929/07-03. loadingSurface is a name, checked for its form, not a list. + it("rejects a route loading surface that is not a kebab-case name", async () => { + const directory = await mkdtemp( + path.join(tmpdir(), "registry-governance-routes-"), + ); + const artifact = path.join(directory, "registries.json"); + try { + spawnSync( + process.execPath, + [ + "scripts/check-registries.ts", + "--governance", + "tests/fixtures/registry/routes/governance.json", + "--artifact", + artifact, + ], + { encoding: "utf8" }, + ); + const { failures } = JSON.parse(await readFile(artifact, "utf8")) as { + failures: string[]; + }; + expect( + failures.filter((failure) => failure.includes(".loadingSurface ")), + ).toEqual([ + "ROUTES.FIRST.loadingSurface value Unknown loading does not match ^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$", + ]); + } finally { + await rm(directory, { recursive: true, force: true }); + } + }); }); diff --git a/tests/unit/second-api-feature-registries.test.ts b/tests/unit/second-api-feature-registries.test.ts index c9554c3b..f1db18aa 100644 --- a/tests/unit/second-api-feature-registries.test.ts +++ b/tests/unit/second-api-feature-registries.test.ts @@ -13,6 +13,9 @@ import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.t * baseline stay as they are. This writes one such feature (plus the bounded * context it declares, so the check survives the sample's removal) into a copy * of the repository and runs the production generator and `check-registries`. + * 0929/07-03. The feature also owns a route with its own search schema and its + * own loading surface name, the values FE-REG-ROUTE once kept in a central + * allowlist. */ const FEATURE_ID = "second-api-feature"; const CONTEXT_ID = "second-api-context"; @@ -33,11 +36,34 @@ const codec = (schemaId: string) => safeParse: (value: unknown) => Object.freeze({ success: true as const, data: value }), }); +const ROUTES = Object.freeze({ + SECOND_ITEM_LIST: Object.freeze({ + routeId: "SECOND_ITEM_LIST", + path: "/second-api/items", + paramsSchema: null, + searchSchema: "SecondItemListQuery", + access: "public", + loadingSurface: "second-item-list", + errorSurface: "feature-boundary", + chunkId: "route-second-item-list", + title: "Second items", + navigationLabel: null, + navigationOrder: null, + }), +}); + // 15-01. Declaration half: what the shell reads at boot. export const SECOND_API_CONTRACT = Object.freeze({ featureId: "${FEATURE_ID}", - routes: {}, - routeRuntimeContracts: {}, + routes: ROUTES, + routeRuntimeContracts: Object.freeze({ + SECOND_ITEM_LIST: Object.freeze({ + routeId: "SECOND_ITEM_LIST", + moduleId: "second-item-list-page", + paramsCodec: "none", + searchCodec: "SecondItemListQuery", + }), + }), invalidation: { topics: Object.freeze([]), namespaces: Object.freeze([]), edges: Object.freeze([]) }, topicVersions: Object.freeze([]), contractPackages: Object.freeze([]), @@ -76,11 +102,13 @@ export const SECOND_API_V2_CONTRACT = Object.freeze({ }), }), schemas: Object.freeze({ + SecondItemListQuery: schema("SecondItemListQuery", "route-search", "REQUEST"), SecondItemParams: schema("SecondItemParams", "api-request", "REQUEST"), SecondItemRequest: schema("SecondItemRequest", "api-request", "REQUEST"), SecondItemPayload: schema("SecondItemPayload", "api-response", "RESPONSE"), }), runtimeSchemas: Object.freeze({ + SecondItemListQuery: codec("SecondItemListQuery"), SecondItemParams: codec("SecondItemParams"), SecondItemRequest: codec("SecondItemRequest"), SecondItemPayload: codec("SecondItemPayload"), @@ -109,7 +137,7 @@ export const FEATURE_CONTEXT_ID = "${CONTEXT_ID}"; export const FEATURE_MODULE = defineFeatureModule({ id: FEATURE_MODULE_ID, contracts: SECOND_API_CONTRACT, - routes: {}, + routes: SECOND_API_CONTRACT.routes, messages: {}, loadRuntime: async () => (await import("./feature-runtime.ts")).FEATURE_RUNTIME, } as const); @@ -147,7 +175,7 @@ afterAll(async () => { await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true }))); }); -describe("adding a feature with an API operation (F-3, 09-07)", () => { +describe("adding a feature with an API operation and a route (F-3, 09-07, 0929/07-03)", () => { it("passes check-registries without edits outside the feature and its context", async () => { const root = await mkdtemp(path.join(tmpdir(), "second-api-feature-")); roots.push(root); @@ -195,5 +223,10 @@ describe("adding a feature with an API operation (F-3, 09-07)", () => { ) as { registries: { registryId: string; rows: Record }[] }; const api = report.registries.find(({ registryId }) => registryId === "FE-REG-API"); expect(Object.keys(api?.rows ?? {})).toContain("GET_SECOND_ITEM"); + const routes = report.registries.find(({ registryId }) => registryId === "FE-REG-ROUTE"); + expect(routes?.rows.SECOND_ITEM_LIST).toMatchObject({ + searchSchema: "SecondItemListQuery", + loadingSurface: "second-item-list", + }); }, 60_000); });