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.

101 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { linkPathOf, refContext, refRoute, refSitePath, routeFor, sitePathOf, targetRoute } from "./links.ts";
5
6test("a g1t:// link names a site path, as on the desktop", () => {
7 assert.equal(sitePathOf("g1t://acme/-/chat/dm/chn_1"), "/acme/-/chat/dm/chn_1");
8 assert.equal(sitePathOf("g1t:///acme/rocket/pull/3?tab=files"), "/acme/rocket/pull/3?tab=files");
9 assert.equal(sitePathOf("https://g1t.sh/acme"), null);
10});
11
12test("an https link to the site names the same path as a g1t:// one", () => {
13 assert.equal(linkPathOf("https://g1t.sh/acme/-/work/12"), "/acme/-/work/12");
14 assert.equal(linkPathOf("g1t://acme/-/work/12"), "/acme/-/work/12");
15 assert.equal(linkPathOf("https://g1t.sh/acme/-/work?repo=web#top"), "/acme/-/work?repo=web");
16 assert.equal(linkPathOf("https://g1t.sh"), "/");
17 assert.equal(linkPathOf("mailto:someone@example.com"), null);
18});
19
20test("Chat's pages open the app's Chat", () => {
21 assert.equal(routeFor("/acme/-/chat"), "/chat?workspace=acme");
22 assert.equal(routeFor("/acme/-/chat/general"), "/chat/general?workspace=acme");
23 assert.equal(routeFor("/acme/-/chat/dm/chn_1"), "/chat/chn_1?workspace=acme");
24 assert.equal(routeFor("/acme/-/chat/browse"), null);
25});
26
27test("Work's pages open the app's Work", () => {
28 assert.equal(routeFor("/acme/-/work"), "/work?workspace=acme");
29 assert.equal(routeFor("/acme/-/work/12"), "/work/12?workspace=acme");
30 assert.equal(routeFor(linkPathOf("g1t://acme/-/work/12")!), "/work/12?workspace=acme");
31 assert.equal(routeFor(linkPathOf("https://g1t.sh/acme/-/work/12")!), "/work/12?workspace=acme");
32 assert.equal(routeFor("/acme/-/work/new"), "/work/new?workspace=acme");
33 // The list keeps the filters the site's does, and drops anything else.
34 assert.equal(routeFor("/acme/-/work?repo=web&label=bug&page=3"), "/work?workspace=acme&label=bug&repo=web");
35 assert.equal(routeFor("/acme/-/work/labels"), null);
36 assert.equal(routeFor("/acme/-/work/milestones/2"), null);
37 assert.equal(routeFor("/acme/-/work/12/edit"), null);
38});
39
40test("an old link to an issue asks g1t what its number names in its repository", () => {
41 assert.equal(routeFor("/acme/rocket/issues/12"), "/ref?repo=acme%2Frocket&number=12");
42 assert.equal(routeFor(linkPathOf("https://g1t.sh/acme/rocket/issues/12")!), "/ref?repo=acme%2Frocket&number=12");
43 assert.equal(routeFor("/acme/rocket/issues"), "/work?workspace=acme&repo=rocket");
44 assert.equal(routeFor("/acme/rocket/issues/new"), "/work/new?workspace=acme&repo=rocket");
45 assert.equal(routeFor("/acme/rocket/issues/12/edit"), null);
46});
47
48test("Code's pages open the app's Code", () => {
49 assert.equal(routeFor("/acme/rocket"), "/code/acme/rocket");
50 assert.equal(routeFor("/acme/rocket/pull/14"), "/code/acme/rocket/pull/14");
51 assert.equal(routeFor("/acme/-/overview"), "/code?workspace=acme");
52 assert.equal(routeFor("/acme/rocket/pull/14/files"), null);
53 assert.equal(routeFor("/acme/rocket/sessions"), null);
54});
55
56test("#N is read where it was written, owner/name#N in that repository, workspace#N in that workspace", () => {
57 const here = { workspace: "acme" };
58 assert.deepEqual(refContext(null, here), { workspace: "acme" });
59 assert.deepEqual(refContext(null, { repo: "acme/web" }), { repo: "acme/web" });
60 assert.deepEqual(refContext("acme/api", here), { repo: "acme/api" });
61 assert.deepEqual(refContext("globex", here), { workspace: "globex" });
62 assert.equal(refRoute({ workspace: "acme" }, 7), "/ref?workspace=acme&number=7");
63 assert.equal(refRoute({ repo: "acme/web" }, 7), "/ref?repo=acme%2Fweb&number=7");
64});
65
66test("what a reference names opens its screen, and the site reads one the app cannot", () => {
67 assert.equal(targetRoute({ kind: "work_item", workspace: "acme", number: 31, item_id: "wki_1" }), "/work/31?workspace=acme");
68 assert.equal(targetRoute({ kind: "pull", repo: "acme/web", number: 9 }), "/code/acme/web/pull/9");
69 assert.equal(targetRoute({ kind: "pull", repo: "nonsense", number: 9 }), null);
70 assert.equal(targetRoute({ kind: "none" }), null);
71 assert.equal(refSitePath({ repo: "acme/web" }, 9), "/acme/web/issues/9");
72 assert.equal(refSitePath({ workspace: "acme" }, 9), "/acme/-/work/9");
73});
74
75test("old links to Agents, Customize and the Marketplace open Home", () => {
76 assert.equal(routeFor("/acme/-/agents"), "/home?workspace=acme");
77 assert.equal(routeFor("/acme/-/agents/skills"), "/home?workspace=acme");
78 assert.equal(routeFor("/acme/-/agents/skills/pdf"), "/home?workspace=acme");
79 assert.equal(routeFor("/acme/-/customize"), "/home?workspace=acme");
80 assert.equal(routeFor("/acme/-/customize/plugins/pdf%40anthropic-agent-skills"), "/home?workspace=acme");
81 assert.equal(routeFor("/acme/-/marketplace/integrations"), "/home?workspace=acme");
82});
83
84test("the integrations directory stays on the site", () => {
85 assert.equal(routeFor("/acme/-/integrations"), null);
86 assert.equal(routeFor("/acme/-/integrations/github"), null);
87});
88
89test("the app's sign-in comes back to its own screen, and the site's own pages stay on the site", () => {
90 assert.equal(routeFor("/oauth/callback?code=c&state=s"), "/oauth/callback?code=c&state=s");
91 assert.equal(routeFor("/settings/tokens"), null);
92 assert.equal(routeFor("/"), "/");
93});
94
95test("a connect link points the app at a g1t", () => {
96 assert.equal(routeFor("/connect?server=https%3A%2F%2Fg1t.example.com"), "/connect?server=https%3A%2F%2Fg1t.example.com");
97 assert.equal(sitePathOf("g1t://connect?server=https%3A%2F%2Fg1t.example.com"), "/connect?server=https%3A%2F%2Fg1t.example.com");
98 // A workspace named connect is still a workspace.
99 assert.equal(routeFor("/connect/-/chat"), "/chat?workspace=connect");
100 assert.equal(routeFor("/connect/web"), "/code/connect/web");
101});