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.

g1t.sh
161 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { DirectoryPerson, DirectoryTeam, PeopleDirectory } from "@g1t/contracts";
5
6import {
7 type PeopleAgent,
8 NO_TEAM,
9 agentPath,
10 agentsOn,
11 groupByTeam,
12 teamsByAgent,
13 budgetFromText,
14 codeAccessWords,
15 directoryEntries,
16 ownsFromText,
17 teamBlock,
18 teamsOfAgent,
19} from "./people.ts";
20
21const person = (username: string, extra: Partial<DirectoryPerson> = {}): DirectoryPerson => ({
22 user_id: `usr_${username}`,
23 username,
24 name: null,
25 avatar: null,
26 bio: null,
27 location: null,
28 pronouns: null,
29 timezone: null,
30 role: "member",
31 title: null,
32 owns: [],
33 joined_at: "2026-10-01T00:00:00Z",
34 ...extra,
35});
36
37const team = (slug: string, name: string, extra: Partial<DirectoryTeam> = {}): DirectoryTeam => ({
38 slug,
39 name,
40 description: null,
41 visibility: "visible",
42 parent: null,
43 lead: null,
44 channel: null,
45 budget_micros: null,
46 people: [],
47 agent_ids: [],
48 repos_count: 0,
49 ...extra,
50});
51
52const agent = (id: string, handle: string, extra: Partial<PeopleAgent> = {}): PeopleAgent => ({
53 id,
54 handle,
55 display_name: handle[0]!.toUpperCase() + handle.slice(1),
56 avatar: null,
57 avatar_seed: handle,
58 title: "",
59 role: "",
60 status: "idle",
61 responsibilities: [],
62 builtin: false,
63 spent_month_micros: 0,
64 ...extra,
65});
66
67const directory: PeopleDirectory = {
68 people: [
69 person("chase", { name: "Chase Pierce", title: "Founder", role: "owner" }),
70 person("sofia", { name: "Sofia Reyes", title: "Head of Sales", owns: ["the forecast"] }),
71 person("jordan", { name: "Jordan Lee", title: "Account Executive", owns: ["Halcyon", "Bluebird"] }),
72 person("kai", { name: "Kai Nakamura", title: "Product Designer" }),
73 ],
74 teams: [
75 team("sales", "Sales", {
76 lead: { kind: "user", username: "sofia", name: "Sofia Reyes", avatar: null },
77 people: [
78 { username: "sofia", role: "maintainer" },
79 { username: "jordan", role: "member" },
80 ],
81 agent_ids: ["agt_david"],
82 repos_count: 0,
83 }),
84 team("design", "Design", { people: [{ username: "kai", role: "maintainer" }], repos_count: 2 }),
85 team("night-shift", "Night shift", { lead: { kind: "agent", agent_id: "agt_atlas" }, agent_ids: ["agt_atlas", "agt_sentinel", "agt_david"] }),
86 ],
87 base_permission: "read",
88 can_manage: true,
89};
90
91const agents = [
92 agent("agt_david", "david", { title: "CRM keeper" }),
93 agent("agt_atlas", "atlas", { title: "Night watch" }),
94 agent("agt_sentinel", "sentinel", { title: "Error watch", responsibilities: ["Watches errors"] }),
95 agent("agt_pax", "pax", { title: "Billing" }),
96];
97
98test("an agent is on the teams it is a member of, like anyone", () => {
99 assert.deepEqual(agentsOn(directory.teams[2]!, agents).map((a) => a.id), ["agt_atlas", "agt_sentinel", "agt_david"]);
100 assert.deepEqual(teamsOfAgent(directory.teams, agents[0]!).map((t) => t.slug), ["sales", "night-shift"]);
101 assert.deepEqual(teamsOfAgent(directory.teams, agents[3]!), []);
102});
103
104test("the Agents sidebar groups agents by their teams: under each team, and the rest last", () => {
105 const teams = teamsByAgent(directory.teams);
106 assert.deepEqual(teams.agt_david, [{ slug: "night-shift", name: "Night shift" }, { slug: "sales", name: "Sales" }]);
107 const groups = groupByTeam(agents, teams).map((g) => [g.label, g.agents.map((a) => a.handle)]);
108 assert.deepEqual(groups, [
109 ["Night shift", ["atlas", "david", "sentinel"]],
110 ["Sales", ["david"]],
111 [NO_TEAM, ["pax"]],
112 ]);
113 assert.deepEqual(groupByTeam(agents.slice(3), {}).map((g) => g.label), [NO_TEAM]);
114});
115
116test("the directory lists people only, in one search; agents are never in it", () => {
117 const names = (query: string) => directoryEntries(directory, query).map((e) => e.person.username);
118 assert.deepEqual(names(""), ["chase", "sofia", "jordan", "kai"]);
119 assert.deepEqual(names("sales"), ["sofia", "jordan"]);
120 assert.deepEqual(names("halcyon"), ["jordan"]);
121 assert.deepEqual(names("owner"), ["chase"]);
122 // What only an agent would match (its handle, title or responsibilities) finds no one here.
123 assert.deepEqual(names("david"), []);
124 assert.deepEqual(names("errors"), []);
125 // A team of agents only is no one's team in the directory.
126 assert.deepEqual(names("night shift"), []);
127 assert.equal(names("nobody here").length, 0);
128 // Every entry is a person with their teams; nothing in the shape says "agent".
129 const sofia = directoryEntries(directory, "sofia")[0]!;
130 assert.deepEqual(Object.keys(sofia), ["person", "teams"]);
131 assert.deepEqual(sofia.teams.map((t) => t.slug), ["sales"]);
132});
133
134test("an agent's profile is its page in Agents, where People links to it", () => {
135 assert.equal(agentPath("acme", "margo"), "/acme/-/agents/margo");
136});
137
138test("forms read plainly", () => {
139 assert.deepEqual(ownsFromText("storefront\n the release process ,, billing"), ["storefront", "the release process", "billing"]);
140 assert.equal(budgetFromText(""), 0);
141 assert.equal(budgetFromText("$150"), 150_000_000);
142 assert.equal(budgetFromText("1,250.50"), 1_250_500_000);
143 assert.equal(budgetFromText("lots"), null);
144 assert.equal(budgetFromText("-5"), null);
145});
146
147test("access to Code says where it comes from", () => {
148 assert.equal(codeAccessWords({ role: "owner" }, "read", []).summary, "Admin on every repository, as an owner");
149 const kai = codeAccessWords({ role: "member" }, "read", [directory.teams[1]!]);
150 assert.equal(kai.summary, "Read on every repository, the workspace's base permission");
151 assert.deepEqual(kai.through, ["Roles on 2 repositories through Design"]);
152 assert.equal(codeAccessWords({ role: "member" }, "none", []).summary, "Only repositories they're given a role on");
153});
154
155test("a team's part of what an agent is told", () => {
156 const told = "## Your teams\n\nIntro.\n\n### Sales\n\nLed by Sofia.\n- @sofia\n\n### Support\n\n- @dev";
157 assert.equal(teamBlock(told, "Sales"), "### Sales\n\nLed by Sofia.\n- @sofia");
158 assert.equal(teamBlock(told, "Support"), "### Support\n\n- @dev");
159 assert.equal(teamBlock(told, "Design"), null);
160 assert.equal(teamBlock(null, "Sales"), null);
161});