Work Resources becomes generic core composition over declarative plugin
`resources[]`, ahead of the `github` / `linear` / `slack` plugins (Wave 2B-2).
- Core knows only `branch` and `url` (cli/resource_urls.py). Every link is
mined raw, so the plugins' kinds apply at view time: installing a plugin
lights up the whole archive with zero re-parse. Notion links are plain
`url` pills.
- New backend/plugins/resources.py: PluginResourceRegistry compiled from the
owner's active plugins' `resources[]` + each plugin's settings (workers,
cwdGlobs, notifPills, channelMap, {config.*} templates); cached on the new
PluginStore.version and kept by identity while unchanged.
- manifest.py: expanded, ReDoS-checked `resources[]` (urlRegex, idRegex,
id/url/label templates, titleToken, bareKeyRegex + team gate,
branchKeyPattern cross-links, ignoreUrlRegex, toolExtractors[], icon,
color, stateTones, clickAction, priority, hueRole); the v3 shape and the
approval fingerprint stay as they were.
- ResourceMiner runs declarative toolExtractors / bare keys in-process (no
subprocess); legacy resourcesAuto / resourceTeams / slackChannels still read.
- resource_view: per-plugin scope, branchKeyPattern cross-linking, priority
primary, generic `<lead> · <title> · <shade>` title; Context cached on
(summaries, meta, registry) with per-transcript memo.
- look.subject → generic (hueKey, shadeKey) from hueRole; past.py generic.
- conv add/rm send raw links / keys; the hub's registry reads them.
- Removed: conversations/pr_state.py, sidecar/routes_gh.py (/gh/pr-states),
deps.pr_states, Profile.resources + Orus defaults (dropped on load),
GET /api/profiles/resource-directory, ProfileResourcesEditor + the
Profile page's Tracking tab.
- Frontend pills read `ui.resources` descriptors (icon, tone, stateTones,
clickAction); historical kinds keep a fallback. ResourceKind widens to str.
- Fixture manifests + test kit for the three plugins in
backend/fixtures/resource_plugins/.
OpenAPI not re-dumped (coordinator does it after Batch 2).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
4.1 KiB
Python
87 lines
4.1 KiB
Python
"""The `conv` CLI (notify.py): what it sends on each transport.
|
|
``python3 -m unittest test_conv`` from ``cli/``."""
|
|
|
|
import io
|
|
import os
|
|
import unittest
|
|
from contextlib import redirect_stderr, redirect_stdout
|
|
from unittest import mock
|
|
|
|
import notify
|
|
|
|
|
|
class TestConv(unittest.TestCase):
|
|
def run_cli(self, argv, env):
|
|
calls = []
|
|
|
|
def fake_call(self_, url, data=None, **kw):
|
|
calls.append((url, data))
|
|
return (202, {"queued": True}) if "/outbox" in url else (200, {"id": "s"})
|
|
out, err = io.StringIO(), io.StringIO()
|
|
with mock.patch.dict(os.environ, env, clear=False), \
|
|
mock.patch.object(notify.Transport, "_call", fake_call), \
|
|
redirect_stdout(out), redirect_stderr(err):
|
|
rc = notify.main(argv)
|
|
return rc, calls, out.getvalue(), err.getvalue()
|
|
|
|
HUB = {"CLAUDE_SESSION_ID": "sid-1", "AI_AGENT_OUTBOX_URL": "", "NOTIFY_AS": "conv"}
|
|
|
|
def test_add_on_the_hub(self):
|
|
rc, calls, out, _ = self.run_cli(
|
|
["add", "https://github.com/orus-tech/orus-monorepo/pull/13722,",
|
|
"--title", "feat: x", "--state", "OPEN", "--primary"], self.HUB)
|
|
self.assertEqual(rc, 0)
|
|
url, data = calls[0]
|
|
self.assertTrue(url.endswith("/api/conversation-meta"))
|
|
self.assertEqual(data["id"], "sid-1")
|
|
r = data["resources"][0]
|
|
# A raw link: the hub's github plugin makes it `pr:orus-tech/…#13722`.
|
|
self.assertEqual((r["kind"], r["url"], r["state"], r["primary"], r["source"]),
|
|
("url", "https://github.com/orus-tech/orus-monorepo/pull/13722",
|
|
"open", True, "agent"))
|
|
self.assertIn("recorded url:", out)
|
|
self.assertIn("(primary)", out)
|
|
|
|
def test_add_through_the_outbox(self):
|
|
env = {**self.HUB, "AI_AGENT_OUTBOX_URL": "http://w:8790", "AI_AGENT_OUTBOX_TOKEN": "t"}
|
|
rc, calls, out, _ = self.run_cli(["add", "INS-2229", "--title", "Separate tenant"], env)
|
|
self.assertEqual(rc, 0)
|
|
url, data = calls[0]
|
|
self.assertEqual(url, "http://w:8790/outbox")
|
|
self.assertEqual(data["kind"], "meta")
|
|
self.assertTrue(data["payload"]["id"].startswith("met_"))
|
|
r = data["payload"]["patch"]["resources"][0]
|
|
# A key: sent as a `ref` the hub's registry reads (the linear plugin).
|
|
self.assertEqual((r["ref"], r["title"]), ("INS-2229", "Separate tenant"))
|
|
self.assertNotIn("kind", r)
|
|
self.assertNotIn("primary", r) # never demotes when re-added
|
|
self.assertIn("recorded INS-2229", out)
|
|
|
|
def test_plugin_kind_and_repo(self):
|
|
rc, calls, _, _ = self.run_cli(["add", "#13722", "--repo", "acme/w", "--kind", "pr"],
|
|
self.HUB)
|
|
self.assertEqual(rc, 0)
|
|
self.assertEqual({k: calls[0][1]["resources"][0][k] for k in ("ref", "kind")},
|
|
{"ref": "acme/w#13722", "kind": "pr"})
|
|
rc, calls, _, err = self.run_cli(["add", "x", "--kind", "Not A Kind"], self.HUB)
|
|
self.assertEqual((rc, calls), (2, []))
|
|
|
|
def test_title_rm_and_refusals(self):
|
|
rc, calls, _, _ = self.run_cli(["title", "INS-2229", "·", "Separate"], self.HUB)
|
|
self.assertEqual(calls[0][1], {"id": "sid-1", "title": "INS-2229 · Separate",
|
|
"titleSource": "agent"})
|
|
# A link goes as itself: the hub drops the kind its plugin reads.
|
|
rc, calls, _, _ = self.run_cli(["rm", "https://linear.app/orus/issue/INS-1/x"], self.HUB)
|
|
self.assertEqual(calls[0][1]["resourcesRemove"], ["https://linear.app/orus/issue/INS-1/x"])
|
|
rc, calls, _, _ = self.run_cli(["rm", "INS-1"], self.HUB)
|
|
self.assertEqual(calls[0][1]["resourcesRemove"], ["INS-1"])
|
|
rc, calls, _, _ = self.run_cli(["rm", "feat-x", "--kind", "branch"], self.HUB)
|
|
self.assertEqual(calls[0][1]["resourcesRemove"], ["branch:feat-x"])
|
|
rc, calls, _, err = self.run_cli(["add", "not a thing at all"], self.HUB)
|
|
self.assertEqual((rc, calls), (2, []))
|
|
self.assertIn("not a resource", err)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|