fix(registries): 계약 조립 실패의 원인을 check:registries에 한 번만 찍는다

문제: 계약 조립이 실패하면 check:registries 출력에 같은 원인이 두 번
나온다. 1103/09-07 수정이 ContractContributionError의 message 끝에
reason을 붙였고, 1103/14-06 수정이 loadErrorText에서 message 뒤에
"(reason: ...)"를 또 붙였다. 두 수정이 다른 브랜치에서 들어왔다.
기존 테스트는 reason이 message에 없는 가짜 오류로만 시험해 중복을
보지 못했다.

고른 방법: loadErrorText가 message에 reason이 이미 들어 있으면 붙이지
않는다. reason을 message에 싣지 않는 오류(기존 테스트의 가짜 오류)는
지금처럼 "(reason: ...)"가 붙는다. 버린 대안: ContractContributionError
message에서 reason을 다시 빼는 것. message만 찍는 다른 출구(부팅 오류,
테스트 출력)가 원인을 잃는다(1103/09-07이 고친 문제).

위험·한계: message 첫 줄만 보므로 여러 줄 reason은 다시 붙는다. 지금
reason은 한 줄이다. docs/manual/reference/errors.md의 출력 형식 줄을
실제 출력에 맞췄다.

검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/registry-governance.test.ts
새 테스트는 실제 ContractContributionError를 던지는 source로
check:registries를 돌려 원인이 한 번만 나오는지 본다.

Refs: 1105/09-03
This commit is contained in:
DongHyeonka
2026-11-05 22:06:33 +09:00
parent e85c8361b6
commit bfd9d50d2b
3 changed files with 70 additions and 4 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ lint / check:architecture / check:i18n → FE-GATE-002, FE-GATE-010
| `FE-REG-ROUTE.<ROUTE_ID>.<field> has unknown value <value>` | `access`·`errorSurface`가 정해진 값이 아니다 | 계약 `routes` |
| `FE-REG-ROUTE.<ROUTE_ID>.paramsSchema references unknown FE-REG-SCHEMA.schemaId=<id>` | 라우트 스키마 ID를 기능이 등록하지 않았다 (`searchSchema`도 같은 꼴) | 계약 스키마 메타 |
| `FE-REG-API.<operationId> has no executable consumer for operationId=<operationId>` | 계약의 operation을 기능 `adapters/`·`application/`에서 쓰지 않는다 | 쓰지 않으면 descriptor를 지운다 |
| `missing registry source <path>: <message> (reason: <reason>)` | 레지스트리 source를 읽다가 오류가 났다. 계약 조립 실패면 `<reason>`이 위 `reason` 표의 값이다. 읽지 못한 레지스트리는 `removed` 증거를 요구하지 않는다 | `<reason>`이 가리키는 곳 |
| `missing registry source <path>: <message>` | 레지스트리 source를 읽다가 오류가 났다. 계약 조립 실패면 `<message>`가 `Installed contract contribution is not composable: <reason>`이고 `<reason>`이 위 `reason` 표의 값이다. 다른 오류가 `reason` 속성을 message와 따로 가지면 끝에 ` (reason: <reason>)`이 붙는다. 읽지 못한 레지스트리는 `removed` 증거를 요구하지 않는다 | `<reason>`이 가리키는 곳 |
| `breaking change missing evidence: <changeId>` | 행을 빼거나 바꿨는데 승인이 없다 | `update:registry-baseline` 또는 `config/contracts/registry-change-evidence.json` |
| `stale breaking evidence <changeId>: no breaking change in the current diff has this changeId. ...` | 지금 diff와 맞지 않는 증거 행 | 그 행을 지운다 |
| `registry baseline approval digest mismatch: approved=<digest> actual=<digest>` | 기준선 파일을 손으로 고쳤다 | `update:registry-baseline`으로 다시 찍는다 |
+7 -3
View File
@@ -152,13 +152,17 @@ async function resolveRegistrySource(
}
/**
* 1103/14-06. A contract composition failure (`ContractContributionError`)
* says only "not composable"; its cause is the `reason` property.
* 1103/14-06. A load error's cause may be only in its `reason` property, so
* it is printed after the message. 1105/09-03. `ContractContributionError`
* already ends its message with the reason (1103/09-07); that cause is
* printed once.
*/
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
return typeof reason === "string" &&
reason.length > 0 &&
!message.includes(reason)
? `${message} (reason: ${reason})`
: message;
}
+62
View File
@@ -2,6 +2,7 @@ import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { describe, expect, it } from "vitest";
import {
@@ -648,4 +649,65 @@ describe("registry governance manifest", () => {
await rm(directory, { recursive: true, force: true });
}
});
// 1105/09-03. The real composition error already ends its message with the
// reason (1103/09-07). The gate prints that cause once, not again in
// `(reason: ...)`.
it("names a ContractContributionError's reason once", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "registry-source-real-error-"));
const errorModule = pathToFileURL(
path.resolve("src/contracts/external-contract-runtime.ts"),
).href;
try {
await mkdir(path.join(directory, "src"), { recursive: true });
await writeFile(
path.join(directory, "src/composed.ts"),
[
`import { ContractContributionError } from ${JSON.stringify(errorModule)};`,
'throw new ContractContributionError("notice-feature/NOTICE_LIST_ITEMS: unknown authProfileId NOTICE_NOPE");',
"",
].join("\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" },
},
],
}),
);
const result = spawnSync(
process.execPath,
[
path.resolve("scripts/check-registries.ts"),
"--governance",
"governance.json",
"--artifact",
"out.json",
"--no-baseline",
],
{ cwd: directory, encoding: "utf8" },
);
const output = `${result.stdout}${result.stderr}`;
expect(result.status).toBe(1);
expect(output).toContain(
"missing registry source src/composed.ts: Installed contract contribution is not composable: notice-feature/NOTICE_LIST_ITEMS: unknown authProfileId NOTICE_NOPE\n",
);
expect(output.split("unknown authProfileId NOTICE_NOPE")).toHaveLength(2);
expect(output).not.toContain("(reason:");
} finally {
await rm(directory, { recursive: true, force: true });
}
});
});