Skip to content

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
kirodotdev:mainfrom
Xianwen-Peng:fix/spec-builder-lazy-state-dir
Closed

fix(test): resolve spec_builder real state dir lazily, not at import — unbreak main CI#1545
Xianwen-Peng wants to merge 1 commit into
kirodotdev:mainfrom
Xianwen-Peng:fix/spec-builder-lazy-state-dir

Conversation

@Xianwen-Peng

Copy link
Copy Markdown
Collaborator

Description

Main CI is currently red (runs on af8774b8 and 794aeed7 both failed), and every open PR inherits the failure: Backend Tests (3.10, 2), (3.12, 2), (Windows) (2) and therefore Coverage Gate fail with:

FAILED test/test_lazy_data_home_paths.py::TestNoImportTimePathResolution::test_no_module_level_path_constants
assert not ['apps/builtins/spec_builder/tests/test_routes.py:88  [module] _REAL_STATE_DIR = ..._state_dir()']

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 through config_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-test test_state_guard_watches_the_whole_directory is updated to assert the snapshot helper uses the accessor.

Related Issues

Unbreaks CI broken by #518 (af8774b8). Guard context: #874, #1059.

Testing

  • Existing tests pass — ran both affected files locally on Python 3.12:
    pytest src/kiro_crew/apps/builtins/spec_builder/tests/test_routes.py test/test_lazy_data_home_paths.py
    284 passed
    
    Before the fix: test_no_module_level_path_constants fails exactly as on main CI; after: passes, and all 268 spec_builder tests still pass (including the autouse leak-guard meta-test).
  • New tests added for new functionality — n/a, this fixes a guard violation; the guard is the test
  • Manual verification performed (describe above)

Checklist

  • Code follows the project style guidelines
  • Self-review completed
  • Documentation updated (if applicable) — the accessor carries a comment explaining the lazy resolution and where first-use happens
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

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.
@Xianwen-Peng
Xianwen-Peng requested a review from a team as a code owner August 5, 2026 01:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) labels Aug 5, 2026
@Xianwen-Peng

Copy link
Copy Markdown
Collaborator Author

Closing — superseded by #1543, which landed the same first-use capture fix and main is green again (65268a1).

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant