Skip to content

Commit c786327

Browse files
committed
Add turtle-agentd smoke tests
1 parent 6346366 commit c786327

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
"""Smoke tests for turtle-agentd and turtle-agentctl v0."""
3+
4+
from __future__ import annotations
5+
6+
import json
7+
import os
8+
import subprocess
9+
import sys
10+
import tempfile
11+
from pathlib import Path
12+
13+
14+
ROOT = Path(__file__).resolve().parents[3]
15+
AGENTD = ROOT / "assets" / "sourceos" / "bin" / "turtle-agentd"
16+
AGENTCTL = ROOT / "assets" / "sourceos" / "bin" / "turtle-agentctl"
17+
18+
19+
def run_agentd(request: dict, env: dict[str, str]) -> dict:
20+
result = subprocess.run(
21+
[sys.executable, str(AGENTD), "--stdio"],
22+
input=json.dumps(request),
23+
text=True,
24+
stdout=subprocess.PIPE,
25+
stderr=subprocess.PIPE,
26+
env=env,
27+
check=False,
28+
)
29+
assert result.returncode == 0, result.stderr or result.stdout
30+
return json.loads(result.stdout)
31+
32+
33+
def run_agentctl(args: list[str], env: dict[str, str]) -> dict:
34+
result = subprocess.run(
35+
[sys.executable, str(AGENTCTL), "--stdio", *args],
36+
text=True,
37+
stdout=subprocess.PIPE,
38+
stderr=subprocess.PIPE,
39+
env=env,
40+
check=False,
41+
)
42+
assert result.returncode == 0, result.stderr or result.stdout
43+
return json.loads(result.stdout)
44+
45+
46+
def main() -> int:
47+
with tempfile.TemporaryDirectory() as tmp:
48+
tmp_path = Path(tmp)
49+
events = tmp_path / "events.ndjson"
50+
receipts = tmp_path / "receipts"
51+
env = dict(os.environ)
52+
env["SOURCEOS_TERMINAL_EVENTS"] = str(events)
53+
env["SOURCEOS_TERMINAL_RECEIPTS"] = str(receipts)
54+
55+
ping = run_agentd({"action": "ping"}, env)
56+
assert ping["status"] == "ok"
57+
assert ping["kind"] == "pong"
58+
assert ping["data"]["service"] == "turtle-agentd"
59+
60+
proposal = run_agentctl(["propose", "echo", "hello"], env)
61+
assert proposal["kind"] == "command_proposal"
62+
assert proposal["data"]["requiresDecision"] is True
63+
assert proposal["data"]["decision"]["decision"] == "ask"
64+
65+
execution = run_agentctl(["request-execution", "echo", "hello"], env)
66+
assert execution["kind"] == "execution_request"
67+
assert execution["data"]["executionAllowed"] is False
68+
assert execution["data"]["decision"]["decision"] == "ask"
69+
70+
sessions = run_agentctl(["sessions"], env)
71+
assert sessions["kind"] == "sessions"
72+
assert sessions["data"]["sessions"] == []
73+
74+
summary = run_agentctl(["summarize"], env)
75+
assert summary["kind"] == "summary"
76+
assert summary["data"]["event_count"] == 0
77+
78+
return 0
79+
80+
81+
if __name__ == "__main__":
82+
raise SystemExit(main())

0 commit comments

Comments
 (0)