script: extract testable main(argv) in script_path_replay and expand unit and CLI coverage #2073

Merged
Ammmae0x merged 3 commits from upstream-pr/2080 into main 2026-11-25 12:34:11 +00:00
Ammmae0x commented 2026-11-25 00:03:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:03:58Z.


Change

Extract a testable main(argv=None) -> int entry point in tools/script_path_replay.py and expand positive and negative unit and CLI coverage in tests/script_state_check.py:

  • tools/script_path_replay.py: extract main(argv=None) -> int, preserving parser.exit(1, ...) error handling on (OSError, ValueError) (zero uncaught Python tracebacks) and preserving select_tree(), state_index(), replay(), and JSON stdout output.
  • tests/script_state_check.py: preserve all existing literal probe tests and add a synthetic RPF9 (9FPR) linked-sibling state hierarchy fixture + mocked ctypes.CDLL resolve_script_path oracle covering:
    • Positive paths: select_tree(), state_index(), replay() across absolute and relative paths (., .., nested, missing, ambiguous, verified camera parameters), and main(argv) JSON stdout validation.
    • Negative controls: non-9FPR magic, missing/duplicate anchor, invalid parent index (i == 0 with parent != 65535, parent >= i), out-of-bounds attribute slices, duplicate state ID attribute, missing/multiple root states containers, non-root node 0, malformed paths ("", "./", "a//b", "a/.", "a/..", ".", ".."), native-vs-parent-index mismatch (actual != expected and unchanged active), and main(argv) missing/invalid archive or missing/failing --host DLL pinning SystemExit(1) with zero tracebacks.

Verification

Tested on commit f7aa7790 (rebased onto upstream/main 6218beb2, Windows x64, Python via out/pe-env):

  1. .\out\pe-env\Scripts\python.exe -B tests/script_state_check.py
    • Result: Ran 22 tests in 0.872s — OK (exit 0).
  2. .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
    • Result: form coverage checks passed (exit 0).
  3. .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
    • Result: Self-test passed. Checked 18 Markdown files and 393 links. (exit 0).
  4. .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
    • Result: Self-test passed. Checked 1413 tracked source, script and build/CI files: no bidirectional controls. (exit 0).

Note: tests/script_state_check.py is already registered in CTest (CMakeLists.txt untouched) and no C++ targets were modified.

Evidence and follow-up

  • All added tests use a synthetic, self-contained in-memory RPF9 (9FPR) fixture and mocked resolve_script_path oracle; no external binaries or game files are used.
  • Negative controls pin exact ValueError messages and SystemExit(1) exit codes with zero raw tracebacks across select_tree(), state_index(), replay(), and main(argv).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593990969 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2080). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:03:58Z. --- ## Change Extract a testable `main(argv=None) -> int` entry point in `tools/script_path_replay.py` and expand positive and negative unit and CLI coverage in `tests/script_state_check.py`: - `tools/script_path_replay.py`: extract `main(argv=None) -> int`, preserving `parser.exit(1, ...)` error handling on `(OSError, ValueError)` (zero uncaught Python tracebacks) and preserving `select_tree()`, `state_index()`, `replay()`, and JSON stdout output. - `tests/script_state_check.py`: preserve all existing literal probe tests and add a synthetic RPF9 (`9FPR`) linked-sibling state hierarchy fixture + mocked `ctypes.CDLL` `resolve_script_path` oracle covering: - Positive paths: `select_tree()`, `state_index()`, `replay()` across absolute and relative paths (`.`, `..`, nested, missing, ambiguous, verified camera parameters), and `main(argv)` JSON stdout validation. - Negative controls: non-`9FPR` magic, missing/duplicate anchor, invalid parent index (`i == 0` with `parent != 65535`, `parent >= i`), out-of-bounds attribute slices, duplicate state ID attribute, missing/multiple root `states` containers, non-root node 0, malformed paths (`""`, `"./"`, `"a//b"`, `"a/."`, `"a/.."`, `"."`, `".."`), native-vs-parent-index mismatch (`actual != expected` and unchanged `active`), and `main(argv)` missing/invalid archive or missing/failing `--host` DLL pinning `SystemExit(1)` with zero tracebacks. ## Verification Tested on commit `f7aa7790` (rebased onto `upstream/main` `6218beb2`, Windows x64, Python via `out/pe-env`): 1. `.\out\pe-env\Scripts\python.exe -B tests/script_state_check.py` - Result: `Ran 22 tests in 0.872s` — `OK` (exit 0). 2. `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` - Result: `form coverage checks passed` (exit 0). 3. `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` - Result: `Self-test passed. Checked 18 Markdown files and 393 links.` (exit 0). 4. `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` - Result: `Self-test passed. Checked 1413 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). Note: `tests/script_state_check.py` is already registered in CTest (`CMakeLists.txt` untouched) and no C++ targets were modified. ## Evidence and follow-up - All added tests use a synthetic, self-contained in-memory RPF9 (`9FPR`) fixture and mocked `resolve_script_path` oracle; no external binaries or game files are used. - Negative controls pin exact `ValueError` messages and `SystemExit(1)` exit codes with zero raw tracebacks across `select_tree()`, `state_index()`, `replay()`, and `main(argv)`. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-25 03:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:25:00Z.

Review: COMMENTED


Review of head f7aa7790c8c2538d83d95832da761d35571ef199 (comment only, no approval).

Scope: tools/script_path_replay.py (+9/-4) extracts main(argv=None) -> int; tests/script_state_check.py (+391) adds a synthetic RPF9 fixture, a Python stand-in for the native resolve_script_path, and positive and negative tests. Title is neutral, no clean-room concerns seen. CI: Linux checks, Windows build/test and fixtures pass. Mergeable.

Commands executed locally (worktree at the head SHA):

  • python3 tests/script_state_check.py -> Ran 22 tests ... OK
  • python3 tests/docs_links_check.py -> Checked 18 Markdown files and 393 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • git diff --check origin/main...HEAD -> clean
  • Win2025 run not requested: no gfx2hlsl, shader or C++ change.

Mutations of the changed logic (each reverted with git checkout -- .):

  1. main returns 2 instead of 0 -> killed (1 failure).
  2. Remove the parser.exit(1, ...) error path -> killed (5 failures, 7 errors).
  3. replay: expected = -2 if matches else -1 changed to expected = -1 (ambiguity reported as missing) -> killed (1 error).
  4. replay: expected = -1 if up > len(active_keys) else containers[0] changed to expected = containers[0] -> survived (22 OK).

Findings

  • P1: none.
  • P2-1 tests/script_state_check.py (_mock_cdll_factory, about lines 330-400): the "native" side is a Python re-implementation of the resolver, and the Python reference in replay() is a second implementation of the same rules. The tests therefore check two Python copies agree. They do not exercise the real host DLL, so a drift in the native resolver is not caught on Linux. Please say in the docstring that this is a model of the native contract, and keep a Windows test that runs replay() against the real host build.
  • P2-2 Mutation 4 survived: no test sends a relative path with more .. than the current depth (for example a first path .. plus a label, or ../../x after a depth-1 match) and expects missing with active unchanged. Please add one such case in ScriptPathReplayNegativeTests.

The main() extraction is behavior-preserving (same parser, same exit paths, JSON on stdout, SystemExit(main())).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050794218 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2080#pullrequestreview-6050794218). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:25:00Z. **Review:** COMMENTED --- Review of head `f7aa7790c8c2538d83d95832da761d35571ef199` (comment only, no approval). **Scope:** `tools/script_path_replay.py` (+9/-4) extracts `main(argv=None) -> int`; `tests/script_state_check.py` (+391) adds a synthetic RPF9 fixture, a Python stand-in for the native `resolve_script_path`, and positive and negative tests. Title is neutral, no clean-room concerns seen. CI: Linux checks, Windows build/test and fixtures pass. Mergeable. **Commands executed locally (worktree at the head SHA):** - `python3 tests/script_state_check.py` -> `Ran 22 tests ... OK` - `python3 tests/docs_links_check.py` -> `Checked 18 Markdown files and 393 links.` - `python3 tests/bidi_controls_check.py` -> `no bidirectional controls` - `git diff --check origin/main...HEAD` -> clean - Win2025 run not requested: no gfx2hlsl, shader or C++ change. **Mutations of the changed logic (each reverted with `git checkout -- .`):** 1. `main` returns 2 instead of 0 -> killed (1 failure). 2. Remove the `parser.exit(1, ...)` error path -> killed (5 failures, 7 errors). 3. `replay`: `expected = -2 if matches else -1` changed to `expected = -1` (ambiguity reported as missing) -> killed (1 error). 4. `replay`: `expected = -1 if up > len(active_keys) else containers[0]` changed to `expected = containers[0]` -> **survived** (22 OK). **Findings** - P1: none. - P2-1 `tests/script_state_check.py` (`_mock_cdll_factory`, about lines 330-400): the "native" side is a Python re-implementation of the resolver, and the Python reference in `replay()` is a second implementation of the same rules. The tests therefore check two Python copies agree. They do not exercise the real host DLL, so a drift in the native resolver is not caught on Linux. Please say in the docstring that this is a model of the native contract, and keep a Windows test that runs `replay()` against the real host build. - P2-2 Mutation 4 survived: no test sends a relative path with more `..` than the current depth (for example a first path `..` plus a label, or `../../x` after a depth-1 match) and expects `missing` with `active` unchanged. Please add one such case in `ScriptPathReplayNegativeTests`. The `main()` extraction is behavior-preserving (same parser, same exit paths, JSON on stdout, `SystemExit(main())`). AI-assisted; commands listed were executed locally.
stan495 commented 2026-11-25 07:00:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T06:34:49Z.

Review: APPROVED


Verified head f7aa7790 on Windows x64 (Python 3.12).

  • python -B tests/script_state_check.py -> passed (Ran 22 tests in 0.762s, OK)

Verdict: Approved at f7aa7790.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052912577 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2080#pullrequestreview-6052912577). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T06:34:49Z. **Review:** APPROVED --- Verified head `f7aa7790` on Windows x64 (Python 3.12). - `python -B tests/script_state_check.py` -> passed (`Ran 22 tests in 0.762s`, `OK`) Verdict: Approved at `f7aa7790`.
tedin7 commented 2026-11-25 12:01:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:36:04Z.

Review: COMMENTED


Re-review of head 05503a043623a52d4471b0f0c4858b792e39077c (comment only, no approval). Previous review was on f7aa779.

Delta since f7aa779: only tests/script_state_check.py (+14). A docstring on _mock_cdll_factory, and an over-up relative path case in ScriptPathReplayNegativeTests (["../alpha", "alpha", "../../gamma"] expects missing, matched, missing with before/after unchanged).

Previous points

  • P2-1 (mock is a Python model of the native resolver): resolved. The docstring now states it models tools/script_path_host.cpp. tests/script_path_check.py runs replay() against the real compiled host library, so the native side stays covered on Windows.
  • P2-2 (mutation 4 survived): resolved. I re-applied it (expected = containers[0] in tools/script_path_replay.py:81) and the suite now fails (FAILED (errors=1)). Reverted with git checkout -- ..

Commands executed locally (worktree at the head SHA):

  • python3 tests/script_state_check.py -> Ran 22 tests ... OK
  • python3 tests/docs_links_check.py -> Checked 18 Markdown files and 393 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • git diff --check origin/main...HEAD -> clean
  • Win2025 not run: no gfx2hlsl, shader or C++ change.

State: title neutral, no clean-room concerns, MERGEABLE. CI was still pending when I looked (Linux checks, Windows build/test, fixtures), so please wait for it to go green.

Findings: P1: none. P2: none. Nit: the over-up case sits inside an existing test body, so a failure there will not name the scenario. A short subTest label would help. Optional.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056882967 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2080#pullrequestreview-6056882967). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:36:04Z. **Review:** COMMENTED --- Re-review of head `05503a043623a52d4471b0f0c4858b792e39077c` (comment only, no approval). Previous review was on `f7aa779`. **Delta since f7aa779:** only `tests/script_state_check.py` (+14). A docstring on `_mock_cdll_factory`, and an over-up relative path case in `ScriptPathReplayNegativeTests` (`["../alpha", "alpha", "../../gamma"]` expects `missing, matched, missing` with before/after unchanged). **Previous points** - P2-1 (mock is a Python model of the native resolver): resolved. The docstring now states it models `tools/script_path_host.cpp`. `tests/script_path_check.py` runs `replay()` against the real compiled host library, so the native side stays covered on Windows. - P2-2 (mutation 4 survived): resolved. I re-applied it (`expected = containers[0]` in `tools/script_path_replay.py:81`) and the suite now fails (`FAILED (errors=1)`). Reverted with `git checkout -- .`. **Commands executed locally (worktree at the head SHA):** - `python3 tests/script_state_check.py` -> `Ran 22 tests ... OK` - `python3 tests/docs_links_check.py` -> `Checked 18 Markdown files and 393 links.` - `python3 tests/bidi_controls_check.py` -> `no bidirectional controls` - `git diff --check origin/main...HEAD` -> clean - Win2025 not run: no gfx2hlsl, shader or C++ change. **State:** title neutral, no clean-room concerns, MERGEABLE. CI was still pending when I looked (Linux checks, Windows build/test, fixtures), so please wait for it to go green. **Findings:** P1: none. P2: none. Nit: the over-up case sits inside an existing test body, so a failure there will not name the scenario. A short `subTest` label would help. Optional. AI-assisted; commands listed were executed locally.
Ammmae0x commented 2026-11-25 12:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T11:34:00Z.


Updated PR #2080 (commit 05503a04) to address the P2 findings:

  1. P2-1 (mock docstring): Documented in _mock_cdll_factory (tests/script_state_check.py) that it models tools/script_path_host.cpp for platform-independent tests while tests/script_path_check.py exercises replay() against the real Windows script_path_host DLL.
  2. P2-2 (over-up relative path mutation): Added ["../alpha", "alpha", "../../gamma"] coverage in ScriptPathReplayNegativeTests.test_replay_rejects_bad_containers_root_paths_and_native_mismatch (tests/script_state_check.py); verified mutating expected = -1 if up > len(active_keys) else containers[0] to expected = containers[0] fails with ValueError: Linked traversal returned -1, parent index returned 2 for ../alpha.
  • Re-ran tests/script_state_check.py (22 tests OK), tests/form_coverage_check.py, tests/docs_links_check.py (393 links), and tests/bidi_controls_check.py (1413 files).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161212913 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2080#issuecomment-7161212913). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T11:34:00Z. --- Updated PR #2080 (commit `05503a04`) to address the P2 findings: 1. **P2-1 (mock docstring)**: Documented in `_mock_cdll_factory` (`tests/script_state_check.py`) that it models `tools/script_path_host.cpp` for platform-independent tests while `tests/script_path_check.py` exercises `replay()` against the real Windows `script_path_host` DLL. 2. **P2-2 (over-up relative path mutation)**: Added `["../alpha", "alpha", "../../gamma"]` coverage in `ScriptPathReplayNegativeTests.test_replay_rejects_bad_containers_root_paths_and_native_mismatch` (`tests/script_state_check.py`); verified mutating `expected = -1 if up > len(active_keys) else containers[0]` to `expected = containers[0]` fails with `ValueError: Linked traversal returned -1, parent index returned 2 for ../alpha`. - Re-ran `tests/script_state_check.py` (22 tests OK), `tests/form_coverage_check.py`, `tests/docs_links_check.py` (393 links), and `tests/bidi_controls_check.py` (1413 files). AI-assisted.
upstream-sync closed this pull request 2026-11-25 13:00:33 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2073
No description provided.