Repository navigation
fix(test): bind the real sel before the cron tests replace it - #40124
Conversation
test_cron_auto_pause_limit.py and test_cron_remove_deletes_history.py replace kiro_crew.sel.sel for a test. CronService.add_job then imports kiro_crew.dashboard.chat_folders_paths for the first time, and that module binds sel by name at import, so the test's stand-in stays bound after the test ends. The next first import of the chat_folders facade in the same process refuses a family whose owners disagree on sel, and every later test that needs the dashboard fails at that import. Under xdist a worker has usually imported the module at collection, so main is green; either file followed by test_power.py in one process fails. Both files now import chat_folders_paths before any test patches. Related: #39702
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Test-only change. It fixes two proven leaks without touching the product, so nothing blocks. Notes
[DESIGN-REVIEWED] 4d08c3d Description read[DESCRIPTION-READ] b59a2326db72f0b405610d3ccd085a0beffcce4417acc013bdf332434b93f0aa That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: A person should decideWhy: the decider estimates a 4% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier 2: reviewer-finding: Design Review. Test-only fix. CronService.add_job lazily imports kiro_crew.dashboard.chat_folders_paths (cron_service/fields.py:67), which binds Tier: 2, held for a person: reviewer-finding: Design Review. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head, the review traced the cause through the code: the lazy chat_folders_paths import in resolve_project_path binds sel by name, and the tests' monkeypatch of kiro_crew.sel.sel gets captured by that binding until the chat_folders facade family check refuses it. The review also reran the before and after commands from the body. On base: 3 failed (with test_power.py) and 1 failed (with the power canary). On head: 89, 11 and 99 passed. The change is test-only and adds no clocks, sleeps, ports, env changes or file writes.
Done well: the comment explains the full failure chain, so a reader can see why the unused import must stay.
Optional:
- Other cron test files patch
seland calladd_jobin the same way. A follow-up could preloadchat_folders_pathsonce intest/conftest.py, and then the per-file imports would not be needed. - Nothing pins the ordering import yet. A teardown that asserts
chat_folders_paths.sel is kiro_crew.sel.selwould make a test fail if someone deletes the import. - #39738 has the same hunk in
test/test_cron_auto_pause_limit.py. It can drop that hunk when it rebases after this PR merges.
Problem / Motivation
Goal: Two cron test files no longer leave a test's stand-in for
kiro_crew.sel.selbound in a module for the rest of the process, so the tests that run after them in the same process pass.test/test_cron_auto_pause_limit.pyandtest/test_cron_remove_deletes_history.pyreplacekiro_crew.sel.selfor a test.CronService.add_jobthen importskiro_crew.dashboard.chat_folders_pathsfor the first time (cron_service/fields.py,resolve_project_path), and that module doesfrom kiro_crew.sel import sel, so it keeps the stand-in aftermonkeypatchhas restoredkiro_crew.sel.sel. The next first import of thekiro_crew.dashboard.chat_foldersfacade in the process checks that its owners agree on every shared name and raises:RuntimeError: kiro_crew.dashboard.chat_folders: names bound to different objects across the family are ['sel'], but the facade declares []Every later test in that process that imports the dashboard fails at that import.
Why it matters
Main is green only because an xdist worker has usually imported
chat_folders_pathsat collection, before any test runs. Run either file with a few neighbours and it fails: a developer runningpytest test/test_cron_auto_pause_limit.py test/test_power.py, a leaf-scope CI run that repeats a small set of changed files, or any change to how files are grouped into processes. Draft #39738 hit it on its first full run: 15 tests red in one process (shard 7 of run 44661146070).Not a goal
chat_foldersfacade's import-time check or any isolation floor.ImportError: cannot import name '_PHASE_EMOJIS' from 'kiro_crew.slack.handler'(listed under Sibling sweep); that is a different defect.What changed (motivation → approach → change)
Symptom: tests after these files fail at the
chat_foldersimport. Cause: a module first imported whilekiro_crew.sel.selis replaced binds the replacement by name. Change: both files importkiro_crew.dashboard.chat_folders_pathsat module level, before any test patches, so the name it binds is the real accessor. Six lines each, test files only.Backwards compatibility
Compatible: test files only; nothing that runs in the product changes.
Removes nothing: two imports are added to two test modules.
Tests
Proof: not provable -- test-only change
python -m pytest -n0 --no-cov -q -p no:cacheprovider test/test_cron_auto_pause_limit.py test/test_power.py-> 3 failed, 86 passed (the threetest_should_prevent_sleep_*tests, each with theRuntimeErrorabove);... test/test_cron_remove_deletes_history.py test/test_power.py::test_should_prevent_sleep_no_sessions-> 1 failed, 10 passed.test/test_flake_pattern_ratchet.py,test/test_process_cache_floor_ratchet.py,test/test_conftest_import_budget.py-> 79 passed. Black, isort, flake8, comment-history, brand and file-line-cap gates pass.Manual verification
N/A — the reproduction above is the whole behaviour, and it is a pytest command.
Real-machine verification
Machine: own development host (EC2, AMD EPYC 9R14), Amazon Linux 2023, x86_64, 32 vCPU / 123 GiB
Before (main 380b086):
python -m pytest -n0 --no-cov -q -p no:cacheprovider test/test_cron_auto_pause_limit.py test/test_power.py-> 3 failed, 86 passed,RuntimeError: kiro_crew.dashboard.chat_folders: names bound to different objects across the family are ['sel']After (head 4d08c3d): the same command -> 89 passed
Cleanup: own computer
Related Issues
Related: #39702
Sibling sweep
Swept:
grep -rlE 'setattr\([a-zA-Z_.]*sel, "sel"|setattr\("kiro_crew\.sel\.sel"|patch\("kiro_crew\.sel\.sel"|patch\.object\([a-zA-Z_.]*sel, "sel"' test src/kiro_crew/apps/builtins(154 test files replacekiro_crew.sel.sel; 333 modules undersrc/kiro_crewbind it withfrom kiro_crew.sel import), then each of the 154 run in its own process followed bytest/test_power.py::test_should_prevent_sleep_no_sessions, which imports the dashboard and its facades.Sibling: test/test_cron_auto_pause_limit.py -- changed here
Sibling: test/test_cron_remove_deletes_history.py -- changed here
Sibling: test/test_cron_origin_injection.py -- not affected -- fails alone on main with a different error (
_PHASE_EMOJISimport), no family errorSibling: test/test_send_message_per_part.py -- not affected -- fails alone on main with the
_PHASE_EMOJISimport error, no family errorSibling: test/test_send_message_session_link.py -- not affected -- fails alone on main with the
_PHASE_EMOJISimport error, no family errorSibling: test/test_send_message_targeted.py -- not affected -- fails alone on main with the
_PHASE_EMOJISimport error, no family errorThe other 148 files left the dashboard import clean. The sweep proves only what that one canary import catches: a stand-in kept by a module outside the facades it imports would not show.
Pattern harvest
Rule candidate: review-prompt
Pattern: a test replaces a module attribute that other modules bind with
from x import name, and the code under test imports such a module for the first time inside the test, so the stand-in outlives the testChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributed under the project's Apache-2.0 license.
AI-assisted, opened by Claude Code