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.

46 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { type ApiSessionTouch, sessionTitle, sessionsQuery, subagentTree, touchedFiles } from "./sessions.ts";
5
6test("subagents are a tree under their session, in the order they started", () => {
7 const children = [
8 { id: "b", parent_id: "root", started_at: "2026-10-17T10:02:00Z" },
9 { id: "a1", parent_id: "a", started_at: "2026-10-17T10:03:00Z" },
10 { id: "a", parent_id: "root", started_at: "2026-10-17T10:01:00Z" },
11 // Its parent is not in the list: it sits under the root.
12 { id: "c", parent_id: "gone", started_at: "2026-10-17T10:04:00Z" },
13 ];
14 assert.deepEqual(
15 subagentTree("root", children).map(({ session, depth }) => [session.id, depth]),
16 [
17 ["a", 1],
18 ["a1", 2],
19 ["b", 1],
20 ["c", 1],
21 ],
22 );
23});
24
25test("the files a session touched, once each", () => {
26 const touched: ApiSessionTouch[] = [
27 { session_id: "s", kind: "file", value: "src/b.ts", at: "2026-10-17T10:02:00Z" },
28 { session_id: "s", kind: "commit", value: "abc", at: "2026-10-17T10:00:00Z" },
29 { session_id: "t", kind: "file", value: "src/a.ts", at: "2026-10-17T10:01:00Z" },
30 { session_id: "t", kind: "file", value: "src/b.ts", at: "2026-10-17T10:03:00Z" },
31 ];
32 assert.deepEqual(touchedFiles(touched), ["src/a.ts", "src/b.ts"]);
33 assert.deepEqual(touchedFiles(undefined), []);
34});
35
36test("a session's name is its title, else its task or first prompt", () => {
37 assert.equal(sessionTitle({ title: "Fix login", task: null, first_prompt: null, agent_type: null }), "Fix login");
38 assert.equal(sessionTitle({ title: null, task: null, first_prompt: "Look at the queue\nand more", agent_type: null }), "Look at the queue");
39 assert.equal(sessionTitle({ title: null, task: null, first_prompt: null, agent_type: "Explore" }), "Explore subagent");
40 assert.equal(sessionTitle(null), "Untitled session");
41});
42
43test("the list's filters are the API's", () => {
44 assert.equal(sessionsQuery({ state: "live" }), "state=live");
45 assert.equal(sessionsQuery({ state: "ended", person: "ada", repo: "web", item: 4 }), "state=ended&person=ada&repo=web&item=4");
46});