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>
102 lines
4.5 KiB
Python
102 lines
4.5 KiB
Python
"""A worker's `conv add` reaching the hub: the outbox mirror applies a
|
|
`met_` item through resource_view.apply_recorded — whitelisted keys only, its
|
|
own session only, raw links / keys read by the hub's active resource plugins
|
|
— and publishes a `meta` event.
|
|
``python -m unittest test_outbox_mirror_meta`` from ``backend/``."""
|
|
|
|
import pathlib
|
|
import tempfile
|
|
import threading
|
|
import types
|
|
import unittest
|
|
from http.server import HTTPServer
|
|
|
|
import meta as meta_mod
|
|
from conversations import resource_view
|
|
from fixtures.resource_plugins.kit import FakePluginStore
|
|
from test_outbox_mirror import FakeOutbox, FakeStore
|
|
from workers import outbox_mirror
|
|
|
|
|
|
class OutboxMeta(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.srv = HTTPServer(("127.0.0.1", 0), FakeOutbox)
|
|
threading.Thread(target=cls.srv.serve_forever, daemon=True).start()
|
|
cls.url = f"http://127.0.0.1:{cls.srv.server_port}"
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.srv.shutdown()
|
|
|
|
def setUp(self):
|
|
FakeOutbox.items, FakeOutbox.calls = [], []
|
|
self.d = tempfile.TemporaryDirectory()
|
|
self.events = []
|
|
self.deps = types.SimpleNamespace(
|
|
meta_store=meta_mod.MetaStore(str(pathlib.Path(self.d.name) / "m.json")),
|
|
hub=types.SimpleNamespace(publish=self.events.append),
|
|
plugin_store=FakePluginStore())
|
|
self.m = outbox_mirror.OutboxMirror(
|
|
FakeStore({"id": "w1", "url": self.url, "token": "w0rker"}),
|
|
create={"meta": lambda d: resource_view.apply_recorded(self.deps, d)},
|
|
status={}, cancel={}, publish=lambda ev: None)
|
|
self.stamped = []
|
|
orig = resource_view.stamp_title
|
|
resource_view.stamp_title = lambda deps, sid: self.stamped.append(sid)
|
|
self.addCleanup(lambda: setattr(resource_view, "stamp_title", orig))
|
|
|
|
def tearDown(self):
|
|
self.d.cleanup()
|
|
|
|
def item(self, patch, sid="s1", oid="met_0123456789ab"):
|
|
FakeOutbox.items = [{"id": oid, "kind": "meta", "status": "queued",
|
|
"payload": {"id": oid, "sessionId": sid, "patch": patch}}]
|
|
self.m.tick()
|
|
return FakeOutbox.calls[-1][2]["hub"]
|
|
|
|
def test_applied_and_published(self):
|
|
self.deps.meta_store.update("s1", {"workerSource": "w1"})
|
|
ack = self.item({"resources": [
|
|
{"kind": "pr", "id": "orus-tech/orus-monorepo#13722", "label": "#13722",
|
|
"url": "https://github.com/orus-tech/orus-monorepo/pull/13722",
|
|
"title": "feat(mrp): x", "state": "open", "primary": True}],
|
|
"title": "INS-2229 · Separate tenant", "titleSource": "agent",
|
|
"account": "personal", "archived": True})
|
|
self.assertTrue(ack.get("ok"), ack)
|
|
m = self.deps.meta_store.get("s1")
|
|
self.assertEqual(m["resources"][0]["source"], "agent")
|
|
self.assertEqual((m["title"], m["titleSource"]), ("INS-2229 · Separate tenant", "agent"))
|
|
self.assertNotIn("account", m)
|
|
self.assertFalse(m.get("archived"))
|
|
self.assertEqual(self.events, [{"type": "meta", "id": "s1"}])
|
|
self.assertEqual(self.stamped, ["s1"])
|
|
|
|
def test_raw_link_and_key_read_hub_side_no_pr_poke(self):
|
|
# `conv add <url>` / `conv add INS-2229` on a worker: the CLI can't
|
|
# know the plugin kinds; the hub's registry reads them. Nothing polls
|
|
# GitHub afterwards (no `pr_states` on deps at all).
|
|
self.deps.meta_store.update("s1", {"workerSource": "w1"})
|
|
ack = self.item({"resources": [
|
|
{"kind": "url", "id": "h", "url": "https://github.com/acme/w/pull/5"},
|
|
{"ref": "INS-2229", "primary": True}],
|
|
"resourcesRemove": ["https://github.com/acme/w/pull/9"]})
|
|
self.assertTrue(ack.get("ok"), ack)
|
|
m = self.deps.meta_store.get("s1")
|
|
self.assertEqual([f"{r['kind']}:{r['id']}" for r in m["resources"]],
|
|
["pr:acme/w#5", "linear:INS-2229"])
|
|
self.assertIn("pr:acme/w#9", m["resourcesHidden"])
|
|
self.assertFalse(hasattr(self.deps, "pr_states"))
|
|
|
|
def test_refused(self):
|
|
self.deps.meta_store.update("s2", {"worker": "w2"})
|
|
self.assertTrue(self.item({"title": "x"}, sid="s2")["failed"]) # elsewhere
|
|
self.assertTrue(self.item({"title": "x", "titleSource": "user"})["failed"])
|
|
self.assertTrue(self.item({"resources": [{"kind": "jira", "id": "1"}]})["failed"])
|
|
self.assertTrue(self.item({"archived": True})["failed"]) # nothing left
|
|
self.assertEqual(self.events, [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|