doctor: check the handoff pipeline; tests cover it end to end
dot doctor gains four checks (daemon active, weekly probe timer scheduled, every pool lane usage=developer-api via the new bin/handoff-pool-check, and the pool readable by free-agent), so a dead daemon or an expired lane stops being invisible. tests/handoff.sh grows two checks for those and becomes hermetic: its daemon test runs in a private HANDOFF_TMUX session and points every brief at a path that does not exist, because a first version started a real worker inside the live session and spent a call. The doctor assertion captures the output instead of piping into grep -q, which with pipefail fails on SIGPIPE once the match is found.
This commit is contained in:
1 parent
767f0f7f8e
commit
653d679dbc
3 files changed
+55
No files matched your search
@@ -727,6 +727,13 @@ cmd_doctor() {
|
||||
chk "konsole-daynight service" "systemctl --user is-active konsole-daynight" "dot switch, then log in to Plasma"
|
||||
chk "daynight-hooks service" "systemctl --user is-active daynight-hooks" "dot switch, then log in to Plasma"
|
||||
if ! in_container; then chk "netbird daemon" "systemctl is-active netbird" "dot system --netbird"; fi
|
||||
|
||||
# Free-model handoff pipeline: a dead daemon or an off-policy lane stays invisible
|
||||
# until someone tries to delegate, so check it here.
|
||||
chk "handoff daemon" "systemctl --user is-active handoff.service" "systemctl --user start handoff"
|
||||
chk "handoff probe timer" "systemctl --user list-timers handoff-probe.timer --no-pager | grep -q handoff-probe.timer" "systemctl --user start handoff-probe.timer"
|
||||
chk "handoff pool policy" "handoff-pool-check" "edit config/free-agent/pool.json: every lane needs usage=developer-api"
|
||||
chk "handoff pool alive" "free-agent --list >/dev/null" "free-agent --list"
|
||||
else
|
||||
chk "day/night daemons (XDG autostart)" "pgrep -f daynight-hooks" "log in to Plasma"
|
||||
fi
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fail when a pool lane is not a developer API. Called by `dot doctor`.
|
||||
#
|
||||
# handoff-pool-check [pool.json]
|
||||
#
|
||||
# Exit 0 = every lane is delegable, 1 = at least one is not, 2 = unreadable pool.
|
||||
set -uo pipefail
|
||||
|
||||
pool="${1:-${HOME}/.config/free-agent/pool.json}"
|
||||
python3 - "$pool" <<'PY'
|
||||
import json, sys
|
||||
path = sys.argv[1]
|
||||
try:
|
||||
models = json.load(open(path)).get("models", [])
|
||||
except Exception as exc:
|
||||
print(f"handoff-pool-check: cannot read {path}: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
bad = [m.get("id", "?") for m in models if m.get("usage") != "developer-api"]
|
||||
if bad:
|
||||
print("handoff-pool-check: not a developer API: " + ", ".join(bad), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not models:
|
||||
print(f"handoff-pool-check: pool is empty ({path})", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
PY
|
||||
@@ -65,6 +65,14 @@ ok "submit stores a non-default role"
|
||||
|
||||
# ---------------------------------------------------------------- orphan detection
|
||||
mkdir -p "$XDG_DATA_HOME/handoff/running"
|
||||
# Nothing in this file may reach a provider: point the brief at a path that does not
|
||||
# exist, so a task that gets started fails on validation instead of calling a model.
|
||||
python3 - "$task" "$tmp/missing-brief.md" <<'PY'
|
||||
import json, sys
|
||||
path, missing = sys.argv[1:3]
|
||||
d = json.load(open(path)); d["brief"] = missing
|
||||
json.dump(d, open(path, "w"))
|
||||
PY
|
||||
mv "$task" "$XDG_DATA_HOME/handoff/running/t-good.json"
|
||||
line="$(handoff list | grep 't-good')"
|
||||
grep -q '^orphan' <<<"$line" || fail "a running task with no window is not reported as orphan (got: $line)"
|
||||
@@ -76,7 +84,11 @@ cat > "$XDG_DATA_HOME/handoff/running/t-lost.json" <<JSON
|
||||
{ "id": "t-lost", "dir": "$tmp", "role": "code", "backend": "free-agent",
|
||||
"brief": "$tmp/does-not-exist.md", "queuedAt": "2026-01-01T00:00:00Z" }
|
||||
JSON
|
||||
# A private tmux session, so a test run can never add a window to the real one.
|
||||
export HANDOFF_TMUX="handoff-test-$$"
|
||||
HANDOFF_MAX_PARALLEL=1 timeout 12 handoff daemon >"$tmp/daemon.log" 2>&1 || true
|
||||
tmux kill-session -t "$HANDOFF_TMUX" 2>/dev/null || true
|
||||
unset HANDOFF_TMUX
|
||||
grep -q "requeued orphan t-lost" "$tmp/daemon.log" || fail "the daemon did not requeue the orphan (log: $(tail -3 "$tmp/daemon.log"))"
|
||||
ok "the daemon requeues an orphan instead of leaving it running"
|
||||
|
||||
@@ -112,4 +124,15 @@ handoff pause >/dev/null && [ -f "$XDG_DATA_HOME/handoff/pause" ] || fail "pause
|
||||
handoff resume >/dev/null && [ ! -f "$XDG_DATA_HOME/handoff/pause" ] || fail "resume did not clear its marker"
|
||||
ok "pause and resume manage the daemon marker"
|
||||
|
||||
# doctor must report the pipeline, not just its handlers
|
||||
doc="$(./bin/dot doctor 2>/dev/null)"
|
||||
grep -q 'handoff pool policy' <<<"$doc" || fail "dot doctor has no handoff checks (lines: $(wc -l <<<"$doc"), tail: $(tail -2 <<<"$doc" | tr '\n' ' '))"
|
||||
ok "dot doctor reports the handoff pipeline"
|
||||
|
||||
# the pool checker must reject a lane that is not a developer API
|
||||
out="$(handoff-pool-check "$tmp/pool-consumer.json" 2>&1)" && fail "handoff-pool-check accepted a consumer lane"
|
||||
grep -q "consumer/app" <<<"$out" || fail "handoff-pool-check did not name the offending lane"
|
||||
handoff-pool-check "$tmp/pool-ok.json" || fail "handoff-pool-check rejected a good pool"
|
||||
ok "handoff-pool-check passes a clean pool and names a bad lane"
|
||||
|
||||
printf '\nHandoff pipeline checks passed\n'
|
||||
Reference in new issue
Block a user