Skip to content

Commit 957327e

Browse files
committed
fix(smoke): clean runtime test agents
1 parent 45f9616 commit 957327e

2 files changed

Lines changed: 88 additions & 76 deletions

File tree

scripts/daemon-smoke-test.sh

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,42 @@ set -euo pipefail
99
# 3. Complete — complete task → daemon cleans up session + worktree
1010
# 4. Cancel — create task → cancel while agent is running → daemon kills agent
1111
#
12-
# Usage: ./scripts/daemon-smoke-test.sh [board_id] [agent_id] [repo_id]
12+
# Usage: ./scripts/daemon-smoke-test.sh <runtime> [board_id] [repo_id]
1313
# Missing arguments are discovered or created. Defaults target the Demo board
1414
# and the slink repository.
1515

16-
BOARD_ID="${1:-}"
17-
AGENT_ID="${2:-}"
18-
REPO_ID="${3:-}"
16+
SMOKE_RUNTIME=""
17+
ARGS=()
18+
while [ "$#" -gt 0 ]; do
19+
case "$1" in
20+
--runtime)
21+
SMOKE_RUNTIME="${2:-}"
22+
if [ -z "$SMOKE_RUNTIME" ]; then
23+
echo "FATAL: --runtime requires a value"
24+
exit 1
25+
fi
26+
shift 2
27+
;;
28+
--runtime=*)
29+
SMOKE_RUNTIME="${1#*=}"
30+
shift
31+
;;
32+
*)
33+
ARGS+=("$1")
34+
shift
35+
;;
36+
esac
37+
done
38+
39+
BOARD_ID="${ARGS[0]:-}"
40+
if [ -z "$SMOKE_RUNTIME" ]; then
41+
SMOKE_RUNTIME="$BOARD_ID"
42+
BOARD_ID="${ARGS[1]:-}"
43+
REPO_ID="${ARGS[2]:-}"
44+
else
45+
REPO_ID="${ARGS[1]:-}"
46+
fi
47+
AGENT_ID=""
1948

2049
PASS=0
2150
FAIL=0
@@ -24,6 +53,20 @@ TIMESTAMP=$(date +%s)
2453
SUBAGENT_ID=""
2554
SUBAGENT_USERNAME=""
2655
AGENT_RUNTIME=""
56+
CREATED_AGENT_IDS=()
57+
58+
cleanup() {
59+
if [ "${#TASKS[@]}" -gt 0 ]; then
60+
for tid in "${TASKS[@]}"; do
61+
ak task cancel "$tid" >/dev/null 2>&1 || true
62+
done
63+
fi
64+
for agent_id in "${CREATED_AGENT_IDS[@]}"; do
65+
ak delete agent "$agent_id" >/dev/null 2>&1 || true
66+
done
67+
}
68+
69+
trap cleanup EXIT
2770

2871
# ── Helpers ──────────────────────────────────────────────────────────────────
2972

@@ -96,68 +139,44 @@ create_repo() {
96139
ak create repo --name "slink" --url "https://github.com/saltbo/slink" -o json | json_query "data.id"
97140
}
98141

99-
discover_agent() {
100-
ak get agent -o json | json_query "data.find((a) => a.builtin !== 1 && a.username === 'codex-smoke-nomodel' && a.runtime_available && a.active_task_count === 0)?.id || data.find((a) => a.builtin !== 1 && a.username === 'codex-smoke-nomodel' && a.runtime_available)?.id || data.find((a) => a.builtin !== 1 && ['codex', 'claude', 'gemini', 'copilot'].includes(a.runtime) && a.runtime_available && a.active_task_count === 0)?.id || data.find((a) => a.builtin !== 1 && ['codex', 'claude', 'gemini', 'copilot'].includes(a.runtime) && a.runtime_available)?.id"
101-
}
102-
103-
discover_runtime() {
104-
local status
105-
status="$(ak status)"
106-
if echo "$status" | grep -q "codex"; then
107-
echo "codex"
108-
return 0
109-
fi
110-
if echo "$status" | grep -q "claude"; then
111-
echo "claude"
112-
return 0
113-
fi
114-
if echo "$status" | grep -q "gemini"; then
115-
echo "gemini"
116-
return 0
117-
fi
118-
if echo "$status" | grep -q "copilot"; then
119-
echo "copilot"
120-
return 0
121-
fi
122-
return 1
123-
}
124-
125142
create_agent() {
126143
local runtime="$1"
127144
local name username bio
128145
case "$runtime" in
129146
codex)
130-
name="Codex Smoke NoModel"
131-
username="codex-smoke-nomodel"
147+
name="Codex Smoke $TIMESTAMP"
148+
username="codex-smoke-$TIMESTAMP"
132149
bio="Codex worker for daemon smoke tests"
133150
;;
134151
claude)
135-
name="Claude Smoke"
136-
username="claude-smoke"
152+
name="Claude Smoke $TIMESTAMP"
153+
username="claude-smoke-$TIMESTAMP"
137154
bio="Claude worker for daemon smoke tests"
138155
;;
139156
gemini)
140-
name="Gemini Smoke"
141-
username="gemini-smoke"
157+
name="Gemini Smoke $TIMESTAMP"
158+
username="gemini-smoke-$TIMESTAMP"
142159
bio="Gemini worker for daemon smoke tests"
143160
;;
144161
copilot)
145-
name="Copilot Smoke"
146-
username="copilot-smoke"
162+
name="Copilot Smoke $TIMESTAMP"
163+
username="copilot-smoke-$TIMESTAMP"
147164
bio="Copilot worker for daemon smoke tests"
148165
;;
149166
*)
150167
fail "unsupported smoke runtime for agent creation: $runtime"
151168
return 1
152169
;;
153170
esac
154-
ak create agent \
171+
local id
172+
id=$(ak create agent \
155173
--name "$name" \
156174
--username "$username" \
157175
--runtime "$runtime" \
158176
--role "fullstack-developer" \
159177
--bio "$bio" \
160-
-o json | json_query "data.id"
178+
-o json | json_query "data.id")
179+
echo "$id"
161180
}
162181

163182
agent_field() {
@@ -167,21 +186,16 @@ agent_field() {
167186

168187
ensure_smoke_subagent() {
169188
local runtime="$1"
170-
local username="smoke-subagent-$runtime"
171-
local existing
172-
existing=$(ak get agent -o json | json_query "data.find((a) => a.username === '$username')?.id" 2>/dev/null || true)
173-
if [ -n "$existing" ]; then
174-
SUBAGENT_ID="$existing"
175-
else
176-
SUBAGENT_ID=$(ak create agent \
177-
--name "Smoke Subagent $runtime" \
178-
--username "$username" \
179-
--runtime "$runtime" \
180-
--role "smoke-subagent" \
181-
--bio "Registered worker used by daemon smoke tests to verify task-local subagent installation" \
182-
--soul "I am a smoke-test helper subagent. Keep answers short and verify delegated work precisely." \
183-
-o json | json_query "data.id")
184-
fi
189+
local username="smoke-subagent-$runtime-$TIMESTAMP"
190+
SUBAGENT_ID=$(ak create agent \
191+
--name "Smoke Subagent $runtime $TIMESTAMP" \
192+
--username "$username" \
193+
--runtime "$runtime" \
194+
--role "smoke-subagent" \
195+
--bio "Registered worker used by daemon smoke tests to verify task-local subagent installation" \
196+
--soul "I am a smoke-test helper subagent. Keep answers short and verify delegated work precisely." \
197+
-o json | json_query "data.id")
198+
CREATED_AGENT_IDS+=("$SUBAGENT_ID")
185199
SUBAGENT_USERNAME="$username"
186200
}
187201

@@ -245,15 +259,16 @@ if [ -z "$BOARD_ID" ]; then BOARD_ID="$(discover_board 2>/dev/null || true)"; fi
245259
if [ -z "$BOARD_ID" ]; then BOARD_ID="$(create_board)"; fi
246260
if [ -z "$REPO_ID" ]; then REPO_ID="$(discover_repo 2>/dev/null || true)"; fi
247261
if [ -z "$REPO_ID" ]; then REPO_ID="$(create_repo)"; fi
248-
if [ -z "$AGENT_ID" ]; then AGENT_ID="$(discover_agent 2>/dev/null || true)"; fi
249-
if [ -z "$AGENT_ID" ]; then
250-
RUNTIME_TO_CREATE="$(discover_runtime 2>/dev/null || true)"
251-
if [ -z "$RUNTIME_TO_CREATE" ]; then
252-
echo "FATAL: no available subagent-capable runtime found (codex, claude, gemini, or copilot). Start a daemon with one of those providers ready."
253-
exit 1
254-
fi
255-
AGENT_ID="$(create_agent "$RUNTIME_TO_CREATE")"
262+
if [ -z "$SMOKE_RUNTIME" ]; then
263+
echo "FATAL: runtime is required. Usage: ./scripts/daemon-smoke-test.sh <runtime> [board_id] [repo_id]"
264+
exit 1
256265
fi
266+
case "$SMOKE_RUNTIME" in
267+
codex | claude | gemini | copilot) ;;
268+
*) echo "FATAL: smoke runtime must support subagents (codex, claude, gemini, or copilot), got: $SMOKE_RUNTIME"; exit 1 ;;
269+
esac
270+
AGENT_ID="$(create_agent "$SMOKE_RUNTIME")"
271+
CREATED_AGENT_IDS+=("$AGENT_ID")
257272
if [ -z "$BOARD_ID" ] || [ -z "$REPO_ID" ] || [ -z "$AGENT_ID" ]; then
258273
echo "FATAL: failed to discover board, repo, or agent"
259274
echo " Board: ${BOARD_ID:-missing}"
@@ -397,13 +412,6 @@ echo " Passed: $PASS"
397412
echo " Failed: $FAIL"
398413
echo "==============================="
399414

400-
# Cleanup test tasks
401-
if [ "${#TASKS[@]}" -gt 0 ]; then
402-
for tid in "${TASKS[@]}"; do
403-
ak task cancel "$tid" >/dev/null 2>&1 || true
404-
done
405-
fi
406-
407415
if [ "$FAIL" -gt 0 ]; then
408416
exit 1
409417
fi

tests/daemon-smoke-script.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ describe("daemon smoke script", () => {
1616
execFileSync("bash", ["-n", scriptPath], { stdio: "pipe" });
1717
});
1818

19-
it("accepts all subagent-capable runtimes during agent discovery", () => {
19+
it("creates temporary agents instead of discovering reusable smoke agents", () => {
2020
const script = readScript();
2121

22-
expect(script).toContain("['codex', 'claude', 'gemini', 'copilot'].includes(a.runtime)");
22+
expect(script).toContain("Usage: ./scripts/daemon-smoke-test.sh <runtime> [board_id] [repo_id]");
23+
expect(script).toContain("runtime is required");
24+
expect(script).toContain("CREATED_AGENT_IDS=()");
25+
expect(script).toContain("trap cleanup EXIT");
26+
expect(script).toContain('ak delete agent "$agent_id"');
2327
expect(script).toContain("codex, claude, gemini, or copilot");
2428
});
2529

2630
it("creates smoke agents for each supported runtime", () => {
2731
const script = readScript();
2832

2933
expect(script).toContain("codex)");
30-
expect(script).toContain('username="codex-smoke-nomodel"');
34+
expect(script).toContain('username="codex-smoke-$TIMESTAMP"');
3135
expect(script).toContain("claude)");
32-
expect(script).toContain('username="claude-smoke"');
36+
expect(script).toContain('username="claude-smoke-$TIMESTAMP"');
3337
expect(script).toContain("gemini)");
34-
expect(script).toContain('username="gemini-smoke"');
38+
expect(script).toContain('username="gemini-smoke-$TIMESTAMP"');
3539
expect(script).toContain("copilot)");
36-
expect(script).toContain('username="copilot-smoke"');
40+
expect(script).toContain('username="copilot-smoke-$TIMESTAMP"');
3741
});
3842

3943
it("checks runtime-specific subagent definition paths", () => {

0 commit comments

Comments
 (0)