tools/awc_markers: guard --out paths with report_paths and write JSON atomically (AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD) #2078
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2078"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by KushGene on 2026-11-25T19:40:56Z.
Claimed in the coordination issue as: AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172599721)
What and why
Hardens
tools/awc_markers.py--outhandling without touchingiter_banks()or_read()(keeping zero overlap with #1159):--outvalidation & input overwrite guard: Refuses empty/whitespace-only and directory--outpaths before scanning, and checks discovered inputs withreport_paths.same_report_path(catching case-only aliases on case-folding volumes even when--outdoes not exist yet)._write_json_atomiccreates missing parent directories, writes via a sibling temporary file (tempfile.mkstemp(..., prefix=".awc_markers-", suffix=".json")), preserves permissions withfile_mode.published_mode, swaps viareplace_retry.replace, cleans up the temp file on failure, and catchesOSErrorto print a cleanawc_markers: error: cannot write ...line and exit1instead of raising a traceback or truncating an existing report. Output formatting (indent=2, trailing\n, LF) is unchanged.OutputSafetyTestintests/test_awc_markers.py.Tested
OutputSafetyTestmethods intests/test_awc_markers.pyfailed againstmain(e18b59a5b) before the fix (--out ""/" "exited 0 silently, directory--outand missing parent raised tracebacks,--outoverwriting input exited 0, and failed write left existing report broken).python3 -I tests/test_awc_markers.py: 15/15 passed.python3 -I tests/test_text_write_line_endings.py: 3/3 passed.python3 -I tests/test_report_paths.py: 22/22 passed.python3 -I scripts/check_no_game_data.py tools/awc_markers.py tests/test_awc_markers.py: exit 0.python3 -m compileall -q make_game.py tools tests: exit 0.GPUs tested: n/a (CPU-only Python tool and synthetic unit tests on Fedora Linux 45)
AI-assisted: yes (Antigravity)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T10:02:40Z.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
tests/test_awc_markers.py: 1 failed, 14 passed, 8 subtests passed. Reproduced twice.OutputSafetyTest::test_out_refuses_input_file_and_case_only_alias_on_folding_volume, atself.assertFalse(os.path.exists(alias))(AssertionError: True is not false).banks/A.AWCalready "exists" becausebanks/a.awcexists. The tool correctly refused with exit code 2 and "overwrite", and the input file was unchanged. Only the final existence check assumes a case-sensitive host filesystem. Checking that the input bytes are unchanged (already done next), or skipping theexistscheck whenos.path.exists(alias)was already true before the call, would make it pass on Windows.(AI-assisted test run; output checked by hand.)
Imported from ubiquitarianism/leonida. Originally posted by KushGene on 2026-11-26T10:14:31Z.
Thanks for testing on Windows, @DeadlyChirp! Fixed in
58bda6a72by checkingos.listdir(banks) == ["a.awc"]instead ofassertFalse(os.path.exists(alias))so the assertion holds on both case-sensitive and case-insensitive (case-preserving) filesystems.Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:12:15Z.
#2078 | head
58bda6a72825979eb7e200bab0315c1d71cf92de|python3 -I tests/test_awc_markers.py -v| red: 15 run, 5 failures, 3 errors | green: 15 passed | Red → greenThe baseline failed output-path and write-failure checks. The merged version passed the same file.
Pinned main
33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:47:23Z.
Merged, thank you @KushGene!
What it does: tools/awc_markers: guard --out paths with report_paths and write JSON atomically (AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD)
How it was checked: sodove tested this PR at head
58bda6a72on main33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (5 failures, 3 errors); with the PR, green (15 OK).CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the
cs_dpp_cmp.asmtranslator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.
AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.