script: support type-qualified path resolution in script_path_host #1658

Merged
Ammmae0x merged 1 commit from upstream-pr/1665 into main 2026-11-25 14:42:00 +00:00
Ammmae0x commented 2026-11-24 16:43:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T16:43:02Z.


Change

Add resolve_script_typed_path to tools/script_path_host.cpp (sharing resolvePathImpl with resolve_script_path) to support type-qualified path resolution in script_path_host:

  • Accepts a caller-supplied types (const std::uint32_t*) hash array parallel to path at each depth.
  • Requires each matched state sibling to carry both a label-kind (kind == 5) id attribute matching path[level] and a label-kind type attribute matching types[level].
  • Preserves existing resolve_script_path id-only behavior unchanged when types == nullptr.
  • Returns -1 on missing or mismatched type attributes, -2 on duplicate (id, type) sibling collisions, and -3 on null types, duplicate/non-label type or id attributes, or out-of-bounds node/attribute indices, leaving *active unchanged on all error paths.
  • Registers script_typed_path_dispatch in CMakeLists.txt running TypedScriptPathTests in tests/script_dispatch_check.py, and documents the behavior in docs/experiments.md.

Verification

All builds and tests ran after the final edit with 0 compiler warnings/errors:

  • cmake --preset dev + cmake --build --preset dev --target script_path_host --clean-first: built cleanly (0 warnings, 0 errors).
  • ctest --preset dev --no-tests=error -R "^script_" -V: 4/4 passed (script_path_links: 5 OK, script_state_literals: 16 OK, script_dispatch_pairs: 10 OK, script_typed_path_dispatch: 5 OK).
  • cmake --preset release + cmake --build --preset release --target script_path_host --clean-first: built cleanly (0 warnings, 0 errors).
  • ctest --preset release --no-tests=error -R "^script_" -V: 4/4 passed (script_path_links: 5 OK, script_state_literals: 16 OK, script_dispatch_pairs: 10 OK, script_typed_path_dispatch: 5 OK).
  • python -B tests/script_state_check.py: 16 tests OK.
  • python -B tests/form_coverage_check.py: form coverage checks passed.
  • python -B tests/docs_links_check.py: Checked 16 Markdown files and 350 links.
  • python -B tests/bidi_controls_check.py: Checked 1277 tracked source, script and build/CI files: no bidirectional controls.

Evidence and follow-up

  • tests/script_dispatch_check.py (TypedScriptPathTests) uses synthetic in-memory 16-byte wire-format Node/Attribute trees (no game files or external dumps).
  • Positive controls verify sibling (id, type) disambiguation (item vs weaponitem), shop-carrier (id, type) pair extraction feeding resolve_script_typed_path, multi-level hierarchy resolution, and relative up=2 branch switching.
  • Negative controls verify *active preservation alongside -1 (missing type attribute, single-level and multi-level mismatched type), -2 (duplicate (id, type) siblings), and -3 (out-of-bounds sibling index, attribute span, container, active, null types, zero depth, non-label type, duplicate type, and non-label id).
  • The native runtime caller that supplies (id, type) remains an open follow-up.

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:6586784041 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1665). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T16:43:02Z. --- ## Change Add `resolve_script_typed_path` to `tools/script_path_host.cpp` (sharing `resolvePathImpl` with `resolve_script_path`) to support type-qualified path resolution in `script_path_host`: - Accepts a caller-supplied `types` (`const std::uint32_t*`) hash array parallel to `path` at each depth. - Requires each matched `state` sibling to carry both a label-kind (`kind == 5`) `id` attribute matching `path[level]` and a label-kind `type` attribute matching `types[level]`. - Preserves existing `resolve_script_path` `id`-only behavior unchanged when `types == nullptr`. - Returns `-1` on missing or mismatched `type` attributes, `-2` on duplicate `(id, type)` sibling collisions, and `-3` on null `types`, duplicate/non-label `type` or `id` attributes, or out-of-bounds node/attribute indices, leaving `*active` unchanged on all error paths. - Registers `script_typed_path_dispatch` in `CMakeLists.txt` running `TypedScriptPathTests` in `tests/script_dispatch_check.py`, and documents the behavior in `docs/experiments.md`. ## Verification All builds and tests ran after the final edit with 0 compiler warnings/errors: - `cmake --preset dev` + `cmake --build --preset dev --target script_path_host --clean-first`: built cleanly (0 warnings, 0 errors). - `ctest --preset dev --no-tests=error -R "^script_" -V`: **4/4 passed** (`script_path_links`: 5 OK, `script_state_literals`: 16 OK, `script_dispatch_pairs`: 10 OK, `script_typed_path_dispatch`: 5 OK). - `cmake --preset release` + `cmake --build --preset release --target script_path_host --clean-first`: built cleanly (0 warnings, 0 errors). - `ctest --preset release --no-tests=error -R "^script_" -V`: **4/4 passed** (`script_path_links`: 5 OK, `script_state_literals`: 16 OK, `script_dispatch_pairs`: 10 OK, `script_typed_path_dispatch`: 5 OK). - `python -B tests/script_state_check.py`: 16 tests OK. - `python -B tests/form_coverage_check.py`: `form coverage checks passed`. - `python -B tests/docs_links_check.py`: `Checked 16 Markdown files and 350 links.` - `python -B tests/bidi_controls_check.py`: `Checked 1277 tracked source, script and build/CI files: no bidirectional controls.` ## Evidence and follow-up - `tests/script_dispatch_check.py` (`TypedScriptPathTests`) uses synthetic in-memory 16-byte wire-format `Node`/`Attribute` trees (no game files or external dumps). - Positive controls verify sibling `(id, type)` disambiguation (`item` vs `weaponitem`), shop-carrier `(id, type)` pair extraction feeding `resolve_script_typed_path`, multi-level hierarchy resolution, and relative `up=2` branch switching. - Negative controls verify `*active` preservation alongside `-1` (missing `type` attribute, single-level and multi-level mismatched `type`), `-2` (duplicate `(id, type)` siblings), and `-3` (out-of-bounds sibling index, attribute span, `container`, `active`, null `types`, zero depth, non-label `type`, duplicate `type`, and non-label `id`). - The native runtime caller that supplies `(id, type)` remains an open follow-up. ## 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-24 17:01:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:48:58Z.

Review: COMMENTED


Review of head 83aed83831.

Scope note: "type-qualified" here means a caller-supplied array of type label hashes, one per path segment, not a string qualifier. So string-parsing concerns (drive letters, UNC, separators, encodings) do not apply; the review covers the (id, type) matching, bounds, and the test.

Verified

  • Built tools/script_path_host.cpp on Linux: g++ -std=c++17 -Wall -Wextra -shared -fPIC '-D__declspec(x)=' tools/script_path_host.cpp. No warnings.
  • python3 -B tests/script_dispatch_check.py <host.so>: 10 tests, OK.
  • python3 -B tests/script_dispatch_check.py <host.so> TypedScriptPathTests (the new CTest command line): 5 tests, OK.
  • python3 -B tests/script_path_check.py <host.so> (existing id-only consumer of resolve_script_path): 5 tests, OK, so the refactor into resolvePathImpl with types == nullptr keeps the id-only behavior.
  • Read the full diff and the full tools/script_path_host.cpp. *active is only written on the success path, so "unchanged on all error paths" in docs/experiments.md is accurate. The documented return codes (-1 missing/mismatched type, -2 duplicate (id, type), -3 malformed/out-of-bounds) match the code and the tests.
  • resolve_script_typed_path rejects a null types with -3 before reaching the shared implementation; the test covers it.
  • Test is deterministic (hand-built trees, no I/O or time), runs in about 8 ms, and the expected node indices are fixture constants rather than values computed by the code under test. Negative cases covered: missing type attribute, mismatched type at depth 1 and 2, duplicate (id, type), out-of-bounds sibling and attribute span, out-of-bounds container/active, null types, zero depth, non-label type, duplicate type attribute, non-label id.

Mutation checks

Each mutation was applied to tools/script_path_host.cpp, rebuilt, and TypedScriptPathTests run, then the file restored with git restore. After the last restore, the full suite passes again (10 tests, OK).

  • M1 type ignored in match (if (idMatch)): detected (4 failures).
  • M2 typed entry point passes nullptr types: detected (6 failures).
  • M3 wrong level index (types[0]): detected (1 failure).
  • M4 null types not rejected: detected (1 failure).
  • M5 missing type attribute counts as match (typeMatch = true): detected (1 failure).
  • M6 duplicate type attribute allowed: detected (1 failure).
  • M7 ambiguity ignored (first match wins): detected (1 failure).
  • M8 type kind not checked: detected (1 failure).
  • M9 id kind not checked: detected (1 failure).
  • M10 type compared against the path hash instead of the type hash: detected (3 failures).

10 of 10 detected; no weak spots found in the new test.

Findings

No P1 or P2 findings. Two nits:

  • nit, tools/script_path_host.cpp:68-72: in typed mode a malformed type attribute (non-label kind, or duplicated) on a sibling whose id does not match still aborts the whole lookup with -3. Repro on the PR's own fixture: in _build_typed_collision_tree(), change node 2's type attribute to an int attribute and call resolve_typed_path(..., [joaat("trigger_a")], [joaat("item")]). Expected if only candidates were validated: 3. Got: (-3, 2) (unchanged active; baseline without the corruption gives (3, 3)). This is consistent with how a malformed id already behaves and the docs say malformed type returns -3, so it may be intended; worth one sentence in the docs that the check applies to every state sibling, not only candidates.
  • nit, CMakeLists.txt (new script_typed_path_dispatch entry): script_dispatch_pairs runs the file with no class filter, so it already executes TypedScriptPathTests; the new entry re-runs the same 5 tests. Harmless (milliseconds), but it is a duplicate of coverage unless the intent is a separately named result. Also types has no length parameter, so the caller must supply depth entries; the Python helper does, and the doc sentence "matching each path depth" states it, but a short array from another caller would read out of bounds.

Not verified

  • Linux only (g++ with the dllexport attribute defined away). Windows, MSVC, the pr preset and the CTest registration itself were not run; the CMake lines were only read and match the neighboring script_dispatch_pairs entry.
  • No fuzzing of arbitrary node/attribute tables beyond the fixtures in the test.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043573268 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1665#pullrequestreview-6043573268). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:48:58Z. **Review:** COMMENTED --- Review of head 83aed83831006b8ab6f59a50fc4c14f3239883bf. Scope note: "type-qualified" here means a caller-supplied array of `type` label hashes, one per path segment, not a string qualifier. So string-parsing concerns (drive letters, UNC, separators, encodings) do not apply; the review covers the (id, type) matching, bounds, and the test. ## Verified - Built `tools/script_path_host.cpp` on Linux: `g++ -std=c++17 -Wall -Wextra -shared -fPIC '-D__declspec(x)=' tools/script_path_host.cpp`. No warnings. - `python3 -B tests/script_dispatch_check.py <host.so>`: 10 tests, OK. - `python3 -B tests/script_dispatch_check.py <host.so> TypedScriptPathTests` (the new CTest command line): 5 tests, OK. - `python3 -B tests/script_path_check.py <host.so>` (existing id-only consumer of `resolve_script_path`): 5 tests, OK, so the refactor into `resolvePathImpl` with `types == nullptr` keeps the id-only behavior. - Read the full diff and the full `tools/script_path_host.cpp`. `*active` is only written on the success path, so "unchanged on all error paths" in `docs/experiments.md` is accurate. The documented return codes (-1 missing/mismatched type, -2 duplicate (id, type), -3 malformed/out-of-bounds) match the code and the tests. - `resolve_script_typed_path` rejects a null `types` with -3 before reaching the shared implementation; the test covers it. - Test is deterministic (hand-built trees, no I/O or time), runs in about 8 ms, and the expected node indices are fixture constants rather than values computed by the code under test. Negative cases covered: missing type attribute, mismatched type at depth 1 and 2, duplicate (id, type), out-of-bounds sibling and attribute span, out-of-bounds container/active, null types, zero depth, non-label type, duplicate type attribute, non-label id. ## Mutation checks Each mutation was applied to `tools/script_path_host.cpp`, rebuilt, and `TypedScriptPathTests` run, then the file restored with `git restore`. After the last restore, the full suite passes again (10 tests, OK). - M1 type ignored in match (`if (idMatch)`): detected (4 failures). - M2 typed entry point passes `nullptr` types: detected (6 failures). - M3 wrong level index (`types[0]`): detected (1 failure). - M4 null `types` not rejected: detected (1 failure). - M5 missing type attribute counts as match (`typeMatch = true`): detected (1 failure). - M6 duplicate `type` attribute allowed: detected (1 failure). - M7 ambiguity ignored (first match wins): detected (1 failure). - M8 `type` kind not checked: detected (1 failure). - M9 `id` kind not checked: detected (1 failure). - M10 type compared against the path hash instead of the type hash: detected (3 failures). 10 of 10 detected; no weak spots found in the new test. ## Findings No P1 or P2 findings. Two nits: - nit, `tools/script_path_host.cpp:68-72`: in typed mode a malformed `type` attribute (non-label kind, or duplicated) on a sibling whose `id` does not match still aborts the whole lookup with -3. Repro on the PR's own fixture: in `_build_typed_collision_tree()`, change node 2's `type` attribute to an int attribute and call `resolve_typed_path(..., [joaat("trigger_a")], [joaat("item")])`. Expected if only candidates were validated: 3. Got: (-3, 2) (unchanged active; baseline without the corruption gives (3, 3)). This is consistent with how a malformed `id` already behaves and the docs say malformed `type` returns -3, so it may be intended; worth one sentence in the docs that the check applies to every `state` sibling, not only candidates. - nit, `CMakeLists.txt` (new `script_typed_path_dispatch` entry): `script_dispatch_pairs` runs the file with no class filter, so it already executes `TypedScriptPathTests`; the new entry re-runs the same 5 tests. Harmless (milliseconds), but it is a duplicate of coverage unless the intent is a separately named result. Also `types` has no length parameter, so the caller must supply `depth` entries; the Python helper does, and the doc sentence "matching each path depth" states it, but a short array from another caller would read out of bounds. ## Not verified - Linux only (g++ with the dllexport attribute defined away). Windows, MSVC, the `pr` preset and the CTest registration itself were not run; the CMake lines were only read and match the neighboring `script_dispatch_pairs` entry. - No fuzzing of arbitrary node/attribute tables beyond the fixtures in the test. AI-assisted; commands listed were executed locally.
stan495 commented 2026-11-25 06:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:48:14Z.

Review: APPROVED


Verified head 83aed838 on Windows x64 (dev preset, MSVC 19.44.35228.0, Python 3.12).

  • cmake --build --preset dev --target script_path_host -> succeeded
  • ctest --preset dev --no-tests=error -R '^script_typed_path_dispatch$' -V -> 1/1 passed

Verdict: Approved at 83aed838.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052476766 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1665#pullrequestreview-6052476766). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T05:48:14Z. **Review:** APPROVED --- Verified head `83aed838` on Windows x64 (`dev` preset, MSVC `19.44.35228.0`, Python 3.12). - `cmake --build --preset dev --target script_path_host` -> succeeded - `ctest --preset dev --no-tests=error -R '^script_typed_path_dispatch$' -V` -> 1/1 passed Verdict: Approved at `83aed838`.
upstream-sync closed this pull request 2026-11-25 15:01:26 +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!1658
No description provided.