WIP: test: one source cutter for the checks (tests/srccut.py), 80 checks moved to it #27

Draft
dyst wants to merge 1 commit from dyst/Longshot:test/srccut into main
First-time contributor

Why

123 checks carry their own copy of a brace counter (def block) to cut a function out of a source file; the copies count braces inside strings, character literals and comments too, and when a function is renamed or reshaped they stop with a bare ValueError or IndexError that doesn't say which source or marker (the trap AGENTS.md warns about, "Tests read the source"). This gives the checks one cutter and moves 80 of them to it, each shown to cut exactly what it cut before.

What changed

  • tests: new tests/srccut.py (standard library):
    • block(text, marker): from the marker to the brace that closes the first { after it (_closing_brace()), counting braces outside string and character literals (raw strings too, and C++14 digit separators), comments and preprocessor lines;
    • between(text, start, end), and find();
    • a marker that is missing, or that appears twice, stops the check with one message naming the source and the marker (CutError; unique=False takes the first on purpose);
    • SRCCUT_CHECK_NAIVE=1 also cuts each block the old way (_naive()) and stops if the two differ: what a migration runs to show it changed nothing.
  • tests: 80 checks import block from it in place of their own copy, one commit per source file they read (vk_menu.cpp, vk_draw.cpp, vk_memory.cpp, vk_texture.cpp, longshot_env.h, hos_main.c, ...). Only exact copies of the plain counter moved; each takes sys.path.insert(0, ...) for its own folder, since python -I leaves it off the path.
  • tests: new tests/test_srccut.py: braces in strings, character literals, raw strings, comments and preprocessor lines; a fixture the old counter cut wrongly; a missing marker and a repeated one name the source; between; an unclosed block; the comparison with the old counter.
  • Not moved:
    • three checks whose block isn't the plain counter (a start offset; positions returned): left as they were;
    • 13 checks whose marker appears more than once in the source (a declaration before the definition, for example). The old counter took the first one silently, so each needs a look rather than unique=False;
    • 51 checks with other cutters (function, body, between, ...): later, by source file.

Flags and settings

Flag New or changed What it does Default now Goal: on by default? Helps on Doesn't help on Untested on Untested, but should help on
SRCCUT_CHECK_NAIVE new (test only) test only: srccut.block also cuts the old way and stops if the two cuts differ unset no (a developer switch) - - - -

Measurements

Nothing to measure in the game: the change is to the checks only; nothing the game runs changes.

What was run, on the GitHub version (NotRexed/Hookshot#2914), not on Longshot:

  • Every moved check, against that day's GitHub main: each run as main has it and as moved with SRCCUT_CHECK_NAIVE=1, with its declared tools (the Builder's clang, the Vulkan headers): 80 of 80 pass both ways, no cut differs.
  • tests/test_srccut.py (new).

Testing

Tested: the runs under Measurements (on the GitHub version) and the game-free checks this description names.

Not tested: in the game (tests only). The checks that were not moved (3 + 13 + 51) were not changed.

Needs other testers: None

Screenshots

Nothing on screen.

Risk and rollback

Only the checks change. A moved check could cut a different piece of source than before (the new cutter skips braces in literals and comments, which the old one counted); SRCCUT_CHECK_NAIVE=1 showed none of the 80 does today. A marker that now appears twice in a source stops its check where the old counter took the first silently. Reverting the commits is enough.

Reviewer notes

Carried over from NotRexed/Hookshot#2914 with the move to Longshot: the same change on Longshot's main, with its rename applied. Its review and discussion are there.

The dev-loop proposal's D2 (NotRexed/Hookshot#2636). A follow-up after NotRexed/Hookshot#2887: run_all.py --changed runs a test helper's importers (srccut's) rather than every check.

The checks were run on the GitHub version; this branch is the same change with the rename applied (the same files and line counts). Forgejo runs no checks, and they were not run again here. The moved checks and test_srccut.py were run, not the whole run_all.py.

Issues

See NotRexed/Hookshot#2636 (D2).

Checklist

For everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description).
  • Rebased on current main.
  • python -I -B tests/run_all.py run and passing (any failure that also fails on main is named above).
  • Tested in the game, or what wasn't is named under Testing.
  • Testing filled in: what was tested, what wasn't, and what needs other testers (with test requests).
  • Measured: main and this PR at named commits, on the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

If applicable

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Flags table filled in; README / docs/development.md switch reference updated.
  • Screenshots for a change that shows on screen.
  • A row in docs/tested-configurations.md for each measured run.
  • MKWVK_API_VERSION bumped (gpu/vk/vk_api.h's MkwVkHost or MkwVkRenderer changed).
  • The SPIR-V headers regenerated with glslang (a shader changed).
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.

🤖 Generated with Claude Code

## Why 123 checks carry their own copy of a brace counter (`def block`) to cut a function out of a source file; the copies count braces inside strings, character literals and comments too, and when a function is renamed or reshaped they stop with a bare `ValueError` or `IndexError` that doesn't say which source or marker (the trap AGENTS.md warns about, "Tests read the source"). This gives the checks one cutter and moves 80 of them to it, each shown to cut exactly what it cut before. ## What changed - tests: new `tests/srccut.py` (standard library): - `block(text, marker)`: from the marker to the brace that closes the first `{` after it (`_closing_brace()`), counting braces outside string and character literals (raw strings too, and C++14 digit separators), comments and preprocessor lines; - `between(text, start, end)`, and `find()`; - a marker that is missing, or that appears twice, stops the check with one message naming the source and the marker (`CutError`; `unique=False` takes the first on purpose); - `SRCCUT_CHECK_NAIVE=1` also cuts each block the old way (`_naive()`) and stops if the two differ: what a migration runs to show it changed nothing. - tests: 80 checks import `block` from it in place of their own copy, one commit per source file they read (`vk_menu.cpp`, `vk_draw.cpp`, `vk_memory.cpp`, `vk_texture.cpp`, `longshot_env.h`, `hos_main.c`, ...). Only exact copies of the plain counter moved; each takes `sys.path.insert(0, ...)` for its own folder, since `python -I` leaves it off the path. - tests: new `tests/test_srccut.py`: braces in strings, character literals, raw strings, comments and preprocessor lines; a fixture the old counter cut wrongly; a missing marker and a repeated one name the source; `between`; an unclosed block; the comparison with the old counter. - Not moved: - three checks whose `block` isn't the plain counter (a start offset; positions returned): left as they were; - 13 checks whose marker appears more than once in the source (a declaration before the definition, for example). The old counter took the first one silently, so each needs a look rather than `unique=False`; - 51 checks with other cutters (`function`, `body`, `between`, ...): later, by source file. ## Flags and settings | Flag | New or changed | What it does | Default now | Goal: on by default? | Helps on | Doesn't help on | Untested on | Untested, but should help on | |---|---|---|---|---|---|---|---|---| | `SRCCUT_CHECK_NAIVE` | new (test only) | test only: `srccut.block` also cuts the old way and stops if the two cuts differ | unset | no (a developer switch) | - | - | - | - | ## Measurements Nothing to measure in the game: the change is to the checks only; nothing the game runs changes. What was run, on the GitHub version (NotRexed/Hookshot#2914), not on Longshot: - Every moved check, against that day's GitHub `main`: each run as `main` has it and as moved with `SRCCUT_CHECK_NAIVE=1`, with its declared tools (the Builder's clang, the Vulkan headers): **80 of 80 pass both ways**, no cut differs. - `tests/test_srccut.py` (new). ## Testing **Tested:** the runs under Measurements (on the GitHub version) and the game-free checks this description names. **Not tested:** in the game (tests only). The checks that were not moved (3 + 13 + 51) were not changed. **Needs other testers:** None ## Screenshots Nothing on screen. ## Risk and rollback Only the checks change. A moved check could cut a different piece of source than before (the new cutter skips braces in literals and comments, which the old one counted); `SRCCUT_CHECK_NAIVE=1` showed none of the 80 does today. A marker that now appears twice in a source stops its check where the old counter took the first silently. Reverting the commits is enough. ## Reviewer notes Carried over from [NotRexed/Hookshot#2914](https://github.com/NotRexed/Hookshot/pull/2914) with the move to Longshot: the same change on Longshot's `main`, with its rename applied. Its review and discussion are there. The dev-loop proposal's D2 ([NotRexed/Hookshot#2636](https://github.com/NotRexed/Hookshot/pull/2636)). A follow-up after [NotRexed/Hookshot#2887](https://github.com/NotRexed/Hookshot/pull/2887): `run_all.py --changed` runs a test helper's importers (srccut's) rather than every check. The checks were run on the GitHub version; this branch is the same change with the rename applied (the same files and line counts). Forgejo runs no checks, and they were not run again here. The moved checks and `test_srccut.py` were run, not the whole `run_all.py`. ## Issues See [NotRexed/Hookshot#2636](https://github.com/NotRexed/Hookshot/pull/2636) (D2). ## Checklist ### For everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`). - [ ] Rebased on current `main`. - [ ] `python -I -B tests/run_all.py` run and passing (any failure that also fails on `main` is named above). - [x] Tested in the game, or what wasn't is named under Testing. - [x] Testing filled in: what was tested, what wasn't, and what needs other testers (with test requests). - [ ] Measured: main and this PR at named commits, on the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### If applicable - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [ ] Flags table filled in; README / docs/development.md switch reference updated. - [ ] Screenshots for a change that shows on screen. - [ ] A row in `docs/tested-configurations.md` for each measured run. - [ ] `MKWVK_API_VERSION` bumped (`gpu/vk/vk_api.h`'s `MkwVkHost` or `MkwVkRenderer` changed). - [ ] The SPIR-V headers regenerated with glslang (a shader changed). - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [ ] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. - [ ] Docs updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Carried over from github.com/jordanella/Hookshot test/srccut (its commits: test: one source cutter for the checks (tests/srccut.py), first the vk_menu.cpp readers; test: the vk_draw.cpp readers cut with tests/srccut.py; test: the vk_memory.cpp readers cut with tests/srccut.py; test: the vk_texture.cpp readers cut with tests/srccut.py; test: the longshot_env.h readers cut with tests/srccut.py; test: the other readers cut with tests/srccut.py; test: the hos_main.c readers cut with tests/srccut.py; test: the vk_xfer.cpp readers cut with tests/srccut.py; test: the vk_framegen.cpp readers cut with tests/srccut.py; test: the nn_fs.c readers cut with tests/srccut.py; test: the vk_fsr3fi.cpp readers cut with tests/srccut.py; test: the nn_vi.c readers cut with tests/srccut.py; test: the vk_imgui.cpp readers cut with tests/srccut.py; test: the nn_hid.c readers cut with tests/srccut.py; test: the nn_audio.c readers cut with tests/srccut.py; test: the rx_buffer.cpp readers cut with tests/srccut.py; test: the fg_scale.c readers cut with tests/srccut.py; test: the nn_libc.c readers cut with tests/srccut.py; test: the vk_internal.h readers cut with tests/srccut.py; test: the vk_temporal.cpp readers cut with tests/srccut.py; test: the nvn_layout.c readers cut with tests/srccut.py; test: the nn_video.c readers cut with tests/srccut.py; test: the vk_vendor.h readers cut with tests/srccut.py; test: three checks keep their own block(): it is not the plain brace counter).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
dyst changed title from test: one source cutter for the checks (tests/srccut.py), 80 checks moved to it to WIP: test: one source cutter for the checks (tests/srccut.py), 80 checks moved to it 2026-11-13 01:13:49 +00:00
Author
First-time contributor

Back to WIP under #48's process: this was carried over before the new template. Its description will be brought to the template and measured on Longshot (main against this PR, at named commits) when it's wanted for review; ask here if you'd like it sooner.

Back to WIP under #48's process: this was carried over before the new template. Its description will be brought to the template and measured on Longshot (main against this PR, at named commits) when it's wanted for review; ask here if you'd like it sooner.
Author
First-time contributor

Description brought to Longshot's PR template (#48). Still WIP: its numbers are from the GitHub version, and it isn't rebased on current main; it gets measured on Longshot (main against this PR, at named commits) before it is marked ready.

Description brought to Longshot's PR template (#48). Still WIP: its numbers are from the GitHub version, and it isn't rebased on current main; it gets measured on Longshot (main against this PR, at named commits) before it is marked ready.
Author
First-time contributor

Description moved to the template's Testing section and whole checklist (#72): what was tested, what wasn't, and what needs other testers (their test requests to open while this is WIP).

Description moved to the template's Testing section and whole checklist (#72): what was tested, what wasn't, and what needs other testers (their test requests to open while this is WIP).
This pull request has changes conflicting with the target branch.
  • tests/test_linux_update_skip.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'test/srccut:dyst-test/srccut'
git switch 'dyst-test/srccut'
Sign in to join this conversation.
No description provided.