Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

134 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 PHONE_TABS,
23 appOf,
24 phoneMoreApps,
25} from "./apps.ts";
26
27test("Work is a built-in app right after Home, for every member", () => {
28 assert.deepEqual(BUILTINS.slice(0, 2).map((app) => app.key), ["home", "work"]);
29 assert.equal(appOf("work").path("acme"), "/acme/-/work");
30 assert.equal(appOf("work").code, undefined, "not part of Code");
31});
32
33test("a phone's bar is Home, Work, Chat and Notifications, with Code first under More", () => {
34 assert.deepEqual([...PHONE_TABS], ["home", "work", "chat", "notifications"]);
35 // Four tabs and More: five slots.
36 assert.equal(PHONE_TABS.length + 1, 5);
37 assert.deepEqual(phoneMoreApps(true), ["code", "artifacts", "routines", "people", "workspace"]);
38 // A member without Code access has the rest, Work still on the bar.
39 assert.deepEqual(phoneMoreApps(false), ["artifacts", "routines", "people", "workspace"]);
40});
41
42test("only integrations are pinned; built-in apps, their pages, old plugins and connectors are not", () => {
43 for (const app of BUILTINS) assert.equal(isPinnable(app.key), false, app.key);
44 for (const page of ["projects", "packages", "security", "context", "memory", "teams", "usage", "gateway", "integrations", "audit"]) {
45 assert.equal(isPinnable(page), false, page);
46 }
47 assert.equal(isPinnable("int-sentry"), true);
48 assert.equal(isPinnable("int-slack"), false, "Slack can't be connected yet");
49 assert.equal(isPinnable("int-mcp"), false, "MCP clients are each person's, not the workspace's");
50 assert.equal(isPinnable("ext-support"), false, "extensions became plugins, which aren't pinned");
51 assert.equal(isPinnable("plg-pli_01"), false);
52 assert.equal(isPinnable("con-con_01"), false);
53 assert.equal(isPinnable("int-Sentry"), false);
54});
55
56test("an integration's app opens its page", () => {
57 assert.equal(installedAppOf("int-sentry")?.path("acme"), "/acme/-/integrations/alerts");
58 assert.equal(installedAppOf("int-linear")?.path("acme"), "/acme/-/integrations/trackers");
59 // AI providers are the workspace's AI settings, not apps.
60 assert.equal(installedAppOf("int-anthropic"), null);
61 assert.equal(installedAppOf("int-webhooks")?.path("acme"), "/acme/-/webhooks");
62 assert.equal(installedAppOf(integrationAppKey("github"))?.listing, "integration:github");
63 // Every key fits what identity keeps (MAX_DOCK_APP_KEY, 32).
64 assert.ok(integrationAppKey("anthropic-endpoint").length <= 32);
65});
66
67test("installed apps are what the workspace connected, opening where each is managed", () => {
68 const apps = installedApps({ sentry: { manage: "/acme/-/integrations/alerts" }, github: { manage: null }, nonsense: { manage: null } });
69 assert.deepEqual(apps.map((app) => app.key), ["int-github", "int-sentry"]);
70 assert.equal(apps[0]!.path("acme"), "/new/github?workspace=acme");
71 assert.deepEqual(appData(apps[1]!, "acme").href, "/acme/-/integrations/alerts");
72 assert.deepEqual(installedApps({}), []);
73 assert.deepEqual(
74 installedApps({ sentry: { manage: null }, anthropic: { manage: null } }).map((app) => [app.key, app.from, app.pinnable]),
75 // AI providers are the workspace's AI settings, not apps.
76 [["int-sentry", "g1t", true]],
77 );
78});
79
80test("pins are kept per workspace, in the order they were pinned", () => {
81 const value = writeDock(writeDock(null, "acme", ["int-sentry", "int-linear"]), "Beta", ["int-jira"]);
82 assert.equal(value, "beta:int-jira,acme:int-sentry.int-linear");
83 assert.deepEqual(pinsIn(value, "acme"), ["int-sentry", "int-linear"]);
84 assert.deepEqual(pinsIn(value, "BETA"), ["int-jira"]);
85 assert.deepEqual(pinsIn(value, "other"), []);
86 // Unpinning everything keeps the workspace, with no pins.
87 assert.deepEqual(pinsIn(writeDock(value, "acme", []), "acme"), []);
88});
89
90test("a cookie someone wrote by hand reads as far as it makes sense", () => {
91 assert.deepEqual(readDock("acme:int-sentry.today.nonsense.int-sentry,BAD SLUG:int-jira,beta"), { acme: ["int-sentry"] });
92 assert.deepEqual(readDock(""), {});
93 const many = Array.from({ length: 30 }, () => "int-sentry").join(".");
94 assert.ok(pinsIn(`acme:${many}`, "acme").length <= MAX_APP_PINS);
95});
96
97test("pins of built-in pages from before are dropped", () => {
98 assert.deepEqual(pinsFrom(["usage", "int-sentry", "projects", "today", "int-sentry", "teams", "int-linear"]), ["int-sentry", "int-linear"]);
99 assert.deepEqual(pinsIn("acme:projects.usage.teams", "acme"), []);
100 assert.deepEqual(pinsFrom([]), []);
101});
102
103test("the account's pins win over the cookie, which is the fallback", () => {
104 const cookie = writeDock(null, "acme", ["int-sentry", "int-linear"]);
105 // Saved with the account, even with nothing pinned: the account's.
106 assert.deepEqual(pinsToShow(["int-jira"], cookie, "acme"), ["int-jira"]);
107 assert.deepEqual(pinsToShow([], cookie, "acme"), []);
108 // Never saved, or identity could not be asked: this device's cookie.
109 assert.deepEqual(pinsToShow(null, cookie, "acme"), ["int-sentry", "int-linear"]);
110 assert.deepEqual(pinsToShow(undefined, null, "acme"), []);
111});
112
113test("a pin form pins or unpins one app", () => {
114 const form = (fields: Record<string, string>) => {
115 const data = new FormData();
116 for (const [name, value] of Object.entries(fields)) data.set(name, value);
117 return data;
118 };
119 assert.deepEqual(appPinFromForm(form({ intent: "pin", app: "int-sentry" })), { app: "int-sentry", pinned: true });
120 assert.deepEqual(appPinFromForm(form({ intent: "unpin", app: "int-sentry" })), { app: "int-sentry", pinned: false });
121 assert.equal(appPinFromForm(form({ intent: "pin", app: "chat" })), null);
122 assert.equal(appPinFromForm(form({ intent: "pin", app: "teams" })), null);
123 assert.equal(appPinFromForm(form({ intent: "drop", app: "int-sentry" })), null);
124 assert.deepEqual(withPin(["int-sentry", "int-jira"], "int-sentry", true), ["int-jira", "int-sentry"]);
125 assert.deepEqual(withPin(["int-sentry", "int-jira"], "int-sentry", false), ["int-jira"]);
126});
127
128test("the cookies last a year and are secure when the site is", () => {
129 assert.match(dockCookie("acme:int-sentry", true), /^g1t_dock=acme%3Aint-sentry; Path=\/; Max-Age=31536000; SameSite=Lax; Secure$/);
130 assert.equal(sidebarCookie(true, false), "g1t_sidebar=closed; Path=/; Max-Age=31536000; SameSite=Lax");
131 assert.equal(sidebarClosed("closed"), true);
132 assert.equal(sidebarClosed("open"), false);
133 assert.equal(sidebarClosed(null), false);
134});