Skip to content

Add the first unit-test suite + repair the broken smoke tests#20

Open
prat96 wants to merge 3 commits into
bbenchoff:mainfrom
GhostRoboticsLab:pr1-tests-and-smoke-fixes
Open

Add the first unit-test suite + repair the broken smoke tests#20
prat96 wants to merge 3 commits into
bbenchoff:mainfrom
GhostRoboticsLab:pr1-tests-and-smoke-fixes

Conversation

@prat96

@prat96 prat96 commented Jul 2, 2026

Copy link
Copy Markdown

What

Adds the first unit-test suite to the repo, and repairs the two smoke-test
entry points that were broken on every platform.

Why

CONTRIBUTING.md lists tests as the Critical Priority ("The project has
zero unit tests. This is the biggest blocker to refactoring."). This starts
that suite — KiCad-free, CPU-only, no new runtime dependencies — and along
the way fixes two commands that silently did the wrong thing:

  • python main.py --test-via built a 2-layer board, which produces an
    empty routing graph (no via layers), so the self-test raised before it could
    test anything. Now uses a 4-layer board and the real engine call sequence.
  • cli mode printed "No copper generated" and exited 0 when a board parsed
    to 0 nets, and skipped the mandatory precompute_all_pad_escapes step (which
    silently drops every net). Now it runs the full sequence and hard-fails
    (exit 1) on a 0-net parse.

It also fixes .gitignore, which ignored test_*.py and tests/* — actively
preventing any test suite from being tracked.

Tests

  • test_lattice — node count, H/V layer discipline, legal planar edges, legal
    via pairs.
  • test_via_accountingEdgeAccountant commit/clear symmetry, usage floored
    at 0, refresh-from-canonical, overuse counting at capacity.
  • test_engine_smoke — the mandatory engine call sequence routes a trivial
    two-pad board end to end.
  • conftest.py — shared fixtures + make_two_pad_board factory.
$ python -m pytest tests/
25 passed

No KiCad, no GPU, no network required.

Checklist

  • Tests pass locally (25 passed on a clean clone)
  • No new runtime dependencies
  • PEP 8 / Google-style docstrings on new code
  • Fixes .gitignore so a fresh clone can collect the suite

prat96 added 3 commits July 2, 2026 20:56
The test was broken on all platforms for three reasons:
- 2-layer board: lateral edges exist only on inner layers, so the graph
  build raised ValueError('No edges'). Use 4 copper layers.
- Pads were never attached to the board/net objects, so bounds fell back
  to 100x100mm and the escape planner found no routable pads.
- precompute_all_pad_escapes was never called, so _parse_requests
  silently dropped the net (no portals).

Assertions now check the live engine state (_via_edges, net_paths,
accounting.present) instead of stale attributes (via_edge_ids, owner,
e_is_via, present_cost) that no longer exist on PathFinderRouter.

Signed-off-by: Pratheek Balakrishna <pratheekb96@gmail.com>
- A board that parses to 0 nets/0 pads now exits 1 with a clear message
  pointing at the file parser instead of the misleading 'No copper
  generated' (the KiCad 10 parse failure was completely silent).
- cli now calls precompute_all_pad_escapes like the GUI/headless paths;
  without portals _parse_requests silently drops every net, so cli could
  never route anything.

Signed-off-by: Pratheek Balakrishna <pratheekb96@gmail.com>
CONTRIBUTING.md lists tests as the "Critical Priority" and the repo has
had zero. Adds a KiCad-free suite with no new runtime dependencies:
lattice invariants, EdgeAccountant via accounting, and an engine-smoke
test that routes a trivial two-pad board through the mandatory call
sequence. conftest.py holds the shared fixtures and make_two_pad_board.

The .gitignore previously ignored test_*.py and tests/*, which blocked
tracking any suite at all; re-include tests/*.py so a clean clone can
collect and run it.

Signed-off-by: Pratheek Balakrishna <pratheekb96@gmail.com>
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.

1 participant