Skip to content

world_names: fail on an unlistable sub-folder instead of silently skipping its manifests - #4404

Open
SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/world-names-walk-onerror
Open

SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/world-names-walk-onerror

Conversation

@SebSilent

Copy link
Copy Markdown
Contributor

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

What and why

world_names.py build_dictionary discovers manifests in a directory tree with os.walk(path) and no
onerror. os.walk silently skips a sub-folder it cannot list, so build reported the remaining manifests
and exited 0, hiding an incomplete scan. Reproduced on 03b09a0: build --manifest on a tree with a
models/manifest.json in the root and in a sub-folder yields 2 names; after chmod 000 on the sub-folder it
yields 1, exit 0. The walk now passes an onerror that re-raises, which main()'s existing
except (OSError, ValueError, json.JSONDecodeError) turns into one ERROR: line (exit 1, the tool's
convention). Same os.walk/onerror completeness gap as #4277 / #4342 / #4355 / #4372 / #4385.

Tested

Linux, Python 3.14.10, CPU only, no game files (synthetic manifests).

  • New tests/test_world_names.py::DictionaryTest::test_unlistable_subfolder_is_a_clean_error_not_a_silent_skip:
    chmod 000 a sub-folder, WN.main(["build", "--manifest", assets, "--out", out]) returns 1 with an ERROR:
    line and no traceback (skips when the folder is still listable, e.g. running as root or on Windows). Red on
    the base: exit 0. Green: whole file 27 OK.
  • python -m compileall -q make_game.py tools tests, git diff --check clean.

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. (no translator rule changed)
  • Docs updated for any new flag, tool or workflow. (no new flag)

AI-assisted (Tacit).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 403e467 on Windows, CPython 3.14.7, CPU only (no GPU, no game files): pass. This adds a real Windows permission failure, because the permission test skips on Windows.

The test file runs 27 cases with one skip, at this head and at the merge base. The permission case skips because chmod does not stop a directory listing on Windows.

I made assets/models/manifest.json and assets/sub/models/manifest.json, each with one synthetic name. Then I removed the "List folder" permission on assets/sub for the current Windows user. os.listdir gives WinError 5.
python -I tools/world_names.py build --manifest assets --out dict.json:

  • At this head: exit status 1, one ERROR line, and no dictionary file.
  • At the merge base (03b09a08): exit status 0 and a dictionary with only one of the two names.
    After I restored the permission, this head gives exit status 0 and finds the two names.

I found no defect. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at 403e4678 on Windows 11: python -I tests/test_world_names.py -> 27 tests, OK (1 skipped); git diff --check clean.

An unlistable sub-folder now fails the world-name scan instead of silently skipping its manifests, matching the other walk fixes. No blocking issue.

@tupacfan04

Copy link
Copy Markdown
Contributor

The fix is right - the base exits 0 and reports 1 name while silently dropping the sub-folder, and the PR exits 1 with one ERROR: [WinError 5] Access is denied: '...sub' line and no output file - but the test is dead in CI.

26/27 tests pass with the new one skipped, compileall/diff --check clean, merge clean.

Same gap as #4417: tests/test_world_names.py:123 skips on Windows and as root, the stdlib suite runs only on windows-latest, and the Ubuntu job excludes these files (ci.yml:141). Patch os.walk to raise, or add a Linux stdlib leg, so the regression is actually checked.

AI-assisted review, no game files, no GPU.

…k a folder

The regression test self-skips on Windows and as root, and CI runs this file
only on windows-latest, so the guard was never exercised in CI. Force
os.scandir to raise for one folder instead, in-process, which reproduces the
same PermissionError on every platform.

AI-assisted.
@SebSilent

Copy link
Copy Markdown
Contributor Author

Both points addressed. The dead chmod test stays as the real-filesystem check, and a new one forces the same PermissionError through os.scandir so it runs on the windows-latest job and under root. Rebased and pushed: head 3cdfe54, 28 tests OK in the file, compileall and diff --check clean.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 3cdfe54 merged with main 98fa503 on Linux (Python 3.12.16): pass - tests/test_world_names.py 28 tests OK; negative control: tools/world_names.py restored from main with the PR test kept -> FAILED (failures=2: 0 != 1 twice).

@SebSilent

Copy link
Copy Markdown
Contributor Author

Done in 3cdfe54. Same approach as #4417: a second test forces os.scandir to raise PermissionError for one sub-folder via mock.patch, so the guard runs on Windows and as root too. The chmod test stays for where it can run. 28 tests OK, the portable one runs everywhere.

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.

5 participants