tooling: canonicalize script paths when checking duplicates #3002

Manually merged
github merged 1 commit from github-bot/gh-3002 into gh-pr/3002/base 2026-11-27 04:23:49 +00:00 AGit
Owner

@⁠ashishdhillon on GitHub · 2026-11-27 04:00 UTC · original
ashishdhillon:tooling/normalize-duplicate-check-paths → main · +29 −6 · 3 files · 1 commits · merged 2026-11-27 04:19 UTC

Change

Follow-up to #2805: tools/run_checks_parallel.py previously compared script paths using exact raw strings in main(), read_check_files(), and merge_checks(), so spelling variants of the same file (such as tests/a_check.py vs ./tests/a_check.py) were not recognized as duplicates and ran twice.

  • Added _command_key(command) using (str(Path(command[0]).resolve()), *command[1:]) to collapse path spelling variants while keeping each command's original display path intact for ::group:: output and error messages, and preserving distinct commands with different arguments.
  • Updated CLI duplicate detection in main(), file-list duplicate detection in read_check_files(), and inline/fragment deduplication in merge_checks() to key on _command_key.
  • Added regression checks for spelling-variant duplicates on the command line (tests/run_checks_parallel_check.py), across --from-dir files (tests/run_checks_fragments_check.py), and between inline and --from-dir commands.

Verification

  • python3 -B tools/run_checks_parallel.py tests/run_checks_parallel_check.py tests/run_checks_fragments_check.py tests/run_checks_parallel_cli_check.py tests/startup_tools_lint_check.py -> all 4 checks passed (run_checks_parallel_cli_check ran 7 tests, OK)
  • python3 -B tests/bidi_controls_check.py --self-test -> Self-test passed.
  • git diff --check -> clean

Evidence and follow-up

All assertions ran locally on macOS (pure-Python tooling tests; Windows GPU suite not run locally as no source build or Windows GPU host is present).

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.

**@⁠ashishdhillon** on GitHub · 2026-11-27 04:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3002) `ashishdhillon:tooling/normalize-duplicate-check-paths` → `main` · +29 −6 · 3 files · 1 commits · merged 2026-11-27 04:19 UTC ## Change Follow-up to #2805: `tools/run_checks_parallel.py` previously compared script paths using exact raw strings in `main()`, `read_check_files()`, and `merge_checks()`, so spelling variants of the same file (such as `tests/a_check.py` vs `./tests/a_check.py`) were not recognized as duplicates and ran twice. - Added `_command_key(command)` using `(str(Path(command[0]).resolve()), *command[1:])` to collapse path spelling variants while keeping each command's original display path intact for `::group::` output and error messages, and preserving distinct commands with different arguments. - Updated CLI duplicate detection in `main()`, file-list duplicate detection in `read_check_files()`, and inline/fragment deduplication in `merge_checks()` to key on `_command_key`. - Added regression checks for spelling-variant duplicates on the command line (`tests/run_checks_parallel_check.py`), across `--from-dir` files (`tests/run_checks_fragments_check.py`), and between inline and `--from-dir` commands. ## Verification - `python3 -B tools/run_checks_parallel.py tests/run_checks_parallel_check.py tests/run_checks_fragments_check.py tests/run_checks_parallel_cli_check.py tests/startup_tools_lint_check.py` -> `all 4 checks passed` (run_checks_parallel_cli_check ran 7 tests, OK) - `python3 -B tests/bidi_controls_check.py --self-test` -> `Self-test passed.` - `git diff --check` -> clean ## Evidence and follow-up All assertions ran locally on macOS (pure-Python tooling tests; Windows GPU suite not run locally as no source build or Windows GPU host is present). ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:02:16 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 04:13 UTC · original · reviewed

Nice fix — Path.resolve() elegantly collapses spelling variants and the regression tests are tight.

Findings

✅ What works well

  • _command_key adds minimal cognitive load: one pure helper, three call-site updates, all same pattern.
  • CLI duplicate detection preserves the unresolved script string in the error message (duplicate command-line script: {script}), which is user-friendly — it shows exactly what the user typed.
  • --from-dir fragment dedup (merge_checks) now correctly matches paths saved in different spellings.
  • Test coverage is excellent: case_dot_two catches the ./scripts/x_check.py vs scripts/x_check.py case, and spelled_twice validates that display output (::group::, ran) stays single.

⚠️ Minor observations

  1. Symlinks / junctions on Windows — Path.resolve() follows symlinks (since Python 3.6). If tests/ itself is a symlinked directory, both spellings resolve to the same real path anyway, so dedup still works. The only edge case would be two distinct filesystem paths resolving to the same inode — extremely rare in this project. No action needed, just noting the behavior.

  2. seen_scripts set in main() — stores tuples of (resolved_path, *rest). Since rest is always empty for CLI scripts, this is effectively set[str]. Consider adding a one-liner comment: # CLI commands have no arguments after the script path, so the key is just the resolved path. — purely for future maintainers.

  3. merge_checks dedup display — when a --from-dir file is skipped as a duplicate of an inline script (or vice versa), the error references seen[key] which stores the first where value. This is correct and user-actionable.

Recommendation

Looks good as-is. A trivial comment on the main() loop would make it slightly easier to read, but it's not blocking.


🏷 One thought for future: if run_checks_parallel.py ever supports arguments after the script path (like --env KEY=VAL), _command_key already handles that via *command[1:] — clean design.

**@⁠KelboLive** on GitHub · 2026-11-27 04:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3002#pullrequestreview-6083409092) · **reviewed** Nice fix — `Path.resolve()` elegantly collapses spelling variants and the regression tests are tight. ## Findings ### ✅ What works well - `_command_key` adds minimal cognitive load: one pure helper, three call-site updates, all same pattern. - CLI duplicate detection preserves the *unresolved* `script` string in the error message (`duplicate command-line script: {script}`), which is user-friendly — it shows exactly what the user typed. - `--from-dir` fragment dedup (`merge_checks`) now correctly matches paths saved in different spellings. - Test coverage is excellent: `case_dot_two` catches the `./scripts/x_check.py` vs `scripts/x_check.py` case, and `spelled_twice` validates that display output (`::group::`, `ran`) stays single. ### ⚠️ Minor observations 1. **Symlinks / junctions on Windows** — `Path.resolve()` follows symlinks (since Python 3.6). If `tests/` itself is a symlinked directory, both spellings resolve to the same real path anyway, so dedup still works. The only edge case would be two distinct filesystem paths resolving to the same inode — extremely rare in this project. No action needed, just noting the behavior. 2. **`seen_scripts` set in `main()`** — stores tuples of `(resolved_path, *rest)`. Since `rest` is always empty for CLI scripts, this is effectively `set[str]`. Consider adding a one-liner comment: `# CLI commands have no arguments after the script path, so the key is just the resolved path.` — purely for future maintainers. 3. **`merge_checks` dedup display** — when a `--from-dir` file is skipped as a duplicate of an inline script (or vice versa), the error references `seen[key]` which stores the *first* `where` value. This is correct and user-actionable. ### Recommendation Looks good as-is. A trivial comment on the `main()` loop would make it slightly easier to read, but it's not blocking. --- 🏷 One thought for future: if `run_checks_parallel.py` ever supports arguments after the script path (like `--env KEY=VAL`), `_command_key` already handles that via `*command[1:]` — clean design.
github-bot changed target branch from main to gh-pr/3002/base 2026-11-27 04:23:47 +00:00
github manually merged commit 92f3126875 into gh-pr/3002/base 2026-11-27 04:23:49 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 04:19 UTC · original · approved these changes

Reviewed 92f31268756b076237fb0f4f6bfdc606cd4f5343. The resolved path affects duplicate comparison only. Execution still receives the original path and the complete argument tail remains in the comparison key. On Windows I ran python -B tests/run_checks_parallel_check.py and python -B tests/run_checks_fragments_check.py on this head; both passed. Required Windows CI passed.

**@⁠R0Y00** on GitHub · 2026-11-27 04:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3002#pullrequestreview-6083443465) · **approved these changes** Reviewed `92f31268756b076237fb0f4f6bfdc606cd4f5343`. The resolved path affects duplicate comparison only. Execution still receives the original path and the complete argument tail remains in the comparison key. On Windows I ran `python -B tests/run_checks_parallel_check.py` and `python -B tests/run_checks_fragments_check.py` on this head; both passed. Required Windows CI passed.
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-27 04:27 UTC · original

Post-merge Python-only audit of 92f31268 (= main): the change is correct, three of its four _command_key sites are pinned by the tests, the merge_checks filter is not

Not a code change; measurements only. No GPU, no C++ and no Windows is involved — tools/run_checks_parallel.py is plain Python, so the whole change can be exercised without the hardware this repository usually needs.

Environment and tree

  • Linux 7.0.0-38-generic, Python 3.11.16 (python3 -B tests/<fixture>.py from the repository root, the way the python-linux job invokes them).
  • git rev-parse HEAD = 92f31268; git status --porcelain --untracked-files=no empty.
  • Merged at 2026-11-27T04:19:46Z. The three files below are byte-identical between 92f31268 and main (comparison of each blob at both refs, not a line number):
tools/run_checks_parallel.py            sha256 6b58a1ddca58fcfc727f339ec53eab4c…  8297 bytes   IDENTICAL
tests/run_checks_parallel_check.py      sha256 ab0480554aecb7bdcbd84f5da8ce9b6b…  6168 bytes   IDENTICAL
tests/run_checks_fragments_check.py     sha256 20e3c282a69518fa554279e763f0aa81…  6411 bytes   IDENTICAL

Baseline

python3 -B tests/run_checks_parallel_check.py         rc=0  run_checks_parallel_check: ok
python3 -B tests/run_checks_parallel_cli_check.py     rc=0  Ran 7 tests — OK
python3 -B tests/run_checks_fragments_check.py        rc=0  run_checks_fragments_check ok

Mutation matrix

One site reverted at a time, git checkout -- tools/run_checks_parallel.py between two mutants, the file sha256 checked before and after the whole matrix (identical, 6b58a1dd…) and git status --porcelain --untracked-files=no empty at the end.

  • M1 :117 key = _command_key(command) → key = tuple(command) — killed by run_checks_fragments_check.py:87 (case_dot_two).
  • M2a :132 known = {_command_key(command) …} → {tuple(command) …} — killed by tests/run_checks_fragments_check.py:89 (dedup; all 4 checks passed).
  • M2b :134 if _command_key(command) not in known] → if tuple(command) not in known] — survives all three fixtures, rc=0.
  • M3 :194 key = _command_key([script]) → key = tuple([script]) — killed by run_checks_parallel_check.py:79.
  • M4 the helper body, return (str(Path(command[0]).resolve()), *command[1:]) → return (command[0], *command[1:]) — killed by run_checks_parallel_check.py:79 and run_checks_fragments_check.py:87.

So the merged code pins three of the four call sites. tests/run_checks_parallel_cli_check.py kills none of the five mutants — not a defect, just worth knowing before it is cited as coverage.

The site nothing pins

M2b is a half-applied version of this exact patch — updating known and leaving the comprehension alone — and it is not equivalent. known holds str(Path(…).resolve()), i.e. absolute paths, while the comprehension compares the raw text of the listing line, which is relative in this repository (tests/…). Under M2b the two never match, so a command that is both listed and inline runs twice, with one identical spelling and no ./ anywhere. Two lines reproduce it from the repository root on both trees:

import os, subprocess, sys, tempfile
from pathlib import Path
runner = Path("tools/run_checks_parallel.py").resolve()
tmp = tempfile.mkdtemp(); listing = os.path.join(tmp, "lists"); os.mkdir(listing)
open("probe_rel_echo.py", "w").write("print('rel echo ran')\n")
open(os.path.join(listing, "a.txt"), "w").write("probe_rel_echo.py\n")
subprocess.run([sys.executable, "-B", str(runner), "-j", "2", "--from-dir", listing, "probe_rel_echo.py"])
os.remove("probe_rel_echo.py")

Observed, same relative spelling on both sides:

head / main  6b58a1dd : group printed once   → all 1 checks passed  ('rel echo ran' × 1)
M2b          c1ac6ec9 : group printed twice  → all 2 checks passed  ('rel echo ran' × 2)

Same result with the repository's own path instead of a probe file: listing tests/mesh_bitcmp_check.py and passing tests/mesh_bitcmp_check.py inline prints one ::group:: on main and two under M2b.

That breaks the rule in tests/checks/README.md:17 ("A command that is also in the inline list runs once") and the docstring of merge_checks ("an entry can move from the inline list to a file without running twice"). The existing dedup case does not see it: it puts the non-canonical spelling inline (dot_echo) and the canonical one in the listing, so it only drives _command_key when building known — case_dot_two likewise drives read_check_files, not the filter.

Scope

  • Latent in CI: the eleven listing files under tests/checks/ use only the tests/… spelling (grep -v -E '^#|^$|^tests/' tests/checks/*/*.txt → no match) and none of the six listed scripts appears in the inline lists of .github/workflows/windows.yml (grep tests/<script>.py → 0 for each), so no pair differs today.
  • Reachable by hand today (probe above), and live the first time a check is both listed and inline — which tests/checks/README.md encourages. merge_checks is on the CI path at windows.yml:178 and --from-dir at :199, so the code runs at every push; only the differing pair is missing.

Two-line follow-up, if you want the site pinned

Add one mirror case next to the existing dedup — add, do not replace (replacing lets M2a survive; measured):

# Same command in both places, non-canonical spelling in the LISTING this time.
mirror = os.path.join(tmp, "case_mirror")
os.mkdir(mirror)
write(os.path.join(mirror, "a.txt"), f"{q(dot_echo)}\n")
mirrored = run("--from-dir", mirror, echo)
assert mirrored.returncode == 0 and "all 1 checks passed" in mirrored.stdout, mirrored.stdout

Measured on top of the head: green on 92f31268, and red under M2b (all 2 checks passed) while M1, M2a and M4 stay red too. A single relative pair on both sides separates M2a and M2b at once, but needs a working directory passed to the fixture's subprocess.

Limits

  • One host, one interpreter (Linux, Python 3.11.16). Path.resolve() goes through the OS on Windows (case, short names); nothing above depends on that, but it was not exercised. This is not a second Windows run — the approval above already has one.
  • Only the three fixtures that name the runner were run (grep -rl 'run_checks_parallel\|merge_checks\|read_check_files' tests/); the wider Python suite was not re-run.
  • The matrix reverts one site at a time; a mutant that breaks two sites reports only the first assertion it reaches.

AI-assisted.

**@⁠thepatrickworld** on GitHub · 2026-11-27 04:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3002#issuecomment-7209813876) **Post-merge Python-only audit of `92f31268` (= `main`): the change is correct, three of its four `_command_key` sites are pinned by the tests, the `merge_checks` filter is not** Not a code change; measurements only. No GPU, no C++ and no Windows is involved — `tools/run_checks_parallel.py` is plain Python, so the whole change can be exercised without the hardware this repository usually needs. ### Environment and tree - Linux 7.0.0-38-generic, Python 3.11.16 (`python3 -B tests/<fixture>.py` from the repository root, the way the `python-linux` job invokes them). - `git rev-parse HEAD` = `92f31268`; `git status --porcelain --untracked-files=no` empty. - Merged at `2026-11-27T04:19:46Z`. The three files below are **byte-identical** between `92f31268` and `main` (comparison of each blob at both refs, not a line number): ``` tools/run_checks_parallel.py sha256 6b58a1ddca58fcfc727f339ec53eab4c… 8297 bytes IDENTICAL tests/run_checks_parallel_check.py sha256 ab0480554aecb7bdcbd84f5da8ce9b6b… 6168 bytes IDENTICAL tests/run_checks_fragments_check.py sha256 20e3c282a69518fa554279e763f0aa81… 6411 bytes IDENTICAL ``` ### Baseline ``` python3 -B tests/run_checks_parallel_check.py rc=0 run_checks_parallel_check: ok python3 -B tests/run_checks_parallel_cli_check.py rc=0 Ran 7 tests — OK python3 -B tests/run_checks_fragments_check.py rc=0 run_checks_fragments_check ok ``` ### Mutation matrix One site reverted at a time, `git checkout -- tools/run_checks_parallel.py` between two mutants, the file sha256 checked before and after the whole matrix (identical, `6b58a1dd…`) and `git status --porcelain --untracked-files=no` empty at the end. - **M1** `:117` `key = _command_key(command)` → `key = tuple(command)` — killed by `run_checks_fragments_check.py:87` (`case_dot_two`). - **M2a** `:132` `known = {_command_key(command) …}` → `{tuple(command) …}` — killed by `tests/run_checks_fragments_check.py:89` (`dedup`; `all 4 checks passed`). - **M2b** `:134` `if _command_key(command) not in known]` → `if tuple(command) not in known]` — **survives all three fixtures, rc=0**. - **M3** `:194` `key = _command_key([script])` → `key = tuple([script])` — killed by `run_checks_parallel_check.py:79`. - **M4** the helper body, `return (str(Path(command[0]).resolve()), *command[1:])` → `return (command[0], *command[1:])` — killed by `run_checks_parallel_check.py:79` and `run_checks_fragments_check.py:87`. So the merged code pins three of the four call sites. `tests/run_checks_parallel_cli_check.py` kills none of the five mutants — not a defect, just worth knowing before it is cited as coverage. ### The site nothing pins M2b is a half-applied version of this exact patch — updating `known` and leaving the comprehension alone — and it is not equivalent. `known` holds `str(Path(…).resolve())`, i.e. **absolute** paths, while the comprehension compares the raw text of the listing line, which is **relative** in this repository (`tests/…`). Under M2b the two never match, so a command that is both listed and inline runs twice, with one identical spelling and no `./` anywhere. Two lines reproduce it from the repository root on both trees: ```python import os, subprocess, sys, tempfile from pathlib import Path runner = Path("tools/run_checks_parallel.py").resolve() tmp = tempfile.mkdtemp(); listing = os.path.join(tmp, "lists"); os.mkdir(listing) open("probe_rel_echo.py", "w").write("print('rel echo ran')\n") open(os.path.join(listing, "a.txt"), "w").write("probe_rel_echo.py\n") subprocess.run([sys.executable, "-B", str(runner), "-j", "2", "--from-dir", listing, "probe_rel_echo.py"]) os.remove("probe_rel_echo.py") ``` Observed, same relative spelling on both sides: ``` head / main 6b58a1dd : group printed once → all 1 checks passed ('rel echo ran' × 1) M2b c1ac6ec9 : group printed twice → all 2 checks passed ('rel echo ran' × 2) ``` Same result with the repository's own path instead of a probe file: listing `tests/mesh_bitcmp_check.py` and passing `tests/mesh_bitcmp_check.py` inline prints one `::group::` on `main` and two under M2b. That breaks the rule in `tests/checks/README.md:17` ("A command that is also in the inline list runs once") and the docstring of `merge_checks` ("an entry can move from the inline list to a file without running twice"). The existing `dedup` case does not see it: it puts the non-canonical spelling **inline** (`dot_echo`) and the canonical one in the listing, so it only drives `_command_key` when building `known` — `case_dot_two` likewise drives `read_check_files`, not the filter. ### Scope - Latent **in CI**: the eleven listing files under `tests/checks/` use only the `tests/…` spelling (`grep -v -E '^#|^$|^tests/' tests/checks/*/*.txt` → no match) and none of the six listed scripts appears in the inline lists of `.github/workflows/windows.yml` (`grep tests/<script>.py` → 0 for each), so no pair differs today. - Reachable by hand today (probe above), and live the first time a check is both listed and inline — which `tests/checks/README.md` encourages. `merge_checks` is on the CI path at `windows.yml:178` and `--from-dir` at `:199`, so the code runs at every push; only the differing pair is missing. ### Two-line follow-up, if you want the site pinned Add one mirror case next to the existing `dedup` — add, do not replace (replacing lets M2a survive; measured): ```python # Same command in both places, non-canonical spelling in the LISTING this time. mirror = os.path.join(tmp, "case_mirror") os.mkdir(mirror) write(os.path.join(mirror, "a.txt"), f"{q(dot_echo)}\n") mirrored = run("--from-dir", mirror, echo) assert mirrored.returncode == 0 and "all 1 checks passed" in mirrored.stdout, mirrored.stdout ``` Measured on top of the head: green on `92f31268`, and red under M2b (`all 2 checks passed`) while M1, M2a and M4 stay red too. A single relative pair on both sides separates M2a and M2b at once, but needs a working directory passed to the fixture's subprocess. ### Limits - One host, one interpreter (Linux, Python 3.11.16). `Path.resolve()` goes through the OS on Windows (case, short names); nothing above depends on that, but it was not exercised. This is not a second Windows run — the approval above already has one. - Only the three fixtures that name the runner were run (`grep -rl 'run_checks_parallel\|merge_checks\|read_check_files' tests/`); the wider Python suite was not re-run. - The matrix reverts one site at a time; a mutant that breaks two sites reports only the first assertion it reaches. _AI-assisted._
This discussion has been locked. Commenting is limited to contributors.
No description provided.