Skip to content
62 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { cleanTitle, defaultWhere, threadLink, whereWords, writableSpaces, writeUpAgents, writeUpMessage } from "./write-up.ts";
5
6test("a thread's link is its conversation with ?thread=", () => {
7 assert.equal(threadLink("https://g1t.sh/", "/acme/-/chat/launch", "msg_1"), "https://g1t.sh/acme/-/chat/launch?thread=msg_1");
8 assert.equal(threadLink("https://g1t.sh", "/acme/-/chat/dm/chn_1", "a b"), "https://g1t.sh/acme/-/chat/dm/chn_1?thread=a%20b");
9});
10
11const spaces = writableSpaces([
12 { id: "s1", name: "Design", viewer_role: "edit", archived_at: null },
13 { id: "s2", name: "Board", viewer_role: "view", archived_at: null },
14 { id: "s3", name: "Old", viewer_role: "manage", archived_at: "2026-01-01T00:00:00Z" },
15 { id: "s4", name: "General", viewer_role: "manage", archived_at: null, is_default: true },
16 { id: "s5", name: "Notes", viewer_role: "comment", archived_at: null },
17]);
18
19test("only spaces the person can add to, not archived, General first", () => {
20 assert.deepEqual(spaces, [
21 { id: "s4", name: "General", is_default: true },
22 { id: "s1", name: "Design", is_default: false },
23 ]);
24});
25
26test("it goes to the conversation in a DM or private channel; to General, else Private, in a public one", () => {
27 assert.deepEqual(defaultWhere(true, spaces), { kind: "conversation" });
28 assert.deepEqual(defaultWhere(false, spaces), { kind: "space", id: "s4", name: "General" });
29 assert.deepEqual(defaultWhere(false, spaces.filter((s) => !s.is_default)), { kind: "private" });
30});
31
32test("@g1t is always offered first, then the conversation's agents, once each", () => {
33 const agents = writeUpAgents([
34 { kind: "user", name: "ana", display_name: "Ana" },
35 { kind: "agent", name: "Scribe", display_name: "Scribe" },
36 { kind: "agent", name: "g1t", display_name: "g1t" },
37 { kind: "agent", name: "scribe", display_name: "Scribe" },
38 { kind: "agent", name: "qa", display_name: " " },
39 ]);
40 assert.deepEqual(agents, [
41 { handle: "g1t", name: "g1t" },
42 { handle: "scribe", name: "Scribe" },
43 { handle: "qa", name: "qa" },
44 ]);
45});
46
47test("a title is one line without double quotes", () => {
48 assert.equal(cleanTitle(' The "launch"\n plan '), "The 'launch' plan");
49 assert.equal(cleanTitle(null), "");
50 assert.equal(cleanTitle("x".repeat(200)).length, 120);
51});
52
53test("the ask names the agent, the kind, where it goes, the title if any, and the thread to cite", () => {
54 const link = "https://g1t.sh/acme/-/chat/launch?thread=msg_1";
55 assert.equal(
56 writeUpMessage({ agent: "g1t", where: { kind: "space", id: "s1", name: "Engineering" }, title: "Launch plan", link }),
57 `@g1t write this thread up as an artifact (a doc) in the Engineering space titled "Launch plan". Link this thread as the source: ${link}`,
58 );
59 assert.equal(writeUpMessage({ agent: "@Scribe", where: { kind: "private" }, title: " ", link }), `@scribe write this thread up as an artifact (a doc) privately (just for me). Link this thread as the source: ${link}`);
60 assert.equal(whereWords({ kind: "conversation" }), "shared with this conversation");
61 assert.equal(whereWords({ kind: "space", id: "s", name: " Product notes " }), "in the Product notes space");
62});