Run opencode as build agent (plan injects READ-ONLY notice), flag workers with 0 tool calls
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+50
@@ -4377,6 +4377,56 @@ class ToolArgumentsTests(unittest.TestCase):
|
||||
self.assertEqual(agent.run_turn("check os", capture=True), "done")
|
||||
|
||||
|
||||
class OpencodeAgentTests(unittest.TestCase):
|
||||
def test_agent_is_not_plan(self):
|
||||
# "plan" makes opencode inject "Plan mode ACTIVE - READ-ONLY" into the
|
||||
# model, which then refuses to emit tai's write tool calls.
|
||||
self.assertNotEqual(tai.OPENCODE_AGENT, "plan")
|
||||
captured = {}
|
||||
|
||||
def fake_run(argv, **kwargs):
|
||||
captured["argv"] = argv
|
||||
return mock.Mock(stdout='{"type":"text","part":{"text":"ok"}}\n', stderr="", returncode=0)
|
||||
|
||||
with mock.patch.object(tai, "opencode_binary", return_value="opencode"), mock.patch.object(tai.subprocess, "run", side_effect=fake_run):
|
||||
self.assertEqual(tai.Opencode.opencode_run("m", "hi", 5), "ok")
|
||||
argv = captured["argv"]
|
||||
self.assertEqual(argv[argv.index("--agent") + 1], tai.OPENCODE_AGENT)
|
||||
|
||||
|
||||
class WorkerIdleTests(unittest.TestCase):
|
||||
def test_idle_worker_is_flagged(self):
|
||||
record = {"id": 1, "task": "t", "status": "done", "elapsed": 3, "tools": 0}
|
||||
self.assertIn("0 tools", tai.strip_ansi(tai.Glow.agent_row(record)))
|
||||
record["tools"] = 2
|
||||
self.assertNotIn("0 tools", tai.strip_ansi(tai.Glow.agent_row(record)))
|
||||
record["tools"] = None
|
||||
self.assertNotIn("0 tools", tai.strip_ansi(tai.Glow.agent_row(record)))
|
||||
running = {"id": 1, "task": "t", "status": "running", "elapsed": 3, "tools": 0}
|
||||
self.assertNotIn("0 tools", tai.strip_ansi(tai.Glow.agent_row(running)))
|
||||
|
||||
def test_poll_notes_zero_tool_calls(self):
|
||||
agent_id = tai.spawn_agent("idle", "t", 60, None, None, 0, lambda task, profile, timeout: "I am in plan mode")
|
||||
tai.poll_agent(agent_id, wait=5)
|
||||
with tai.AGENTS_LOCK:
|
||||
tai.AGENTS[agent_id]["tools"] = 0
|
||||
status, text = tai.poll_agent(agent_id)
|
||||
self.assertEqual(status, "done")
|
||||
self.assertIn("ran 0 tool calls", text)
|
||||
with tai.AGENTS_LOCK:
|
||||
tai.AGENTS[agent_id]["tools"] = 3
|
||||
self.assertNotIn("0 tool calls", tai.poll_agent(agent_id)[1])
|
||||
|
||||
def test_tools_counts_dispatches(self):
|
||||
tools = tai.Tools.__new__(tai.Tools)
|
||||
tools.calls = 0
|
||||
tools.handlers = {"echo": lambda args: "x"}
|
||||
tools.app = mock.Mock(store=None)
|
||||
tools.dispatch("echo", {})
|
||||
tools.dispatch("nope", {})
|
||||
self.assertEqual(tools.calls, 2)
|
||||
|
||||
|
||||
class OpencodeParseTests(unittest.TestCase):
|
||||
def test_single_answer(self):
|
||||
answer = {"content": "hi", "tool_calls": []}
|
||||
|
||||
Reference in New Issue
Block a user