From e2940da418adc77b5fb36f903db36ac06665c0c8 Mon Sep 17 00:00:00 2001 From: Valentino Zegna Date: Tue, 1 Dec 2026 14:18:11 -0800 Subject: [PATCH] test: export_design's refusal of a pin on two nets is checked on two real designs labcomm-projecton and scr-236 join the fixtures. Neither can have a golden, so the golden test and gen-golden skip a design with a pin on several nets. --- scripts/AGENTS.md | 2 +- scripts/gen-golden.ts | 6 ++++++ src/cli/export-design.test.ts | 28 ++++++++++++++++++++++++++++ test/fixtures | 2 +- test/integration/golden.test.ts | 4 ++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/scripts/AGENTS.md b/scripts/AGENTS.md index 0e78ffc1..608bd96e 100644 --- a/scripts/AGENTS.md +++ b/scripts/AGENTS.md @@ -22,7 +22,7 @@ node --import tsx scripts/gen-golden.ts --all - `format`: `cadence` or `altium` - `name`: output file name (without the `.netlist.json` suffix) - `path`: path to the design file (.DSN, .PrjPcb, or pstxnet.dat) -- `--all`: regenerate all golden files from discovered fixtures. A fixture the parsers refuse, listed in `UNSUPPORTED_FIXTURES` in `test/utils.ts`, is skipped: it has no golden, and the golden test checks its refusal instead +- `--all`: regenerate all golden files from discovered fixtures. A fixture the parsers refuse, listed in `UNSUPPORTED_FIXTURES` in `test/utils.ts`, is skipped: it has no golden, and the golden test checks its refusal instead. A design with a pin on several nets (`labcomm-projecton`, `scr-236`) is skipped too, in both modes: a Universal Netlist gives each pin one net, so no golden can hold it, and `src/cli/export-design.test.ts` checks that `export_design` refuses it A golden is only rewritten when its content actually moved. The tests compare structurally, so a parser that merely reorders the keys it writes would diff --git a/scripts/gen-golden.ts b/scripts/gen-golden.ts index 38224daa..3df9484d 100644 --- a/scripts/gen-golden.ts +++ b/scripts/gen-golden.ts @@ -1,6 +1,7 @@ #!/usr/bin/env -S node --import tsx import path from "node:path"; import { parseDesign } from "../src/parsers/index.js"; +import { exportRefusal } from "../src/cli/export-design.js"; import { parseCadenceDatDesign } from "../src/parsers/cadence/index.js"; import { findCadenceDatFiles } from "../src/parsers/cadence/discovery.js"; import { @@ -37,6 +38,11 @@ const generateOne = async (format: Format, name: string, designPath: string): Pr console.log( ` Components: ${Object.keys(result.components).length}, Nets: ${Object.keys(result.nets).length}` ); + // A design with a pin on several nets has no golden: the file cannot hold it. + if (exportRefusal(result) !== undefined) { + console.log(` Skipped: ${format}/${name} (a pin is on several nets)`); + return false; + } const written = await saveGolden(format, name, result, parsePath); console.log( written diff --git a/src/cli/export-design.test.ts b/src/cli/export-design.test.ts index 23e2bb6e..f5e0ea32 100644 --- a/src/cli/export-design.test.ts +++ b/src/cli/export-design.test.ts @@ -257,6 +257,34 @@ describe("export_design refuses a design the file cannot hold", () => { }, PARSE_TIMEOUT ); + + it.skipIf(!hasFixtures).each([ + [ + "wired to two nets", + ["cadence", "labcomm-projecton", "LABCOMM_PROJECTON.DSN"], + "U10.4 is on 2 nets (+10V, N5769); U10.11 is on 2 nets (-10V, N5793). ", + ], + [ + "wired on one section and unconnected on another", + ["cadence", "scr-236", "SCR-236.dsn"], + "U9.14 is on IN_VCC and also left unconnected; U9.7 is on GND_PT_IN and also left unconnected; U11.14 is on IN_VCC and also left unconnected; U11.7 is on GND_PT_IN and also left unconnected. ", + ], + ])( + "refuses a real design with a pin %s", + async (_case, fixture, pins) => { + const out = path.join(dir, "refused.netlist.json"); + + const outcome = await exportDesign(fixturePath(...fixture), "--output", out); + + expect(outcome.exitCode).toBe(1); + expect(JSON.parse(outcome.stdout!).error).toBe( + pins + + "A Universal Netlist gives each pin one net, so this design cannot be exported until each pin is wired to one net." + ); + expect(existsSync(out)).toBe(false); + }, + PARSE_TIMEOUT + ); }); describe.skipIf(!hasFixtures)("export_design on a design with named variants", () => { diff --git a/test/fixtures b/test/fixtures index e92bc3ec..34f06103 160000 --- a/test/fixtures +++ b/test/fixtures @@ -1 +1 @@ -Subproject commit e92bc3ec1d621176bbc52412631364e460493f07 +Subproject commit 34f0610384da3d416ed85d2e64c52e10489a4bbf diff --git a/test/integration/golden.test.ts b/test/integration/golden.test.ts index c8ea98c1..082b8d40 100644 --- a/test/integration/golden.test.ts +++ b/test/integration/golden.test.ts @@ -11,6 +11,7 @@ * 4. Commit the golden JSON file to test/golden/{format}/{name}.netlist.json */ +import { exportRefusal } from "../../src/cli/export-design.js"; import path from "node:path"; import { describe, it, expect } from "vitest"; import { @@ -102,6 +103,9 @@ describe("Parser Golden Output", { timeout: PARSE_TIMEOUT }, async () => { it("should match golden output", async () => { const golden = await loadGolden(fixture.format, projectName); + // A design with a pin on several nets has no golden: the file cannot hold it. + if (!golden && exportRefusal(await parseDesign(designFile)) !== undefined) return; + if (!golden) { throw new Error( `Missing golden output for ${fixture.format}/${projectName}. ` +