tools/hashdict: write --out atomically, use shared report_paths guard, and accept UTF-8 BOM in --lookup (HASHDICT-ATOMIC-JSON-AND-PATH-GUARD) #2075
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2075"
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:36:48Z.
Claimed in the coordination issue as: HASHDICT-ATOMIC-JSON-AND-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172506299)
What and why
Hardens
tools/hashdict.pyoutput handling and--lookupinput decoding without changing output bytes:--outwrites: Writes JSON through a sibling temporary file (tempfile.mkstemp(..., prefix=".hashdict-", suffix=".json")), preserves permissions withfile_mode.published_mode, and swaps viareplace_retry.replace, cleaning up the temp file on failure so an interrupted or failing write no longer truncates an existing dictionary.--outvalidation & shared path guard: Refuses empty/whitespace-only and directory--outpaths before scanning inputs or creating parent directories, and checks--extraandindex.jsoninputs withreport_paths.same_report_path(catching case-only aliases on case-folding volumes even when--outdoes not exist yet).--lookup: Opens--lookupdictionaries withutf-8-sig(matching the existingindex.jsonreader inhashdict.py), so dictionaries saved with a BOM by Windows PowerShell 5.1 / Notepad are accepted cleanly.tests/test_hashdict.py(test_write_failure_preserves_existing_output_and_leaves_no_temp_file,test_out_rejects_empty_and_directory_paths,test_out_refuses_case_only_input_alias_on_folding_volume,test_lookup_accepts_utf8_bom_dictionary).Tested
tests/test_hashdict.pyfailed againstmain(e18b59a5b) before the fix (existingouttruncated tob''onjson.dumperror, whitespace--outaccepted, case-only alias written, UTF-8 BOM rejected).python3 -I tests/test_hashdict.py: 47/47 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/hashdict.py tests/test_hashdict.py: exit 0.python3 -m compileall -q make_game.py tools tests: exit 0.GPUs tested: n/a (CPU-only Python tool and 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:53Z.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
tests/test_hashdict.py: 1 failed, 45 passed, 1 skipped, 22 subtests passed. Reproduced twice. The skip is the symlink case (Developer Mode is off, WinError 1314).OutputPathTest::test_out_refuses_case_only_input_alias_on_folding_volume(tests/test_hashdict.py:819,AssertionError: True is not false).assertFalse(os.path.exists(alias))style check fails even though the tool refused the write. The check needs to allow a case-insensitive host filesystem.(AI-assisted test run; output checked by hand.)
Imported from ubiquitarianism/leonida. Originally posted by KushGene on 2026-11-26T10:14:25Z.
Thanks for testing on Windows, @DeadlyChirp! Fixed in
48b2141a2by checkingos.listdir(os.path.join(carve, "common")) == ["index.json"]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:10Z.
#2075 | head
48b2141a29defc80b3806eaac8c7fa803574c8a6|python3 -I tests/test_hashdict.py -v| red: 47 run, 4 failures, 1 error | green: 47 passed | Red → greenBaseline checks failed on the JSON input/output cases added to this 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:33Z.
Merged, thank you @KushGene!
What it does: tools/hashdict: write --out atomically, use shared report_paths guard, and accept UTF-8 BOM in --lookup (HASHDICT-ATOMIC-JSON-AND-PATH-GUARD)
How it was checked: sodove tested this PR at head
48b2141a2on 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 (2 failures, 1 error); with the PR, green (47 OK, 1 skip).Our count on main was 2 failures and 1 error (sodove's 4 and 1): one symlink/hard-link case is skipped on our machine; the verdict is the same.
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.