Skip to content

ps_oracle: refuse an unusable --json before the device opens; a failed write is one error line - #6206

Open
Koro4e wants to merge 2 commits into
ItsNotRexed:mainfrom
Koro4e:ps-oracle-json
Open

Koro4e wants to merge 2 commits into
ItsNotRexed:mainfrom
Koro4e:ps-oracle-json

Conversation

@Koro4e

@Koro4e Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Finding + claim in the coordination issue: tools/ps_oracle.py:840 wrote its --json inside the measurement's finally block with no guard.

The folder is refused right after parse_args, before the oracle opens, and the write is wrapped: one ERROR: cannot write ... line and exit 2 instead of an OSError escaping through the finally.

Tested

  • python -m pytest tests/test_ps_oracle.py -q: all pass, including the new JsonGuard test calling main() directly (no GPU needed).
  • Negative control: with main's tool the new test fails.

Note: the image_query_probe half of the same claim is released - that tool already owns this (parent created, one cannot write line, exit 2, summary kept, pinned by its tests).

Two commits: the tool, then the test. Windows 11, Python 3.12.10, CPU only. No game files. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator changes.)

… write one error line (finding in the coordination issue, claim 7102450817)
@AsgerCode

Copy link
Copy Markdown

Tested dad8ae5 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_ps_oracle.py: 22 tests, OK (2 skipped: OnHardware, needs LEONIDA_PS_ORACLE_BUILD and an AMD GPU). python -I tests/test_ps_helper_probe.py (imports ps_oracle): 6 tests, OK (1 skipped).
  • Negative control (merge-base tools/ps_oracle.py, PR tests): test_a_json_that_names_a_folder_is_refused_first fails. The old code still returns 2 here, because --asm s_endpgm is read as a file name that does not exist. The assertIn("--json is a directory") is what catches the change.
  • Merge with current main (8575d36e): clean. main changed tools/ps_oracle.py twice since the merge base (ps_oracle: a --json that names the --asm/--ps/--vs input is refused (EGEN-PSORACLE-JSON-INPUT) #6790 input guard, ps_oracle: set the selected target format on every harness call #6770 format env). On the merged tree test_ps_oracle.py gives 24 tests, OK (2 skipped), and the cases below give the same results.
  • Not run: the real device path (Oracle with vk_harness on a GPU).

I reached the write path without a GPU: I replaced ps_oracle.Oracle with a fake that returns 4 pixels, then called main(["--build", d, "--asm", body.s, "--size", "2", "2", "--json", X]):

--json PR head merge base
existing folder exit 2, ERROR: --json is a directory, not a report file: ..., fake Oracle never built PermissionError traceback after the run
same folder by 8.3 short name exit 2, same line, never built PermissionError traceback
file in a missing folder exit 2 after the run, summary printed, ERROR: cannot write ...: No such file or directory FileNotFoundError traceback
read-only existing file exit 2 after the run, ERROR: cannot write ...: Permission denied PermissionError traceback
nosuch\ (missing, trailing separator) exit 2 after the run, ERROR: cannot write ...: Invalid argument OSError traceback
new file in an existing folder exit 0, report written exit 0

Nits, none blocking:

  1. No test covers the new try/except OSError around the write, which is half of the change. A test like the cases above (patch P.Oracle with a small fake, or a mock.Mock(device=..., wave64=False) as ps_oracle: preserve shader inputs when writing JSON reports #4812 does, and point --json at a file in a missing folder) would pin "one error line, exit 2, summary kept".
  2. The title says an unusable --json is refused before the device opens. Only an existing folder is. A missing parent folder or a read-only file still runs the device, then fails at the end. The body describes this correctly. If the early refusal is meant to cover more, os.path.isdir(os.path.dirname(os.path.abspath(a.json))) up front would also catch the missing-folder case.

Overlap with open PRs:

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested dad8ae5 merged with main edc722c on Linux/Python 3.12.16: pass

Merge was clean (tools/ps_oracle.py, tests/test_ps_oracle.py).

  • python -I tests/test_ps_oracle.py: Ran 24 tests, OK (skipped=2; the skipped ones are the hardware tests, no GPU involved).
  • Negative control (tools/ps_oracle.py restored from upstream/main, tests from the PR): Ran 24 tests, FAILED (failures=1): test_a_json_that_names_a_folder_is_refused_first. PR version restored afterwards.

Diff read: a --json path that is a folder is refused with exit 2 before any device work (the test uses a build path that does not exist, so a late guard would fail on that instead), and an OSError while writing the report after the run is now one ERROR: cannot write ... line with exit 2. The write-error branch has no test, and I did not run the oracle on a GPU.

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.

3 participants