Files
ai-agent/cli/test_library_surface.py
gabrielvidalandClaude Opus 5.5 aee457cdbf Merge origin/main into hub-mcp-plugin
main moved cron jobs into the cron-jobs plugin (#37) and retired the core
Send later doors for the scheduled-conversations plugin's commands (#36),
both touching the core MCP files this branch moves into the hub-mcp plugin.

- The MCP stays out of core: backend/mcpserver/, cli/mcp_tools.py,
  cli/mcp_server.py, their tests and business/aiApps/ stay deleted (main's
  edits to them — no schedule group, no cron / schedule tools — are the
  plugin's to apply).
- Cron and Send later follow main: backend/cron/routes.py gone (its
  by-name worker pick is runs.start's at fire time now), no ai-agent
  later / scheduled / unschedule — so a worker's narrowed CLI drops them
  from its command lists (workers/cli.py) and schedules nothing; Full
  reaches the plugin's commands.
- authz: neither runs.schedule nor mcp.connect.
- Settings: neither Scheduled jobs nor AI apps in the registry; both old
  addresses redirect to their plugin's page.
- Regenerated openapi.json, src/generated, rolesCatalog.json,
  matrix.golden.txt and telemetry features.json.
- cli/test_library_surface.py: parse_when left with `ai-agent later`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:14:16 +01:00

66 lines
3.2 KiB
Python

"""The CLI as a library: the names a live plugin's handlers lean on.
The ``hub-mcp`` plugin (``~/projects/ai-agent-plugins/plugins/hub-mcp`` — the
hub's MCP server, core's until 2026-11-28) builds its tools on this
directory's modules, imported from ``AIA_CLI_DIR`` and pointed at the
``hub.api`` bridge (backend ``plugins/hubapi.py``). It lives in another repo,
so nothing there breaks here when one of these is renamed or changes shape —
this test does. Change a name: change it in the plugin's
``handlers/hubmcp_tools.py`` too (its docstring lists what it uses, and its
own test checks that list against its code).
"""
import inspect
import unittest
import ai_agent
import plugin_commands
AI_AGENT = (
"Hub", "HubError", "VIEW_URL", "LIVE_STATES",
"resolve", "wait_session", "wait_done", "detail", "final_answer", "render_messages",
"search_hits", "pick_model", "waiting",
"_ago", "_title", "_messages", "_machines", "_sid", "_snippet", "_clip", "_goal", "_now_iso",
)
# (``parse_when`` left with ``ai-agent later`` on 2026-11-28 — the plugin's
# ``schedule_conversation`` used it, a tool that goes too: Send later is the
# scheduled-conversations plugin's ``plugin_scheduled-conversations_*`` tools.)
PLUGIN_COMMANDS = ("catalogue", "describe", "input_schema", "call_tool")
class LibrarySurface(unittest.TestCase):
def test_the_names_a_plugin_imports_exist(self):
missing = [f"ai_agent.{n}" for n in AI_AGENT if not hasattr(ai_agent, n)]
missing += [f"plugin_commands.{n}" for n in PLUGIN_COMMANDS
if not hasattr(plugin_commands, n)]
self.assertEqual(missing, [])
def test_the_hub_client_takes_a_base_and_headers(self):
# how a handler points it at its bridge, as the caller a connection is for
params = inspect.signature(ai_agent.Hub.__init__).parameters
self.assertEqual(list(params)[1:3], ["base", "headers"])
hub = ai_agent.Hub(base="http://127.0.0.1:1/proxy/tools/plugins/x/hub/",
headers={"Authorization": "Bearer t", "X-AIA-As-User": "dom"})
self.assertEqual(hub.base, "http://127.0.0.1:1/proxy/tools/plugins/x/hub")
self.assertEqual(hub.headers["X-AIA-As-User"], "dom")
for method in ("call", "get", "post"):
self.assertTrue(callable(getattr(hub, method)))
self.assertEqual(list(inspect.signature(ai_agent.Hub.call).parameters)[1:4],
["method", "path", "body"])
def test_a_hub_error_carries_its_code_and_detail(self):
e = ai_agent.HubError(403, "nope")
self.assertEqual((e.code, e.detail), (403, "nope"))
def test_a_bridges_own_refusal_reads_as_its_message(self):
# the hub.api bridge answers {"error": {message, kind}}, the API {"detail": …}
self.assertEqual(ai_agent._detail('{"error": {"message": "read only", "kind": "read_only"}}'),
"read only")
self.assertEqual(ai_agent._detail('{"detail": {"message": "paused", "kind": "guests_locked"}}'),
"paused")
self.assertEqual(ai_agent._detail('{"detail": "no such conversation"}'), "no such conversation")
if __name__ == "__main__":
unittest.main()