tools/awc_markers: guard --out paths with report_paths and write JSON atomically (AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD) #2078

Merged
leonida/mandy
KushGene merged 2 commits from fix/awc-markers-atomic-out-guard into main 2026-11-28 10:47:21 +00:00

Pull request successfully merged and closed

KushGene commented 2026-11-25 19:40:56 +00:00

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 --out handling without touching iter_banks() or _read() (keeping zero overlap with #1159):

  • Early --out validation & input overwrite guard: Refuses empty/whitespace-only and directory --out paths before scanning, and checks discovered inputs with report_paths.same_report_path (catching case-only aliases on case-folding volumes even when --out does not exist yet).
  • Atomic JSON writes & error handling: _write_json_atomic creates missing parent directories, writes via a sibling temporary file (tempfile.mkstemp(..., prefix=".awc_markers-", suffix=".json")), preserves permissions with file_mode.published_mode, swaps via replace_retry.replace, cleans up the temp file on failure, and catches OSError to print a clean awc_markers: error: cannot write ... line and exit 1 instead of raising a traceback or truncating an existing report. Output formatting (indent=2, trailing \n, LF) is unchanged.
  • Regression tests: Added 4 tests in OutputSafetyTest in tests/test_awc_markers.py.

Tested

  • Confirmed all 4 new OutputSafetyTest methods in tests/test_awc_markers.py failed against main (e18b59a5b) before the fix (--out "" / " " exited 0 silently, directory --out and missing parent raised tracebacks, --out overwriting 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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, with how it was confirmed. (n/a)
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`](tools/awc_markers.py) `--out` handling without touching `iter_banks()` or `_read()` (keeping zero overlap with #1159): - **Early `--out` validation & input overwrite guard:** Refuses empty/whitespace-only and directory `--out` paths before scanning, and checks discovered inputs with `report_paths.same_report_path` (catching case-only aliases on case-folding volumes even when `--out` does not exist yet). - **Atomic JSON writes & error handling:** `_write_json_atomic` creates missing parent directories, writes via a sibling temporary file (`tempfile.mkstemp(..., prefix=".awc_markers-", suffix=".json")`), preserves permissions with `file_mode.published_mode`, swaps via `replace_retry.replace`, cleans up the temp file on failure, and catches `OSError` to print a clean `awc_markers: error: cannot write ...` line and exit `1` instead of raising a traceback or truncating an existing report. Output formatting (`indent=2`, trailing `\n`, LF) is unchanged. - **Regression tests:** Added 4 tests in `OutputSafetyTest` in [`tests/test_awc_markers.py`](tests/test_awc_markers.py). ### Tested - Confirmed all 4 new `OutputSafetyTest` methods in `tests/test_awc_markers.py` failed against `main` (`e18b59a5b`) before the fix (`--out ""` / `" "` exited 0 silently, directory `--out` and missing parent raised tracebacks, `--out` overwriting 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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`, with how it was confirmed. (n/a)
DeadlyChirp commented 2026-11-26 10:02:40 +00:00

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.
  • Failing test: OutputSafetyTest::test_out_refuses_input_file_and_case_only_alias_on_folding_volume, at self.assertFalse(os.path.exists(alias)) (AssertionError: True is not false).
  • Cause: NTFS is case-insensitive, so banks/A.AWC already "exists" because banks/a.awc exists. 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 the exists check when os.path.exists(alias) was already true before the call, would make it pass on Windows.

(AI-assisted test run; output checked by hand.)

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. - Failing test: `OutputSafetyTest::test_out_refuses_input_file_and_case_only_alias_on_folding_volume`, at `self.assertFalse(os.path.exists(alias))` (`AssertionError: True is not false`). - Cause: NTFS is case-insensitive, so `banks/A.AWC` already "exists" because `banks/a.awc` exists. 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 the `exists` check when `os.path.exists(alias)` was already true before the call, would make it pass on Windows. (AI-assisted test run; output checked by hand.)
KushGene commented 2026-11-26 10:14:31 +00:00

Thanks for testing on Windows, @DeadlyChirp! Fixed in 58bda6a72 by checking os.listdir(banks) == ["a.awc"] instead of assertFalse(os.path.exists(alias)) so the assertion holds on both case-sensitive and case-insensitive (case-preserving) filesystems.

Thanks for testing on Windows, @DeadlyChirp! Fixed in 58bda6a72 by checking `os.listdir(banks) == ["a.awc"]` instead of `assertFalse(os.path.exists(alias))` so the assertion holds on both case-sensitive and case-insensitive (case-preserving) filesystems.
sodove commented 2026-11-28 10:12:15 +00:00

#2078 | head 58bda6a72825979eb7e200bab0315c1d71cf92de | python3 -I tests/test_awc_markers.py -v | red: 15 run, 5 failures, 3 errors | green: 15 passed | Red → green

The 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.

#2078 | head `58bda6a72825979eb7e200bab0315c1d71cf92de` | `python3 -I tests/test_awc_markers.py -v` | red: 15 run, 5 failures, 3 errors | green: 15 passed | **Red → green** The 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](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:47:23 +00:00

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 58bda6a72 on main 33db04a70: 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.asm translator 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.

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 `58bda6a72` on main `33db04a70`: 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.asm` translator 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.
Sign in to join this conversation.
No description provided.