mission_tables: refuse a single named file that is not a PSIN container (#6926)

Squash-merged after diff review of PR #6926 - mission_tables: refuse a single named file that is not a PSIN container
This commit is contained in:
evilclanker9000
2026-11-23 16:42:37 +01:00
committed by GitHub
parent 5278085d06
commit 167feec512
3 changed files with 37 additions and 0 deletions

View File

@ -166,6 +166,10 @@ at, from inflated PSIN streams or a directory of carved `.bin` streams:
python -I tools/mission_tables.py <file-or-dir> [--json] [--limit N]
```
A lone path is the PSIN file: a file without the `PSIN` magic is one `ERROR: <path>: not a PSIN container`
line and exit 2, while a folder is the place for the bare carved streams and is scanned as before. A PSIN
file that holds no records is still a clean run.
It prints per-file record, chunk, state and entity counts, plus each resolved entity's archetype
hash, link hash, position and rotation. Pointers are scored in three encodings: **file-absolute**,
**linked pool** (`pool_block_base + (offset >> 4)`), and **block-indexed** (`kind` is a 1-based

View File

@ -413,6 +413,28 @@ class TestCli(unittest.TestCase):
self.assertEqual(completed.stdout.count(" records="), 2)
self.assertIn("2 files,", completed.stdout)
def test_a_single_file_without_the_magic_is_refused(self):
# A lone argument is a PSIN file; a folder is where the bare carved .bin streams live. Naming a file
# that is neither used to end in "1 files, 0 records" and exit 0, so a wrong path looked like a run.
with tempfile.TemporaryDirectory() as folder:
path = os.path.join(folder, "not-a-container.bin")
with open(path, "wb") as handle:
handle.write(b"\x01" * 64)
completed = subprocess.run([sys.executable, "-I", TOOL, path], capture_output=True, text=True)
self.assertEqual(completed.returncode, 2)
self.assertIn("not a PSIN container", completed.stderr)
self.assertEqual(completed.stdout, "")
def test_a_folder_still_scans_a_stream_without_the_magic(self):
# Negative control: the same bytes in a folder are a carved stream and are still counted.
with tempfile.TemporaryDirectory() as folder:
with open(os.path.join(folder, "bare.bin"), "wb") as handle:
handle.write(b"\x01" * 64)
completed = subprocess.run([sys.executable, "-I", TOOL, folder], capture_output=True, text=True)
self.assertEqual(completed.returncode, 0, completed.stderr)
self.assertIn("1 files, 0 records", completed.stdout)
self.assertIn("skipped bytes 64", completed.stdout)
if __name__ == "__main__":
unittest.main()

View File

@ -552,6 +552,17 @@ def main(argv=None):
if not os.path.exists(args.src):
print(f"ERROR: {args.src}: no such file or folder", file=sys.stderr)
return 2
if os.path.isfile(args.src):
# A lone argument is the inflated PSIN file; the bare carved streams are what a folder holds.
try:
with open(args.src, "rb") as handle:
magic = handle.read(4)
except OSError as error:
print(f"ERROR: {args.src}: {error}", file=sys.stderr)
return 2
if magic != b"PSIN":
print(f"ERROR: {args.src}: not a PSIN container", file=sys.stderr)
return 2
try:
files = collect(args.src, args.limit)
except OSError as error: