#1599

manifest, turing_atlas: refuse report paths that replace inputs or are folders

Openliang-kai-shuiwants to merge intofrom

Claimed in the coordination issue as: https://github.com/ItsNotRexed/Leonida/issues/1548#issuecomment-7079163134

What and why

Two report-path bugs on main 41f44826, both with hand-built folders only (CPU, no game data):

  • tools/manifest.py create <game> --out <game>/a.txt -> exit 0. walk() excludes only the manifest path itself, so a.txt is hashed first and then replaced by the manifest with os.replace(); the recorded hash no longer matches the copy (a later verify reports it CHANGED).
  • tools/turing_atlas.py --out <existing directory> -> the atlas is built and then the write dies with a PermissionError traceback.

Fixes:

  • manifest.py: before hashing, refuse a target that is an existing file inside the folder unless it already reads as a manifest (re-creating one in place stays allowed), and refuse every hard-link alias of a file that will be hashed. Missing parent folders still get created as before.
  • turing_atlas.py: reject a directory --out with one turing_atlas: error: line and exit 2.
commandmainthis branch
manifest create <game> --out <game>/a.txtexit 0, a.txt replacedexit 2, ERROR: --out would overwrite the input ..., file untouched
manifest create <game> --out <hard link to a hashed file>exit 0, input rewrittenexit 2, refused
manifest create <game> --out <game>/manifest.json (new file)worksworks (allowed)
manifest create <game> --out <existing dir>OSError from os.replaceone ERROR: --out is a folder line, exit 2
turing_atlas --out <existing dir>PermissionError tracebackexit 2, one --out is a folder line

Tested

  • python -I tests/test_manifest.py -> 26 tests OK (4 new).
  • python -I tests/test_turing_atlas.py -> 12 tests OK (1 new).
  • Negative control: both test files run against untouched origin/main in a separate worktree -> manifest 2 failures + 1 error, atlas 1 error, all from the new cases.
  • End-to-end: the two commands above now exit 2 and leave the game file untouched.
  • python -m compileall -q tools/manifest.py tools/turing_atlas.py tests/test_manifest.py tests/test_turing_atlas.py and git diff --check clean.

CPU only, no game data.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md ??not applicable.