diff --git a/tests/offline/test_lsf_oracles.py b/tests/offline/test_lsf_oracles.py index 2b1e5f09..0ff7b4d2 100644 --- a/tests/offline/test_lsf_oracles.py +++ b/tests/offline/test_lsf_oracles.py @@ -81,6 +81,19 @@ class TestLsfOracles(unittest.TestCase): } with self.assertRaises(SystemExit): helper.retain_json(p, drifted, check=True) + # Changing the repository-relative directory must be rejected even with matching basename. + moved_dir = { + "records": [ + { + "engine": "FECS", + "image_file": "/other/checkout/analysis/other-dir/fecs-original-image.bin", + "layout_file": "/other/checkout/analysis/lsf-580/fecs-original-layout.bin", + "image_sha256": "abc", + } + ] + } + with self.assertRaises(SystemExit): + helper.retain_json(p, moved_dir, check=True) # JSON type changes (e.g. false vs 0) must be treated as drift. p2 = Path(td) / "types.json" p2.write_text('{"physical_gpu_access": false}\n') diff --git a/tools/_lsf_oracle_elf.py b/tools/_lsf_oracle_elf.py index 10e64161..58f6077b 100644 --- a/tools/_lsf_oracle_elf.py +++ b/tools/_lsf_oracle_elf.py @@ -76,12 +76,24 @@ def retain_bytes(path: Path, data: bytes, check: bool) -> None: path.write_bytes(data) +def _strip_checkout_root(path_str: str) -> str: + norm = path_str.replace("\\", "/") + root_prefix = str(ROOT).replace("\\", "/").rstrip("/") + "/" + if norm.startswith(root_prefix): + return norm[len(root_prefix) :] + for anchor in ("/analysis/", "/reports/", "/src/", "/tests/"): + idx = norm.find(anchor) + if idx >= 0: + return norm[idx + 1 :] + return norm + + def _normalize_report_paths(obj): if isinstance(obj, dict): out = {} for k, v in obj.items(): if k in ("image_file", "layout_file") and isinstance(v, str): - out[k] = Path(v).name + out[k] = _strip_checkout_root(v) else: out[k] = _normalize_report_paths(v) return out