Skip to content

bvh_rehydrate: use report_paths.same_report_path for --out guard - #6391

Open
BBareth wants to merge 1 commit into
ItsNotRexed:mainfrom
BBareth:fix/bvh-rehydrate-report-paths
Open

BBareth wants to merge 1 commit into
ItsNotRexed:mainfrom
BBareth:fix/bvh-rehydrate-report-paths

Conversation

@BBareth

@BBareth BBareth commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6214 (comment)

What and why

tools/bvh_rehydrate.py previously guarded --out against overwriting input files (dehydrated, --geom VB/IB, --compare) with os.path.exists(a.out) + os.path.samefile, which misses case-folding aliases on volumes like vfat/exFAT/CIFS when --out does not exist yet. Replacing it with report_paths.same_report_path reuses the repository's shared collision helper and covers all platforms/filesystems uniformly, with a regression test in tests/test_bvh_rehydrate.py.

Tested

  • Environment: macOS (arm64), Python 3.9.6, CPU only, no game data.
  • python3 -I -m compileall -q tools/bvh_rehydrate.py tests/test_bvh_rehydrate.py -> exit 0
  • python3 -I tests/test_bvh_rehydrate.py -v -> 17/17 passed
  • python3 -I tests/test_text_write_line_endings.py -> 3/3 passed

AI-assisted: yes

Checklist

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

@AsgerCode

Copy link
Copy Markdown

Tested a27c3a7 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): fail, the new test mocks same_report_path and passes when the real helper is broken, and the description's "old guard missed" case is not shown

What I ran:

  • python -I tests/test_bvh_rehydrate.py: 17 tests, OK. Importers: test_bvh_geometry_check.py 7, test_bvh_match.py 33, test_bvh_packing_check.py 30, all OK.
  • Merge with current main: clean (main is 237 commits ahead and changed tools/bvh_rehydrate.py in bvh_rehydrate: write a parent-table entry only inside [64, offsetToElements) (ASSET-567) #6788 and tools/report_paths.py in report_paths: resolve each path once in same_report_path, not twice (EGEN-REPORTPATHS-RESOLVE-ONCE) #6268). On the merged tree: test_bvh_rehydrate.py 19 tests, test_bvh_geometry_check.py 7, test_bvh_match.py 40, test_bvh_packing_check.py 31, test_report_paths.py 22 (1 skipped), all OK.
  • Helper broken on purpose (same_report_path always returns False): the existing test_out_must_not_overwrite_an_input fails, but the new test_out_uses_same_report_path_for_folding_alias still passes. It replaces R.same_report_path with a lambda, so it never runs the real helper.
  • Negative control (merge base's tools/bvh_rehydrate.py with the PR's tests): the new test fails only with AttributeError: module 'bvh_rehydrate' has no attribute 'same_report_path', which is the missing name, not a missed alias.
  • The guard covers every file that main() opens: the positional input, both --geom parts, and --compare (--transform is text, not a file).

Old guard vs new guard, same hand-made inputs, python -I tools/bvh_rehydrate.py <in> --geom <vb>,<ib> --out <X> (inputs checked by SHA-256 after each run):

--out merge base PR
exact path of the input exit 2, "must not overwrite" exit 2, same
upper-case spelling of the input exit 2 exit 2
sub\..\<ib> exit 2 exit 2
8.3 short name of the VB (GetShortPathNameW) exit 2 exit 2
hard link to the IB (os.link) exit 2 exit 2
input name with a trailing . exit 2 exit 2
<vb>::$DATA exit 2 exit 2
upper-case spelling of --compare exit 2 exit 2
new file, no alias exit 0 exit 0

No input changed in any row. On NTFS the two guards give the same answer for every alias I tried.

About the description: it says the old os.path.exists + samefile guard "misses case-folding aliases on volumes like vfat/exFAT/CIFS when --out does not exist yet". If --out is another case of an existing input on a folding volume, then os.path.exists(--out) is true, so the old guard runs. If --out does not exist, there is no file to overwrite. The existing IN.BIN subtest already passes on main for that reason. I could not try vfat/exFAT/CIFS here. As written, this PR is a consistency refactor, not a bug fix. That is fine, but the description and the test name should say so.

Suggested fix:

  1. Remove the lambda. Test a real alias through the real helper, for example a hard link to the IB (os.link) or a sub/../ib.bin spelling, and check that the IB bytes do not change. With same_report_path forced to False, the merged tree overwrites the input for the exact-path, upper-case and sub\.. cases (exit 0), so a real-alias test fails on a broken helper.
  2. Change the description to say that the old guard already refused these aliases, and that the change moves bvh_rehydrate to the shared helper.

Overlap: no other open PR changes this guard. #4352 (bvh_rehydrate: the output write and --compare read report failures as one line) conflicts with this PR in tools/bvh_rehydrate.py, but it already conflicts with main. #4196, #5138 and #6616 merge cleanly with this PR. #6401 (rtti_scan, same author) has the same mocked test and the same kind of description claim.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested a27c3a7 merged with main ff686df on Linux/Python 3.12.16: pass

Commands run (merged worktree, -I isolated mode):

  • python -I tests/test_bvh_rehydrate.py -> Ran 19 tests, OK
  • python -I tests/test_report_paths.py -> OK
  • Negative control: git checkout upstream/main -- tools/bvh_rehydrate.py, rerun test_bvh_rehydrate.py -> FAILED (errors=1): module 'bvh_rehydrate' has no attribute 'same_report_path'. Restored with git checkout HEAD -- tools/bvh_rehydrate.py. This is a refactor, so the control shows only that the test needs the shared helper.

Diff read: the --out-versus-inputs guard (the dehydrated file, every --geom file, and --compare) now calls report_paths.same_report_path instead of os.path.samefile behind an os.path.exists(a.out) and isfile check, so an --out that does not exist yet but resolves to the same name on a case-folding volume is also refused. The new test stubs same_report_path to simulate the folding alias, so the real folding behavior is covered by tests/test_report_paths.py, not here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants