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.

171 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import {
5 KIND_CHOICES,
6 KIND_CHOICE_SETS,
7 bare,
8 choiceOf,
9 hasRelease,
10 kindLabel,
11 latestTag,
12 libraryPackages,
13 neverDeploys,
14 primaryLink,
15 projectPlan,
16 projectChanges,
17 linksFromForm,
18 linksToShow,
19 packageLine,
20 packagePath,
21 publishGuide,
22} from "./project-kind.ts";
23
24const pkg = (over: Record<string, unknown>) => ({
25 ecosystem: "composer" as const,
26 name: "psr/log",
27 workspace: "flagon-io",
28 latest: "3.0.2",
29 versions: 3,
30 updated_at: "2026-10-01T00:00:00Z",
31 ...over,
32});
33
34test("a package reads as its registry, its name and its latest version", () => {
35 assert.equal(packageLine(pkg({})), "Composer · psr/log 3.0.2");
36 assert.equal(packageLine(pkg({ ecosystem: "npm", name: "ui", latest: null })), "npm · @flagon-io/ui");
37 assert.equal(packagePath(pkg({})), "/flagon-io/-/packages/composer/psr/log");
38});
39
40test("what a library publishes comes before an image, released ones first", () => {
41 const list = [
42 pkg({ ecosystem: "container", name: "img", updated_at: "2026-10-05T00:00:00Z" }),
43 pkg({ name: "empty", versions: 0, updated_at: "2026-10-04T00:00:00Z" }),
44 pkg({}),
45 ];
46 assert.deepEqual(
47 libraryPackages(list).map((p) => p.name),
48 ["psr/log", "empty", "img"],
49 );
50 assert.equal(hasRelease(list), true);
51 assert.equal(hasRelease([pkg({ versions: 0 })]), false);
52 assert.equal(hasRelease([]), false);
53});
54
55test("each ecosystem links to how it publishes", () => {
56 assert.equal(publishGuide("composer")?.guide, "https://docs.g1t.sh/guides/composer/");
57 assert.equal(publishGuide("composer")?.start, "git tag v1.0.0 && git push --tags");
58 assert.equal(publishGuide("npm")?.start, "npm publish");
59 assert.equal(publishGuide("go")?.guide, "https://docs.g1t.sh/guides/go/");
60 assert.equal(publishGuide("python")?.guide, "https://docs.g1t.sh/guides/packages/");
61 assert.equal(publishGuide(null), null);
62});
63
64test("each choice sets a kind and where it runs, and reads back", () => {
65 for (const choice of KIND_CHOICES) {
66 const set = KIND_CHOICE_SETS[choice.value];
67 const setting = { kind: set.kind === "auto" ? null : set.kind, runs: set.runs === "auto" ? null : set.runs };
68 assert.equal(choiceOf(setting), choice.value);
69 }
70 // Set through the API to an app, with where it runs left open: no choice says that.
71 assert.equal(choiceOf({ kind: "app", runs: null }), null);
72});
73
74test("a project's badge says what it is and where it runs", () => {
75 assert.equal(kindLabel({ kind: "app", runs: "elsewhere" }), "App, deploys itself");
76 assert.equal(kindLabel({ kind: "app", runs: "g1t" }), "App on g1t.page");
77 assert.equal(kindLabel({ kind: "app", runs: null }), "App");
78 assert.equal(kindLabel({ kind: "tool", runs: null }), "Tool");
79 assert.equal(kindLabel({ kind: "other", runs: null }), "Project");
80});
81
82test("links show homepage, docs, then the rest, never twice", () => {
83 const links = {
84 homepage: "https://g1t.sh/",
85 homepageInherited: false,
86 docs: "https://docs.g1t.sh",
87 custom: [
88 { label: "Status", url: "https://status.g1t.sh" },
89 { label: "Docs again", url: "http://docs.g1t.sh/" },
90 ],
91 };
92 assert.deepEqual(
93 linksToShow(links).map((link) => [link.type, link.label]),
94 [
95 ["homepage", "g1t.sh"],
96 ["docs", "Docs"],
97 ["custom", "Status"],
98 ],
99 );
100 // Production's address already shows on the page: the homepage pointing there is left out.
101 assert.deepEqual(
102 linksToShow(links, ["https://g1t.sh"]).map((link) => link.type),
103 ["docs", "custom"],
104 );
105 assert.equal(bare("https://g1t.sh/docs/"), "g1t.sh/docs");
106});
107
108test("an overview form changes only what it carries", () => {
109 const kind = new FormData();
110 kind.set("choice", "elsewhere");
111 kind.set("productionUrl", "g1t.sh");
112 assert.deepEqual(projectChanges(kind), { kind: "app", runs: "elsewhere", productionUrl: "g1t.sh" });
113 const about = new FormData();
114 about.set("description", "");
115 about.set("homepage", "https://g1t.sh");
116 about.set("links", "rows");
117 // Every row removed: the list is cleared, not left as it was.
118 assert.deepEqual(projectChanges(about), { description: "", homepage: "https://g1t.sh", links: [] });
119 const bogus = new FormData();
120 bogus.set("choice", "sometimes");
121 assert.deepEqual(projectChanges(bogus), {});
122});
123
124test("the latest release is the newest tag by its commit", () => {
125 assert.deepEqual(
126 latestTag([
127 { name: "v1.0.0", commit: { authoredAt: "2026-09-01T00:00:00Z" } },
128 { name: "v1.1.0", commit: { authoredAt: "2026-10-01T00:00:00Z" } },
129 { name: "nightly", commit: null },
130 ]),
131 { name: "v1.1.0", at: "2026-10-01T00:00:00Z" },
132 );
133 assert.equal(latestTag([]), null);
134});
135
136test("cards show production, else the homepage or docs", () => {
137 const links = { homepage: "https://acme.dev", homepageInherited: false, docs: "https://docs.acme.dev", custom: [] };
138 assert.equal(primaryLink({ runs: "g1t", productionUrl: null, links }, "https://web-acme.g1t.page"), "https://web-acme.g1t.page");
139 assert.equal(primaryLink({ runs: "elsewhere", productionUrl: "https://app.acme.dev", links }, null), "https://app.acme.dev");
140 assert.equal(primaryLink({ runs: null, productionUrl: null, links }, null), "https://acme.dev");
141 assert.equal(primaryLink({ runs: null, productionUrl: null, links: { ...links, homepage: null } }, null), "https://docs.acme.dev");
142 assert.equal(neverDeploys({ setting: { kind: "tool", runs: null } }), true);
143 assert.equal(neverDeploys({ setting: { kind: "docs", runs: null } }), false);
144});
145
146test("custom links are read from a form's rows, blank rows left out", () => {
147 const form = new FormData();
148 for (const [label, url] of [
149 ["Status", "status.g1t.sh"],
150 ["", ""],
151 ["", "npmjs.com/x"],
152 ]) {
153 form.append("linkLabel", label!);
154 form.append("linkUrl", url!);
155 }
156 assert.deepEqual(linksFromForm(form), [
157 { label: "Status", url: "status.g1t.sh" },
158 { label: "", url: "npmjs.com/x" },
159 ]);
160});
161
162test("only what g1t deploys leads with production", () => {
163 assert.equal(projectPlan({ kind: "app", runs: "g1t" }), "production");
164 assert.equal(projectPlan({ kind: "docs", runs: "g1t" }), "production");
165 assert.equal(projectPlan({ kind: "app", runs: "elsewhere" }), "elsewhere");
166 assert.equal(projectPlan({ kind: "app", runs: null }), "unknown");
167 assert.equal(projectPlan({ kind: "tool", runs: null }), "release");
168 assert.equal(projectPlan({ kind: "library", runs: null }), "release");
169 assert.equal(projectPlan({ kind: "docs", runs: "elsewhere" }), "docs");
170 assert.equal(projectPlan({ kind: "other", runs: null }), "other");
171});