test: give the debug cases and annual integration their own predbat instance - #4530
Merged
Conversation
…nstance The debug regression cases planned against the shared instance, and read_debug_yaml only restores the attributes its dump actually carries - so anything the dump omits inherited whatever the previous test left behind. That made the golden plans depend on test ordering, and made the plan produced inside the suite differ from the one `--debug <case>` produces standalone. Both have caused real confusion: the goldens have had to be regenerated simply because the registry order changed, and a case that passes alone could fail in the suite. Each case now gets a freshly created instance, built the same way the standalone path builds one. The three now agree exactly - verified that predbat_debug_pre_saving1 produces an identical plan standalone, running debug_cases alone, and in the full suite. Doing that removed a mask. debug_cases had been overwriting most of the shared instance immediately before annual_integration ran, and annual_integration never sets up the state it plans against; left with the ambient state instead it went from 34s to 463s - silently, still passing. It gets a fresh instance for the same reason, which also makes it faster than it was before any of this (55s -> 34s). Full suite 144.77s -> 119.86s, and it no longer depends on what ran before what. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes order-sensitive state leakage in the unit-test harness by ensuring tests that load partial debug dumps (and tests that implicitly depend on prior state) run against freshly created PredBat instances, matching the standalone --debug <case> execution path.
Changes:
- Update
run_debug_casesto create a newPredBatinstance per debug YAML case instead of reusing the sharedmy_predbat. - Introduce
run_annual_integration_isolatedand routeannual_integrationthrough it so the integration test runs against a fresh instance rather than inherited ambient state.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the order-sensitivity that has already forced two golden regenerations and produced several confusing failures.
The problem
run_debug_casesplanned against the sharedmy_predbat, andread_debug_yamlonly restores the attributes its dump actually carries — so anything the dump omits inherited whatever the previous test left behind.Two consequences, both real:
TEST_REGISTRYchanged which state leaked in, which changed the plan, which brokepredbat_debug_pre_saving1and forced a regeneration that had nothing to do with the planner.--debug cases/<case>.yamlstandalone produced a different plan from the same case run inside the suite, so reproducing a suite failure by hand didn't reproduce the plan.test_single_debug.pyalready carried a hand-maintained list of attributes to reset for exactly this reason —dynamic_load_baseline,battery_rate_max_export,rate_max_base,rate_export_max_forward. That is whack-a-mole; the next omitted attribute starts it again.The fix
Each case gets a freshly created instance, built the same way the standalone path builds one.
Verified
predbat_debug_pre_saving1now produces a byte-identical plan in all three contexts:--debug cases/predbat_debug_pre_saving1.yamlstandalone./run_all --test debug_cases./run_allPreviously the first differed from the last.
What that uncovered
Removing the leak removed a mask.
debug_caseshad been overwriting most of the shared instance immediately beforeannual_integrationran, andannual_integrationnever sets up the state it plans against. Left with the ambient state instead, it went from 34s to 463s — silently, still passing.It gets a fresh instance for the same reason. That also makes it faster than it was before any of this: 55s → 34s, because it is no longer planning against whatever a previous test happened to leave.
Effect
./run_allannual_integrationdebug_casesFaster, and no longer dependent on what ran before what.
./run_alland./run_all --quickboth pass; pre-commit clean.Note
The per-attribute resets in
test_single_debug.pyare now redundant, since a fresh instance starts from the same defaults they were restoring. I have left them: they are harmless, and removing them is a separate change that wants its own verification.🤖 Generated with Claude Code