diff --git a/scripts/check-registries.ts b/scripts/check-registries.ts index 347000d3..b34bba0c 100644 --- a/scripts/check-registries.ts +++ b/scripts/check-registries.ts @@ -368,8 +368,11 @@ for (const specification of governance.registries) { `${pathToFileURL(path.resolve(sourcePath)).href}?registry-check=${Date.now()}` )) as Record; rows = registryModule[specification.exportName]; - } catch { - if (!rows) failures.push(`missing registry source ${specification.path}`); + } 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 registryRows = projectRegistryRows(specification, rows); diff --git a/tests/unit/registry-governance.test.ts b/tests/unit/registry-governance.test.ts index 3f547496..8c2e0586 100644 --- a/tests/unit/registry-governance.test.ts +++ b/tests/unit/registry-governance.test.ts @@ -484,4 +484,56 @@ describe("registry governance manifest", () => { await rm(directory, { recursive: true, force: true }); } }); + + it("names the load error of a registry source that exists but fails to import", async () => { + const directory = await mkdtemp(path.join(tmpdir(), "registry-source-error-")); + try { + await mkdir(path.join(directory, "src"), { recursive: true }); + await writeFile( + path.join(directory, "src/broken.ts"), + 'import { missingExport } from "./absent.ts";\nexport const ROWS = [missingExport];\n', + ); + await writeFile(path.join(directory, "src/absent.ts"), "export const other = 1;\n"); + await writeFile( + path.join(directory, "governance.json"), + JSON.stringify({ + schemaVersion: 1, + sourceDirectories: [], + registries: [ + { + registryId: "FIXTURE-BROKEN", + path: "src/broken.ts", + exportName: "ROWS", + owner: "fixture", + requiredFields: ["id"], + uniqueFields: ["id"], + }, + ], + compatibilityImpact: { + allowed: ["none", "additive", "behavior-change", "breaking"], + current: "none", + }, + }), + ); + const result = spawnSync( + process.execPath, + [ + path.resolve("scripts/check-registries.ts"), + "--governance", + "governance.json", + "--no-baseline", + "--artifact", + "out.json", + ], + { cwd: directory, encoding: "utf8" }, + ); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "missing registry source src/broken.ts: The requested module './absent.ts' does not provide an export named 'missingExport'", + ); + } finally { + await rm(directory, { recursive: true, force: true }); + } + }); });