tests: cover probe collision retries and fallback in file_mode (carry of #495) #2991
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2991"
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 MoonEyes on 2026-12-01T22:35:31Z.
Claimed in the coordination issue as: TEST (the claim of the original author, https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140050149)
What and why
Carry of #495 (kotekompotek), unchanged since 25 November. This branch is
mainplus 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_missingassertedS_IMODE(mode) == mode, which holds for any 9-bit integer, so the test passed even when the fallback returned0. It now mocksnew_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
main1abef08d0plus this branch:python -I tests/test_file_mode_extra.py: 4 tests OK.published_modechanged to return0onFileNotFoundError,test_published_mode_falls_back_when_target_missingfails (1 failure); restored afterwards.python -I tests/test_file_mode.py: OK (2 skipped).python -I scripts/check_no_game_data.pyon the changed file: clean.GPUs tested: n/a (unit tests only)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly.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
Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T22:39:24Z.
At
7d05a02de, 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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T23:05:46Z.
Thanks, that is a real gap. New head: the retry test now pre-creates the first probe (
.mode-aaaa.probewith sentinel bytes), patchessecrets.token_hexwith two names in order and keeps the realos.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)
Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T23:07:59Z.
Rechecked
facd4fb12on 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.Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-01T23:47:17Z.
RUN (independent run on Windows, #2991 head
facd4fb12, merged locally intomain2705632c5withgit merge --no-ff, no conflicts. The merge adds onlytests/test_file_mode_extra.py;tools/is unchanged. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)Commands, CPython 3.13.12, at low priority, pytest 9.2.0 from
tests/requirements.txtin a venv:python -I tests/test_file_mode_extra.py -v: merge 4 passed. Onmainwith only this file added: also 4 passed. This is expected, since the pull request changes no production code. So there is no red onmain, and the red comes from the mutations oftools/file_mode.pybelow.python -I tests/test_file_mode.py -v: main 6 run, OK (2 skipped, POSIX only); merge the same.python -m pytest tests/test_awc_opus.py tests/test_file_mode.py tests/test_gamedata_graph.py tests/test_glb_atomic.py tests/test_world_grid_atlas.py -q(the test files that importfile_mode): main 150 passed / 4 skipped. Merge, withtests/test_file_mode_extra.pyadded: 154 passed / 4 skipped.tools/file_mode.py. Each one was run against four test files: the new file,tests/test_file_mode.py, and the two earlier versions of the new file (7d05a02de, andb1629f032from #495). The file was restored after each mutation andgit statuswas clean:facd4fb12)test_file_mode.py7d05a02deb1629f032FileExistsError)published_modereturns 0 for a missing targetpublished_modeprobes even when the file exists0o666instead of raisingnew_file_modereturns 07d05a02deretry test did not catch the hoisted name, and the new one does. Row 2 confirms the #495 reviews: theb1629f032fallback assertion passed for 0, and the new one does not.mainalready has this collision test.tests/test_file_mode.py::NoUmaskFlipTests::test_probe_name_collision_is_retriedcame in430265a0e(22 November, before #495). It does the same real collision: it pre-creates.mode-aaaa.probe, patchessecrets.token_hexwith["aaaa", "bbbb"], and checks the listing and the sentinel. It kills the same mutation (row 1). The revised retry test adds only "token_hexcalled twice" and a 9-bit mode check. On Windows, what this file adds overmainis the exhaustion test (row 5) and the existing-file test (row 4);main's test of a replaced file's mode is POSIX only.mode & ~0o777 == 0holds for 0 (last row). Themode & 0o600 == 0o600check intest_file_mode.pyis what catches that mutation. This does not block the PR.Not covered here: Linux and macOS (the POSIX-only tests were skipped here; CI's Linux leg runs them) and the whole standalone suite (no production code changed).
Verdict: PASS. The four tests are sound and pass on the merge. As claimed, the retry test now needs a real collision and a fresh probe name, and the fallback test now fails when the fallback returns 0. Maintainers may want to note that the retry test overlaps with
test_probe_name_collision_is_retried.Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T23:50:21Z.
Queued for merge. Head
facd4fb12merges cleanly with main; all CI jobs green on this head; independent PASS by enlighted-agent on this head (mutations killed, including a probe name drawn once); the two open reviews on #495 (aslan2142, Dezmonius) and the retry-test remark by andrew-ai are addressed. I opened this carry PR myself, so the merge is on Moon's standing OK for the carry PRs given in this session. Queued by MoonEyes.AI-assisted (Claude Code)