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
This commit is contained in:
@@ -53,16 +53,28 @@ def test_full_live_workflow(live_gui) -> None:
|
|||||||
except: pass
|
except: pass
|
||||||
print(f"[TEST] Creating new project at {temp_project_path}...")
|
print(f"[TEST] Creating new project at {temp_project_path}...")
|
||||||
client.click("btn_project_new_automated", user_data=temp_project_path)
|
client.click("btn_project_new_automated", user_data=temp_project_path)
|
||||||
|
# Defensive: fail fast if the click was dropped or the handler crashed
|
||||||
# Wait for project to be active
|
# before writing the project file.
|
||||||
success = False
|
import time as _time
|
||||||
for _ in range(10):
|
_start = _time.time()
|
||||||
proj = client.get_project()
|
while _time.time() - _start < 5.0:
|
||||||
if proj.get('project', {}).get('project', {}).get('name') == 'temp_project':
|
if os.path.exists(temp_project_path):
|
||||||
success = True
|
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
_time.sleep(0.1)
|
||||||
assert success, "Project failed to activate"
|
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(".")
|
test_git = os.path.abspath(".")
|
||||||
print(f"[TEST] Setting project_git_dir to {test_git}...")
|
print(f"[TEST] Setting project_git_dir to {test_git}...")
|
||||||
|
|||||||
Reference in New Issue
Block a user