rootsig_census: reserve root and disasm index.json paths before first write (ROOTSIG-CENSUS-JSON-GUARD)

This commit is contained in:
jesusACD
2026-11-24 18:01:13 -05:00
parent 8270eaea3e
commit 85b44dd105
2 changed files with 17 additions and 8 deletions

View File

@ -305,6 +305,20 @@ class TestCensus(unittest.TestCase):
with open(path, "rb") as fh:
self.assertEqual(fh.read(), snapshots[path])
def test_json_refuses_manifest_paths_before_either_file_exists(self):
disasm = os.path.join(self.tmp.name, "disasm")
os.mkdir(disasm)
for directory in (self.tmp.name, disasm):
with self.subTest(directory=directory):
target = os.path.join(directory, "index.json")
self.assertFalse(os.path.exists(target))
run = subprocess.run([sys.executable, "-I", TOOL, self.tmp.name, "--disasm", disasm, "--json", target],
capture_output=True, text=True)
self.assertEqual(run.returncode, 2, run.stderr)
self.assertIn("would overwrite an input file", run.stderr)
self.assertEqual(run.stdout, "")
self.assertFalse(os.path.exists(target))
def test_json_guard_delegates_to_shared_same_report_path(self):
self.write("sig", [(b"RTS0", rts0(params=[("cbv", 0)]))], user_sgprs=8)
out = os.path.join(self.tmp.name, "ALIAS.JSON")

View File

@ -295,11 +295,8 @@ def summarize(rows):
def _census_inputs(root, disasm=None):
"""Existing files in `root` (and `disasm` when given) that `--json` must not overwrite."""
paths = []
manifest = os.path.join(root, "index.json")
if os.path.isfile(manifest):
paths.append(manifest)
"""Manifest paths and existing inputs that `--json` must not overwrite."""
paths = [os.path.join(root, "index.json")]
with os.scandir(root) as entries:
for entry in entries:
if entry.name.lower().endswith(".dxbc") and entry.is_file():
@ -311,9 +308,7 @@ def _census_inputs(root, disasm=None):
if entry.name.lower().endswith(".json") and entry.is_file():
paths.append(entry.path)
if disasm:
disasm_manifest = os.path.join(disasm, "index.json")
if os.path.isfile(disasm_manifest):
paths.append(disasm_manifest)
paths.append(os.path.join(disasm, "index.json"))
with os.scandir(disasm) as entries:
for entry in entries:
if entry.name.lower().endswith(".s") and entry.is_file():