fix: make hole circuit json parse against circuit-json schemas (#2843)#2844
fix: make hole circuit json parse against circuit-json schemas (#2843)#2844DPS0340 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
2a44052 to
1096444
Compare
|
Housekeeping — rebased onto current Since I have several PRs open here now, a note on how they interact so none of this lands on you: Five of the seven are fully independent — they touch different files and merge in any order:
Two pairs conflict, and both are trivial:
Happy to do the merge myself: say the word and I'll combine any subset into a single PR, or rebase the losers as soon as the first one lands. I'd rather you not spend time on conflict resolution for my changes. I verified the above rather than assuming it — checked all 21 branch pairs for conflicts and confirmed each rebases cleanly onto |
1096444 to
b10de27
Compare
Closes #2843.
Two independent defects that both make core emit circuit JSON which fails
any_circuit_element.parse().1.
pcb_component_id: nullon board-level holesPrimitiveComponentinitialises ids tonull(pcb_component_id: string | null = null), and the holes resolve their owner with??, which only falls through onundefined. A hole inside a footprint has an owner; one placed directly on the board doesn't, sonullreached circuit JSON — and every id on these schemas isz.string().optional(), which rejectsnull.Isolated it before fixing, so the diagnosis isn't a guess:
Fixed with a small
optionalIdhelper at the two sites where the schema actually permits an absent id.2.
circular_hole_with_rect_padmissinghole_shape/pad_shapeFound while verifying the first fix — the test still failed, and the culprit was a different element. That schema variant requires both fields:
PlatedHole.tsomitted them at that one insertion site while the neighbouring pill variants in the same file already set them, so I matched the existing pattern. A plain<chip footprint="dip8" />was enough to trigger this.Deliberately out of scope
The sweep also found
pcb_silkscreen_textandpcb_fabrication_note_textcarryingpcb_component_id: null. I tried the same normalisation there andtscrejected it — those schemas require a non-optional string. That makes it a design question (what should a board-level silkscreen text reference?) rather than a null→undefined fix, so I reverted it and reported it in #2843 instead of guessing.Verification
The test bites. Reverting
Hole.ts+PlatedHole.ts:The test asserts both directions: board-level holes have no id, footprint holes keep theirs (
typeof === "string"), and every hole passesany_circuit_element.safeParse. So it can't be satisfied by blanket-clearing the field.Suite:
1260 pass / 0 fail,tsc --noEmit0 errors,biome formatclean.One inline snapshot changed —
plated-hole-pill-rotated2had"pcb_component_id": nullrecorded, i.e. the bug was captured in an expectation. It now readsundefined.Worth noting how this was found: validating core's own output against
circuit-json's exported schemas across several board shapes. It's cheap and it also surfacedpcb_group.anchor_alignment: nullandschematic_group.subcircuit_id: null, which I've left for separate triage.