Skip to content

Commit aa37dc6

Browse files
committed
test(tools): add coverage for WorkerRestart and WorkerTerminate tools
WorkerRestart and WorkerTerminate had zero test coverage despite being public tools in the tool spec. Also confirms one design decision worth noting: restart resets trust_gate_cleared=false, so an allowlisted worker that gets restarted must re-acquire trust via the normal observe flow (by design — trust is per-session, not per-CWD). Tests added: - worker_terminate_sets_finished_status - worker_restart_resets_to_spawning (verifies status=spawning, prompt_in_flight=false, trust_gate_cleared=false) - worker_terminate_on_unknown_id_returns_error - worker_restart_on_unknown_id_returns_error 85 tool tests passing, 0 failing.
1 parent 6ddfa78 commit aa37dc6

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

rust/crates/tools/src/lib.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5554,6 +5554,96 @@ mod tests {
55545554
fs::remove_dir_all(&worktree).ok();
55555555
}
55565556

5557+
#[test]
5558+
fn worker_terminate_sets_finished_status() {
5559+
// Create a worker in running state
5560+
let created = execute_tool(
5561+
"WorkerCreate",
5562+
&json!({"cwd": "/tmp/terminate-test", "trusted_roots": ["/tmp"]}),
5563+
)
5564+
.expect("WorkerCreate should succeed");
5565+
let output: serde_json::Value = serde_json::from_str(&created).expect("json");
5566+
let worker_id = output["worker_id"].as_str().expect("worker_id").to_string();
5567+
5568+
// Terminate
5569+
let terminated = execute_tool(
5570+
"WorkerTerminate",
5571+
&json!({"worker_id": worker_id}),
5572+
)
5573+
.expect("WorkerTerminate should succeed");
5574+
let term_output: serde_json::Value = serde_json::from_str(&terminated).expect("json");
5575+
assert_eq!(term_output["status"], "finished", "terminated worker should be finished");
5576+
assert_eq!(
5577+
term_output["prompt_in_flight"], false,
5578+
"prompt_in_flight should be cleared on termination"
5579+
);
5580+
}
5581+
5582+
#[test]
5583+
fn worker_restart_resets_to_spawning() {
5584+
// Create and advance worker to ready_for_prompt
5585+
let created = execute_tool(
5586+
"WorkerCreate",
5587+
&json!({"cwd": "/tmp/restart-test", "trusted_roots": ["/tmp"]}),
5588+
)
5589+
.expect("WorkerCreate should succeed");
5590+
let output: serde_json::Value = serde_json::from_str(&created).expect("json");
5591+
let worker_id = output["worker_id"].as_str().expect("worker_id").to_string();
5592+
5593+
// Advance to ready_for_prompt via observe
5594+
execute_tool(
5595+
"WorkerObserve",
5596+
&json!({"worker_id": worker_id, "screen_text": "Ready for input\n>"}),
5597+
)
5598+
.expect("WorkerObserve should succeed");
5599+
5600+
// Restart
5601+
let restarted = execute_tool(
5602+
"WorkerRestart",
5603+
&json!({"worker_id": worker_id}),
5604+
)
5605+
.expect("WorkerRestart should succeed");
5606+
let restart_output: serde_json::Value = serde_json::from_str(&restarted).expect("json");
5607+
assert_eq!(
5608+
restart_output["status"], "spawning",
5609+
"restarted worker should return to spawning"
5610+
);
5611+
assert_eq!(
5612+
restart_output["prompt_in_flight"], false,
5613+
"prompt_in_flight should be cleared on restart"
5614+
);
5615+
assert_eq!(
5616+
restart_output["trust_gate_cleared"], false,
5617+
"trust_gate_cleared should be reset on restart (re-trust required)"
5618+
);
5619+
}
5620+
5621+
#[test]
5622+
fn worker_terminate_on_unknown_id_returns_error() {
5623+
let result = execute_tool(
5624+
"WorkerTerminate",
5625+
&json!({"worker_id": "worker_nonexistent_00000000"}),
5626+
);
5627+
assert!(result.is_err(), "terminating unknown worker should fail");
5628+
assert!(
5629+
result.unwrap_err().contains("worker not found"),
5630+
"error should mention worker not found"
5631+
);
5632+
}
5633+
5634+
#[test]
5635+
fn worker_restart_on_unknown_id_returns_error() {
5636+
let result = execute_tool(
5637+
"WorkerRestart",
5638+
&json!({"worker_id": "worker_nonexistent_00000001"}),
5639+
);
5640+
assert!(result.is_err(), "restarting unknown worker should fail");
5641+
assert!(
5642+
result.unwrap_err().contains("worker not found"),
5643+
"error should mention worker not found"
5644+
);
5645+
}
5646+
55575647
#[test]
55585648
fn worker_tools_detect_misdelivery_and_arm_prompt_replay() {
55595649
let created = execute_tool(

0 commit comments

Comments
 (0)