fix(test): resolve spec_builder real state dir lazily, not at import — unbreak main CI - #1545
Closed
Xianwen-Peng wants to merge 1 commit into
Closed
Conversation
test_lazy_data_home_paths::test_no_module_level_path_constants fails on main since the Spec Builder builtin landed: its test harness binds _REAL_STATE_DIR = routes._state_dir() at module level, which the repo-wide guard forbids (issue kirodotdev#874 -- an import-time binding freezes whichever KIROCREW_HOME was active at collection). This breaks the Backend Tests shard 2 jobs and the Coverage Gate on every PR. Replace the module-level constant with the sanctioned override-hook pattern: a lazy _real_state_dir() accessor that resolves on first use. First use is the autouse fixture's setup, which still runs BEFORE _redirect_state monkeypatches the module attributes, so the guard keeps snapshotting the USER's live directory exactly as before. Update the meta-test to assert the accessor is used by the snapshot helper.
Collaborator
Author
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.
Description
Main CI is currently red (runs on
af8774b8and794aeed7both failed), and every open PR inherits the failure:Backend Tests (3.10, 2),(3.12, 2),(Windows) (2)and thereforeCoverage Gatefail with:The Spec Builder builtin (#518, merged as
af8774b8) added a test harness that binds_REAL_STATE_DIR = routes._state_dir()at module level._state_dir()resolves throughconfig_dir(), so this is exactly the import-time data-home freeze the repo-wide guard from issue #874 forbids — the transitive-factory detector added in #1059/#1451 catches it.Fix: replace the module-level constant with the sanctioned override-hook pattern (per the guard's own docstring): a lazy
_real_state_dir()accessor that resolves on first use and caches. The harness's safety-net semantics are preserved: first use is the autouse fixture's setup (_live_state_snapshot()before_redirect_state(...)runs), so it still captures the USER's real live state dir before any monkeypatching — the property the original comment ("Captured at import, before any test can monkeypatch") was protecting. The meta-testtest_state_guard_watches_the_whole_directoryis updated to assert the snapshot helper uses the accessor.Related Issues
Unbreaks CI broken by #518 (
af8774b8). Guard context: #874, #1059.Testing
test_no_module_level_path_constantsfails exactly as on main CI; after: passes, and all 268 spec_builder tests still pass (including the autouse leak-guard meta-test).Checklist
Contribution License Agreement