From b6972c31de41560c562d51f0a5ddc9495c866a95 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 8 Jun 2026 13:26:54 -0400 Subject: [PATCH] test(live_workflow): use wait_for_project_switch + defensive file check Replaces the 10x1s blind poll of derived state with a condition-based wait on /api/project_switch_status. Also adds a defensive file existence check that fails fast (within 5s) if the click was dropped or the project creation handler crashed. The new wait surfaces a clear error message ('Project switch did not complete in 30s. Last status: ...') instead of the generic 'Project failed to activate', and exposes _project_switch_error if the controller reported one. - tests/test_live_workflow.py: replaced poll loop (lines 57-65) with wait_for_project_switch + os.path.exists defensive check --- tests/test_live_workflow.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/test_live_workflow.py b/tests/test_live_workflow.py index b31043fc..a3b7777b 100644 --- a/tests/test_live_workflow.py +++ b/tests/test_live_workflow.py @@ -53,16 +53,28 @@ def test_full_live_workflow(live_gui) -> None: except: pass print(f"[TEST] Creating new project at {temp_project_path}...") client.click("btn_project_new_automated", user_data=temp_project_path) - - # Wait for project to be active - success = False - for _ in range(10): - proj = client.get_project() - if proj.get('project', {}).get('project', {}).get('name') == 'temp_project': - success = True + # Defensive: fail fast if the click was dropped or the handler crashed + # before writing the project file. + import time as _time + _start = _time.time() + while _time.time() - _start < 5.0: + if os.path.exists(temp_project_path): break - time.sleep(1) - assert success, "Project failed to activate" + _time.sleep(0.1) + assert os.path.exists(temp_project_path), ( + f"temp_project.toml not created within 5s of click. " + f"Click may have been dropped or _cb_new_project_automated crashed." + ) + + # Wait for project switch to complete (deterministic, condition-based). + # Replaces the prior 10x1s blind poll of derived state. + status = client.wait_for_project_switch(expected_path=temp_project_path, timeout=30.0) + assert not status.get("timeout"), ( + f"Project switch did not complete in 30s. Last status: {status}" + ) + assert not status.get("error"), ( + f"Project switch failed with error: {status.get('error')}" + ) test_git = os.path.abspath(".") print(f"[TEST] Setting project_git_dir to {test_git}...")