Files
ai-agent/sidecar/test_liveness.py
Gabriel Vidal 3a0ef08dcf feat(worker): sidecar runs as a paired macOS worker — feed, pairing, launchd installer
- liveness falls back to psutil where there is no /proc (macOS)
- GET /feed + /feed/file: the hub pulls transcripts it has no mount for
- POST /pair trades a one-time code for the worker's bearer; /unpair drops it
- /health reports worker identity + permission mode
- worker/install-macos.sh: venv, launchd agent bound to the Tailscale IP,
  prints the pairing string (addr/code/claude login)
- Dockerfile copies every sidecar module (claude_cli was missing, so the
  in-container runner could not import)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 13:49:07 +02:00

45 lines
1.3 KiB
Python

"""Run liveness on both backends: /proc (Linux host) and psutil (macOS worker)."""
import os
import subprocess
import pytest
import sidecar
@pytest.fixture(params=["proc", "psutil"])
def backend(request, monkeypatch):
if request.param == "psutil":
pytest.importorskip("psutil")
monkeypatch.setattr(sidecar, "_HAVE_PROC", False)
elif not sidecar._HAVE_PROC:
pytest.skip("no /proc here")
return request.param
def test_self_is_live_and_fingerprinted(backend):
pid = os.getpid()
st = sidecar._proc_starttime(pid)
assert st is not None
assert sidecar._alive({"pid": pid, "starttime": st})
assert not sidecar._alive({"pid": pid, "starttime": st + 12345})
def test_zombie_is_dead(backend):
p = subprocess.Popen(["true"])
rec = {"pid": p.pid, "starttime": sidecar._proc_starttime(p.pid)}
# not in sidecar._procs, so _reap() won't wait on it: it stays a zombie
import time
time.sleep(0.3)
assert sidecar._proc_state(p.pid) == "Z"
assert not sidecar._alive(rec)
p.wait()
def test_health_reports_worker_identity(tmp_path, monkeypatch):
monkeypatch.setenv("WORKER_STATE_DIR", str(tmp_path))
h = sidecar.health()
assert h["workerId"] and h["hostname"] and h["platform"]
assert "paired" in h and h["permissionMode"]