From ad7bc40ab6da60a038cb4dacd08ad9797223f3e9 Mon Sep 17 00:00:00 2001 From: Md Athar Ali Date: Thu, 26 Nov 2026 11:54:17 +0530 Subject: [PATCH] Invalidate the DRC cache when custom design rules change --- docs/validate.md | 2 +- src/copper_pilot_cli/validate/design.py | 2 +- tests/test_validate.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/validate.md b/docs/validate.md index caf5789..c9dfa41 100644 --- a/docs/validate.md +++ b/docs/validate.md @@ -177,7 +177,7 @@ for that stage. - **Cache.** `.copperpilot/validate/cache/.json`, where the key hashes the check spec, preamble, limits, profile, `--context` file hashes, the `--repeat`/`--effort` overrides, and the check's `inputs` (`sch` = all - sheets, `pcb`, `pro`, `libs` = `.kicad_sym` + `.kicad_mod` + lib tables, + sheets, `pcb`, `pro` = project settings and custom design rules, `libs` = `.kicad_sym` + `.kicad_mod` + lib tables, `intent` = `.copperpilot/README.md`, `PLANS.md`, `plans/*.md`, `all` = the whole tree). A PCB-only change re-runs only PCB-dependent checks. `intake.*` checks always run. diff --git a/src/copper_pilot_cli/validate/design.py b/src/copper_pilot_cli/validate/design.py index 613a3f4..83214b4 100644 --- a/src/copper_pilot_cli/validate/design.py +++ b/src/copper_pilot_cli/validate/design.py @@ -105,7 +105,7 @@ def _matches_input(relative: str, kind: str) -> bool: if kind == "pcb": return suffix == ".kicad_pcb" if kind == "pro": - return suffix == ".kicad_pro" + return suffix in {".kicad_pro", ".kicad_dru"} if kind == "libs": return suffix in _LIB_SUFFIXES or path.name in _LIB_TABLES if kind == "intent": diff --git a/tests/test_validate.py b/tests/test_validate.py index 9042529..72629f2 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -475,6 +475,21 @@ def test_input_hashes_select_by_kind(tmp_path) -> None: assert not input_hashes(tmp_path, ["libs"]) +def test_drc_cache_key_tracks_custom_design_rules(tmp_path) -> None: + make_project(tmp_path) + runner = runner_for(tmp_path) + check = runner.config.check("pcb.drc") + rules = tmp_path / "board" / "board.kicad_dru" + without_rules = runner.cache_key(check) + rules.write_text('(version 1)\n(rule "width" (constraint track_width (min 0.2mm)))\n') + with_rules = runner.cache_key(check) + assert with_rules != without_rules + rules.write_text(rules.read_text().replace("0.2mm", "0.3mm")) + assert runner.cache_key(check) != with_rules + rules.unlink() + assert runner.cache_key(check) == without_rules + + def test_snapshot_is_read_only_and_excludes_git_and_copperpilot(tmp_path) -> None: make_project(tmp_path) (tmp_path / ".git").mkdir()