Skip to content

test_navmesh_nodes: skip the read-only --out case when the 0o444 file stays writable - #8880

Open
DefectiveMuffins wants to merge 1 commit into
ItsNotRexed:mainfrom
DefectiveMuffins:navmeshnodes-root-test
Open

DefectiveMuffins wants to merge 1 commit into
ItsNotRexed:mainfrom
DefectiveMuffins:navmeshnodes-root-test

Conversation

@DefectiveMuffins

Copy link
Copy Markdown

Claim: #8504 (comment) (NAVMESHNODES-ROOT-TEST / coordinator TEST-1905)

What and why

tests/test_navmesh_nodes.py's ArchiveTest.test_cli_refuses_an_unwritable_out_before_the_archives_are_read creates a 0o444 --out file (read-only.json) and asserts that tools/navmesh_nodes.py refuses it (out_problem(path) checking not os.access(path, os.W_OK)) before reading either input archive. When the test suite runs as uid 0 on a writable filesystem (for example in a root container or under unshare -r), CAP_DAC_OVERRIDE makes a 0o444 file writable: os.access(out, os.W_OK) returns True, out_problem(out) returns None, and navmesh_nodes.py rightly proceeds to read junk.rpf and fails with ERROR: .../junk.rpf: not an RPF7/8/9 archive, failing the test's self.assertIn("read-only", cp.stderr).

Following the existing capability-probe pattern in tests/test_bvh_match.py (test_readonly_json_is_one_error_line), test_cli_refuses_an_unwritable_out_before_the_archives_are_read now probes with open(out, "ab"): after os.chmod(out, 0o444) and calls self.skipTest("the 0o444 --out is still writable (running as root, or a file system ignoring modes)") only when opening the 0o444 file for writing succeeds. Unprivileged runs—and uid 0 runs where out is on a read-only mount (EROFS)—raise OSError on the probe and execute the unchanged refusal and assertions ("read-only", "not an RPF9 archive", and unchanged file contents).

No open PR dependencies (Depends on: none). Separate from closed #6108 (post-scan write error handling) and #6608 (merged).

Tested

AI-assisted. Tested on Fedora Linux (kernel 7.3.3-300.fc45.x86_64), CPython 3.12.16 (-I -B); CPU-only standard-library unit test (no GPU used, no game files):

  • Commit 321d50c7b42efb77c713072d21f346e80a9035be (parent 867d922f09b86583859796a174df89555fb32da8):
    • Normal user (euid != 0): python -I -B tests/test_navmesh_nodes.py -v — 17/17 pass (Ran 17 tests in 0.490s — OK, 0 skipped).
    • Root user on writable filesystem (euid == 0): unshare -r python -I -B tests/test_navmesh_nodes.py -v — 16 pass, 1 skipped (Ran 17 tests in 0.445s — OK (skipped=1)).
    • Root user with read-only.json on a read-only bind mount (unshare -rm remounting read-only.json with mount -o remount,ro,bind): test_cli_refuses_an_unwritable_out_before_the_archives_are_read runs and passes (Ran 1 test in 0.036s — OK, skipped=0).
    • Red control (tests/test_navmesh_nodes.py at 867d922f09b86583859796a174df89555fb32da8 under unshare -r): fails test_cli_refuses_an_unwritable_out_before_the_archives_are_read with AssertionError: 'read-only' not found in 'ERROR: .../junk.rpf: not an RPF7/8/9 archive\n'.
    • python -I -B -m compileall -q tests/test_navmesh_nodes.py: exit 0.
    • python -I -B scripts/check_no_game_data.py tests/test_navmesh_nodes.py: exit 0.
    • git diff --check HEAD~1..HEAD: exit 0.

… stays writable

test_cli_refuses_an_unwritable_out_before_the_archives_are_read failed as
uid 0 (root containers, `unshare -r`): CAP_DAC_OVERRIDE makes the 0o444
--out writable, so the tool rightly went on to read the archives. Probe an
append-open on the file first, as tests/test_bvh_match.py does, and skip only
when that succeeds. A normal user, or root on a read-only mount, still runs
the unchanged refusal and its assertions.

NAVMESHNODES-ROOT-TEST
@catminou4

Copy link
Copy Markdown

Tested on Apple M1 Max, macOS 27.2.1 arm64, Python 3.12.16: python -I tests/test_navmesh_nodes.py → 17 tests OK. No game files. AI-assisted (Devin).

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review (321d50c7)

What changed: test_navmesh_nodes skips the read-only --out case when a 0o444 file stays writable (e.g. root).

Checked: test_navmesh_nodes 16 OK (1 skipped). Complements #8884's preserve change.

Looks correct; no game files.

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