A resource plugin can declare a `hueRole: group` kind — what an issue belongs to (a Linear project); its issue kind names it with `groupBy`. The linear plugin's `linear-project` uses it (plugin 1.1.0, ai-agent-plugins branch linear-projects). Decided in form linear-projects-icons-colour_yfnahd. - Lookups only: get_project and list_projects (a new extractor field, `itemsPath: projects[]`, reads each item of a listing without tagging the conversation) teach Linear's icon and colour; `vendor_icons` turns `Brush` / `:heavy_plus_sign:` into glyph keys (`brush`, `emoji:➕`, gemoji table vendored). PARSER_VERSION 47 re-mines past lookups. - Colour (`cardColour: group`, the default): a card wears its issue's project colour, each issue of the project a shade (`LookColors.group_color`, `shade_hex` ≡ the PWA's `shadeHex`); a palette hue when Linear's is unknown; an issue with no known project keeps issue + PR colours. A Settings → Tags colour on `linear:project/<name>` wins (the PWA re-shades it with `colorGroup` / `colorShade`); *Colour…* on such a card writes that tag. - Icon (`iconOrder: group`): project › label › team; the project's tag icon, else Linear's own. - Pill (`groupPills`): the issue's project beside it, in its own icon and colour (`Resource.icon` / `color`; the glyph is tinted, not the pill). - `groupLooks` off: only what Settings → Tags sets. - Emoji tag icons (`emoji:<char>`), Linear's look as a project tag's derived default in Settings → Tags, the mock seeds two projects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
283 lines
14 KiB
Python
283 lines
14 KiB
Python
"""Linear projects — the linear plugin's ``hueRole: group`` kind
|
||
(fixtures/resource_plugins/linear): what get_project / list_projects teach
|
||
(the project's name, Linear's icon and colour), the project pill beside its
|
||
issue, the card colour (the project's, each issue a shade of it) and the
|
||
plugin's look settings (``cardColour``, ``iconOrder``, ``groupPills``,
|
||
``groupLooks``). ``python -m pytest test_linear_projects.py`` from
|
||
``backend/``."""
|
||
|
||
import json
|
||
import pathlib
|
||
import tempfile
|
||
import unittest
|
||
|
||
from conversations import look
|
||
from conversations import resource_view as rv
|
||
from conversations import vendor_icons
|
||
from fixtures.resource_plugins.kit import FakePluginStore, registry
|
||
from plugins import resources as plugin_resources
|
||
from plugins.manifest import ManifestError, validate_manifest
|
||
from test_resources import T
|
||
|
||
PROJECT_URL = "https://linear.app/orus/project/activity-config-migrations-4f81c6823b68"
|
||
PROJECT_KEY = "linear-project:activity-config-migrations-4f81c6823b68"
|
||
GET_PROJECT = json.dumps({
|
||
"id": "P-TECH-190", "icon": "Brush", "color": "#5E6AD2",
|
||
"name": "Activity config migrations", "url": PROJECT_URL,
|
||
"status": {"id": "x", "name": "Planned", "type": "planned"}})
|
||
LIST_PROJECTS = json.dumps({"projects": [
|
||
{"name": "Activity config migrations", "icon": "Brush", "color": "#5e6ad2",
|
||
"url": PROJECT_URL},
|
||
{"name": "Activity JSON Configuration MS", "icon": ":heavy_plus_sign:", "color": "#bec2c8",
|
||
"url": "https://linear.app/orus/project/activity-json-configuration-ms-0123456789ab"},
|
||
], "hasNextPage": False})
|
||
|
||
|
||
def issue(key, project="Activity config migrations"):
|
||
return json.dumps({"id": key, "title": f"Issue {key}", "status": "Todo",
|
||
"url": f"https://linear.app/orus/issue/{key}", "labels": ["rcph"],
|
||
"project": project, "team": "Squad Insurance Factory"})
|
||
|
||
|
||
def ctx_of(*summaries, reg=None):
|
||
"""The view's shared context over a whole (tiny) archive."""
|
||
reg = reg or registry()
|
||
parts = [rv._derive(reg, s) for s in summaries]
|
||
teams, names, titles, metas, xrefs, gseen = {}, {}, {}, {}, {}, {}
|
||
for t, n, ti, me, x, gs in parts:
|
||
for k, v in t.items():
|
||
teams.setdefault(k, set()).update(v)
|
||
names.update(n)
|
||
for k, v in ti.items():
|
||
titles.setdefault(k, v)
|
||
for k, v in me.items():
|
||
cur = metas.setdefault(k, {})
|
||
for f, fv in v.items():
|
||
cur.setdefault(f, fv)
|
||
xrefs.update(x)
|
||
for k, v in gs.items():
|
||
gseen.setdefault(k, v)
|
||
teams.setdefault("linear", set()).add("INS")
|
||
return rv.Context(reg, teams, names, titles, metas, xrefs, gseen)
|
||
|
||
|
||
def card(s, ctx):
|
||
return rv.merge(s["resourcesAuto"], [], [], ctx, ctx.registry.kinds, True)
|
||
|
||
|
||
class TestMining(unittest.TestCase):
|
||
def test_get_project_names_the_project_and_its_look(self):
|
||
s = T().user("look at the project").tool(
|
||
"mcp__linear__get_project", {"query": "activity-config-migrations-4f81c6823b68"},
|
||
GET_PROJECT).parse()
|
||
info = s["resourceInfo"][PROJECT_KEY]
|
||
self.assertEqual((info["title"], info["icon"], info["color"], info["state"]),
|
||
("Activity config migrations", "Brush", "#5E6AD2", "Planned"))
|
||
self.assertIn(PROJECT_KEY, [f"{r['kind']}:{r['id']}" for r in s["resourcesAuto"]])
|
||
|
||
def test_a_listing_teaches_every_project_without_tagging_them(self):
|
||
s = T().user("which projects?").tool("mcp__linear__list_projects", {"query": "Activity"},
|
||
LIST_PROJECTS).parse()
|
||
self.assertEqual(s["resourceInfo"]["linear-project:activity-json-configuration-ms-0123456789ab"]
|
||
["icon"], ":heavy_plus_sign:")
|
||
self.assertEqual(s["resourceInfo"][PROJECT_KEY]["title"], "Activity config migrations")
|
||
self.assertFalse([r for r in s["resourcesAuto"] if r["kind"] == "linear-project"])
|
||
|
||
def test_a_project_link_is_a_project_pill(self):
|
||
s = T().user(f"see {PROJECT_URL}/overview").parse()
|
||
rs = card(s, ctx_of(s))
|
||
p = next(r for r in rs if r["kind"] == "linear-project")
|
||
self.assertEqual((p["id"], p["label"], p["url"]),
|
||
("activity-config-migrations-4f81c6823b68", "Activity config migrations",
|
||
PROJECT_URL))
|
||
self.assertTrue(p["primary"]) # alone, it is what the conversation is about
|
||
|
||
|
||
class TestProjectPill(unittest.TestCase):
|
||
def setUp(self):
|
||
self.archive = T().user("projects").tool("mcp__linear__list_projects", {},
|
||
LIST_PROJECTS).parse()
|
||
|
||
def test_the_issues_project_sits_next_to_it_with_linears_look(self):
|
||
s = T().user("fix INS-2700 https://linear.app/orus/issue/INS-2700").tool(
|
||
"mcp__linear__get_issue", {"id": "INS-2700"}, issue("INS-2700")).parse()
|
||
rs = card(s, ctx_of(s, self.archive))
|
||
self.assertEqual([r["kind"] for r in rs], ["linear", "linear-project"])
|
||
p = rs[1]
|
||
self.assertEqual((p["label"], p["icon"], p["color"], p["url"], p["via"]),
|
||
("Activity config migrations", "brush", "#5e6ad2", PROJECT_URL, "issue"))
|
||
self.assertTrue(p["firstTurn"])
|
||
self.assertFalse(p.get("primary"))
|
||
# the project never joins the resource title
|
||
self.assertTrue(rv.title_for(rs, "x", registry()).startswith("INS-2700 · "))
|
||
|
||
def test_a_project_known_by_name_only(self):
|
||
s = T().user("fix https://linear.app/orus/issue/INS-2701").tool(
|
||
"mcp__linear__get_issue", {"id": "INS-2701"}, issue("INS-2701", "Electronic signature")).parse()
|
||
p = next(r for r in card(s, ctx_of(s)) if r["kind"] == "linear-project")
|
||
self.assertEqual((p["id"], p["label"]), ("name:electronic-signature", "Electronic signature"))
|
||
self.assertFalse(p.get("url") or p.get("icon") or p.get("color"))
|
||
|
||
def test_settings_turn_the_pill_and_linears_look_off(self):
|
||
s = T().user("fix https://linear.app/orus/issue/INS-2700").tool(
|
||
"mcp__linear__get_issue", {"id": "INS-2700"}, issue("INS-2700")).parse()
|
||
off = registry(settings={"linear": {"linearWorkspace": "orus", "groupPills": False}})
|
||
self.assertEqual([r["kind"] for r in card(s, ctx_of(s, self.archive, reg=off))], ["linear"])
|
||
plain = registry(settings={"linear": {"linearWorkspace": "orus", "groupLooks": False}})
|
||
p = card(s, ctx_of(s, self.archive, reg=plain))[1]
|
||
self.assertFalse(p.get("icon") or p.get("color"))
|
||
|
||
def test_hidden_stays_hidden(self):
|
||
s = T().user("fix https://linear.app/orus/issue/INS-2700").tool(
|
||
"mcp__linear__get_issue", {"id": "INS-2700"}, issue("INS-2700")).parse()
|
||
ctx = ctx_of(s, self.archive)
|
||
rs = rv.merge(s["resourcesAuto"], [], [PROJECT_KEY], ctx, ctx.registry.kinds, True)
|
||
self.assertEqual([r["kind"] for r in rs], ["linear"])
|
||
|
||
|
||
class TestColour(unittest.TestCase):
|
||
def setUp(self):
|
||
self.tmp = tempfile.TemporaryDirectory()
|
||
self.colors = look.LookColors(str(pathlib.Path(self.tmp.name) / "c.json"))
|
||
self.archive = T().user("projects").tool("mcp__linear__list_projects", {},
|
||
LIST_PROJECTS).parse()
|
||
|
||
def tearDown(self):
|
||
self.tmp.cleanup()
|
||
|
||
def resolve(self, key, reg=None, archive=True, sid=None):
|
||
s = T().user(f"fix https://linear.app/orus/issue/{key}").tool(
|
||
"mcp__linear__get_issue", {"id": key}, issue(key)).parse()
|
||
ctx = ctx_of(s, *([self.archive] if archive else []), reg=reg)
|
||
rs = card(s, ctx)
|
||
subject, hue = look.subject(rs, ctx.registry.roles)
|
||
return look.resolve(None, sid=sid or key, subject_key=subject, seen="2026-11-30T10:00:00Z",
|
||
colors=self.colors, linear={"project": "Activity config migrations"},
|
||
group=rv.group_look(ctx, hue, subject), hue_key=hue,
|
||
prefs=ctx.registry.look)
|
||
|
||
def test_the_projects_colour_each_issue_a_shade(self):
|
||
a, b, c = (self.resolve(k) for k in ("INS-1", "INS-2", "INS-3"))
|
||
self.assertEqual((a["color"], a["colorGroup"], a["colorShade"]),
|
||
("#5e6ad2", "Activity config migrations", None))
|
||
self.assertEqual((b["color"], b["colorShade"]), (look.shade_hex("#5e6ad2", "300"), "300"))
|
||
self.assertEqual(c["colorShade"], "700")
|
||
self.assertEqual(self.resolve("INS-1")["color"], "#5e6ad2") # stable
|
||
self.assertEqual((a["linear"]["projectIcon"], a["linear"]["projectColor"],
|
||
a["linear"]["iconOrder"]), ("brush", "#5e6ad2", "group"))
|
||
|
||
def test_without_linears_colour_a_palette_hue_for_the_project(self):
|
||
a = self.resolve("INS-1", archive=False)
|
||
b = self.resolve("INS-2", archive=False)
|
||
self.assertIn(a["color"], look.COLORS)
|
||
self.assertEqual(b["color"], f"{a['color']}-300")
|
||
self.assertEqual(a["colorGroup"], "Activity config migrations")
|
||
|
||
def test_card_colour_per_issue_and_label_first(self):
|
||
reg = registry(settings={"linear": {"linearWorkspace": "orus", "cardColour": "hue",
|
||
"iconOrder": "label"}})
|
||
a = self.resolve("INS-1", reg=reg)
|
||
b = self.resolve("INS-2", reg=reg)
|
||
self.assertIsNone(a["colorGroup"])
|
||
self.assertNotEqual(a["color"], b["color"]) # one hue per issue
|
||
self.assertEqual(a["linear"]["iconOrder"], "label")
|
||
self.assertEqual(a["linear"]["projectIcon"], "brush") # the look is still known
|
||
|
||
def test_linears_look_off(self):
|
||
reg = registry(settings={"linear": {"linearWorkspace": "orus", "groupLooks": False}})
|
||
a = self.resolve("INS-1", reg=reg)
|
||
self.assertIn(a["color"], look.COLORS)
|
||
self.assertNotIn("projectIcon", a["linear"])
|
||
|
||
def test_a_set_colour_wins(self):
|
||
s = T().user("fix https://linear.app/orus/issue/INS-1").tool(
|
||
"mcp__linear__get_issue", {"id": "INS-1"}, issue("INS-1")).parse()
|
||
ctx = ctx_of(s, self.archive)
|
||
rs = card(s, ctx)
|
||
subject, hue = look.subject(rs, ctx.registry.roles)
|
||
out = look.resolve({"color": "rose"}, sid="x", subject_key=subject, seen=None,
|
||
colors=self.colors, group=rv.group_look(ctx, hue, subject),
|
||
hue_key=hue, prefs=ctx.registry.look)
|
||
self.assertEqual((out["color"], out["colorGroup"]), ("rose", None))
|
||
|
||
def test_a_project_alone_wears_its_colour(self):
|
||
s = T().user(f"plan {PROJECT_URL}").parse()
|
||
ctx = ctx_of(s, self.archive)
|
||
rs = card(s, ctx)
|
||
subject, hue = look.subject(rs, ctx.registry.roles)
|
||
self.assertEqual((subject, hue), (PROJECT_KEY, None))
|
||
out = look.resolve(None, sid="p", subject_key=subject, seen=None, colors=self.colors,
|
||
group=rv.group_look(ctx, hue, subject), hue_key=hue,
|
||
prefs=ctx.registry.look)
|
||
self.assertEqual((out["color"], out["colorShade"]), ("#5e6ad2", None))
|
||
|
||
def test_group_order_persists(self):
|
||
self.resolve("INS-1")
|
||
self.resolve("INS-2")
|
||
self.colors.flush()
|
||
again = look.LookColors(str(pathlib.Path(self.tmp.name) / "c.json"))
|
||
self.assertEqual(again.groups["group:Activity config migrations"], ["linear:INS-1", "linear:INS-2"])
|
||
|
||
|
||
class TestHelpers(unittest.TestCase):
|
||
def test_shade_hex(self):
|
||
self.assertEqual(look.shade_hex("#5e6ad2", None), "#5e6ad2")
|
||
self.assertEqual(look.shade_hex("#000000", "300"), "#737373")
|
||
self.assertEqual(look.shade_hex("#ffffff", "700"), "#a6a6a6")
|
||
self.assertEqual(look.shade_hex("#5E6AD2", "400"), "#818bdc")
|
||
self.assertEqual(look.shade_hex("#919191", "300"), "#c3c3c3") # 194.5 rounds up, like JS
|
||
self.assertEqual(look.shade_color("violet", "300"), "violet-300")
|
||
|
||
def test_vendor_icons(self):
|
||
self.assertEqual(vendor_icons.icon_key("Brush"), "brush")
|
||
self.assertEqual(vendor_icons.icon_key(":heavy_plus_sign:"), "emoji:➕")
|
||
self.assertEqual(vendor_icons.icon_key("🚀"), "emoji:🚀")
|
||
self.assertEqual(vendor_icons.icon_key("Desktop"), "monitor")
|
||
self.assertEqual(vendor_icons.icon_key("BarChart"), "chart-column")
|
||
for none in ("Project", ":no_such_code:", "", None, "<script>"):
|
||
self.assertIsNone(vendor_icons.icon_key(none))
|
||
self.assertEqual(vendor_icons.hex_color("#ABCDEF"), "#abcdef")
|
||
self.assertIsNone(vendor_icons.hex_color("blue"))
|
||
|
||
def test_subject_group_alone(self):
|
||
roles = {"linear": "hue", "pr": "shade", "linear-project": "group"}
|
||
self.assertEqual(look.subject([{"kind": "linear-project", "id": "p-0123456789ab"},
|
||
{"kind": "linear", "id": "INS-1"}], roles),
|
||
("linear:INS-1", "linear:INS-1"))
|
||
self.assertEqual(look.subject([{"kind": "linear-project", "id": "p-0123456789ab"}], roles),
|
||
("linear-project:p-0123456789ab", None))
|
||
|
||
def test_look_prefs_defaults(self):
|
||
reg = registry()
|
||
self.assertEqual((reg.look.colour_by, reg.look.icon_order, reg.look.group_pills,
|
||
reg.look.group_looks), ("group", "group", True, True))
|
||
self.assertEqual(reg.group_def.kind, "linear-project")
|
||
no_linear = registry(plugins=("github", "slack"))
|
||
self.assertIsNone(no_linear.group_def)
|
||
|
||
|
||
class TestManifest(unittest.TestCase):
|
||
def _manifest(self, resource):
|
||
d = tempfile.mkdtemp()
|
||
pathlib.Path(d, "plugin.json").write_text(json.dumps({
|
||
"schema": 1, "id": "x", "name": "X", "version": "1.0.0", "resources": [resource]}))
|
||
return d
|
||
|
||
def test_items_path_and_group_by(self):
|
||
ok = self._manifest({"id": "p", "urlRegex": "^https://x/(?P<id>\\d+)", "hueRole": "group",
|
||
"groupBy": "project",
|
||
"toolExtractors": [{"tool": "mcp__*__list", "itemsPath": "items[]",
|
||
"urlFields": ["url"]}]})
|
||
r = validate_manifest(ok)["resources"][0]
|
||
self.assertEqual((r["hueRole"], r["groupBy"], r["toolExtractors"][0]["itemsPath"]),
|
||
("group", "project", "items[]"))
|
||
bad = self._manifest({"id": "p", "urlRegex": "^https://x/(?P<id>\\d+)",
|
||
"toolExtractors": [{"tool": "t", "itemsPath": "items",
|
||
"urlFields": ["url"]}]})
|
||
with self.assertRaises(ManifestError):
|
||
validate_manifest(bad)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|