Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

linkedThreads.test.ts

147 lines4.9 KB

1import { assert, expect, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as SqlClient from "effect/unstable/sql/SqlClient";
4​
5import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
6import { listLinkedPullRequestThreads } from "./linkedThreads.ts";
7​
8it.effect(
9 "finds active and archived threads for exactly one pull request, excluding deleted and dismissed links",
10 () =>
11 Effect.gen(function* () {
12 const sql = yield* SqlClient.SqlClient;
13 const createdAt = "2026-09-01T00:00:00.000Z";
14 const archivedAt = "2026-09-03T00:00:00.000Z";
15 yield* sql`
16 INSERT INTO projection_projects (project_id, title, workspace_root, scripts_json, created_at, updated_at)
17 VALUES ('project-1', 'Project', '/tmp/project', '[]', ${createdAt}, ${createdAt})
18 `;
19 const fixtures = [
20 {
21 id: "forgejo-old",
22 host: "forge.example",
23 repository: "acme/web",
24 number: 7,
25 source: "manual",
26 url: "http://forge.example:3000/acme/web/pulls/7",
27 },
28 {
29 id: "forgejo-other-port",
30 host: "forge.example:4000",
31 repository: "acme/web",
32 number: 7,
33 source: "manual",
34 url: "http://forge.example:4000/acme/web/pulls/7",
35 },
36 {
37 id: "azure",
38 host: "dev.azure.com",
39 repository: "org/project/_git/web",
40 number: 7,
41 source: "manual",
42 },
43 {
44 id: "other-org",
45 host: "dev.azure.com",
46 repository: "other/project/_git/web",
47 number: 7,
48 source: "manual",
49 },
50 { id: "active", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
51 {
52 id: "archived",
53 host: "github.com",
54 repository: "acme/web",
55 number: 7,
56 source: "created",
57 },
58 { id: "deleted", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
59 {
60 id: "dismissed",
61 host: "github.com",
62 repository: "acme/web",
63 number: 7,
64 source: "stack-dismissed",
65 },
66 {
67 id: "other-host",
68 host: "github.example.com",
69 repository: "acme/web",
70 number: 7,
71 source: "manual",
72 },
73 {
74 id: "other-repository",
75 host: "github.com",
76 repository: "acme/api",
77 number: 7,
78 source: "manual",
79 },
80 {
81 id: "other-number",
82 host: "github.com",
83 repository: "acme/web",
84 number: 8,
85 source: "manual",
86 },
87 ];
88 for (const fixture of fixtures) {
89 yield* sql`
90 INSERT INTO projection_threads (
91 thread_id, project_id, title, model_selection_json, created_at, updated_at, archived_at, deleted_at
92 ) VALUES (
93 ${fixture.id}, 'project-1', ${fixture.id}, '{"instanceId":"codex","model":"gpt-5.4"}',
94 ${createdAt}, ${fixture.id === "archived" ? archivedAt : createdAt},
95 ${fixture.id === "archived" ? archivedAt : null},
96 ${fixture.id === "deleted" ? archivedAt : null}
97 )
98 `;
99 yield* sql`
100 INSERT INTO projection_thread_pull_requests (thread_id, host, repository, number, url, source, linked_at)
101 VALUES (${fixture.id}, ${fixture.host}, ${fixture.repository}, ${fixture.number},
102 ${fixture.url ?? "https://github.com/acme/web/pull/7"}, ${fixture.source}, ${createdAt})
103 `;
104 }
105​
106 expect(
107 (yield* listLinkedPullRequestThreads({
108 host: "forge.example:3000",
109 repository: "acme/web",
110 number: 7,
111 })).threads.map((thread) => thread.id),
112 ).toEqual(["forgejo-old"]);
113 expect(
114 (yield* listLinkedPullRequestThreads({
115 host: "forge.example:4000",
116 repository: "acme/web",
117 number: 7,
118 })).threads.map((thread) => thread.id),
119 ).toEqual(["forgejo-other-port"]);
120 expect(
121 (yield* listLinkedPullRequestThreads({
122 host: "org.visualstudio.com",
123 repository: "project/_git/web",
124 number: 7,
125 })).threads.map((thread) => thread.id),
126 ).toEqual(["azure"]);
127 const result = yield* listLinkedPullRequestThreads({
128 host: "GitHub.Com",
129 repository: "ACME/WEB",
130 number: 7,
131 });
132 expect(result).toEqual({
133 threads: [
134 { id: "archived", projectId: "project-1", title: "archived", archivedAt },
135 { id: "active", projectId: "project-1", title: "active", archivedAt: null },
136 ],
137 });
138 assert.deepStrictEqual(
139 yield* listLinkedPullRequestThreads({
140 host: "github.com",
141 repository: "acme/web",
142 number: 99,
143 }),
144 { threads: [] },
145 );
146 }).pipe(Effect.provide(SqlitePersistenceMemory)),
147);