scripts: red_green.py checks a pull request red and green locally (TEST-RED-GREEN-LOCAL) #2787

Merged
TheGeogeo merged 1 commit from upstream-pr/2787 into main 2026-11-30 22:33:36 +00:00
TheGeogeo commented 2026-11-30 20:53:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T20:53:20Z.


Claimed in the coordination issue as: TEST-RED-GREEN-LOCAL (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7290856448)

What and why

CONTRIBUTING.md asks for a test that fails on main and passes with the change. Verifiers check that by hand today, each in their own way: a worktree, a cherry-pick of the test file, two builds, then reading two test logs. docs/testing.md describes it only for C++ runtime/ on fork CI. This adds scripts/red_green.py (standard library), which does it locally for the D3D12 crates and the Python tests:

python -I scripts/red_green.py <pull request number>
  • Green is current main (it fetches origin/main and the pull request) with the pull request merged.

  • Red is current main plus only the pull request's tests:

    • test files, whole: a file under a tests folder, *_tests.rs, tests.rs;
    • in other Rust files, the hunks that change only #[cfg(test)] items: a #[cfg(test)] mod x { ... } block, a #[cfg(test)] mod x_tests; line, a #[cfg(test)] function. Blank lines and comments around them are allowed. Braces in strings, raw strings, chars and comments do not end a block. A hunk that mixes test and other code stays on the green side only.

    That change is committed on the merge base and cherry-picked onto main with a 3-way merge. A conflict, or a pull request with no test, is "red not constructible".

  • It runs cargo test --locked --no-fail-fast -p <crate> for every crate under d3d12/crates or d3d12/apps the pull request touches. It runs from d3d12/, so the pinned toolchain applies. It also runs each changed tests/**/test*.py with unittest.

  • Both sides run in one worktree with one cargo target dir under <git common dir>/red-green, red first, never in parallel. A lock file refuses a second run. The worktree and the target dir stay, so the next run builds only what changed. Shared target dirs across worktrees were left out because they rebuild each other's crates.

  • It prints, per test: red then green; pass on red and fail on green; fail on both (failing on main too); found on one side only. Then the verdict:

    • red then green (exit 0);
    • no red, red does not build, green fails, red not constructible, green not constructible, no tests ran (exit 1);
    • a usage or git error exits 2.

    red does not build is the case docs/testing.md calls "does not build without the pull request's new file". --json gives everything.

  • docs/testing.md has a new subsection next to the fork-CI recipe. C++ runtime/ tests stay with that recipe.

Tested

On Windows 11 Pro 10.0.26300, Python 3.12, git 2.56.1.windows.1:

  • tests/test_red_green.py, 13 tests, all passing. They use throwaway git repositories and a stub cargo, with no game data:
    • a fix with its test goes red then green;
    • a test that passes on both sides is no red;
    • a change with no test is red not constructible;
    • a pull request that breaks a test is green fails;
    • a test that needs new code is red does not build;
    • a conflict with the base;
    • a second run at the same time is refused;
    • a Python fix with its test, and the test of a new tool that does not import on red;
    • hunk selection: the test hunk kept and the code hunk left out, a mod x_tests; line, cfg(not(test)), a mixed hunk, braces in raw strings and chars.
  • On real pull requests, against main d8ca18240:
    • #2784 (leonida-lua): red then green for its 5 new tests, 35 pass on both, in 29 s from a cold target dir. That matches the red/green its verifier reported (35 + 5 failing on main, 40/40 with it).
    • #2777 (leonida-shader): the red side took source_hash_tests.rs and the mod source_hash_tests; hunk of lib.rs, and left build.rs (the fix) out. Result: red then green for 2 tests, 401 pass on both, in 792 s. That matches its verifier's check: 2 of the 3 new tests fail on main by assertion.
  • tests/test_docs_*.py, tests/test_tool_stdout_encoding.py, tests/test_ci_registration.py, scripts/check_no_game_data.py on the changed files, and git diff --check are clean.

GPUs tested: n/a (no GPU code)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5573558651 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2787). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T20:53:20Z. --- Claimed in the coordination issue as: TEST-RED-GREEN-LOCAL (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7290856448) ### What and why CONTRIBUTING.md asks for a test that fails on `main` and passes with the change. Verifiers check that by hand today, each in their own way: a worktree, a cherry-pick of the test file, two builds, then reading two test logs. docs/testing.md describes it only for C++ `runtime/` on fork CI. This adds `scripts/red_green.py` (standard library), which does it locally for the D3D12 crates and the Python tests: ``` python -I scripts/red_green.py <pull request number> ``` - **Green** is current `main` (it fetches `origin/main` and the pull request) with the pull request merged. - **Red** is current `main` plus only the pull request's tests: - test files, whole: a file under a `tests` folder, `*_tests.rs`, `tests.rs`; - in other Rust files, the hunks that change only `#[cfg(test)]` items: a `#[cfg(test)] mod x { ... }` block, a `#[cfg(test)] mod x_tests;` line, a `#[cfg(test)]` function. Blank lines and comments around them are allowed. Braces in strings, raw strings, chars and comments do not end a block. A hunk that mixes test and other code stays on the green side only. That change is committed on the merge base and cherry-picked onto `main` with a 3-way merge. A conflict, or a pull request with no test, is "red not constructible". - It runs `cargo test --locked --no-fail-fast -p <crate>` for every crate under `d3d12/crates` or `d3d12/apps` the pull request touches. It runs from `d3d12/`, so the pinned toolchain applies. It also runs each changed `tests/**/test*.py` with unittest. - Both sides run in one worktree with one cargo target dir under `<git common dir>/red-green`, red first, never in parallel. A lock file refuses a second run. The worktree and the target dir stay, so the next run builds only what changed. Shared target dirs across worktrees were left out because they rebuild each other's crates. - It prints, per test: red then green; pass on red and fail on green; fail on both (failing on `main` too); found on one side only. Then the verdict: - `red then green` (exit 0); - `no red`, `red does not build`, `green fails`, `red not constructible`, `green not constructible`, `no tests ran` (exit 1); - a usage or git error exits 2. `red does not build` is the case docs/testing.md calls "does not build without the pull request's new file". `--json` gives everything. - docs/testing.md has a new subsection next to the fork-CI recipe. C++ `runtime/` tests stay with that recipe. ### Tested On Windows 11 Pro 10.0.26300, Python 3.12, git 2.56.1.windows.1: - `tests/test_red_green.py`, 13 tests, all passing. They use throwaway git repositories and a stub cargo, with no game data: - a fix with its test goes red then green; - a test that passes on both sides is `no red`; - a change with no test is `red not constructible`; - a pull request that breaks a test is `green fails`; - a test that needs new code is `red does not build`; - a conflict with the base; - a second run at the same time is refused; - a Python fix with its test, and the test of a new tool that does not import on red; - hunk selection: the test hunk kept and the code hunk left out, a `mod x_tests;` line, `cfg(not(test))`, a mixed hunk, braces in raw strings and chars. - On real pull requests, against `main` `d8ca18240`: - #2784 (`leonida-lua`): `red then green` for its 5 new tests, 35 pass on both, in 29 s from a cold target dir. That matches the red/green its verifier reported (35 + 5 failing on `main`, 40/40 with it). - #2777 (`leonida-shader`): the red side took `source_hash_tests.rs` and the `mod source_hash_tests;` hunk of `lib.rs`, and left `build.rs` (the fix) out. Result: `red then green` for 2 tests, 401 pass on both, in 792 s. That matches its verifier's check: 2 of the 3 new tests fail on `main` by assertion. - `tests/test_docs_*.py`, `tests/test_tool_stdout_encoding.py`, `tests/test_ci_registration.py`, `scripts/check_no_game_data.py` on the changed files, and `git diff --check` are clean. GPUs tested: n/a (no GPU code) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
OreoFR commented 2026-11-30 20:57:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T20:57:45Z.


Verified by OreoFR (another owner than TheGeogeo) on macOS 27.2.1, Apple M5, Python 3.12.16, Rust (rustup), main d8ca18240 merged with head 1f08a8abb.

  • MEASURED, green: tests/test_red_green.py 13 passed. Red (main + only the test): 1 error at import, as expected for a new script.
  • tests/test_docs_*.py 57 passed; tests/test_tool_stdout_encoding.py 4 passed; check_no_game_data.py on the three changed files: clean.
  • MEASURED, a real run on macOS: python -I scripts/red_green.py 2784 from the merged tree → red then green (5) (the 5 new leonida_lua::tests::* gate-driver tests), pass on both: 35, verdict: red then green, exit 0. That matches my manual red/green of #2784 (35 + 5 failed → 40/40), so the tool works off Windows for a crate that builds here.
  • Not covered: a PR whose crate does not build on macOS (leonida-gpu), and the Windows-only test modules.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7291715420 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2787#issuecomment-7291715420). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T20:57:45Z. --- Verified by OreoFR (another owner than TheGeogeo) on macOS 27.2.1, Apple M5, Python 3.12.16, Rust (rustup), `main` `d8ca18240` merged with head `1f08a8abb`. - MEASURED, green: `tests/test_red_green.py` **13 passed**. Red (`main` + only the test): 1 error at import, as expected for a new script. - `tests/test_docs_*.py` 57 passed; `tests/test_tool_stdout_encoding.py` 4 passed; `check_no_game_data.py` on the three changed files: clean. - MEASURED, **a real run on macOS**: `python -I scripts/red_green.py 2784` from the merged tree → `red then green (5)` (the 5 new `leonida_lua::tests::*` gate-driver tests), `pass on both: 35`, `verdict: red then green`, exit 0. That matches my manual red/green of #2784 (35 + 5 failed → 40/40), so the tool works off Windows for a crate that builds here. - Not covered: a PR whose crate does not build on macOS (`leonida-gpu`), and the Windows-only test modules. AI-assisted: Claude Code
MoonEyes commented 2026-11-30 22:33:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T22:33:33Z.


Merging. Head 1f08a8abb merges cleanly with main 6494909b7 and does not force a rebase of #2566. CI green on this head. Verified by OreoFR on it; I ran it on main + PR: 13 tests OK, docs tests OK (Windows, Python 3.14); without the new script its test does not import. I read the script's git and subprocess calls: it works in its own worktree. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7294004339 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2787#issuecomment-7294004339). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T22:33:33Z. --- Merging. Head `1f08a8abb` merges cleanly with `main` `6494909b7` and does not force a rebase of #2566. CI green on this head. Verified by OreoFR on it; I ran it on main + PR: 13 tests OK, docs tests OK (Windows, Python 3.14); without the new script its test does not import. I read the script's git and subprocess calls: it works in its own worktree. Merged by MoonEyes. AI-assisted (Claude Code).
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
ProjectLeonida/mandy!2787
No description provided.