Skip to content

Add maxViaCount constraint to trace props - #781

Merged
seveibar merged 1 commit into
mainfrom
agent/add-trace-max-via-count
Aug 4, 2026
Merged

Add maxViaCount constraint to trace props#781
seveibar merged 1 commit into
mainfrom
agent/add-trace-max-via-count

Conversation

@seveibar

@seveibar seveibar commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What changed

  • add an optional maxViaCount prop to <trace>
  • accept only non-negative integer limits
  • add parsing coverage for zero, negative, and fractional values

Why

RF, clock, and other critical PCB traces often need an explicit via budget. For example, maxViaCount={0} lets a design state that an antenna matching or feed trace must remain on one layer instead of relying on autorouter heuristics.

The prop is optional and has no default, so existing routing behavior is unchanged.

Follow-up implementation

Core should pass this constraint into circuit-json, and the autorouter should reject routes whose via count exceeds the limit. If no valid route exists, routing should fail with a constraint-specific error instead of silently inserting a via.

Validation

  • bun test tests/trace.test.ts
  • bun run typecheck
  • bun run build
  • bun run format:check
  • required generated-document scripts (no generated diff)

@seveibar
seveibar marked this pull request as ready for review August 4, 2026 01:27
@seveibar
seveibar merged commit 781328e into main Aug 4, 2026
5 checks passed
Comment thread tests/trace.test.ts
Comment on lines +92 to +104
test("supports limiting the maximum number of PCB vias", () => {
const raw: TraceProps = {
from: "A",
to: "B",
maxViaCount: 0,
}

const parsed = traceProps.parse(raw)

expect(parsed.maxViaCount).toBe(0)
expect(() => traceProps.parse({ ...raw, maxViaCount: -1 })).toThrow()
expect(() => traceProps.parse({ ...raw, maxViaCount: 1.5 })).toThrow()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style guide states that a *.test.ts file may have AT MOST one test(...) call. This new test block ("supports limiting the maximum number of PCB vias") is being added to trace.test.ts, which already contains at least one other test(...) (e.g., the "accepts start/end aliases for trace endpoints" test at line 92/106, and others visible earlier in the file). Once a file has more than one test, the tests must be split into multiple numbered files — for example, trace1.test.ts, trace2.test.ts, etc. Please move this new test into its own numbered file (e.g., trace2.test.ts or an appropriate number) to comply with the one-test-per-file rule.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tscircuitbot

Copy link
Copy Markdown
Contributor

Thank you for your contribution! 🎉

PR Rating: ⭐⭐
Impact: Minor

Track your contributions and see the leaderboard at: tscircuit Contribution Tracker


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants