tools: preserve repo-relative directories in LSF --check path normalization

This commit is contained in:
morebrackets
2026-12-02 06:12:44 -08:00
parent 2cd1ffffd8
commit d3b2d5356c
2 changed files with 26 additions and 1 deletions

View File

@ -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')

View File

@ -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