seveibar/pd-dual-stepper-controller

Bottom-side PCB silkscreen artwork consisting of embedded mirrored TS Circuit SVG logos, with via-clearance-aware lower-board placement.

Version
0.1.0
License
unset
Stars
0

tests/ground-pour-selection.test.ts

import { expect, test } from "bun:test";
import { installGroundPourFinalization, selectConnectedGroundPours } from "../routing/ground-pour-selection";

const pour = (id: string, x: number) => ({
  type: "pcb_copper_pour", pcb_copper_pour_id: id, layer: "top", source_net_id: "ground",
  brep_shape: { outer_ring: {vertices: [{x,y:0},{x:x+1,y:0},{x,y:1}]}, inner_rings: [] },
});

test("only the independently audited floating copper is removed", () => {
  const connected= pour("connected",0), floating=pour("floating",3);
  const regions=[{geometry:connected,keep:true},{geometry:floating,keep:false}];
  expect(selectConnectedGroundPours([floating,connected],regions)).toEqual(["floating"]);
  expect(selectConnectedGroundPours([{...connected,pcb_copper_pour_id:"new-id"},floating],regions)).toEqual(["floating"]);
});

test("changed copper geometry, layer, net or count requires a fresh ground audit", () => {
  const original=pour("connected",0), regions=[{geometry:original,keep:true}];
  for(const changed of [pour("connected",0.01),{...original,layer:"bottom"},{...original,source_net_id:"other"}]) {
    expect(()=>selectConnectedGroundPours([changed],regions)).toThrow("Ground pour geometry changed");
  }
  expect(()=>selectConnectedGroundPours([],regions)).toThrow();
  expect(()=>selectConnectedGroundPours([original,pour("extra",3)],regions)).toThrow();
});

test("placement-only CLI renders still run normal DRC without applying a routed-pour selection", () => {
  let checked=false;
  const board={
    root:{pcbDisabled:false,pcbRoutingDisabled:true,db:{toArray(){throw new Error("Placement has no routed pours");}}},
    doInitialPcbDesignRuleChecks(){checked=true;},
  };
  installGroundPourFinalization(board);
  board.doInitialPcbDesignRuleChecks();
  expect(checked).toBe(true);
});