Skip to content
125 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import {
5 BUILTINS,
6 MAX_APP_PINS,
7 appData,
8 appPinFromForm,
9 dockCookie,
10 installedAppOf,
11 installedApps,
12 integrationAppKey,
13 isPinnable,
14 pinsFrom,
15 pinsIn,
16 pinsToShow,
17 readDock,
18 sidebarClosed,
19 sidebarCookie,
20 withPin,
21 writeDock,
22} from "./apps.ts";
23
24test("only integrations are pinned; built-in apps, their pages, plugins and connectors are not", () => {
25 for (const app of BUILTINS) assert.equal(isPinnable(app.key), false, app.key);
26 for (const page of ["projects", "packages", "security", "context", "memory", "teams", "usage", "gateway", "integrations", "audit"]) {
27 assert.equal(isPinnable(page), false, page);
28 }
29 assert.equal(isPinnable("int-sentry"), true);
30 assert.equal(isPinnable("int-slack"), false, "Slack can't be connected yet");
31 assert.equal(isPinnable("int-mcp"), false, "MCP clients are each person's, not the workspace's");
32 assert.equal(isPinnable("ext-support"), false, "extensions became plugins, which aren't pinned");
33 assert.equal(isPinnable("plg-pli_01"), false);
34 assert.equal(isPinnable("con-con_01"), false);
35 assert.equal(isPinnable("int-Sentry"), false);
36});
37
38test("an integration's app opens its page", () => {
39 assert.equal(installedAppOf("int-sentry")?.path("acme"), "/acme/-/integrations/alerts");
40 assert.equal(installedAppOf("int-linear")?.path("acme"), "/acme/-/integrations/trackers");
41 assert.equal(installedAppOf("int-anthropic")?.path("acme"), "/acme/-/integrations/models");
42 assert.equal(installedAppOf("int-webhooks")?.path("acme"), "/acme/-/webhooks");
43 assert.equal(installedAppOf(integrationAppKey("github"))?.listing, "integration:github");
44 // Every key fits what identity keeps (MAX_DOCK_APP_KEY, 32).
45 assert.ok(integrationAppKey("anthropic-endpoint").length <= 32);
46});
47
48test("installed apps are the plugins that are on, the connectors, and what the workspace connected, opening where each is managed", () => {
49 const apps = installedApps({ sentry: { manage: "/acme/-/integrations/alerts" }, github: { manage: null }, nonsense: { manage: null } });
50 assert.deepEqual(apps.map((app) => app.key), ["int-github", "int-sentry"]);
51 assert.equal(apps[0]!.path("acme"), "/new/github?workspace=acme");
52 assert.deepEqual(appData(apps[1]!, "acme").href, "/acme/-/integrations/alerts");
53 assert.deepEqual(installedApps({}), []);
54 const pdf = { id: "pli_1", ref: "pdf@anthropic-agent-skills", name: "pdf", display_name: null, description: "PDFs", marketplace: "anthropic-agent-skills", enabled: true };
55 const off = { ...pdf, id: "pli_2", ref: "xlsx@anthropic-agent-skills", name: "xlsx", enabled: false };
56 const notion = { id: "con_1", title: "Notion", about: null, url: "https://mcp.notion.com/mcp" };
57 const all = installedApps({ sentry: { manage: null } }, [pdf, off], [notion]);
58 assert.deepEqual(
59 all.map((app) => [app.key, app.from, app.pinnable]),
60 [
61 ["plg-pli_1", "anthropic-agent-skills", false],
62 ["con-con_1", "Connector", false],
63 ["int-sentry", "g1t", true],
64 ],
65 );
66 assert.equal(all[0]!.path("acme"), "/acme/-/customize/plugins/pdf%40anthropic-agent-skills");
67 assert.equal(all[1]!.path("acme"), "/acme/-/customize/connectors/con_1");
68 assert.equal(all[1]!.about, "https://mcp.notion.com/mcp");
69});
70
71test("pins are kept per workspace, in the order they were pinned", () => {
72 const value = writeDock(writeDock(null, "acme", ["int-sentry", "int-linear"]), "Beta", ["int-jira"]);
73 assert.equal(value, "beta:int-jira,acme:int-sentry.int-linear");
74 assert.deepEqual(pinsIn(value, "acme"), ["int-sentry", "int-linear"]);
75 assert.deepEqual(pinsIn(value, "BETA"), ["int-jira"]);
76 assert.deepEqual(pinsIn(value, "other"), []);
77 // Unpinning everything keeps the workspace, with no pins.
78 assert.deepEqual(pinsIn(writeDock(value, "acme", []), "acme"), []);
79});
80
81test("a cookie someone wrote by hand reads as far as it makes sense", () => {
82 assert.deepEqual(readDock("acme:int-sentry.today.nonsense.int-sentry,BAD SLUG:int-jira,beta"), { acme: ["int-sentry"] });
83 assert.deepEqual(readDock(""), {});
84 const many = Array.from({ length: 30 }, () => "int-sentry").join(".");
85 assert.ok(pinsIn(`acme:${many}`, "acme").length <= MAX_APP_PINS);
86});
87
88test("pins of built-in pages from before Apps were Customize's are dropped", () => {
89 assert.deepEqual(pinsFrom(["usage", "int-sentry", "projects", "today", "int-sentry", "teams", "int-linear"]), ["int-sentry", "int-linear"]);
90 assert.deepEqual(pinsIn("acme:projects.usage.teams", "acme"), []);
91 assert.deepEqual(pinsFrom([]), []);
92});
93
94test("the account's pins win over the cookie, which is the fallback", () => {
95 const cookie = writeDock(null, "acme", ["int-sentry", "int-linear"]);
96 // Saved with the account, even with nothing pinned: the account's.
97 assert.deepEqual(pinsToShow(["int-jira"], cookie, "acme"), ["int-jira"]);
98 assert.deepEqual(pinsToShow([], cookie, "acme"), []);
99 // Never saved, or identity could not be asked: this device's cookie.
100 assert.deepEqual(pinsToShow(null, cookie, "acme"), ["int-sentry", "int-linear"]);
101 assert.deepEqual(pinsToShow(undefined, null, "acme"), []);
102});
103
104test("a pin form pins or unpins one app", () => {
105 const form = (fields: Record<string, string>) => {
106 const data = new FormData();
107 for (const [name, value] of Object.entries(fields)) data.set(name, value);
108 return data;
109 };
110 assert.deepEqual(appPinFromForm(form({ intent: "pin", app: "int-sentry" })), { app: "int-sentry", pinned: true });
111 assert.deepEqual(appPinFromForm(form({ intent: "unpin", app: "int-sentry" })), { app: "int-sentry", pinned: false });
112 assert.equal(appPinFromForm(form({ intent: "pin", app: "chat" })), null);
113 assert.equal(appPinFromForm(form({ intent: "pin", app: "teams" })), null);
114 assert.equal(appPinFromForm(form({ intent: "drop", app: "int-sentry" })), null);
115 assert.deepEqual(withPin(["int-sentry", "int-jira"], "int-sentry", true), ["int-jira", "int-sentry"]);
116 assert.deepEqual(withPin(["int-sentry", "int-jira"], "int-sentry", false), ["int-jira"]);
117});
118
119test("the cookies last a year and are secure when the site is", () => {
120 assert.match(dockCookie("acme:int-sentry", true), /^g1t_dock=acme%3Aint-sentry; Path=\/; Max-Age=31536000; SameSite=Lax; Secure$/);
121 assert.equal(sidebarCookie(true, false), "g1t_sidebar=closed; Path=/; Max-Age=31536000; SameSite=Lax");
122 assert.equal(sidebarClosed("closed"), true);
123 assert.equal(sidebarClosed("open"), false);
124 assert.equal(sidebarClosed(null), false);
125});