Files
ai-agent/cli/test_resource_urls.py
gabrielvidalandClaude Opus 5.5 c8fa334528 refactor(resources): plugin-driven resource kinds — retire live PR polling and Profile.resources
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>
2026-11-26 11:59:25 +01:00

117 lines
5.7 KiB
Python

"""The core's resource URL model (resource_urls.py) on links taken from real
work prompts: every link is a plain ``url`` record (the backend's plugin
registry turns a PR / an issue / a thread link into its kind at view time),
plus git branches. ``python3 -m pytest test_resource_urls.py`` from ``cli/``."""
import unittest
import resource_urls as ru
PR_URL = "https://github.com/orus-tech/orus-monorepo/pull/"
class TestUrls(unittest.TestCase):
def test_every_link_is_a_plain_url_record_with_its_full_link(self):
for raw in (PR_URL + "13722",
"https://linear.app/orus/issue/INS-2229/separate-tenant",
"https://orus-insurance.slack.com/archives/C02GDHPF1RR/p1791878511818179",
"https://app.notion.com/p/orus-team/Ouverture-DROM-3cf0ab24de31814bb058d2aa9d124dac"):
r = ru.parse_url(raw)
self.assertEqual((r["kind"], r["url"]), ("url", raw), raw)
self.assertEqual(ru.KINDS, ("branch", "url"))
def test_junk_is_stripped(self):
for raw in (PR_URL + "13258,", PR_URL + "13258)", PR_URL + "13258`",
PR_URL + "13258#issuecomment-6128419520."):
self.assertEqual(ru.parse_url(raw)["url"], PR_URL + "13258", raw)
# a reply link keeps its query: the slack plugin reads its thread_ts
reply = ("https://orus-insurance.slack.com/archives/C02GDHPF1RR/"
"p1791986119904219?thread_ts=1791878511.818179&cid=C02GDHPF1RR")
self.assertEqual(ru.parse_url(reply + ")")["url"], reply)
def test_not_resources(self):
for raw in ("http://localhost:3001/bo/admin/time",
"https://accounts.google.com/o/oauth2/auth?x=1",
"https://orus-insurance.slack.com/archives/<channel_id>/p<timestamp>",
"https://cdnjs.cloudflare.com/ajax/libs/x", "https://unpkg.com",
"https://example.org/", "ftp://x.io/a/b"):
self.assertIsNone(ru.parse_url(raw), raw)
self.assertIsNotNone(ru.parse_url("https://example.org/a/b"))
def test_other_url(self):
r = ru.parse_url("https://app.orus.eu/bo/subscriptions/c7bee84b-7e2a-5b4b-b3c3-048d0940a219?tab_id=health")
self.assertEqual(r["kind"], "url")
self.assertTrue(r["label"].startswith("app.orus.eu/bo/subscriptions"))
# same link, a fragment apart → one resource
self.assertEqual(
r["id"], ru.parse_url("https://app.orus.eu/bo/subscriptions/c7bee84b-7e2a-5b4b-"
"b3c3-048d0940a219?tab_id=health#x")["id"])
class TestFindAll(unittest.TestCase):
def test_spawned_prompt(self):
text = (f"check this PR {PR_URL}13694\nin link with this thread maybe ?\n"
"https://orus-insurance.slack.com/archives/C03AQQ21WFL/p1792030252499889")
self.assertEqual([r["url"] for r in ru.find_all(text)],
[PR_URL + "13694",
"https://orus-insurance.slack.com/archives/C03AQQ21WFL/p1792030252499889"])
def test_zsh_escaped_fragment_and_command_args(self):
text = (f"<command-args>{PR_URL}13172</command-args> and {PR_URL}"
"13254\\#discussion_r4122996809")
self.assertEqual([r["url"] for r in ru.find_all(text)],
[PR_URL + "13172", PR_URL + "13254"])
def test_no_bare_keys_in_the_core(self):
# `INS-2175` is the linear plugin's (bareKeyRegex), not the core's.
self.assertEqual(ru.find_all("fix INS-2175, dates are ISO-8601"), [])
def test_branch_typed_in_prompt(self):
rs = ru.find_all("on this branch: ins-2171-pricing-update-must-be-after-server-updated\n"
f"the 2.3 version ({PR_URL}13598)")
self.assertEqual([ru.key(r) for r in rs][0],
"branch:ins-2171-pricing-update-must-be-after-server-updated")
self.assertEqual([r["kind"] for r in rs], ["branch", "url"])
# not inside a URL, and not a plain word-number pair
self.assertEqual(ru.find_all("see utf-8 and https://x.io/a/ins-2171-foo-bar"),
[ru.parse_url("https://x.io/a/ins-2171-foo-bar")])
def test_url_spans(self):
text = "x https://a.io/b y"
self.assertEqual(ru.url_spans(text), [(2, 16)])
class TestBranches(unittest.TestCase):
def test_branch_ignores(self):
for b in ("main", "HEAD", "-q", "../x", ""):
self.assertIsNone(ru.branch(b), b)
self.assertEqual(ru.branch("ins-2229-x")["label"], "ins-2229-x")
class TestParseCli(unittest.TestCase):
def test_cli_inputs(self):
self.assertEqual(ru.parse(PR_URL + "13722,")["kind"], "url")
self.assertEqual(ru.key(ru.parse("ins-2229-separate-tenant", kind="branch")),
"branch:ins-2229-separate-tenant")
self.assertEqual(ru.key(ru.parse("feature/foo")), "branch:feature/foo")
# A key, an id, a plugin kind: the hub's registry reads them.
for raw, kind in (("ins-2229", None), ("#13722", None), (PR_URL + "1", "pr")):
self.assertIsNone(ru.parse(raw, kind=kind), raw)
class TestMerge(unittest.TestCase):
def test_merge(self):
a = {"kind": "pr", "id": "x#1", "title": "A", "firstSeen": "2026-10-02",
"firstTurn": True, "url": "u", "bare": True}
b = {"kind": "pr", "id": "x#1", "title": "B", "firstSeen": "2026-10-01",
"url": None, "state": "merged"}
m = ru.merge(a, b)
self.assertEqual((m["title"], m["url"], m["state"], m["firstSeen"], m["firstTurn"]),
("B", "u", "merged", "2026-10-01", True))
self.assertNotIn("bare", m)
self.assertEqual(ru.titleize("separate-tenant_x"), "Separate tenant x")
if __name__ == "__main__":
unittest.main()