Skip to content

world_archetypes: refuse --out equal to the input, one error line for a bad --out - #3330

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-archetypes-out
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-archetypes-out

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

What broke

tools/world_archetypes.py with --out equal to the input file (world_archetypes.py x.bin --out x.bin) ran the scan, then opened the input for writing: the 3000-byte input became a 293-byte JSON report. --out under a regular file, or naming a folder, raised FileExistsError/IsADirectoryError tracebacks, again only after the whole scan.

Fix

The report path is checked right after argument parsing, before the scan: same_report_path against the input, a folder as --out, and makedirs failures each give one world_archetypes.py: error: ... line and exit 2. The final write is also guarded.

Tested

  • python -I tests/test_world_archetypes.py: 15 tests OK, Python 3.12.16, Linux (WSL2).
  • Negative control: with only tools/world_archetypes.py reverted to upstream/main, the two new tests fail (input truncated; traceback).

Claim: #3232

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Verified on origin/main 16282101, Windows 11, Python 3.12.0 — the guard is pinned by the PR's own tests.

  • python -IB tests/test_world_archetypes.py on this branch → OK.
  • Control (tool reverted to main, test kept) → 1 failure + 1 error: test_out_equal_to_the_input_is_refused_and_leaves_it_alone fails and test_out_under_a_regular_file_or_naming_a_folder_is_one_error errors. Both name the refusal that the PR adds, and the "leaves it alone" half is the part I care about — it checks the input is untouched, not just that the exit code is 2.

One note from a sibling tool, since this is the same class as my #2930: world_archetypes already refused a folder --out, so this closes the remaining alias (input == out) rather than a new guard. No objection.

@tomgamer22 tomgamer22 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.

The checks now run before the scan and use the shared report_paths.same_report_path (realpath + normcase, falling back to samefile), so other spellings of the input's path are refused too. Both new tests fail on the merge base and pass here. AI-assisted review (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 10509fb into ItsNotRexed:main Nov 23, 2026
3 of 10 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.

4 participants