tscircuit / tscircuit/core

group emits null anchor_alignment and subcircuit_id, failing circuit-json validation

Open Beginner friendly
#2,845 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
58
Forks
203
Avg merge
7h 39m
Merged PRs (30d)
286

Description

What happens

<group /> emits two fields as null where circuit-json accepts a string or nothing, so the elements fail validation:

<board width="30mm" height="30mm">
  <group name="G1" pcbX={4}>
    <resistor name="R1" resistance="1k" footprint="0402" />
  </group>
</board>
pcb_group:       anchor_alignment: Expected 'top_left' | ... , received null
schematic_group: subcircuit_id: Expected string, received null
Cause

Both are explicit nulls written at insert time:

// lib/components/primitive-components/Group/Group.ts:468
anchor_alignment: props.pcbAnchorAlignment ?? null,

// lib/components/primitive-components/Group/Group.ts:1590
subcircuit_id: this.subcircuit_id!,   // the field is `string | null = null`

The schemas are:

pcb_group.anchor_alignment  →  ninePointAnchor.default("center")
schematic_group.subcircuit_id  →  z.string().optional()

So undefined is correct in both cases — and for anchor_alignment it's strictly better than null, because omitting it lets the schema's own "center" default apply instead of storing a value the schema rejects.

A group placed outside any subcircuit legitimately has no subcircuit_id; the ! assertion just hid that it was null rather than a string.

These were already baked into expectations

Three existing tests record the invalid values, which is why nothing caught it:

  • tests/groups/group-outline.test.tsx"anchor_alignment": null
  • tests/components/primitive-components/group-subcircuit-id.test.tsx"anchor_alignment": null
  • tests/groups/group-schematic-box.test.tsx"subcircuit_id": null
Context

Third and final batch from validating core's output against circuit-json's own schemas (see #2841 for display_offset_x/y, #2843 for the hole elements). With this, <group /> no longer contributes schema violations.

PR ready.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/components/primitive-components/Group/Group.ts at the two insertion sites identified in the issue, then review the expected values in tests/groups/group-outline.test.tsx, tests/components/primitive-components/group-subcircuit-id.test.tsx, and tests/groups/group-schematic-box.test.tsx. Run those tests and circuit-JSON validation; done means a bare group emits no rejected null fields and all expectations pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.