Skip to content
60 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { askPage, askWhere, foldAnswer, proposalTitle } from "./ask.ts";
5
6test("the page says which repository, issue or pull request the person is on", () => {
7 assert.deepEqual(askPage("/Acme/web/issues/12"), { path: "/Acme/web/issues/12", repo: { namespace: "acme", name: "web" }, issue: 12 });
8 assert.deepEqual(askPage("/acme/web/pull/3/files"), { path: "/acme/web/pull/3/files", repo: { namespace: "acme", name: "web" }, pull: 3 });
9 assert.deepEqual(askPage("/acme/web/tree/main"), { path: "/acme/web/tree/main", repo: { namespace: "acme", name: "web" } });
10 assert.deepEqual(askPage("/acme/web/issues"), { path: "/acme/web/issues", repo: { namespace: "acme", name: "web" } });
11 // A workspace's own pages, and g1t's, name no repository.
12 assert.deepEqual(askPage("/acme/-/chat/general"), { path: "/acme/-/chat/general" });
13 assert.deepEqual(askPage("/settings/profile"), { path: "/settings/profile" });
14 assert.deepEqual(askPage("/acme"), { path: "/acme" });
15 assert.deepEqual(askPage(""), { path: "/" });
16});
17
18test("the composer says where the question is asked from", () => {
19 assert.equal(askWhere(askPage("/acme/web/issues/12")), "On issue #12");
20 assert.equal(askWhere(askPage("/acme/web/pull/3")), "On pull request #3");
21 assert.equal(askWhere(askPage("/acme/web")), "In web");
22 assert.equal(askWhere(askPage("/acme/-/chat")), null);
23});
24
25test("an answer's kept lines fold into its steps, each as it last was, and its sources", () => {
26 const started = {
27 type: "tool" as const,
28 id: "step_0_0",
29 name: "workspace",
30 action: "activity",
31 label: "Read activity in acme since 2026-10-12",
32 status: "running" as const,
33 summary: null,
34 link: "https://g1t.sh/acme",
35 };
36 const folded = foldAnswer([
37 started,
38 { ...started, id: "step_0_1", name: "repository", action: "list", label: "Listed repositories" },
39 { ...started, status: "done", summary: "12 results" },
40 { type: "text", text: "ignored" },
41 null,
42 { type: "sources", sources: [{ title: "#7 Fix login", url: "https://g1t.sh/acme/web/pull/7", cited: true }, { url: 3 }] },
43 ]);
44 assert.deepEqual(
45 folded.steps.map((step) => [step.id, step.status, step.summary]),
46 [
47 ["step_0_0", "done", "12 results"],
48 ["step_0_1", "running", null],
49 ],
50 );
51 assert.equal(folded.sources.length, 1);
52 assert.equal(folded.sources[0]!.url, "https://g1t.sh/acme/web/pull/7");
53 assert.deepEqual(foldAnswer("junk"), { steps: [], sources: [], proposals: [] });
54});
55
56test("a proposed session is kept once and says what it will do", () => {
57 const proposal = { type: "proposal" as const, id: "proposal_0_0", repo: "acme/web", issue: 12, title: null, body: null, mode: "implement" as const, instruction: null };
58 const folded = foldAnswer([proposal, proposal, { ...proposal, id: "proposal_0_1", issue: null, title: "Add a route", mode: "plan" }, { type: "proposal", id: "x", repo: "acme/web" }]);
59 assert.deepEqual(folded.proposals.map(proposalTitle), ["Implement #12 in acme/web", "Plan “Add a route” in acme/web"]);
60});