Open History to see the last commit
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: "azure",
22 host: "dev.azure.com",
23 repository: "org/project/_git/web",
24 number: 7,
25 source: "manual",
26 },
27 {
28 id: "other-org",
29 host: "dev.azure.com",
30 repository: "other/project/_git/web",
31 number: 7,
32 source: "manual",
33 },
34 { id: "active", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
35 {
36 id: "archived",
37 host: "github.com",
38 repository: "acme/web",
39 number: 7,
40 source: "created",
41 },
42 { id: "deleted", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
43 {
44 id: "dismissed",
45 host: "github.com",
46 repository: "acme/web",
47 number: 7,
48 source: "stack-dismissed",
49 },
50 {
51 id: "other-host",
52 host: "github.example.com",
53 repository: "acme/web",
54 number: 7,
55 source: "manual",
56 },
57 {
58 id: "other-repository",
59 host: "github.com",
60 repository: "acme/api",
61 number: 7,
62 source: "manual",
63 },
64 {
65 id: "other-number",
66 host: "github.com",
67 repository: "acme/web",
68 number: 8,
69 source: "manual",
70 },
71 ];
72 for (const fixture of fixtures) {
73 yield* sql`
74 INSERT INTO projection_threads (
75 thread_id, project_id, title, model_selection_json, created_at, updated_at, archived_at, deleted_at
76 ) VALUES (
77 ${fixture.id}, 'project-1', ${fixture.id}, '{"instanceId":"codex","model":"gpt-5.4"}',
78 ${createdAt}, ${fixture.id === "archived" ? archivedAt : createdAt},
79 ${fixture.id === "archived" ? archivedAt : null},
80 ${fixture.id === "deleted" ? archivedAt : null}
81 )
82 `;
83 yield* sql`
84 INSERT INTO projection_thread_pull_requests (thread_id, host, repository, number, url, source, linked_at)
85 VALUES (${fixture.id}, ${fixture.host}, ${fixture.repository}, ${fixture.number},
86 'https://github.com/acme/web/pull/7', ${fixture.source}, ${createdAt})
87 `;
88 }
89
90 expect(
91 (yield* listLinkedPullRequestThreads({
92 host: "org.visualstudio.com",
93 repository: "project/_git/web",
94 number: 7,
95 })).threads.map((thread) => thread.id),
96 ).toEqual(["azure"]);
97 const result = yield* listLinkedPullRequestThreads({
98 host: "GitHub.Com",
99 repository: "ACME/WEB",
100 number: 7,
101 });
102 expect(result).toEqual({
103 threads: [
104 { id: "archived", projectId: "project-1", title: "archived", archivedAt },
105 { id: "active", projectId: "project-1", title: "active", archivedAt: null },
106 ],
107 });
108 assert.deepStrictEqual(
109 yield* listLinkedPullRequestThreads({
110 host: "github.com",
111 repository: "acme/web",
112 number: 99,
113 }),
114 { threads: [] },
115 );
116 }).pipe(Effect.provide(SqlitePersistenceMemory)),
117);