mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
217 lines
6.3 KiB
Python
217 lines
6.3 KiB
Python
"""End-to-end detached phrocs tests.
|
|
|
|
These exercise the real `phrocs` binary: spawn detached → wait → stop.
|
|
Skipped when phrocs isn't on PATH so local and CI runs where only Python
|
|
code is available don't fail.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
def _phrocs_bin() -> str | None:
|
|
return shutil.which("phrocs")
|
|
|
|
|
|
requires_phrocs = pytest.mark.skipif(
|
|
_phrocs_bin() is None,
|
|
reason="phrocs binary not on PATH",
|
|
)
|
|
|
|
|
|
def _phrocs_supports_subcommands() -> bool:
|
|
"""Return True if the resolved phrocs understands the new wait/stop/detach
|
|
subcommands. Older phrocs builds will error or hang."""
|
|
bin_path = _phrocs_bin()
|
|
if bin_path is None:
|
|
return False
|
|
try:
|
|
result = subprocess.run(
|
|
[bin_path, "--help"],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5,
|
|
)
|
|
except (OSError, subprocess.TimeoutExpired):
|
|
return False
|
|
text = (result.stdout or "") + (result.stderr or "")
|
|
return "wait" in text and "stop" in text
|
|
|
|
|
|
requires_detached_phrocs = pytest.mark.skipif(
|
|
not _phrocs_supports_subcommands(),
|
|
reason="phrocs on PATH doesn't support detached subcommands",
|
|
)
|
|
|
|
|
|
def _write_happy_config(path: Path) -> None:
|
|
path.write_text(
|
|
"""procs:
|
|
fast:
|
|
shell: "echo READY; sleep 60"
|
|
ready_pattern: "READY"
|
|
slow:
|
|
shell: "sleep 1; echo READY; sleep 60"
|
|
ready_pattern: "READY"
|
|
"""
|
|
)
|
|
|
|
|
|
def _write_crash_config(path: Path) -> None:
|
|
path.write_text(
|
|
"""procs:
|
|
ok:
|
|
shell: "echo READY; sleep 60"
|
|
ready_pattern: "READY"
|
|
bad:
|
|
shell: "echo about-to-die; sleep 0.2; exit 7"
|
|
ready_pattern: "never"
|
|
"""
|
|
)
|
|
|
|
|
|
@requires_phrocs
|
|
@requires_detached_phrocs
|
|
def test_happy_path(tmp_path: Path) -> None:
|
|
config = tmp_path / "config.yaml"
|
|
_write_happy_config(config)
|
|
phrocs = _phrocs_bin()
|
|
assert phrocs is not None
|
|
|
|
start = subprocess.run(
|
|
[phrocs, "--detach", "--config", str(config)],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
assert start.returncode == 0, start.stderr
|
|
|
|
try:
|
|
wait = subprocess.run(
|
|
[phrocs, "wait", "--timeout", "15"],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=20,
|
|
)
|
|
assert wait.returncode == 0, f"wait stderr: {wait.stderr}, stdout: {wait.stdout}"
|
|
assert "ready" in wait.stdout
|
|
stop = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
assert stop.returncode == 0, stop.stderr
|
|
finally:
|
|
subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
|
|
|
|
@requires_phrocs
|
|
@requires_detached_phrocs
|
|
def test_crashed_process_reports_exit_1(tmp_path: Path) -> None:
|
|
config = tmp_path / "config.yaml"
|
|
_write_crash_config(config)
|
|
phrocs = _phrocs_bin()
|
|
assert phrocs is not None
|
|
|
|
subprocess.run([phrocs, "--detach", "--config", str(config)], cwd=tmp_path, check=True, timeout=10)
|
|
try:
|
|
wait = subprocess.run(
|
|
[phrocs, "wait", "--timeout", "10"],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=15,
|
|
)
|
|
assert wait.returncode == 1
|
|
assert "bad" in wait.stderr
|
|
# A crashed child should not take down the detached manager.
|
|
stop = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
assert stop.returncode == 0, stop.stderr
|
|
finally:
|
|
subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
|
|
|
|
@requires_phrocs
|
|
@requires_detached_phrocs
|
|
def test_stop_is_idempotent(tmp_path: Path) -> None:
|
|
phrocs = _phrocs_bin()
|
|
assert phrocs is not None
|
|
|
|
# No detached phrocs running at all — stop should still succeed.
|
|
first = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=5)
|
|
assert first.returncode == 0
|
|
second = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=5)
|
|
assert second.returncode == 0
|
|
|
|
|
|
def _write_oneshot_config(path: Path) -> None:
|
|
path.write_text(
|
|
"""procs:
|
|
migrate:
|
|
shell: "echo migrating; exit 0"
|
|
web:
|
|
shell: "echo READY-web; sleep 60"
|
|
ready_pattern: "READY-web"
|
|
"""
|
|
)
|
|
|
|
|
|
@requires_phrocs
|
|
@requires_detached_phrocs
|
|
def test_wait_returns_ready_when_oneshot_proc_exits_zero(tmp_path: Path) -> None:
|
|
config = tmp_path / "config.yaml"
|
|
_write_oneshot_config(config)
|
|
phrocs = _phrocs_bin()
|
|
assert phrocs is not None
|
|
|
|
subprocess.run([phrocs, "--detach", "--config", str(config)], cwd=tmp_path, check=True, timeout=10)
|
|
try:
|
|
wait = subprocess.run(
|
|
[phrocs, "wait", "--timeout", "10"],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=15,
|
|
)
|
|
assert wait.returncode == 0, f"wait stderr: {wait.stderr}, stdout: {wait.stdout}"
|
|
assert "ready" in wait.stdout
|
|
stop = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
assert stop.returncode == 0, stop.stderr
|
|
finally:
|
|
subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
|
|
|
|
@requires_phrocs
|
|
@requires_detached_phrocs
|
|
def test_second_instance_refused(tmp_path: Path) -> None:
|
|
config = tmp_path / "config.yaml"
|
|
_write_happy_config(config)
|
|
phrocs = _phrocs_bin()
|
|
assert phrocs is not None
|
|
|
|
first = subprocess.run(
|
|
[phrocs, "--detach", "--config", str(config)],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
assert first.returncode == 0
|
|
try:
|
|
second = subprocess.run(
|
|
[phrocs, "--detach", "--config", str(config)],
|
|
cwd=tmp_path,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
assert second.returncode != 0
|
|
assert "already running" in second.stderr
|
|
stop = subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|
|
assert stop.returncode == 0, stop.stderr
|
|
finally:
|
|
subprocess.run([phrocs, "stop"], cwd=tmp_path, capture_output=True, text=True, timeout=10)
|