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

Open
github-bot wants to merge 1 commit from github-bot/gh-1762 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 11:37 UTC · original
kirigayakazima:fix/psin-names-atomic-refs-and-case-json → main · +106 −6 · 2 files · 1 commits · open

Claimed in the coordination issue as: PSIN-NAMES-ATOMIC-REFS-AND-CASE-JSON #1608

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 11:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1762) `kirigayakazima:fix/psin-names-atomic-refs-and-case-json` → `main` · +106 −6 · 2 files · 1 commits · open Claimed in the coordination issue as: PSIN-NAMES-ATOMIC-REFS-AND-CASE-JSON https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:04 +00:00
Author
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 12:27 UTC · original · approved these changes

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

**@⁠ShotTechOp** on GitHub · 2026-11-25 12:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1762#pullrequestreview-6057577924) · **approved these changes** 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1762/head:github-bot/gh-1762'
git switch 'github-bot/gh-1762'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1762'
git switch 'github-bot/gh-1762'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1762'
git switch 'github-bot/gh-1762'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1762'
git switch 'main'
git merge --squash 'github-bot/gh-1762'
git switch 'main'
git merge --ff-only 'github-bot/gh-1762'
git switch 'main'
git merge 'github-bot/gh-1762'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.