From bfd9d50d2bdd205520865f093bcabfe5a9a651ec Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:06:33 +0900 Subject: [PATCH] =?UTF-8?q?fix(registries):=20=EA=B3=84=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=EB=A6=BD=20=EC=8B=A4=ED=8C=A8=EC=9D=98=20=EC=9B=90?= =?UTF-8?q?=EC=9D=B8=EC=9D=84=20check:registries=EC=97=90=20=ED=95=9C=20?= =?UTF-8?q?=EB=B2=88=EB=A7=8C=20=EC=B0=8D=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 계약 조립이 실패하면 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 --- docs/manual/reference/errors.md | 2 +- scripts/check-registries.ts | 10 +++-- tests/unit/registry-governance.test.ts | 62 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/docs/manual/reference/errors.md b/docs/manual/reference/errors.md index 5ba0d59e..c0461617 100644 --- a/docs/manual/reference/errors.md +++ b/docs/manual/reference/errors.md @@ -151,7 +151,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` 증거를 요구하지 않는다 | ``이 가리키는 곳 | +| `missing registry source : ` | 레지스트리 source를 읽다가 오류가 났다. 계약 조립 실패면 ``가 `Installed contract contribution is not composable: `이고 ``이 위 `reason` 표의 값이다. 다른 오류가 `reason` 속성을 message와 따로 가지면 끝에 ` (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 73c3c11d..313ababb 100644 --- a/scripts/check-registries.ts +++ b/scripts/check-registries.ts @@ -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; } diff --git a/tests/unit/registry-governance.test.ts b/tests/unit/registry-governance.test.ts index e038d441..e9541785 100644 --- a/tests/unit/registry-governance.test.ts +++ b/tests/unit/registry-governance.test.ts @@ -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 }); + } + }); });