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

Open
opened 2026-11-26 21:19:58 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2078
Author: @KushGene
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/awc-markers-atomic-out-guard


📝 Commits (2)

  • b3a5a9e tools/awc_markers: guard --out paths with report_paths and write JSON atomically (AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD)
  • 58bda6a tests/test_awc_markers: check directory entries instead of alias existence on folding volumes

📊 Changes

2 files changed (+206 additions, -12 deletions)

View changed files

📝 tests/test_awc_markers.py (+131 -0)
📝 tools/awc_markers.py (+75 -12)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2078 **Author:** [@KushGene](https://github.com/KushGene) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/awc-markers-atomic-out-guard` --- ### 📝 Commits (2) - [`b3a5a9e`](https://github.com/ubiquitarianism/leonida/commit/b3a5a9e669ccacbdc1e3182a413dfd3e869a2999) tools/awc_markers: guard --out paths with report_paths and write JSON atomically (AWC-MARKERS-ATOMIC-OUT-AND-PATH-GUARD) - [`58bda6a`](https://github.com/ubiquitarianism/leonida/commit/58bda6a72825979eb7e200bab0315c1d71cf92de) tests/test_awc_markers: check directory entries instead of alias existence on folding volumes ### 📊 Changes **2 files changed** (+206 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_awc_markers.py` (+131 -0) 📝 `tools/awc_markers.py` (+75 -12) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2084
No description provided.