Files
ai-agent/backend/test_plans_bridge.py
gabrielvidalandClaude Opus 5.5 f2abb17738 feat(plugins): Plans leaves the core for the live plans plugin
backend/plans/ (store + /api/plans, /api/plan, /api/plan/answers),
schemas/plans.py and ConversationDetail.plans are gone; data/plans is the
`plans` plugin's (ai-agent-plugins, plugins/plans).

- plugins/plans_bridge.py: list_plans / get_plan through the plugin that
  provides `plans.index` (and its `get`), as the owner — [] / None without it
- graph.read builds its plan nodes from plans_bridge
- `ai-agent plans` and MCP browse("plans") / read_document("plan") call
  /api/plugins/plans/actions/{index,get}, and say so when the plugin is off
- frontend: business/plans/ removed; /plans and /plans/:slug redirect to
  /plugins/plans/plans[/<slug>]; the Write card's built-in plan widget, the
  Files/nav entries, usePlans and the tags' plan counts are gone; the Details
  drawer's Plans card became `pluginSlots` (conversation.details slots, saved
  layouts carried over); a bare slot may resize(0) to fold away
- openapi.json + src/generated: only the plan paths/models removed (the spec
  is edited, not re-dumped — see the PR notes); mocks and French keys follow
- test_plans_bridge.py; CLI tests for the plugin route

authz/matrix.golden.txt is left for the coordinator (the plan routes left
lab.read / lab.settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:16:27 +01:00

104 lines
4.1 KiB
Python

"""plugins/plans_bridge.py — the hub reads plans through the `plans` plugin
(``provides: {"plans.index": …}`` + its ``get`` action) since Plans left the
core (2026-11-25), and has none without it."""
from __future__ import annotations
import json
import os
import pathlib
import tempfile
import unittest
from unittest.mock import patch
import main
from plugins import plans_bridge
from plugins.store import OWNER_UID, PluginStore
INDEX = """import json, os
print(json.dumps({"plans": [
{"slug": "p1", "title": "One", "sessionId": "s1", "dir": os.environ.get("AIA_PLANS_DIR", "")},
{"title": "no slug"}, "junk"]}))
"""
GET = """import json, sys
p = json.load(sys.stdin)
if p.get("slug") != "p1":
print(json.dumps({"_error": {"status": 404, "kind": "not_found", "message": "plan not found"}}))
else:
print(json.dumps({"slug": "p1", "title": "One", "content": "# One"}))
"""
BROKEN = "import sys\nsys.exit(3)\n"
def _plugin(root: pathlib.Path, *, index: str = INDEX, provides: bool = True) -> pathlib.Path:
root.mkdir(parents=True, exist_ok=True)
(root / "a").mkdir(exist_ok=True)
(root / "a" / "index.py").write_text(index, encoding="utf-8")
(root / "a" / "get.py").write_text(GET, encoding="utf-8")
mf = {
"schema": 1, "id": "plans", "name": "Plans",
"capabilities": ["plans.read"],
"actions": {"index": {"script": "a/index.py"}, "get": {"script": "a/get.py"}},
}
if provides:
mf["provides"] = {"plans.index": "index"}
(root / "plugin.json").write_text(json.dumps(mf), encoding="utf-8")
return root
class PlansBridgeTest(unittest.TestCase):
def setUp(self):
self.td = tempfile.TemporaryDirectory()
self.root = pathlib.Path(self.td.name)
self.deps = main.app.state.ai
def tearDown(self):
self.td.cleanup()
def _store(self, **kw) -> PluginStore:
store = PluginStore(self.root / "data")
store.install(OWNER_UID, str(_plugin(self.root / "src", **kw)), is_owner=True, approve=True)
return store
def test_no_plugin_means_no_plans(self):
with patch.object(self.deps, "plugin_store", PluginStore(self.root / "empty")):
self.assertFalse(plans_bridge.available(self.deps))
self.assertEqual(plans_bridge.list_plans(self.deps), [])
self.assertIsNone(plans_bridge.get_plan(self.deps, "p1"))
def test_lists_and_gets_through_the_plugin(self):
store = self._store()
with patch.object(self.deps, "plugin_store", store), \
patch.dict(os.environ, {"PLANS_DIR": str(self.root / "plans")}):
self.assertTrue(plans_bridge.available(self.deps))
plans = plans_bridge.list_plans(self.deps)
self.assertEqual([p["slug"] for p in plans], ["p1"])
# The owner run gets the plans dir (the `plans.read` capability).
self.assertEqual(plans[0]["dir"], str((self.root / "plans").resolve()))
self.assertEqual(plans_bridge.get_plan(self.deps, "p1")["content"], "# One")
self.assertIsNone(plans_bridge.get_plan(self.deps, "nope"))
self.assertIsNone(plans_bridge.get_plan(self.deps, ""))
def test_disabled_or_not_providing(self):
store = self._store()
store.update(OWNER_UID, "plans", enabled=False)
with patch.object(self.deps, "plugin_store", store):
self.assertEqual(plans_bridge.list_plans(self.deps), [])
with patch.object(self.deps, "plugin_store", PluginStore(self.root / "d2")) as st:
st.install(OWNER_UID, str(_plugin(self.root / "src2", provides=False)), is_owner=True, approve=True)
self.assertEqual(plans_bridge.list_plans(self.deps), [])
def test_a_failing_plugin_never_breaks_the_hub(self):
store = self._store(index=BROKEN)
with patch.object(self.deps, "plugin_store", store):
self.assertEqual(plans_bridge.list_plans(self.deps), [])
def test_core_plans_routes_are_gone(self):
paths = {getattr(r, "path", "") for r in main.app.routes}
for gone in ("/api/plans", "/api/plan", "/api/plan/answers"):
self.assertNotIn(gone, paths)
if __name__ == "__main__":
unittest.main()