Skip to content

ps_oracle: preserve shader inputs when writing JSON reports - #4812

Closed
illusionart453-max wants to merge 2 commits into
ItsNotRexed:mainfrom
illusionart453-max:fix/ps-oracle-report-alias
Closed

illusionart453-max wants to merge 2 commits into
ItsNotRexed:mainfrom
illusionart453-max:fix/ps-oracle-report-alias

Conversation

@illusionart453-max

@illusionart453-max illusionart453-max commented Nov 23, 2026 •

Copy link
Copy Markdown

A JSON report can alias the ISA source or either template shader and replace it after a successful run. Use report_paths.same_report_path before constructing the oracle to reject direct paths and file aliases. CPU tests reproduce six original overwrite cases across --asm, --vs and --ps, then verify preserved bytes and that oracle startup is skipped. A separate successful-report test verifies output and oracle cleanup.

Claimed as a new BUILD/TEST item (ID pending assignment)
#4683 (comment)

Verified on Windows 11, Python 3.15.2, CPU only.

  • python -I tests/test_ps_oracle.py ran 22 tests, OK with 1 hardware-dependent skip. Six new preservation subcases failed before the fix.
  • python -I tests/test_report_paths.py passed.
  • git diff --check passed.

AI-assisted (Codex). Synthetic inputs only.
Depends on no other PR.

Hard-link portability follow-up (d3255b2): unsupported hard links skip only those subtests; direct-path preservation checks continue. Mocking os.link failure reproduced three errors before the change and gives three skips, no failures/errors and three direct-path calls after it. Normal run remains 22 tests OK with one hardware skip. Adapted from @KkelebekK's review note; CPU only.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4ef9e6ea on Windows 11, CPython 3.14.7: the input protection passes.

I ran python -I tests/test_ps_oracle.py -v. The 21 CPU tests pass. The hardware test skips because this installation lacks spirv-as. Against the merge-base implementation at 98fa503f, all six input preservation cases fail.

I also ran the CLI with --asm source.s --json SOURCE.S in a temporary directory on a case-insensitive Windows volume. It exits 2 and preserves the original shader bytes.

AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent verification at 4ef9e6ea2e683687a5ab3b8c8b4b11e2934c9983 on Windows 11, Python 3.15.2 (CPU-only).

  • python -I tests/test_ps_oracle.py: 22 tests, OK (1 skipped).
  • python -I tests/test_report_paths.py: 15 tests, OK (1 skipped).
  • git diff --check from the main merge base to HEAD: clean.
  • Red control: restored only tools/ps_oracle.py from HEAD^ and reran python -I tests/test_ps_oracle.py: six preservation subcases failed, exit 1. Restored the PR file; worktree clean.

AI-assisted (Devin); no game files.

@lines9686-rgb

Copy link
Copy Markdown
Contributor

Tested 4ef9e6e on Windows 11 (26200), Python 3.12: pass. tests/test_ps_oracle.py OK (1 skipped, as on main); against the base's tools/ps_oracle.py (98fa503) the same file fails 6, so the report-writing path is what the new cases check. Merges cleanly with main; compileall OK. No game files. AI-assisted (Claude Code).

@KkelebekK

Copy link
Copy Markdown

Reviewed and tested 4ef9e6ea (alone and merged with main 3faac557), CPU only: Linux, Python 3.14.10. Merges cleanly with main.

No blocking issues. Non-blocking: the linked=True subtests call os.link without the skipTest fallback that test_report_paths.py uses. On a file system or sandbox without hard links they would error rather than skip.

AI-assisted.

@illusionart453-max

Copy link
Copy Markdown
Author

@KkelebekK Addressed the hard-link portability note in d3255b2. When os.link is unsupported or raises OSError, only that hard-link subtest skips; the three direct-path checks still run. With os.link mocked to fail, the prior test gives three errors, while the update gives three skips, zero errors/failures, and exactly three calls through the direct-path checks. Normal filesystem: 22 tests OK, one existing hardware skip. Thanks for the review. AI-assisted, CPU only.

@SweatierKey

Copy link
Copy Markdown
Contributor

Independent CPU verification on Linux (Python 3.13.5, head d3255b28, base main 3faac557):

  • python3 -I -m py_compile tools/ps_oracle.py tests/test_ps_oracle.py — clean.
  • python3 -I tests/test_ps_oracle.py -v — 21 passed, 1 skipped (hardware oracle) in 0.008s.
  • python3 -I tests/test_ps_helper_probe.py — 5 passed, 1 skipped (0.007s).
  • Verified the d3255b28 portability fix directly by mocking os.link to raise OSError: Cli.test_report_cannot_replace_shader_inputs passed with 3 skipped (only the 3 hard-link subtests skipped; all 3 direct-path subtests still ran and passed).
  • git diff --check origin/main...HEAD — clean.

Looks good to merge.

@kapitche

Copy link
Copy Markdown
Contributor

Tested d3255b2 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.
Ran tests/test_ps_oracle.py (22 tests OK, 1 skipped: the real-GPU draw needs LEONIDA_PS_ORACLE_BUILD) and tests/test_report_paths.py (OK).
Negative control: with tools/ps_oracle.py reset to main, test_report_cannot_replace_shader_inputs fails for all 6 subtests (--asm/--vs/--ps, plain and hard-linked); the second new test (a distinct --json still writes and closes the oracle) passes on main too, as expected for a regression guard. Restored, all pass.
The change is small: --json is checked with report_paths.same_report_path against --asm/--vs/--ps before the oracle is opened, and the tests use a mocked Oracle, so no GPU was involved.

@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 d3255b283 on Windows 11: pytest tests/test_ps_oracle.py -q -> 21 passed, 1 skipped, 41 subtests passed; git diff --check clean.

The report-alias checks now skip a hard link the filesystem cannot create/read (the os.link unavailable case) instead of failing the test on that host, so the alias coverage still runs where links work and is honestly skipped elsewhere; the added cases cover the unavailable-link path. No blocking issue.

@Andretuta

Copy link
Copy Markdown
Contributor

Tested d3255b28 alone and merged with main 3faac557, CPU only. Linux, Python 3.12.16. Merges cleanly.

  • test_ps_oracle: 22 OK, 1 skip. test_ps_helper_probe, test_report_paths and test_report_path_case are OK. Same results on the branch and on the merge. compileall and git diff --check are clean.
  • Red control: with main's tools/ps_oracle.py, all six preservation subtests fail.
  • CLI with no build: --json as a symlink to --asm, as ./sub/../source.s, or as the absolute path of --ps each exit 2 and leave the file unchanged. A distinct --json still reaches the oracle (exit 77).

Non-blocking:

  • tests/test_ps_oracle.py:316: two blank lines before test_nothing_to_do_is_a_usage_error inside the class (E303).
  • The check also runs with --show-template and no --asm, where nothing is written, so --show-template --ps x --json x is refused. Harmless.

Looks good to merge. AI-assisted (Devin); no game files.

@MichaelL401

Copy link
Copy Markdown
Contributor

Tested d3255b28 on Linux, CPU only (no GPU), Python 3.12.16: pass.

  • python -I tests/test_ps_oracle.py: OK (1 skipped), both on the head and merged onto current main 3faac557 (the branch is 8 commits behind and merges cleanly). Negative control: with main's tools/ps_oracle.py, the same suite gives 6 failures.

Code read: --json is refused before anything runs when it names the same file as --asm, --vs or --ps, using the shared report_paths.same_report_path.

AI-assisted (Claude).

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55 (clean merge): test_ps_oracle.py passes 22 tests with 1 GPU-gated skip, including the new alias cases — the --json-over-input guard fires with exit 2 before the Oracle is constructed, and hard-link aliases are exercised where links exist (they do here). test_report_paths.py still passes 15/15. Note long-open #4152 also edits tools/report_paths.py — no conflict with this PR today, but land order may touch it. No CI checks are reported on the branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested d3255b2 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_ps_oracle.py -> OK (skipped=1)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@illusionart453-max

Copy link
Copy Markdown
Author

Conflict review against main 5d74c27 confirms this is superseded by 5bc205a / #6790. Added both PR regressions to current main without changing the tool: 25 tests run, 23 pass and 2 hardware tests skip. Identical paths and external hard-link aliases to --asm/--vs/--ps are refused before Oracle construction, input bytes remain unchanged, and a distinct report still writes and closes the mock oracle. Closing the duplicate, branch retained. Windows 11/Python 3.15.0, synthetic inputs, AI-assisted.

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.