Files
odysseus/tests/test_cookbook_dependency_completion_regression.py
SHORYA BAJ f876fc7704 fix(cookbook): don't mark successful dependency installs as crashed (#1315)
Pip dependency installs are tracked as download tasks but finish with the
runner's "=== Process exited with code 0 ===" sentinel and pip's
"Successfully installed" line — never the HuggingFace download markers
(DONE / 100% / /snapshots/ / DOWNLOAD_OK) the download heuristics look for.

Once the tmux pane is gone, the backend's only completion check is the HF
cache lookup, which a pip package (e.g. llama-cpp-python[server], no "/")
never matches, so it reports "stopped" — and the frontend maps a stopped
download to "crashed". The reconnect loop's session-gone heuristic had the
same gap. Result: a clean install (exit 0) showed "crashed" in the Running
tab while the Dependencies tab correctly showed it installed.

Add a shared _depInstallSucceeded() helper that keys off the exit-0
sentinel (falling back to pip's success line, rejecting ERROR/Traceback)
and wire it into both the session-gone heuristic and the background status
reconciler, gated on payload._dep so real model downloads are unaffected.

Also fixes the pre-existing test_background_status_poll_reconciles_into_local_tasks
assertion that no longer matched the evolved reconciler, and adds regression
coverage for both paths.
2026-06-04 12:55:06 +01:00

88 lines
3.6 KiB
Python

from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def _read(rel_path: str) -> str:
return (ROOT / rel_path).read_text(encoding="utf-8")
def test_backend_status_treats_download_exit_zero_as_completed():
source = _read("routes/cookbook_routes.py")
assert "exit_match = re.search(r\"=== process exited with code\\s+(-?\\d+)\"" in source
assert "elif has_exit and task_type == \"download\":" in source
assert "status = \"completed\" if exit_code == 0 else \"error\"" in source
def test_background_status_poll_reconciles_into_local_tasks():
source = _read("static/js/cookbookRunning.js")
assert "const statusById = new Map(tasks.map(t => [t.session_id, t]));" in source
assert "const nextStatus = live.status === 'completed'" in source
assert "? 'done'" in source
assert ": (live.status === 'error'" in source
assert "? 'error'" in source
assert "_saveTasks(localTasks);" in source
assert "completedDeps.forEach(t => _refreshDepsAfterInstall(t));" in source
def test_local_windows_session_commands_use_local_powershell_log_dir():
source = _read("static/js/cookbookRunning.js")
assert "const host = task.remoteHost;" in source
assert "host ? '$env:TEMP\\\\odysseus-sessions' : '$env:TEMP\\\\odysseus-tmux'" in source
assert "return host ? `ssh ${pf}${host}" in source
assert ": `powershell -Command \"${ps}\"`;" in source
def test_dep_install_success_recognized_from_exit_sentinel():
"""A pip dependency install reports success via the runner's exit-0
sentinel / pip's "Successfully installed" line, not the HuggingFace
download markers. The shared helper must key off those, so an install
whose tmux pane is gone isn't misread as crashed."""
source = _read("static/js/cookbookRunning.js")
assert "function _depInstallSucceeded(output) {" in source
assert "=== Process exited with code" in source
assert "Successfully installed" in source
def test_session_gone_heuristic_honors_dep_install_success():
"""The reconnect loop's session-gone branch (download tasks need an HF
marker to look successful) must also accept a finished dependency install,
otherwise a clean pip install with no HF markers is marked crashed."""
source = _read("static/js/cookbookRunning.js")
assert "const depInstallSucceeded = !!task.payload?._dep && _depInstallSucceeded(lastOutput);" in source
assert (
"const looksSuccessful = depInstallSucceeded "
"|| (task.type === 'download' ? downloadLooksSuccessful : serveLooksReady);"
) in source
def test_background_poll_recovers_done_for_stopped_dependency_install():
"""When the backend reports a finished dependency install as "stopped"
(its pip package is never in the HF cache the dead-session check inspects),
the reconciler must recover "done" from the retained output instead of
downgrading the card to crashed."""
source = _read("static/js/cookbookRunning.js")
assert "const depDone = !!task.payload?._dep && _depInstallSucceeded(task.output);" in source
assert "depDone ? 'done' : (task.type === 'download' ? 'crashed' : 'stopped')" in source
def test_dependency_install_payload_keeps_env_path_for_refresh():
source = _read("static/js/cookbook.js")
assert "env_path: _envState.envPath || ''" in source
def test_local_dependency_probe_refreshes_user_site_visibility():
source = _read("routes/shell_routes.py")
assert "importlib.invalidate_caches()" in source
assert "user_site = site.getusersitepackages()" in source
assert "if user_site and os.path.isdir(user_site) and user_site not in sys.path:" in source