Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions tests/repros/repro-fanout-multilayer-edge-capacity.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { expect, test } from "bun:test"
import { Fragment } from "react"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("repro: multilayer breakout edge capacity omits stagger space", async () => {
const { circuit } = getTestFixture()
circuit.add(
<board
width={18}
height={20}
layers={4}
routingDisabled
minTraceWidth={0.15}
minTraceToPadEdgeClearance={0.2}
minViaPadDiameter={0.3}
>
<breakout
name="B1"
pcbY={4}
padding="0.3mm"
fanoutRoutingLayers={["top", "inner1", "inner2", "bottom"]}
>
<chip name="U1" footprint="bga16_grid4x4_p1mm" />
</breakout>
<chip name="U2" footprint="bga16_grid4x4_p1mm" pcbY={-5} />
{Array.from({ length: 16 }, (_, index) => (
<trace
key={`signal_${index}`}
name={`SIGNAL_${index + 1}`}
from={`U1.pin${index + 1}`}
to={`U2.pin${index + 1}`}
/>
))}
{Array.from({ length: 4 }, (_, busIndex) => (
<Fragment key={`bus_${busIndex}`}>
<bus
name={`BUS_${busIndex}`}
connections={Array.from(
{ length: 4 },
(_, pinIndex) => `SIGNAL_${busIndex * 4 + pinIndex + 1}`,
)}
preferredLayers={["top", "inner1", "inner2", "bottom"]}
/>
</Fragment>
))}
<pcbnotetext
text="Multilayer endpoints need stagger space: overflow exits another edge"
pcbY={8}
fontSize={0.3}
/>
</board>,
)
await circuit.renderUntilSettled()
const errors = circuit.db.pcb_autorouting_error.list()
// Snapshot the current rejection even though the other edges have room.
expect(errors).toHaveLength(1)
expect(errors[0]!.message).toContain("need 4.50mm but expose only 4.10mm")
const points = circuit.db.pcb_breakout_point.list()
expect(points).toHaveLength(0)
const group = circuit.db.pcb_group.getWhere({ name: "B1" })!
const minY = group.center.y - group.height! / 2
const bottomPoints = points.filter((point) => Math.abs(point.y - minY) < 0.01)
expect(bottomPoints).toHaveLength(0)
// Mark emitted board-world positions in mm (+X right, +Y up).
for (const point of points) {
circuit.db.pcb_note_rect.insert({
center: { x: point.x, y: point.y },
width: 0.16,
height: 0.16,
stroke_width: 0.05,
layer: "top",
color: "#215bca",
is_filled: true,
})
}
circuit.db.pcb_note_text.insert({
text: `Placed exits: ${points.length}/16 | Boundary planning errors: ${errors.length}`,
anchor_position: { x: 0, y: 7 },
anchor_alignment: "center",
font: "tscircuit2024",
font_size: 0.3,
color: errors.length ? "#c52828" : "#215bca",
layer: "top",
})
await expect(circuit).toMatchPcbSnapshot(import.meta.path, {
backgroundColor: "white",
showPcbGroups: true,
})
})
173 changes: 173 additions & 0 deletions tests/repros/repro-fanout-routed-layer-impact.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { expect, test } from "bun:test"
import {
checkEachPcbTraceNonOverlapping,
checkHoleTraceClearance,
checkPadTraceClearance,
checkPadPadClearance,
checkTracesAreContiguous,
} from "@tscircuit/checks"
import { Fragment } from "react"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("repro: multilayer fanout completes a routed controller link", async () => {
const { circuit } = getTestFixture()
circuit.add(
<board
width={18}
height={20}
layers={4}
minTraceWidth={0.15}
minTraceToPadEdgeClearance={0.1}
minTraceToHoleEdgeClearance={0.1}
minViaPadDiameter={0.3}
>
<breakout
name="B1"
pcbY={4}
padding="0.3mm"
fanoutRoutingLayers={["top", "inner1", "inner2", "bottom"]}
>
<chip name="U1" footprint="bga16_grid4x4_p0.8mm" />
</breakout>
<chip name="U2" footprint="bga16_grid4x4_p0.8mm" pcbY={-5} />
{Array.from({ length: 16 }, (_, index) => (
<trace
key={`signal_${index}`}
name={`SIGNAL_${index + 1}`}
from={`U1.pin${index + 1}`}
to={`U2.pin${index + 1}`}
/>
))}
{Array.from({ length: 4 }, (_, busIndex) => (
<Fragment key={`bus_${busIndex}`}>
<bus
name={`BUS_${busIndex}`}
connections={Array.from(
{ length: 4 },
(_, pinIndex) => `SIGNAL_${busIndex * 4 + pinIndex + 1}`,
)}
preferredLayers={["top", "inner1", "inner2", "bottom"]}
/>
</Fragment>
))}
<pcbnotetext
text="16-signal BGA link | Four layers | Fanout → global routing"
pcbY={9}
fontSize={0.34}
color="#202832"
/>
<pcbnotetext
text="U1 controller"
pcbX={-6}
pcbY={6.5}
fontSize={0.3}
color="#202832"
/>
<pcbnotetext
text="BGA16 | 0.8mm"
pcbX={-6}
pcbY={6}
fontSize={0.27}
color="#202832"
/>
<pcbnotetext
text="U2: BGA16 peripheral, 0.8mm pitch"
pcbY={-7.2}
fontSize={0.3}
color="#202832"
/>
</board>,
)
await circuit.renderUntilSettled()
const json = circuit.getCircuitJson()
const routingErrors = circuit.db.pcb_autorouting_error.list()
const exits = circuit.db.pcb_breakout_point.list()
const traces = circuit.db.pcb_trace.list()
const vias = circuit.db.pcb_via.list()
const routedSignalIds = new Set(traces.map((trace) => trace.source_trace_id))
const connectedSignals = circuit.db.source_trace
.list()
.filter((trace) => routedSignalIds.has(trace.source_trace_id))

// Record the current planning failure while retaining the actual fallback routes.
expect(routingErrors).toHaveLength(1)
expect(routingErrors[0]!.message).toContain(
"declared breakout edges need 3.60mm but expose only 3.40mm",
)
expect(exits).toHaveLength(0)
expect(connectedSignals).toHaveLength(16)
expect(traces).toHaveLength(16)
expect(vias).toHaveLength(24)
expect(
json.filter(
(element) =>
element.type.endsWith("_error") &&
element.type !== "pcb_autorouting_error",
),
).toEqual([])
expect(checkEachPcbTraceNonOverlapping(json)).toEqual([])
expect(checkHoleTraceClearance(json)).toEqual([])
expect(checkPadTraceClearance(json)).toEqual([])
expect(checkPadPadClearance(json)).toEqual([])
expect(checkTracesAreContiguous(json)).toEqual([])

let wireLength = 0
for (const trace of traces) {
for (let pointIndex = 1; pointIndex < trace.route.length; pointIndex++) {
const previous = trace.route[pointIndex - 1]!
const point = trace.route[pointIndex]!
if (
previous.route_type === "wire" &&
point.route_type === "wire" &&
previous.layer === point.layer
) {
wireLength += Math.hypot(point.x - previous.x, point.y - previous.y)
}
}
}
// Native notes use emitted board-world geometry in mm (+X right, +Y up).
const breakout = circuit.db.pcb_group.getWhere({ name: "B1" })!
circuit.db.pcb_note_rect.insert({
center: breakout.center,
width: breakout.width!,
height: breakout.height!,
stroke_width: 0.025,
layer: "top",
color: "#58697b",
is_filled: false,
})
for (const note of [
{
text: `Fanout exits: ${exits.length}/16 | Planning errors: ${routingErrors.length} | Connected signals: ${connectedSignals.length}/16`,
y: 8,
},
{
text: `Copper: ${wireLength.toFixed(2)}mm | ${vias.length} vias | ${traces.length} trace fragments`,
y: -8.2,
},
{
text: routingErrors.length
? "Fanout rejected: global routing falls back to original pads"
: "Fanout accepted: global routing continues from all 16 exits",
y: -9,
},
]) {
circuit.db.pcb_note_text.insert({
text: note.text,
anchor_position: { x: 0, y: note.y },
anchor_alignment: "center",
font: "tscircuit2024",
font_size: 0.3,
layer: "top",
color: routingErrors.length ? "#c52828" : "#215bca",
})
}
await expect(circuit).toMatchPcbSnapshot(import.meta.path, {
backgroundColor: "white",
width: 1000,
height: 1100,
showPcbGroups: false,
showDebugObjects: false,
shouldDrawRatsNest: false,
})
}, 60_000)
90 changes: 90 additions & 0 deletions tests/repros/repro-fanout-unbused-layer-assignment.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { expect, test } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("repro: unbused fanout endpoints ignore allowed layers", async () => {
const { circuit } = getTestFixture()
circuit.add(
<board width={24} height={14} layers={4} routingDisabled>
{[-6, 6].map((pcbX, index) => (
<breakout
key={pcbX}
name={`B${index + 1}`}
pcbX={pcbX}
padding={1}
fanoutRoutingLayers={["inner1", "bottom"]}
>
<chip name={`U${index + 1}`} footprint="bga16_grid4x4_p1mm" />
</breakout>
))}
{Array.from({ length: 10 }, (_, index) => (
<trace
key={`signal_${index}`}
name={`SIGNAL_${index + 1}`}
from={`U1.pin${index + 1}`}
to={`U2.pin${index + 1}`}
/>
))}
<bus
name="PINNED"
connections={["SIGNAL_1", "SIGNAL_2"]}
preferredLayer="bottom"
/>
<pcbnotetext
text="10 signals per boundary | Allowed: inner1 + bottom | PINNED: bottom"
pcbY={5}
fontSize={0.35}
/>
</board>,
)
await circuit.renderUntilSettled()
expect(circuit.db.pcb_autorouting_error.list()).toEqual([])
const points = circuit.db.pcb_breakout_point.list()
expect(points).toHaveLength(20)
expect(new Set(points.map((point) => point.layer))).toEqual(
new Set(["top", "bottom"]),
)
const forbiddenPoints = points.filter((point) => point.layer === "top")
// Record the current bug; the stacked fix changes this to zero.
expect(forbiddenPoints).toHaveLength(16)
for (const name of ["SIGNAL_1", "SIGNAL_2"]) {
const sourceTrace = circuit.db.source_trace.getWhere({ name })!
const pinnedPoints = points.filter(
(point) => point.source_trace_id === sourceTrace.source_trace_id,
)
expect(pinnedPoints.map((point) => point.layer)).toEqual([
"bottom",
"bottom",
])
}
// The PCB renderer does not draw breakout endpoints. Mark the emitted
// board-world positions (mm, +X right, +Y up) with their assigned layer.
for (const point of points) {
circuit.db.pcb_note_rect.insert({
center: { x: point.x, y: point.y },
width: 0.2,
height: 0.2,
stroke_width: 0.05,
layer: "top",
color:
point.layer === "inner1"
? "#b45c00"
: point.layer === "bottom"
? "#215bca"
: "#c52828",
is_filled: true,
})
}
circuit.db.pcb_note_text.insert({
text: `Forbidden top endpoints: ${forbiddenPoints.length}/${points.length} | Orange: inner1 | Blue: bottom | Red: top`,
anchor_position: { x: 0, y: -5 },
anchor_alignment: "center",
font: "tscircuit2024",
font_size: 0.3,
color: "#333333",
layer: "top",
})
await expect(circuit).toMatchPcbSnapshot(import.meta.path, {
backgroundColor: "white",
showPcbGroups: true,
})
})
Loading