psin_names: publish --refs atomically and match .JSON case-insensitively (PSIN-NAMES-ATOMIC-REFS-AND-CASE-JSON) #1762

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/psin-names-atomic-refs-and-case-json into main 2026-11-28 13:28:13 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-25 11:37:23 +00:00

Claimed in the coordination issue as: PSIN-NAMES-ATOMIC-REFS-AND-CASE-JSON https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161241950

What and why

Hardens tools/psin_names.py:

  1. Case-insensitive .json extension in load_names: Use path.lower().endswith(".json") so uppercase NAMES.JSON is parsed as JSON rather than split line-by-line as raw JSON syntax text.
  2. Normalize inside_src path comparison: Apply os.path.normcase after os.path.realpath when checking whether --refs falls inside src so commonpath matches same_report_path case semantics consistently.
  3. Atomic --refs TSV publish with Windows read-only cleanup: Stage --refs into tempfile.NamedTemporaryFile in the destination directory, apply published_mode(dest), publish via replace_retry, and restore 0o600 before unlinking on failure. Mid-scan errors or failed replaces over read-only targets preserve any previous TSV intact and leave no .psin_names-*.tmp files.

Adds 3 synthetic regression tests in tests/test_psin_names.py.

Tested

Windows 11 x64 (10.0.26100), Python 3.14.7, CPU only, synthetic PSIN inputs only (no game files). Commit 8f2c0e351254c778ba8a41b32629ff89dd93fb0b.

  • python -I tests/test_psin_names.py -v:
    • against main (bcaa13da) with all 20 tests: 2 failures (test_uppercase_json_extension_is_parsed_as_json and test_refs_failure_preserves_previous_file_and_cleans_staging — truncates previous refs.tsv on mid-run error);
    • with the fix: 20 tests, OK (0 skipped).
  • python -I tests/test_ci_registration.py: 16 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/psin_names.py tests/test_psin_names.py, python -m compileall -q tools tests, git diff --check: exit 0.

GPUs tested: n/a

AI-assisted: yes

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: no translator change)
Claimed in the coordination issue as: PSIN-NAMES-ATOMIC-REFS-AND-CASE-JSON https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161241950 ### What and why Hardens `tools/psin_names.py`: 1. **Case-insensitive `.json` extension in `load_names`**: Use `path.lower().endswith(".json")` so uppercase `NAMES.JSON` is parsed as JSON rather than split line-by-line as raw JSON syntax text. 2. **Normalize `inside_src` path comparison**: Apply `os.path.normcase` after `os.path.realpath` when checking whether `--refs` falls inside `src` so `commonpath` matches `same_report_path` case semantics consistently. 3. **Atomic `--refs` TSV publish with Windows read-only cleanup**: Stage `--refs` into `tempfile.NamedTemporaryFile` in the destination directory, apply `published_mode(dest)`, publish via `replace_retry`, and restore `0o600` before unlinking on failure. Mid-scan errors or failed replaces over read-only targets preserve any previous TSV intact and leave no `.psin_names-*.tmp` files. Adds 3 synthetic regression tests in `tests/test_psin_names.py`. ### Tested Windows 11 x64 (`10.0.26100`), Python `3.14.7`, CPU only, synthetic PSIN inputs only (no game files). Commit `8f2c0e351254c778ba8a41b32629ff89dd93fb0b`. - `python -I tests/test_psin_names.py -v`: - against `main` (`bcaa13da`) with all 20 tests: **2 failures** (`test_uppercase_json_extension_is_parsed_as_json` and `test_refs_failure_preserves_previous_file_and_cleans_staging` — truncates previous `refs.tsv` on mid-run error); - with the fix: **20 tests, OK** (0 skipped). - `python -I tests/test_ci_registration.py`: **16 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/psin_names.py tests/test_psin_names.py`, `python -m compileall -q tools tests`, `git diff --check`: exit `0`. GPUs tested: n/a AI-assisted: yes ### 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: no translator change)
ShotTechOp approved these changes 2026-11-25 12:27:02 +00:00
ShotTechOp left a comment

Independent Windows 11 / Python 3.12.10 review of 8f2c0e35 applied onto origin/main (0d80bc5d) — CPU-only, synthetic inputs, no game files.

Checks run

  • Clean apply onto origin/main (0d80bc5d): clean.
  • python -I tests/test_psin_names.py -v: 20/20 OK.
  • Negative control (reverted tools/psin_names.py to origin/main with the PR's tests): 2 failures (test_refs_failure_preserves_previous_file_and_cleans_staging overwrote the previous --refs file on error, and test_uppercase_json_extension_is_parsed_as_json parsed .JSON as plain text instead of JSON).
  • python -m compileall -q tools/psin_names.py tests/test_psin_names.py: exit 0.
  • python -I scripts/check_no_game_data.py tools/psin_names.py tests/test_psin_names.py: exit 0.
  • git diff --check origin/main: clean.

Code audit

  • Matching .json via path.lower().endswith(".json") and normalizing containment checks with os.path.normcase(os.path.realpath(...)) handles case-insensitive Windows paths cleanly.
  • Publishing --refs through tempfile.NamedTemporaryFile(encoding="utf-8", newline="\n") + published_mode(dest) + replace_retry with 0o600 cleanup in finally preserves existing reports on mid-scan / replace failures and avoids read-only staging leftovers.

LGTM. AI-assisted (Antigravity).

Independent Windows 11 / Python 3.12.10 review of `8f2c0e35` applied onto `origin/main` (`0d80bc5d`) — CPU-only, synthetic inputs, no game files. ### Checks run - Clean apply onto `origin/main` (`0d80bc5d`): clean. - `python -I tests/test_psin_names.py -v`: **20/20 OK**. - Negative control (reverted `tools/psin_names.py` to `origin/main` with the PR's tests): **2 failures** (`test_refs_failure_preserves_previous_file_and_cleans_staging` overwrote the previous `--refs` file on error, and `test_uppercase_json_extension_is_parsed_as_json` parsed `.JSON` as plain text instead of JSON). - `python -m compileall -q tools/psin_names.py tests/test_psin_names.py`: exit 0. - `python -I scripts/check_no_game_data.py tools/psin_names.py tests/test_psin_names.py`: exit 0. - `git diff --check origin/main`: clean. ### Code audit - Matching `.json` via `path.lower().endswith(".json")` and normalizing containment checks with `os.path.normcase(os.path.realpath(...))` handles case-insensitive Windows paths cleanly. - Publishing `--refs` through `tempfile.NamedTemporaryFile(encoding="utf-8", newline="\n")` + `published_mode(dest)` + `replace_retry` with `0o600` cleanup in `finally` preserves existing reports on mid-scan / replace failures and avoids read-only staging leftovers. LGTM. AI-assisted (Antigravity).
zmasi commented 2026-11-28 11:53:16 +00:00

#1762 | head 8f2c0e351254c778ba8a41b32629ff89dd93fb0b (merged cleanly with main 24549bdb1) | python -I tests/test_psin_names.py | red on main: FAILED (failures=2) (clobbered existing --refs file on scan error and parsed .JSON as plain lines) | green on PR+main: 20 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited load_names and main in tools/psin_names.py (matching .json case-insensitively, normalizing src_real/refs_real with os.path.normcase before commonpath, and staging --refs via NamedTemporaryFile + published_mode + replace_retry with guaranteed temp cleanup on failure; directly exercised the os.name == "nt" read-only destination preservation branch on Windows 11). Also verified tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

#1762 | head 8f2c0e351254c778ba8a41b32629ff89dd93fb0b (merged cleanly with main 24549bdb1) | `python -I tests/test_psin_names.py` | red on main: `FAILED (failures=2)` (clobbered existing `--refs` file on scan error and parsed `.JSON` as plain lines) | green on PR+main: `20 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `load_names` and `main` in `tools/psin_names.py` (matching `.json` case-insensitively, normalizing `src_real`/`refs_real` with `os.path.normcase` before `commonpath`, and staging `--refs` via `NamedTemporaryFile` + `published_mode` + `replace_retry` with guaranteed temp cleanup on failure; directly exercised the `os.name == "nt"` read-only destination preservation branch on Windows 11). Also verified `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 13:28:18 +00:00

Merged after local re-verification: this PR merged onto main 7a80e8a0a without conflict, and its test file(s) (tests/test_psin_names.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after local re-verification: this PR merged onto `main` 7a80e8a0a without conflict, and its test file(s) (`tests/test_psin_names.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.