Skip to content

test_mod_pack_output_alias: key the fake samefile on realpath, as report_paths does; passes on macOS (TEST-MOD-PACK-ALIAS-REALPATH) - #2175

Closed
Tauwni wants to merge 2 commits into
ProjectLeonida:mainfrom
Tauwni:fix/mod-pack-alias-test-realpath
Closed

Tauwni wants to merge 2 commits into
ProjectLeonida:mainfrom
Tauwni:fix/mod-pack-alias-test-realpath

Conversation

@Tauwni

@Tauwni Tauwni commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-MOD-PACK-ALIAS-REALPATH (#1608 (comment))

What and why

tests/test_mod_pack_output_alias.py fails on macOS on main:

FAIL: test_alias_preflight_precedes_output_truncation (relative='mod.json')
AssertionError: ModsError not raised
FAIL: ... (relative='nested/notes.txt')
AssertionError: ModsError not raised

The test patches report_paths.os.path.samefile with a fake that answers true for the two paths it built. But report_paths.same_report_path passes samefile the os.path.realpath of each path. On macOS, tempfile's folder /var/folders/... resolves to /private/var/folders/..., so the fake never matches and the alias check never fires. On Linux and Windows the temporary folder isn't a symlink, so the test passes there.

The fix is only in the test: the fake keys on normcase(realpath(path)), like report_paths does. tools/ is unchanged.

Tested

Apple M3, macOS 26.5.1, Python 3.15, on main ad41fd517:

  • Before: 2 failures. With TMPDIR set to a folder that isn't a symlink, the old test passes, which confirms the cause.
  • After: OK, with both the default and a real TMPDIR.
  • With the alias guard in pack_mod disabled, the fixed test fails (4 failures), so it still catches the bug it was written for.
  • tests/test_report_paths.py OK.

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.

🤖 Generated with Claude Code

…s, as report_paths does

On macOS the temporary folder /var/... resolves to /private/var/..., so the fake never matched the resolved paths
report_paths passes it and test_alias_preflight_precedes_output_truncation failed (ModsError not raised).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EdenBendheim

Copy link
Copy Markdown
Contributor

Note

🤖 gpt-6.2-sol responding on behalf of EdenBendheim

Independent verification of head 904dfe2500b739fb3e2f418d3246e5f7ca70c6bf applied to current main a73a57e13 (macOS 27.3, Apple M1 Max, Python 3.12.14, synthetic fixtures only).

  • Main: both alias-preflight subtests fail with the default temporary directory; resolving TMPDIR through realpath makes them pass.
  • PR: test_mod_pack_output_alias.py passes 3/3 under both configurations.
  • test_report_paths.py: all 24 tests accounted for (23 passed, one expected platform skip).
  • Clean simulated merge, no-game-data and diff checks.

This resolves the other pre-existing failure observed in the full standalone test run for #2193. Test-only correction, no defects found.

@real-rusher

Copy link
Copy Markdown

Checked on main a73a57e (Ubuntu 24.04 x86-64, Python 3.13). Merges cleanly. python -I tests/test_mod_pack_output_alias.py: 3 tests OK with this PR, and also OK on main: the failure it fixes is macOS-only by its title, and Linux does not reproduce it, so this is only a Linux no-regression check, not a confirmation of the macOS fix.

AI-assisted: yes (Claude Code)

@real-rusher

Copy link
Copy Markdown

Follow-up to my earlier comment: the failure does reproduce on Linux once the temp folder is reached through a link. With TMPDIR pointing at a symbolic link (/tmp/linktmp -> /tmp/realtmp), python -I tests/test_mod_pack_output_alias.py fails on main (2 failures) and passes with this PR.

Possible duplicate: the older open #1412 (TEST-MOD-PACK-ALIAS-MACOS) makes the same fix to the same file and also passes this control; the two conflict, so only one of them should land.

AI-assisted: yes (Claude Code)

@TheGeogeo

TheGeogeo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Independent check on Windows of head 011fbd3a9e, merged into main 935a2cd5b (clean merge). Windows 11 Pro 10.0.26300, Python 3.12.4, CPU only, synthetic fixtures, no game data.

The failure is not macOS-only. It also happens on Windows when TEMP is an 8.3 short name, which is the default on this machine (C:\Users\<USERNA~1>\AppData\Local\Temp, the 8.3 form of C:\Users\<username>). realpath expands it to the long spelling, so the fake samefile never sees the names it was keyed on, the same way /var becomes /private/var on macOS.

  • main 935a2cd5b: python -I tests/test_mod_pack_output_alias.py fails, 2 failures in 3 tests (ModsError not raised, both subtests of test_alias_preflight_precedes_output_truncation). The file also fails in a local run of the Windows check job's standalone-test step. With TEMP and TMP set to the long spelling, the same file passes, 3 of 3.
  • This PR merged with main: 3 of 3 OK with the short TEMP (4 runs) and with the long one. The head alone: OK.
  • Negative control: with the raise ModsError(...) in pack_mod (tools/leonida_mods.py:492) replaced by pass, the test fails (4 failures). It still catches the alias.
  • tests/test_report_paths.py: OK. scripts/check_no_game_data.py and git diff --check on the changed file: clean.

So the description's "On Linux and Windows the temporary folder isn't a symlink, so the test passes there" does not hold for Windows with a short-name TEMP. The change fixes that case too.

Duplicate, as real-rusher noted: #1412 (head 09970b7531) makes the same change. Merged with the same main, it gives the same results here: 3 of 3 with both TEMP spellings, and 4 failures with the guard removed. Only one of the two should land.

AI-assisted: yes (Claude Code).

Status: OK to merge. The gain is real: it turns a test that fails on main on Windows (short-name TEMP) and on macOS green, and keeps it catching the alias. Duplicate of #1412 (same change, opened first): merge one of the two and close the other.

@wavehs

wavehs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Verified independently on main bd6ba97ab (macOS 27.2.1 arm64, Python 3.15.2, no numpy), with the PR diff applied:

Before (python3 -I tests/test_mod_pack_output_alias.py, unmodified main):

FAIL: test_alias_preflight_precedes_output_truncation (relative='mod.json')
AssertionError: ModsError not raised
FAIL: test_alias_preflight_precedes_output_truncation (relative='nested/notes.txt')
AssertionError: ModsError not raised
Ran 3 tests ... FAILED (failures=2)

After: Ran 3 tests ... OK.

Negative control: with the same_report_path preflight removed from pack_mod, the fixed test fails again (FAILED (failures=4)), so it still catches the alias it was written for, not just the spelling.

I also confirmed the cause from the other side: pointing TMPDIR at a folder that is not a symlink makes the old test pass. The change is test-only, and os.path.realpath is exactly what report_paths.same_report_path now feeds samefile. Looks right to me.

AI-assisted (verification run only).

@wavehs

wavehs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Heads-up for the coordinator: this is a duplicate of #1412 (milk4sale, opened 2026-11-24 23:42, before this one), and that PR is the stronger of the two:

Both apply cleanly to main bd6ba97ab; I verified this one's test result (3 tests OK) in my comment above, so there is nothing wrong with it — just no reason to merge both. My vote is to land #1412 and close this one; if this one lands first, #1412 needs closing instead.

AI-assisted (review only).

@Tauwni

Tauwni commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #1412 (milk4sale), which was opened first with the same realpath fix and also covers the Windows side. Thanks @wavehs for spotting it. I confirmed #1412 on the M3 there.

AI-assisted (Claude Code).

@Tauwni Tauwni closed this Nov 26, 2026
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