diff --git a/docs/manual/reference/errors.md b/docs/manual/reference/errors.md index 4cf83d62..8397a68f 100644 --- a/docs/manual/reference/errors.md +++ b/docs/manual/reference/errors.md @@ -144,6 +144,7 @@ lint / check:architecture / check:i18n → FE-GATE-002, FE-GATE-010 | `FE-REG-ROUTE.. has unknown value ` | `access`·`errorSurface`가 정해진 값이 아니다 | 계약 `routes` | | `FE-REG-ROUTE..paramsSchema references unknown FE-REG-SCHEMA.schemaId=` | 라우트 스키마 ID를 기능이 등록하지 않았다 (`searchSchema`도 같은 꼴) | 계약 스키마 메타 | | `FE-REG-API. has no executable consumer for operationId=` | 계약의 operation을 기능 `adapters/`·`application/`에서 쓰지 않는다 | 쓰지 않으면 descriptor를 지운다 | +| `missing registry source : (reason: )` | 레지스트리 source를 읽다가 오류가 났다. 계약 조립 실패면 ``이 위 `reason` 표의 값이다. 읽지 못한 레지스트리는 `removed` 증거를 요구하지 않는다 | ``이 가리키는 곳 | | `breaking change missing evidence: ` | 행을 빼거나 바꿨는데 승인이 없다 | `update:registry-baseline` 또는 `config/contracts/registry-change-evidence.json` | | `stale breaking evidence : no breaking change in the current diff has this changeId. ...` | 지금 diff와 맞지 않는 증거 행 | 그 행을 지운다 | | `registry baseline approval digest mismatch: approved= actual=` | 기준선 파일을 손으로 고쳤다 | `update:registry-baseline`으로 다시 찍는다 | diff --git a/scripts/check-registries.ts b/scripts/check-registries.ts index b34bba0c..73c3c11d 100644 --- a/scripts/check-registries.ts +++ b/scripts/check-registries.ts @@ -116,6 +116,13 @@ const owners = new Map(); const snapshots: RegistrySnapshot[] = []; const rowsByRegistry = new Map(); const sourcesByRegistry = new Map(); +/** + * 1103/14-06. Registries whose source did not load. Their failure is already + * reported with its cause, so the checks that read their rows (references, + * the baseline comparison) skip them instead of reporting the same failure + * again as a deleted registry. + */ +const unloadedRegistries = new Set(); const registryExtensions = [".ts", ".tsx", ".mts", ".cts"]; async function resolveRegistrySource( @@ -144,6 +151,33 @@ async function resolveRegistrySource( return candidates[0] ?? null; } +/** + * 1103/14-06. A contract composition failure (`ContractContributionError`) + * says only "not composable"; its cause is the `reason` property. + */ +function loadErrorText(error: Error): string { + const message = error.message.split("\n")[0] ?? ""; + const reason: unknown = (error as Error & { reason?: unknown }).reason; + return typeof reason === "string" && reason.length > 0 + ? `${message} (reason: ${reason})` + : message; +} + +function withoutRegistries( + snapshot: Readonly>, + registryIds: ReadonlySet, +): Readonly> { + if (registryIds.size === 0 || !Array.isArray(snapshot.registries)) { + return snapshot; + } + return { + ...snapshot, + registries: (snapshot.registries as Array<{ registryId?: unknown }>).filter( + (registry) => !registryIds.has(String(registry.registryId)), + ), + }; +} + type FieldLookup = Readonly<{ found: boolean; value: unknown; @@ -371,8 +405,12 @@ for (const specification of governance.registries) { } catch (error) { // A source that exists but fails to load names its error, so a broken // import in a feature contract is not reported as a missing file. - const reason = sourcePath && error instanceof Error ? `: ${error.message.split("\n")[0]}` : ""; - if (!rows) failures.push(`missing registry source ${specification.path}${reason}`); + const reason = sourcePath && error instanceof Error ? `: ${loadErrorText(error)}` : ""; + if (!rows) { + failures.push(`missing registry source ${specification.path}${reason}`); + unloadedRegistries.add(specification.registryId); + continue; + } } const registryRows = projectRegistryRows(specification, rows); @@ -534,6 +572,7 @@ for (const specification of governance.registries) { for (const reference of specification.references ?? []) { const targetRows = rowsByRegistry.get(reference.registryId); if (!targetRows) { + if (unloadedRegistries.has(reference.registryId)) continue; failures.push( `${specification.registryId} references unknown registry ${reference.registryId}`, ); @@ -672,7 +711,10 @@ if (baselinePath && approvalPath && evidencePath) { `registry baseline approval digest mismatch: approved=${approvalResult.approvedDigest} actual=${approvalResult.actualDigest}`, ); } - const registryDiff = diffRegistrySnapshots(baseline, currentSnapshot); + const registryDiff = diffRegistrySnapshots( + withoutRegistries(baseline, unloadedRegistries), + currentSnapshot, + ); compatibility = registryDiff; const evidence = JSON.parse( await readFile(evidencePath, "utf8"), diff --git a/tests/unit/registry-governance.test.ts b/tests/unit/registry-governance.test.ts index 8c2e0586..e038d441 100644 --- a/tests/unit/registry-governance.test.ts +++ b/tests/unit/registry-governance.test.ts @@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest"; import { diffRegistrySnapshots, + registrySnapshotDigest, validateBreakingEvidence, verifyRegistryBaselineApproval, } from "../../scripts/lib/registry-compatibility.ts"; @@ -536,4 +537,115 @@ describe("registry governance manifest", () => { await rm(directory, { recursive: true, force: true }); } }); + + // 1103/14-06. A contract contribution that fails to compose throws while + // the registry source loads. The gate names the cause the error carries in + // `reason` and does not also report the unloaded registries as deleted + // (`removed` evidence) or as unknown reference targets. + it("names a load error's reason and reports no cascade for the registries it did not load", async () => { + const directory = await mkdtemp(path.join(tmpdir(), "registry-source-reason-")); + const run = (extra: readonly string[]) => + spawnSync( + process.execPath, + [ + path.resolve("scripts/check-registries.ts"), + "--governance", + "governance.json", + "--artifact", + "out.json", + ...extra, + ], + { cwd: directory, encoding: "utf8" }, + ); + try { + await mkdir(path.join(directory, "src"), { recursive: true }); + await writeFile( + path.join(directory, "src/composed.ts"), + 'export const ROWS = { A: { id: "A" } };\n', + ); + await writeFile( + path.join(directory, "src/routes.ts"), + 'export const ROUTES = { R: { id: "R", target: "A" } };\n', + ); + await writeFile( + path.join(directory, "governance.json"), + JSON.stringify({ + schemaVersion: 1, + sourceDirectories: [], + registries: [ + { + registryId: "FIXTURE-COMPOSED", + path: "src/composed.ts", + exportName: "ROWS", + owner: "fixture", + keyField: "id", + requiredFields: ["id"], + fieldTypes: { id: "string" }, + }, + { + registryId: "FIXTURE-ROUTES", + path: "src/routes.ts", + exportName: "ROUTES", + owner: "fixture", + keyField: "id", + requiredFields: ["id", "target"], + fieldTypes: { id: "string", target: "string" }, + references: [ + { + field: "target", + registryId: "FIXTURE-COMPOSED", + targetField: "id", + }, + ], + }, + ], + }), + ); + const healthy = run(["--no-baseline"]); + expect(healthy.status, healthy.stderr).toBe(0); + const report = JSON.parse( + await readFile(path.join(directory, "out.json"), "utf8"), + ) as { registries: unknown[] }; + const baseline = { schemaVersion: 2, registries: report.registries }; + await writeFile(path.join(directory, "baseline.json"), JSON.stringify(baseline)); + await writeFile( + path.join(directory, "approval.json"), + JSON.stringify({ + schemaVersion: 1, + snapshotDigest: registrySnapshotDigest(baseline), + owner: "fixture", + reason: "fixture", + approvedAt: "2026-11-04T00:00:00.000Z", + }), + ); + await writeFile( + path.join(directory, "evidence.json"), + JSON.stringify({ schemaVersion: 1, changes: [] }), + ); + const withBaseline = [ + "--baseline", + "baseline.json", + "--approval", + "approval.json", + "--compatibility-evidence", + "evidence.json", + ]; + expect(run(withBaseline).status).toBe(0); + + await writeFile( + path.join(directory, "src/composed.ts"), + 'throw Object.assign(new Error("Installed contract contribution is not composable"), { reason: "notice-feature/NOTICE_LIST_ITEMS: unknown authProfileId NOTICE_NOPE" });\n', + ); + const broken = run(withBaseline); + const output = `${broken.stdout}${broken.stderr}`; + + expect(broken.status).toBe(1); + expect(output.trim().split("\n")).toEqual([ + "Registry governance failed:", + "missing registry source src/composed.ts: Installed contract contribution is not composable (reason: notice-feature/NOTICE_LIST_ITEMS: unknown authProfileId NOTICE_NOPE)", + ]); + } finally { + await rm(directory, { recursive: true, force: true }); + } + }); });