Files
ai-agent/backend/test_plugin_checks.py
gabrielvidalandClaude Opus 5.5 98294ee4e7 feat(plugins): the Details drawer's Lifecycle checks card moves to the lifecycle plugin
The core no longer draws the committed / pushed / merged / deployed /
notified / completed row in a conversation's Details: the `lifecycle`
plugin's `conv-checks` slot does, reading it through a new hub bridge.

- `GET /proxy/tools/plugins/{pid}/hub/conversations/{cid}/checks` behind the
  new `conversations.checks` capability (plugins/hubchecks.py): the stamps
  as the conversation's card has them (cards._conv_meta — the sidecar's,
  else lifecycleAuto) and its resolved state (a subagent's own), by
  conversation or session id; the owner any, a guest theirs and those
  shared with them, 404 otherwise. Not an operator capability.
- DETAIL_CARD_RENAMES: `checks` → `plugin:lifecycle:conv-checks`, so a saved
  arrangement keeps its slot. LifecycleChecks is gone; StatusChecks stays
  for the list cards and the project / service pages.
- docs/plugins.md (capability table, bridges, the retired-widgets table),
  CLAUDE.md, the unused French string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:39:40 +01:00

159 lines
7.3 KiB
Python

"""``conversations.checks`` (2026-11-27) — the bridge the ``lifecycle``
plugin's Details card reads, since the *Lifecycle checks* card left the core:
one conversation's stamps as its card has them (the sidecar's, else the
transcript's ``lifecycleAuto``) and its resolved state, by conversation or
session id; the owner reads any, a guest theirs and those shared with them;
a plugin without the capability is refused. Not an operator capability."""
from __future__ import annotations
import json
import os
import pathlib
import tempfile
import unittest
from unittest.mock import patch
os.environ.setdefault("INTERNAL_API_TOKEN", "tok")
from fastapi.testclient import TestClient # noqa: E402
import main # noqa: E402
from plugins import manifest # noqa: E402
from plugins.store import OWNER_UID, PluginStore # noqa: E402
from toolproxy import access # noqa: E402
PID = "lc"
MINE = "aaaaaaaa-1111-4111-8111-111111111111" # the owner's session
CEL = "bbbbbbbb-2222-4222-8222-222222222222" # a guest's
SHARED = "cccccccc-3333-4333-8333-333333333333" # someone else's, shared with cel
DOM = "dddddddd-4444-4444-8444-444444444444" # another guest's, not shared
CONV = "0193a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b" # MINE's conversation id
PATHS = {CONV: "/t/p/mine.jsonl", "cid-cel": "/t/p/cel.jsonl",
"cid-shared": "/t/p/shared.jsonl", "cid-dom": "/t/p/dom.jsonl"}
BY_SID = {MINE: CONV, CEL: "cid-cel", SHARED: "cid-shared", DOM: "cid-dom"}
SUMMARIES = {
"/t/p/mine.jsonl": {"sessionId": MINE, "messages": 4, "turnEnded": True,
"endedAt": "2026-11-27T10:00:00Z",
"lifecycleAuto": {"committed": "2026-11-27T09:00:00Z",
"deployed": "2026-11-27T09:30:00Z"}},
"/t/p/cel.jsonl": {"sessionId": CEL, "messages": 2, "endedAt": "2026-11-27T10:00:00Z"},
"/t/p/shared.jsonl": {"sessionId": SHARED, "messages": 2, "endedAt": "2026-11-27T10:00:00Z"},
"/t/p/dom.jsonl": {"sessionId": DOM, "messages": 2, "endedAt": "2026-11-27T10:00:00Z"},
}
META = {
# the skills' stamp wins over the transcript's (committed); a stamp only
# the transcript has fills in (deployed)
MINE: {"committed": "2026-11-27T09:05:00Z", "pushed": "2026-11-27T09:06:00Z",
"state": "finished", "title": "secret title"},
CEL: {"owner": "cel", "merged": "2026-11-27T09:10:00Z"},
SHARED: {"owner": "dom", "participants": ["cel"], "notified": "2026-11-27T09:20:00Z"},
DOM: {"owner": "dom", "pushed": "2026-11-27T09:00:00Z"},
}
class FakeStore:
summaries_version = object()
def get_summary(self, path):
return SUMMARIES.get(path)
def all_summaries(self):
return list(SUMMARIES.items())
class FakeMeta:
def peek(self, sid):
return META.get(sid) or {}
def items(self):
return list(META.items())
def _src(root: pathlib.Path, caps) -> pathlib.Path:
root.mkdir(parents=True, exist_ok=True)
(root / "plugin.json").write_text(json.dumps(
{"schema": 1, "id": PID, "name": "Lifecycle", "capabilities": list(caps)}))
return root
class TestManifest(unittest.TestCase):
def test_a_known_capability_any_user_may_approve(self):
with tempfile.TemporaryDirectory() as td:
mf = manifest.validate_manifest(_src(pathlib.Path(td), ["conversations.checks"]))
self.assertEqual(mf["capabilities"], ["conversations.checks"])
self.assertFalse(manifest.requires_operator(mf))
labels = [i["label"] for i in manifest.capability_summary(mf)]
self.assertTrue(any("committed, pushed, merged, deployed and notified" in x for x in labels), labels)
class TestBridge(unittest.TestCase):
def setUp(self):
self.tc = TestClient(main.app)
def _get(self, cid, uid=OWNER_UID, caps=("conversations.checks",)):
with tempfile.TemporaryDirectory() as td:
store = PluginStore(pathlib.Path(td) / "data")
store.install(uid, str(_src(pathlib.Path(td) / "src", caps)), is_owner=True, approve=True)
deps = main.app.state.ai
tok = access.mint_handler(uid, PID, ttl=600)
with patch.object(deps, "plugin_store", store), \
patch.object(deps, "store", FakeStore()), \
patch.object(deps, "meta_store", FakeMeta()), \
patch("conversations.ids.path_of", PATHS.get), \
patch("conversations.catalog._conv_ids_by_session", lambda _d: BY_SID):
return self.tc.get(f"/proxy/tools/plugins/{PID}/hub/conversations/{cid}/checks",
headers={"Authorization": f"Bearer {tok}"})
def test_the_owner_reads_the_stamps_as_the_card_has_them(self):
for cid in (CONV, MINE): # by conversation id, and by session id
r = self._get(cid)
self.assertEqual(r.status_code, 200, r.text)
self.assertEqual(r.json(), {
"sessionId": MINE, "conversationId": CONV, "state": "finished",
"committed": "2026-11-27T09:05:00Z", "pushed": "2026-11-27T09:06:00Z",
"merged": None, "deployed": "2026-11-27T09:30:00Z", "notified": None})
self.assertNotIn("title", r.json()) # never the conversation's text
def test_the_owner_reads_a_guests_too(self):
r = self._get(CEL)
self.assertEqual(r.status_code, 200, r.text)
self.assertEqual(r.json()["merged"], "2026-11-27T09:10:00Z")
def test_a_guest_reads_their_own_and_shared_only(self):
own = self._get(CEL, uid="cel")
shared = self._get(SHARED, uid="cel")
self.assertEqual((own.status_code, shared.status_code), (200, 200), own.text + shared.text)
self.assertEqual(shared.json()["notified"], "2026-11-27T09:20:00Z")
for cid in (DOM, MINE, CONV):
self.assertEqual(self._get(cid, uid="cel").status_code, 404, cid)
def test_a_subagent_has_its_own_state(self):
with patch("conversations.tree._sidechain_state", lambda _d, _p: "running"):
r = self._get(CONV)
self.assertEqual(r.json()["state"], "running")
def test_refusals(self):
self.assertEqual(self._get(MINE, caps=()).status_code, 403)
self.assertEqual(self._get("eeeeeeee-5555-4555-8555-555555555555").status_code, 404)
self.assertEqual(self._get("x" * 80).status_code, 404)
# another plugin's handler token is refused
with tempfile.TemporaryDirectory() as td:
store = PluginStore(pathlib.Path(td) / "data")
store.install(OWNER_UID, str(_src(pathlib.Path(td) / "src", ["conversations.checks"])),
is_owner=True, approve=True)
deps = main.app.state.ai
with patch.object(deps, "plugin_store", store), \
patch.object(deps, "store", FakeStore()), \
patch.object(deps, "meta_store", FakeMeta()), \
patch("conversations.ids.path_of", PATHS.get), \
patch("conversations.catalog._conv_ids_by_session", lambda _d: BY_SID):
other = self.tc.get(f"/proxy/tools/plugins/{PID}/hub/conversations/{MINE}/checks",
headers={"Authorization": f"Bearer {access.mint_handler(OWNER_UID, 'zz', ttl=600)}"})
self.assertEqual(other.status_code, 403) # another plugin's handler token
if __name__ == "__main__":
unittest.main()