Skip to content

tests: cover probe collision retries and fallback in file_mode (carry of #495) - #2991

Open
MoonEyes wants to merge 4 commits into
ProjectLeonida:mainfrom
MoonEyes:carry/495
Open

MoonEyes wants to merge 4 commits into
ProjectLeonida:mainfrom
MoonEyes:carry/495

Conversation

@MoonEyes

@MoonEyes MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: TEST (the claim of the original author, #14 (comment))

What and why

Carry of #495 (kotekompotek), unchanged since 25 November. This branch is main plus the head of #495 (the author's commit is kept), and one commit of mine that answers the two reviews on #495 (aslan2142, Dezmonius).

The reviews found that test_published_mode_falls_back_when_target_missing asserted S_IMODE(mode) == mode, which holds for any 9-bit integer, so the test passed even when the fallback returned 0. It now mocks new_file_mode, checks that the target's own directory is probed and that the sentinel comes back. A second test checks that an existing file keeps its own mode and does not probe.

Tested

Windows 11, no GPU, no game files, on main 1abef08d0 plus this branch:

  • python -I tests/test_file_mode_extra.py: 4 tests OK.
  • Red: with published_mode changed to return 0 on FileNotFoundError, test_published_mode_falls_back_when_target_missing fails (1 failure); restored afterwards.
  • python -I tests/test_file_mode.py: OK (2 skipped).
  • python -I scripts/check_no_game_data.py on the changed file: clean.
  • Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md. (n/a: tests only)

Supersedes #495 once merged; the original stays open until a maintainer decides.

AI-assisted (Claude Code)

🤖 Generated with Claude Code

kotekompotek and others added 3 commits November 25, 2026 13:55
The old assertion (S_IMODE(mode) == mode) passes for any 9-bit integer, even 0.
The test now mocks new_file_mode, checks the target's own directory is probed and
the sentinel is returned, and a second test checks an existing file keeps its mode.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@andrew-ai

Copy link
Copy Markdown

At 7d05a02, all four new tests pass on Windows even if the probe name is generated once before the retry loop. With that change a real collision exhausts the retries on the same file. The mocked open succeeds on its third call regardless of the path.

Could the retry-success test pre-create the first probe with sentinel bytes and patch secrets.token_hex to return two distinct names in order? With real os.open, the current implementation returned 0o666, preserved the sentinel, and removed the second probe. Moving name generation outside the loop raised FileExistsError and requested only one name. This would make the test catch the regression. Codex-assisted.

The mocked open succeeded on its third call whatever the path, so generating the
probe name once before the loop still passed. The test now pre-creates the first
probe, patches secrets.token_hex with two names and keeps the real os.open.
Reported by andrew-ai on the carry PR.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MoonEyes

MoonEyes commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, that is a real gap. New head: the retry test now pre-creates the first probe (.mode-aaaa.probe with sentinel bytes), patches secrets.token_hex with two names in order and keeps the real os.open. Green on the fixed tool (4 tests); red when the probe name is generated once before the retry loop (1 error). The sentinel file is checked untouched.

AI-assisted (Claude Code)

@andrew-ai

Copy link
Copy Markdown

Rechecked facd4fb on Windows. All four tests passed. Moving name generation above the retry loop now fails the revised collision test with FileExistsError, which the earlier test missed. My original finding is resolved. Codex-assisted.

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