Files
roboco/tests/unit/mcp_servers/test_intake_server.py
T
Renn F a88045aacf feat(grok): convert interactive intake/secretary to the grok CLI; delete opencode
Move the last Grok runtime off opencode onto xAI's official `grok` CLI, for full
parity with the Claude path. The intake/secretary chat now runs per-turn headless
`grok -p` invocations that resume one session id (proven live: context carries
across runs), with streaming-json deltas mapped to the existing panel StreamChunk
kinds — the IntakeDriver loop, message source, relay, and idle reaper are reused
unchanged; only the SessionFactory differs (GrokCliSession replaces the
opencode-serve session).

- GrokCliSession + a pure, unit-tested streaming-json -> StreamChunk assembler
  (thought coalesced to one block, text streamed live, end captures the session
  id for -r, fenced-draft fallback, clear errors incl. rate-limit).
- intake propose_draft and secretary read_company_state/read_task/submit_directive
  are now FastMCP servers (roboco-intake / roboco-secretary) wired into
  ~/.grok/config.toml, launched via `uv run --directory /app` to resolve the
  installed package. The secretary tools reuse the shared backend helpers.
- Orchestrator: interactive spawn mounts the subscription auth + per-agent usage
  dir (no metered xAI key, no permission env — grok flags carry per-role perms);
  usage/cost now read a captured usage.json (drop the opencode.db reader, the
  _opencode_db_path/_grok_usage_from_opencode methods, and the cost-cap's
  opencode read). hosts["opencode"] -> hosts["grok_usage"]; OPENCODE_DATA_DIR ->
  GROK_USAGE_DATA_DIR.
- Fix one-shot usage capture: `-s` does not pin the session id (grok generates
  its own), so the entrypoint now reads the real id back from the JSON run log
  and the reader uses it; usage is captured per-turn on the interactive path.
- Delete the opencode layer: opencode_config/opencode_usage/opencode_session, the
  docker/grok/*.js plugins, the old one-shot entrypoint, and their tests.
- Compose (all three files), .env.example, and stale comments updated to the
  grok-CLI runtime; add the SuperGrok auth mount + grok-usage dir.

Gate green: ruff, mypy (296 files), xenon, tests. NAS build/verify pending.
2026-06-19 04:42:25 +02:00

93 lines
3.0 KiB
Python

"""roboco-intake MCP server — propose_draft delivers the draft to the relay."""
from __future__ import annotations
from typing import Any
import httpx
import pytest
from roboco.mcp import intake_server
def _client(handler: Any) -> httpx.AsyncClient:
return httpx.AsyncClient(transport=httpx.MockTransport(handler))
@pytest.mark.asyncio
async def test_post_draft_posts_to_the_relay(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("ROBOCO_API_URL", "http://orch:8000")
seen: dict[str, Any] = {}
def handler(request: httpx.Request) -> httpx.Response:
seen["url"] = str(request.url)
seen["json"] = __import__("json").loads(request.content)
return httpx.Response(200, json={"ok": True})
async with _client(handler) as client:
result = await intake_server.post_draft(
"sess-1", {"title": "Build X"}, client=client
)
assert result == {"ok": True}
assert seen["url"] == "http://orch:8000/api/prompter/live/sess-1/events"
assert seen["json"]["kind"] == "draft"
assert seen["json"]["tool"] == "propose_draft"
assert seen["json"]["data"] == {"title": "Build X"}
@pytest.mark.asyncio
async def test_post_draft_reports_http_error() -> None:
def handler(_request: httpx.Request) -> httpx.Response:
return httpx.Response(503)
async with _client(handler) as client:
result = await intake_server.post_draft("s", {}, client=client)
assert result == {"error": "http_503"}
@pytest.mark.asyncio
async def test_post_draft_reports_request_failure() -> None:
def handler(_request: httpx.Request) -> httpx.Response:
raise httpx.ConnectError("boom")
async with _client(handler) as client:
result = await intake_server.post_draft("s", {}, client=client)
assert result["error"] == "request_failed"
assert "boom" in result["detail"]
@pytest.mark.asyncio
async def test_propose_draft_requires_a_live_session(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.delenv("ROBOCO_PROMPTER_SESSION_ID", raising=False)
msg = await intake_server.propose_draft({"title": "X"})
assert "No live session id" in msg
@pytest.mark.asyncio
async def test_propose_draft_acks_on_success(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("ROBOCO_PROMPTER_SESSION_ID", "sess-1")
async def _ok(_sid: str, _draft: dict[str, Any]) -> dict[str, Any]:
return {"ok": True}
monkeypatch.setattr(intake_server, "post_draft", _ok)
msg = await intake_server.propose_draft({"title": "X"})
assert "Draft submitted" in msg
@pytest.mark.asyncio
async def test_propose_draft_reports_relay_failure(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("ROBOCO_PROMPTER_SESSION_ID", "sess-1")
async def _fail(_sid: str, _draft: dict[str, Any]) -> dict[str, Any]:
return {"error": "http_503"}
monkeypatch.setattr(intake_server, "post_draft", _fail)
msg = await intake_server.propose_draft({"title": "X"})
assert "Could not submit the draft" in msg
assert "http_503" in msg