# wait_for_ready_test_pattern_20260605 Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Replace `time.sleep(N)` in `test_workspace_profiles_sim.py` and `test_auto_switch_sim.py` with polling helpers that wait for the operation to complete. Tests should pass consistently across machines. **Architecture:** Inline polling helpers (or extracted to `tests/helpers.py` if 3+ tests need them). 100ms poll interval, 5s default timeout. **Tech Stack:** Python 3.11+, pytest 9.0, time-based polling. --- ## File Structure | File | Change | Purpose | |---|---|---| | `tests/test_workspace_profiles_sim.py` | Modify | Replace time.sleep with polling | | `tests/test_auto_switch_sim.py` | Modify | Replace time.sleep with polling | No production code changes. No new shared module (helpers are inlined for now). --- ## Task 1: Migrate `test_workspace_profiles_sim.py` **Files:** - Modify: `tests/test_workspace_profiles_sim.py` - [ ] **Step 1.1: Pre-edit checkpoint** ```powershell cd C:\projects\manual_slop; git status --short ``` - [ ] **Step 1.2: Read the test** Read `tests/test_workspace_profiles_sim.py` to see the current `time.sleep` calls. - [ ] **Step 1.3: Add the polling helpers at the top of the file** After the existing imports, add: ```python import time def wait_for_save_completion(client, profile_name, timeout=5.0): """Poll until the saved profile appears in the workspace profiles.""" deadline = time.time() + timeout while time.time() < deadline: profiles = client.get_value('workspace_profiles') or {} if profile_name in profiles: return time.sleep(0.1) raise TimeoutError(f"Profile '{profile_name}' did not appear in workspace_profiles within {timeout}s") def wait_for_load_completion(client, item, expected, timeout=5.0): """Poll until the item's value matches expected.""" deadline = time.time() + timeout while time.time() < deadline: if client.get_value(item) == expected: return time.sleep(0.1) raise TimeoutError(f"Item '{item}' did not become {expected!r} within {timeout}s") ``` Use exactly 1-space indentation. No comments. - [ ] **Step 1.4: Replace the `time.sleep` calls** In the test body, replace: - `time.sleep(2.0)` after `save_workspace_profile` → `wait_for_save_completion(client, "test_restore")` - `time.sleep(2.0)` after `load_workspace_profile` → `wait_for_load_completion(client, 'ui_separate_tier1', True)` - The other `time.sleep(1.0)` calls after `set_value` can stay (set_value is synchronous in the controller) OR be replaced with `wait_for_load_completion` for consistency. **Recommended:** keep the `set_value` sleeps for now (set_value writes to controller synchronously; the sleep is for the GUI to process the change), but replace the save/load ones. - [ ] **Step 1.5: Run the test** ```powershell cd C:\projects\manual_slop; uv run pytest tests/test_workspace_profiles_sim.py -v --timeout=30 ``` Expected: 1 passed. - [ ] **Step 1.6: Commit** ```powershell cd C:\projects\manual_slop; git add tests/test_workspace_profiles_sim.py git -C C:\projects\manual_slop commit -m "test(workspace_profiles): replace time.sleep with wait_for_X polling helpers" $h = git -C C:\projects\manual_slop log -1 --format='%H' git -C C:\projects\manual_slop notes add -m "Replaced time.sleep(2.0) with wait_for_save_completion and wait_for_load_completion polling helpers. 100ms poll interval, 5s default timeout. Per the Authoring Robust live_gui Tests rules in docs/guide_testing.md: use wait-for-ready pattern, not fixed sleeps." $h ``` --- ## Task 2: Migrate `test_auto_switch_sim.py` **Files:** - Modify: `tests/test_auto_switch_sim.py` - [ ] **Step 2.1: Read the test** Read `tests/test_auto_switch_sim.py` to see the current `time.sleep` calls. - [ ] **Step 2.2: Add the polling helpers at the top of the file** Same as Task 1 Step 1.3 (or import from a shared location if extracted in the future). - [ ] **Step 2.3: Replace the `time.sleep(1)` calls after each `trigger_tier(...)` call** The test triggers a tier-2 then tier-3 transition. After each trigger, wait for `show_windows['Diagnostics']` to reach the expected value: ```python trigger_tier('Tier 2 (Tech Lead)') wait_for_load_completion(client, 'show_windows', {'Diagnostics': False}) assert client.get_value('show_windows').get('Diagnostics', False) == False trigger_tier('Tier 3 (Worker): task-1') wait_for_load_completion(client, 'show_windows', {'Diagnostics': True}) assert client.get_value('show_windows').get('Diagnostics', False) == True ``` - [ ] **Step 2.4: Run the test** ```powershell cd C:\projects\manual_slop; uv run pytest tests/test_auto_switch_sim.py -v --timeout=60 ``` Expected: 1 passed. - [ ] **Step 2.5: Commit** ```powershell cd C:\projects\manual_slop; git add tests/test_auto_switch_sim.py git -C C:\projects\manual_slop commit -m "test(auto_switch): replace time.sleep with wait_for_load_completion polling" $h = git -C C:\projects\manual_slop log -1 --format='%H' git -C C:\projects\manual_slop notes add -m "Replaced time.sleep(1) after each trigger_tier with wait_for_load_completion. The auto-switch applies a workspace profile; the test now polls until the expected show_windows state is observed." $h ``` --- ## Task 3: Verify both tests pass in the full batched suite **Files:** (no file changes; verification only) - [ ] **Step 3.1: Run both tests** ```powershell cd C:\projects\manual_slop; uv run pytest tests/test_workspace_profiles_sim.py tests/test_auto_switch_sim.py -v --timeout=60 ``` Expected: 2 passed. - [ ] **Step 3.2: Commit (no-op)** ```powershell cd C:\projects\manual_slop; git -c core.autocrlf=false commit --allow-empty -m "verify: wait_for_ready migration unblocks 2 tests" ``` --- ## Task 4: Update tracks.md **Files:** - Modify: `conductor/tracks.md` - [ ] **Step 4.1: Add a brief note** Find the live_gui_test_hardening_v2 entry and add: "Sub-track `wait_for_ready_test_pattern_20260605` complete: time.sleep replaced with polling helpers in test_workspace_profiles_sim and test_auto_switch_sim." - [ ] **Step 4.2: Commit** ```powershell cd C:\projects\manual_slop; git add conductor/tracks.md git -C C:\projects\manual_slop commit -m "conductor: wait_for_ready_test_pattern sub-track complete" ``` --- ## Self-Review - **Spec coverage:** 2 tests migrated; polling helpers defined; fixed sleeps replaced. - **Placeholders:** None. - **Type consistency:** Polling helpers return None on success, raise TimeoutError on failure. Test assertions unchanged. - **Risk:** Low — only test files change. --- ## Execution Handoff Inline execution. 4 tasks, atomic commits. User runs the full batched suite to confirm.