Skip to content

world_names: refuse build --out overwriting an input - #4471

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
leoleahy:fix/world-names-build-out-overwrite
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
leoleahy:fix/world-names-build-out-overwrite

Conversation

@leoleahy

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #4421 (comment)

What and why

tools/world_names.py already refuses resolve --out when the output path would overwrite any input (--dict, --maps, --archetypes) via same_report_path, tested by CliTest.test_resolve_out_refuses_to_overwrite_an_input.

build had no equivalent guard: passing --out pointing to any --manifest, --scan, --names, --rpf9-names, or --xml file — or to a models/manifest.json discovered under a --manifest <dir> tree, or a hard link to any of them — silently overwrote the input file with the generated dictionary JSON and exited 0.

Changes:

  • Add _build_input_paths(args) and check same_report_path(args.out, path) in _build() before calling build_dictionary(), raising ValueError(f"build: --out {args.out} would overwrite input {path}") (matching _resolve()'s error format and exit code 1). When --out does not exist yet, directory traversal is skipped to avoid a redundant walk.
  • Add CliTest.test_build_out_refuses_to_overwrite_an_input in tests/test_world_names.py covering all five input flags, directory-discovered models/manifest.json, and hard links to both direct and discovered inputs.

Distinct from #4404 (build_dictionary os.walk onerror) with no overlapping hunks.

Tested

Windows 11, Python 3.14.8, CPU only, no game files (synthetic fixtures only).

  • At HEAD (63e1f44d): python -I tests/test_world_names.py -> 25 tests, OK.
  • Negative control (16282101 tools/world_names.py + HEAD tests): 8 subtest failures in test_build_out_refuses_to_overwrite_an_input (inputs silently overwritten on base).
  • python -m compileall -q tools/world_names.py tests/test_world_names.py, git diff --check, LF check (i/lf w/lf), and git merge-tree --write-tree upstream/main HEAD all clean.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md).
  • No translator rule changed.
  • No new CLI flags added.

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 63e1f44d on Windows 11: python -I tests/test_world_names.py -> 25 tests, OK; git diff --check clean.

world_names build --out now refuses to overwrite an input, and the path tests pass. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 63e1f44d on Linux (Ubuntu), CPython 3.10.12, CPU only, synthetic inputs, no game files: pass.

  • python -I tests/test_world_names.py: 25/25 OK.
  • Negative control: with main's tools/world_names.py the new test_build_out_refuses_to_overwrite_an_input fails on all 8 parametrized inputs — build --out proceeds/returns 2 instead of refusing.
  • git diff --check clean; compileall clean.

AI-assisted (Devin).

@mrbean56

Copy link
Copy Markdown

Tested 63e1f44deb on Linux (Debian 13), Python 3.13.5: pass.

  • pytest tests/test_world_names.py -q: 25 passed, 14 subtests passed.
  • Negative control: with main's tools/world_names.py and this test file, 8 tests fail (including test_build_out_refuses_to_overwrite_an_input on both the explicit and directory-manifest rows, and the hard-link rows), so the guard is pinned.
  • Walked the implicit case by hand: a tree with models/manifest.json, build --manifest <tree> --out <tree>/models/manifest.json prints one ERROR: build: --out … would overwrite input … line and exits 1 through main's existing ValueError handler; the 3-byte input file is unchanged. Pointing --manifest at the file itself is caught by the explicit check too.
  • The os.path.exists(args.out) gate is sound: if the output does not exist it cannot overwrite anything, so skipping the tree walk there costs nothing.

No GPU, no game data. AI-assisted.

@memorypressure

Copy link
Copy Markdown

Checked at 63e1f44 merged with main 3faac55: merges cleanly (older base, an ancestor of main — not stacked). tests/test_world_names.py passes fully including the new refusals across all six input kinds plus direct and discovered hardlinks (rc 1, one stderr line, input bytes untouched, stdout empty). The guard reuses same_report_path from report_paths.py and mirrors the existing resolve-side check, and it precedes any write or makedirs; test_report_paths, test_world_index and test_world_place all pass. test_joaat_agreement is red identically on clean main — the known utf-8/latin-1 breakage pending #4753/#4882, unrelated to this PR. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@ItsNotRexed
ItsNotRexed merged commit 6b907a2 into ItsNotRexed:main Nov 23, 2026
2 checks passed
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.

6 participants