···11# SPDX-License-Identifier: AGPL-3.0-only
22# Copyright (c) 2026 sol pbc
3344-"""Tests for cogitate coder mode: write flag, handoff command, coder agent."""
44+"""Tests for cogitate coder mode: write flag, coder agent."""
5566import asyncio
77import importlib
88from unittest.mock import AsyncMock, patch
99-1010-from typer.testing import CliRunner
1111-1212-from think.call import call_app
1313-1414-runner = CliRunner()
1515-1691710# ---------------------------------------------------------------------------
1811# Write flag — Anthropic provider
···183176184177 cmd = mock_runner_cls.call_args.kwargs["cmd"]
185178 assert "--allowed-tools" not in cmd
186186-187187-188188-# ---------------------------------------------------------------------------
189189-# sol call handoff command
190190-# ---------------------------------------------------------------------------
191191-192192-193193-class TestHandoffCommand:
194194- """Tests for sol call handoff subcommand."""
195195-196196- @patch("think.cortex_client.cortex_request", return_value="1710864123456")
197197- def test_handoff_success(self, mock_cortex):
198198- """Handoff reads stdin, calls cortex_request, prints agent_id."""
199199- result = runner.invoke(call_app, ["handoff", "coder"], input="Fix the bug\n")
200200-201201- assert result.exit_code == 0
202202- assert "1710864123456" in result.output
203203- mock_cortex.assert_called_once_with(
204204- prompt="Fix the bug", name="coder", config=None
205205- )
206206-207207- def test_handoff_empty_stdin(self):
208208- """Empty stdin produces error and exit code 1."""
209209- result = runner.invoke(call_app, ["handoff", "coder"], input="")
210210-211211- assert result.exit_code == 1
212212- assert (
213213- "no prompt" in result.output.lower()
214214- or "no prompt" in (result.stderr or "").lower()
215215- )
216216-217217- def test_handoff_whitespace_only_stdin(self):
218218- """Whitespace-only stdin produces error."""
219219- result = runner.invoke(call_app, ["handoff", "coder"], input=" \n \n")
220220-221221- assert result.exit_code == 1
222222-223223- @patch("think.cortex_client.cortex_request", return_value=None)
224224- def test_handoff_cortex_failure(self, mock_cortex):
225225- """When cortex_request returns None, handoff reports error."""
226226- result = runner.invoke(call_app, ["handoff", "coder"], input="Fix the bug\n")
227227-228228- assert result.exit_code == 1
229229- assert (
230230- "failed" in result.output.lower()
231231- or "failed" in (result.stderr or "").lower()
232232- )
233233-234179235180# ---------------------------------------------------------------------------
236181# muse/coder.md existence and frontmatter
-19
tests/test_engage.py
···2020 return runner.invoke(_engage_app(), [*args], input=input_text)
212122222323-def _call_app():
2424- call_mod = importlib.reload(importlib.import_module("think.call"))
2525- return call_mod.call_app
2626-2727-2823class TestEngage:
2924 def test_fire_and_forget(self):
3025 with patch(
···139134 mock_cr.assert_called_once_with(
140135 prompt="do stuff", name="coder", config={"day": "20260404"}
141136 )
142142-143143-144144-class TestHandoffDeprecated:
145145- def test_handoff_still_works(self):
146146- with patch("think.cortex_client.cortex_request", return_value="agent-123"):
147147- result = runner.invoke(_call_app(), ["handoff", "coder"], input="fix the bug\n")
148148-149149- assert result.exit_code == 0
150150- assert "agent-123" in result.output
151151-152152- def test_handoff_hidden(self):
153153- result = runner.invoke(_call_app(), ["--help"])
154154-155155- assert "handoff" not in result.output
-56
tests/test_handoff.py
···11-# SPDX-License-Identifier: AGPL-3.0-only
22-# Copyright (c) 2026 sol pbc
33-44-"""Tests for the handoff CLI command."""
55-66-import importlib
77-from unittest.mock import patch
88-99-from typer.testing import CliRunner
1010-1111-runner = CliRunner()
1212-1313-1414-def _call_app():
1515- call_mod = importlib.reload(importlib.import_module("think.call"))
1616- return call_mod.call_app
1717-1818-1919-def _invoke_handoff(*args, input_text=""):
2020- return runner.invoke(_call_app(), ["handoff", *args], input=input_text)
2121-2222-2323-def _assert_handoff_success():
2424- with patch(
2525- "think.cortex_client.cortex_request", return_value="agent-123"
2626- ) as mock_cr:
2727- result = _invoke_handoff("coder", input_text="fix the bug\n")
2828- assert result.exit_code == 0
2929- assert "agent-123" in result.output
3030- mock_cr.assert_called_once_with(prompt="fix the bug", name="coder", config=None)
3131-3232-3333-def _assert_handoff_empty_stdin():
3434- result = _invoke_handoff("coder", input_text="")
3535- assert result.exit_code == 1
3636- assert (
3737- "no prompt" in result.output.lower()
3838- or "no prompt" in (result.stderr or "").lower()
3939- )
4040-4141-4242-def _assert_handoff_cortex_failure():
4343- with patch("think.cortex_client.cortex_request", return_value=None):
4444- result = _invoke_handoff("coder", input_text="fix the bug\n")
4545- assert result.exit_code == 1
4646-4747-4848-class TestHandoff:
4949- def test_success(self):
5050- _assert_handoff_success()
5151-5252- def test_empty_stdin(self):
5353- _assert_handoff_empty_stdin()
5454-5555- def test_cortex_failure(self):
5656- _assert_handoff_cortex_failure()
-16
think/call.py
···13131414import importlib
1515import logging
1616-import sys
1716from pathlib import Path
18171918import typer
···109108 if facet:
110109 parts.append(f"[{facet}]")
111110 typer.echo(f"Navigate: {' '.join(parts)}")
112112-113113-114114-@call_app.command("handoff", hidden=True)
115115-def handoff(
116116- agent: str = typer.Argument(help="Agent name to hand off to (e.g. coder)."),
117117-) -> None:
118118- """Spawn a cogitate agent with a request from stdin (fire-and-forget)."""
119119- prompt = sys.stdin.read()
120120- if not prompt.strip():
121121- typer.echo("Error: no prompt provided on stdin.", err=True)
122122- raise typer.Exit(1)
123123-124124- from think.engage import _engage
125125-126126- _engage(agent, prompt.strip())
127111128112129113def main() -> None:
+1-2
think/engage.py
···3344"""CLI for delegating work to cogitate agents.
5566-Provides ``sol engage <name>`` as the primary agent delegation command,
77-replacing ``sol call handoff`` with richer options.
66+Provides ``sol engage <name>`` for delegating work to cogitate agents.
87"""
98109import sys