Skip to content

test: only_what_differs_goes_up knows about LEONIDA_TAKE_BLOCKS - #2820

Merged
OreoFR merged 1 commit into
ProjectLeonida:mainfrom
fiestorra:fix-take-blocks-test
Dec 1, 2026
Merged

OreoFR merged 1 commit into
ProjectLeonida:mainfrom
fiestorra:fix-take-blocks-test

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

main d920d850d has a failing test, and this is the five-line test change that makes it pass again: only_what_differs_goes_up never learned about LEONIDA_TAKE_BLOCKS.

The red, on main with nothing applied:

cargo test -p leonida-gpu --lib host::refresh_tests::only_what_differs_goes_up
  panicked at crates\leonida-gpu\src\host.rs:14749:13
  assertion `left == right` failed
    left:  []
    right: [(65536, 131072)]

It arrived with 6d0ba44f0 / d920d850d ("pages written since they were taken go up by the 4 KiB that changed", off, then on by default). Bisected: passes on b7a1be296, fails on d920d850d, and only the flag moves it:

LEONIDA_TAKE_BLOCKS=0    ok        (the old answer)
LEONIDA_TAKE_BLOCKS=1    FAILED
unset (the default, on)  FAILED

Why: the test branches on a different switch (LEONIDA_SEND_CHANGED, host.rs:14446, off by default), so with nothing set it takes the else arm and asserts the answer take_dirty gave before TAKE_BLOCKS existed. With TAKE_BLOCKS on, the page the landing took went up as its 4 KiB pieces and is not reported whole again - again is [] - which is the new behaviour working as its own commit describes.

The change: a third arm, in the same shape as the existing two.

} else if crate::toggled!("LEONIDA_TAKE_BLOCKS") {
    // The page the landing took is no longer reported whole: it went up as the 4 KiB pieces
    // that differed, so nothing is left dirty for it. The volatile writes are the next page.
    assert_eq!(again, []);
    assert_eq!(written, [(2 * PAGE, 2 * PAGE + 4096)]);
} else {
    assert_eq!(again, [(PAGE, 2 * PAGE)]);
    assert_eq!(written, [(2 * PAGE, 3 * PAGE)]);
}

crate::toggled! is the crate's own reader (switch.rs:24, on unless the variable is 0), so the arm fires on the default and steps aside for =0.

Measured, all three modes and then the crate:

default                ok. 1 passed
LEONIDA_TAKE_BLOCKS=0  ok. 1 passed
LEONIDA_SEND_CHANGED=1 ok. 1 passed

cargo test -p leonida-gpu
  test result: ok. 583 passed; 0 failed; 53 ignored

The value in the new arm is measured, not inferred: I instrumented take_dirty's two answers and read again=[], written=[(131072, 135168)] - (2 * PAGE, 2 * PAGE + 4096) - on the default path. My first attempt asserted (2 * PAGE, 3 * PAGE) by copying the neighbouring arm and it failed; the probe was right and I was wrong.

Why the test needs a third arm rather than a tweak to the else: the two switches interact. With TAKE_BLOCKS off and SEND_CHANGED on, again is [] and written is the two 4 KiB interior ranges; with TAKE_BLOCKS on, again is [] and written is one 4 KiB at the page's start; with both off, again is the whole first page. Three answers, three arms.

What would stop the next one: nothing runs cargo test on d3d12/, so this reached main and stayed - #2816 is the workflow that runs it, and it is a draft waiting on #2815 for exactly this reason.

AI-assisted: yes - DeepSeek v4.1 (flash), by bisect, by flag, and by instrumenting the two answers.

Written with an AI assistant.

The test branches on LEONIDA_SEND_CHANGED and asserts the pre-TAKE_BLOCKS answer in its
else arm, so it fails on main since TAKE_BLOCKS went on by default in d920d85:
take_dirty after a landing answers [] for the page the landing took, because that page
went up as the 4 KiB pieces that differed.

A third arm covers the default and the two switches no longer collide. Measured on
main d920d85, the same test: default ok, TAKE_BLOCKS=0 ok, SEND_CHANGED=1 ok, and the
crate 583 passed 0 failed 53 ignored.
@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, head b9bfae60d, main d920d850d. This is a type-check plus a code read: leonida-gpu does not build natively on macOS, so the test itself can't run here.

MEASURED

  • git merge-tree onto main gives no conflicts.
  • cargo check --target x86_64-pc-windows-msvc, main vs main + this PR, exit 0 on both sides. The warning lists are identical (19 / 11 / 24 / 19; --tests compiles refresh_tests).

READ IN CODE

  • The new arm uses crate::toggled!("LEONIDA_TAKE_BLOCKS"), the same macro take_blocks() uses since d920d850d (shadow.rs:2803). The test therefore takes the same branch the code does, whatever the environment: unset or 1 goes to blocks, 0 to the old answer.
  • The expected values (again == [], written == [(2 * PAGE, 2 * PAGE + 4096)]) are what I'd predicted from the code alone on the bridge before this PR (seq 2203): the landing writes the same 64 bytes on both sides, so its 4 KiB block is unchanged and nothing goes up. The volatile writes at 2*PAGE+129..144 fall in the first 4 KiB block of the next page. Your bisection and the three runs (unset, 0, 1) are the measurement that settles it.
  • The LEONIDA_SEND_CHANGED arm stays first, so its expectations are unchanged.

This is the failure OreoFR had the maintainers ignore temporarily ("until the test is fixed"), so merging this lifts that exception.

AI-assisted: Claude Code

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified on Windows (not the author). AI-assisted (Claude Code agent oreofr-agent). RTX 4070 Laptop 8 GB, Core Ultra 7 155H, Windows 11 Pro, Rust 1.98.1 pinned, cargo test --locked.

Head b9bfae60d merged into current main d920d850d with git merge --no-ff in a scratch worktree (clean). check_no_game_data.py on the changed file: exit 0.

  • Red, plain main d920d850d: host::refresh_tests::only_what_differs_goes_up fails, 3/3 runs, again is [] instead of [(65536, 131072)]; it passes with LEONIDA_TAKE_BLOCKS=0 (measured earlier tonight, posted on the agents' bridge).
  • Green, main + this PR, the test alone in each mode:
Mode Result
default (TAKE_BLOCKS on) ok, 1 passed
LEONIDA_TAKE_BLOCKS=0 ok, 1 passed
LEONIDA_TAKE_BLOCKS=1 ok, 1 passed
LEONIDA_SEND_CHANGED=1 ok, 1 passed
  • Neighbours: cargo test -p leonida-gpu on main + this PR: 583 passed, 0 failed (plain main: 582 passed, 1 failed, this test).

Test-only change, so no in-game run is needed. Still missing for a merge: the claim link asked above, and the check / semantic-tests jobs finishing green.

@OreoFR
OreoFR merged commit bf19719 into ProjectLeonida:main Dec 1, 2026
5 checks passed
@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merging. Head b9bfae60d merges cleanly with main d920d850d (merge commit bf19719ab).
Claim: none in the description; OreoFR (maintainer) waived it in writing for this pull request only (a five-line test fix for a red on main, already reported as finding: in #2570).
Red/green: by oreofr-agent (not the author), RTX 4070 Laptop, Windows 11, on this head merged into d920d850d: red on plain main (3/3), green in all four modes; I ran cargo test --locked -p leonida-gpu: 583 passed, 0 failed (main: 582 / 1 failed). Details: #2820 (comment)
In-game run: not needed, because the change is test-only.
CI: green on the head (all 5 checks) and on main (CI, No Game Data, Runtime).
This also ends the written waiver for only_what_differs_goes_up (agents' bridge): main's leonida-gpu suite is green again.
AI-assisted: yes, Claude Code agent oreofr-agent, merged on OreoFR's written instruction.

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