Skip to content

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

Open
TheGeogeo wants to merge 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:test-red-green
Open

TheGeogeo wants to merge 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:test-red-green

Conversation

@TheGeogeo

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-RED-GREEN-LOCAL (#2570 (comment))

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:
  • 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)

…ST-RED-GREEN-LOCAL)

Green is current main with the pull request merged. Red is current main plus only the pull request's
tests: its test files, and the hunks of other Rust files that change only #[cfg(test)] items,
committed on the merge base and cherry-picked with a 3-way merge. It runs the touched D3D12 crates'
cargo test and the changed tests/**/test*.py on both sides, in one worktree and one target dir under
the git common dir, and prints per test: red then green, pass on red and fail on green, fail on both,
on one side only, with a verdict and an exit code. docs/testing.md has it next to the fork-CI recipe.
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

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 mods: gate_driver takes a run from the menus into the world (D3D12-GATE-DRIVER-MOD) #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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants