fix(registry): 기능 라우트를 추가해도 governance를 고치지 않게 한다 (0929/07-03)

문제
FE-REG-ROUTE governance가 paramsSchema·searchSchema·loadingSurface를 참조
기능 값까지 적은 닫힌 목록으로 둔다. 기능이 자기 search 스키마나 자기
로딩 화면 이름을 가진 라우트를 더하면 check:registries가 "has unknown
value"로 실패하고, 템플릿 소유 파일인 registry-governance.json을 고쳐야
한다. 목록은 contract 일부라 고치면 breaking 증거나 재승인도 필요하다.
두 다운스트림 모두 여기서 충돌했다. 스키마 id는 이미 references가
FE-REG-SCHEMA와 대조하므로 목록은 같은 사실의 세 번째 사본이고,
loadingSurface는 data-surface 속성 말고 읽는 코드가 없다. 문서는
"governance file do not change"라고 적지만 그 약속을 고정하는 테스트는
라우트 없는 기능만 넣었다.

고른 방법 (2026-11-03 결정, 리뷰 (B))
- paramsSchema·searchSchema를 FE-REG-ROUTE allowedValues에서 뺐다.
  references 검사는 그대로라 등록되지 않은 스키마 id는 계속 실패한다.
- loadingSurface는 목록 대신 이름 형식만 본다. governance에 선언형 키
  fieldPatterns(필드 → 고정된 정규식)를 더하고 check-registries가 문자열
  값을 대조한다. FE-REG-ROUTE는 kebab-case
  ^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$를 쓴다. fieldPatterns는 선언한
  레지스트리에서만 contract 스냅샷에 들어가므로 다른 레지스트리의
  contract는 바뀌지 않고, 정규식을 바꾸면 contract 변경(breaking)으로
  잡힌다.
- second-api-feature-registries 테스트의 두 번째 기능에 자기 search 스키마
  (SecondItemListQuery)와 전용 loading surface(second-item-list)를 가진
  라우트를 넣었다. 저장소 사본에 기능 디렉터리와 context만 더하고
  check-registries가 PASS인지 본다. 지시의 two-feature-install-typecheck는
  app 타입 검사만 돌려 governance를 보지 않으므로, check-registries를 돌리는
  이 테스트를 확장했다.
- 라우트 fixture(check:routes:fixture)의 governance도 같은 모양으로 바꾸고,
  형식에 맞지 않는 이름("Unknown loading")이 거절되는 단위 테스트를 더했다.
- starter-experience.md가 이 테스트를 가리키고, 라우트의 스키마·로딩 화면이
  governance 수정 없이 들어가는 이유를 적는다.
- 두 contract 변경(allowedValues 축소, fieldPatterns 추가)은 breaking이다.
  이 커밋에서는 증거 2건으로 게이트를 통과시키고, 기준선 재승인은 이번
  작업 묶음 끝에서 한 번에 한다.

이유: 기능 하나를 추가할 때 템플릿 파일을 고치게 만드는 지점이다. 두
다운스트림 모두에서 충돌했다.

버린 대안
- 문서만 "allowlist를 고치고 증거를 쓴다"로 정정: 기능마다 비용이
  반복된다.
- 기능 계약이 자기 allowlist 값을 기여하는 확장 메커니즘: 등록 규약이
  하나 더 생긴다.

위험·한계
- loadingSurface 오타는 이제 형식만 맞으면 통과한다. 이 값은 로딩
  요소의 data-surface 속성일 뿐이라 동작이 바뀌지 않는다. loadingSurface가
  로딩 컴포넌트 선택 같은 실행 의미를 갖게 되면 닫힌 목록을 다시 둔다.
- errorSurface·access는 라우터가 의미로 읽으므로 닫힌 목록을 유지한다.
  기능이 새 errorSurface를 쓰려면 지금처럼 governance를 고친다.
- 다운스트림은 다음 동기화에서 자기가 이 목록에 더한 값을 지운다.
  CHANGELOG [계약] 행이 필요하다.

검증
- RED(수정 전): 확장한 second-api-feature-registries 테스트가
  "FE-REG-ROUTE.SECOND_ITEM_LIST.searchSchema has unknown value
  SecondItemListQuery", "...loadingSurface has unknown value
  second-item-list"로 실패. 새 형식 테스트는 수정 전 checker로
  "expected [] to deeply equal [ Array(1) ]"로 실패.
- GREEN: 두 테스트 통과. 증거 없이 check-registries는 "breaking change
  missing evidence" 2건(allowedValues contract-field-changed,
  fieldPatterns contract-field-added)으로 실패, 증거를 넣은 뒤
  "11 registries PASS".
- 회귀: registry-compatibility·registry-governance·second-api-feature-
  registries·release-artifacts·two-feature-install-typecheck 57/57.
  compatibility fixtures 11 PASS. check:routes:fixture는 기대대로
  "duplicates routeId=DUPLICATE"로 실패. verify-documentation-readiness
  PASS_SCOPED. tsc node·test rc=0, 바꾼 파일 eslint rc=0.
- 미실행: check:architecture, test:sample-removal(pnpm 필요).

Refs: docs/reviews/2026-09-29-maturity-review/07-contracts.md
This commit is contained in:
DongHyeonka
2026-11-03 00:55:33 +09:00
parent 4ada84e1ec
commit e8d7fb427f
8 changed files with 124 additions and 17 deletions
@@ -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"
}
]
}
+3 -11
View File
@@ -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",
+6
View File
@@ -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
+22
View File
@@ -50,6 +50,8 @@ type RegistrySpecification = Readonly<{
uniqueFieldSets?: readonly (readonly string[])[];
snapshotProjection?: RegistrySnapshotProjection;
allowedValues?: Readonly<Record<string, readonly unknown[]>>;
/** Field name to an anchored regular expression its string value matches. */
fieldPatterns?: Readonly<Record<string, string>>;
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 }
: {}),
+3 -1
View File
@@ -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",
+1 -1
View File
@@ -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",
},
+31
View File
@@ -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 });
}
});
});
@@ -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<string, unknown> }[] };
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);
});