Skip to content

shader_library: a --save that names the input is refused, not written over it (EGEN-SHADERLIB-SAVE-SRC) - #6478

Open
evilclanker9000 wants to merge 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/7-shaderlib-save-src
Open

evilclanker9000 wants to merge 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/7-shaderlib-save-src

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

What changed

tools/shader_library.py reads its input, then opens --save for writing. Nothing stopped the two from being the same file, so the documented form

python -I tools/shader_library.py <package>\shaders.rpf --save shaders.rpf

read the archive and then replaced it with the 2,333-byte library taken out of it: the user's shaders.rpf is gone, and the run exits 0 as if it had worked.

  • tools/shader_library.py: ap.error("--save must not overwrite the input") when report_paths.same_report_path(a.save, a.src), the guard the other tools use (user_sgpr_census.py, script_qtable.py, ...). Exit 2 and one line on stderr, before anything is read or written.
  • Module usage and docs/shader_library.md say the refusal, since --save is the documented way to write the library out.

Why it matters

The only documented inputs are shaders.rpf and a file written with --save; the wrong spelling of --save destroys the first one, and the command is otherwise correct. same_report_path also catches a hard link and, on Windows, a case-only spelling (SHADERS.RPF).

Test

python -I tests/test_shader_library.py (new Main.test_save_must_not_overwrite_the_input; no game data, the archive is built by the test module).

Before, on main at 4beffda88, the test fails and the output shows the damage:

FAIL: test_save_must_not_overwrite_the_input
library: 2333 bytes written to C:\Users\Lucas\AppData\Local\Temp\tmpeg38z4q1\shaders.rpf
AssertionError: SystemExit not raised

After, the whole file passes:

Ran 10 tests in 0.142s

OK

End to end through the CLI, with a hand-built archive in %TEMP%:

same path  : exit 2 | shader_library.py: error: --save must not overwrite the input
intact     : True
other path : exit 0 | library: 2333 bytes written to ...\lib.bin
saved bytes: 2333
case only  : exit 2 | shader_library.py: error: --save must not overwrite the input
intact     : True

GPU

No GPU needed; standard-library Python only.

Notes

AI-assisted.

--save opens its path for writing after the input is read, so 'shader_library.py shaders.rpf --save shaders.rpf' replaced the archive with the 2 KB library extracted from it. Guard it with report_paths.same_report_path, as the other tools do, so a case or hard-link spelling of the input is refused too.
…archive intact

Fails before the guard: main() returned 0 and wrote the library over shaders.rpf ('library: 2333 bytes written to ...\\shaders.rpf'). The test also asserts the file's bytes are unchanged, which is the damage the guard prevents.
@milas6669

Copy link
Copy Markdown

Tested head 3c760d8cb on Windows 11 (build 26200), Python 3.14 (python -I), clean worktree:

  • tests/test_shader_library.py: 10/10 tests passed in 9.81s, including the new Main.test_save_must_not_overwrite_the_input check.
  • Verified same_report_path check triggers before reads/writes, rejecting --save collisions (and case-variant paths on Windows) with exit 2 and ap.error("--save must not overwrite the input").
  • Full tree scripts/check_no_game_data.py exits 0.

Clean, minimal guard using the shared report_paths.same_report_path utility. Synthetic tests only, no game files. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 3c760d8 merged with main 8bcf3eb on Linux/Python 3.12.16: pass

Commands run (merged worktree, -I isolated mode):

  • python -I tests/test_shader_library.py -> Ran 11 tests, OK
  • Negative control: git checkout upstream/main -- tools/shader_library.py docs/shader_library.md, rerun -> FAILED (failures=1): SystemExit not raised, and the old tool printed library: 2333 bytes written over the synthetic input archive (the test's temp copy). Restored with git checkout HEAD -- tools/shader_library.py docs/shader_library.md.

Diff read: main() calls ap.error("--save must not overwrite the input") (exit 2, before the input is opened) when report_paths.same_report_path(a.save, a.src); the module docstring and docs/shader_library.md say so. The test checks the exit code, the message and that the input bytes are unchanged.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 3c760d8c on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27: pass

  • python -I tests/test_shader_library.py: Ran 11 tests, OK. With only the non-test files reverted to main: FAILED (failures=1), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

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