@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 56 lines 2.57 KB
Raw
1 import { IssueTrackerKind } from "@t3tools/contracts";
2 import { expect, it } from "@effect/vitest";
3 import * as Effect from "effect/Effect";
4 import * as Schema from "effect/Schema";
5 import * as SqlClient from "effect/sql/SqlClient";
6
7 import * as SqlitePersistence from "../persistence/Sqlite.ts";
8 import { listLinkedIssueThreads } from "./linkedThreads.ts";
9
10 const encodePayload = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
11
12 it.effect("finds every thread linked to exactly one issue, newest activity first", () =>
13 Effect.gen(function* () {
14 const sql = yield* SqlClient.SqlClient;
15 const at = (day: number) => `2026-11-0${day}T00:00:00.000Z`;
16 const issue = { tracker: "linear", host: "linear.app", scope: "eng", key: "ENG-7" };
17 const fixtures = [
18 { id: "older", day: 1, issues: [issue] },
19 { id: "newer", day: 2, issues: [{ ...issue, key: "ENG-8" }, issue] },
20 { id: "settled", day: 3, issues: [issue], payload: { settledOverride: "settled" } },
21 { id: "archived", day: 4, issues: [issue], archived: true },
22 { id: "deleted", day: 5, issues: [issue], deleted: true },
23 { id: "side-chat", day: 5, issues: [issue], payload: { lineage: { sideChat: true } } },
24 { id: "other-key", day: 5, issues: [{ ...issue, key: "ENG-70" }] },
25 { id: "other-scope", day: 5, issues: [{ ...issue, scope: "design" }] },
26 { id: "other-tracker", day: 5, issues: [{ ...issue, tracker: "github" }] },
27 { id: "unlinked", day: 5, issues: [] },
28 ];
29 for (const fixture of fixtures) {
30 const payload = yield* encodePayload({ ...fixture.payload, issues: fixture.issues });
31 yield* sql`
32 INSERT INTO orchestration_v2_projection_threads (
33 thread_id, project_id, title, default_provider, runtime_mode, interaction_mode,
34 created_at, updated_at, archived_at, deleted_at, payload_json
35 ) VALUES (
36 ${fixture.id}, 'project-1', ${fixture.id}, 'codex', 'full-access', 'default',
37 ${at(1)}, ${at(fixture.day)}, ${fixture.archived ? at(fixture.day) : null},
38 ${fixture.deleted ? at(fixture.day) : null}, ${payload}
39 )
40 `;
41 }
42
43 const result = yield* listLinkedIssueThreads({
44 tracker: IssueTrackerKind.make("linear"),
45 host: "Linear.app",
46 scope: "ENG",
47 key: "ENG-7",
48 });
49 expect(result.threads.map((thread) => [thread.id, thread.settled, thread.archivedAt])).toEqual([
50 ["archived", false, at(4)],
51 ["settled", true, null],
52 ["newer", false, null],
53 ["older", false, null],
54 ]);
55 }).pipe(Effect.provide(SqlitePersistence.layerMemory)),
56 );