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}...")