1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Schema from "effect/Schema";
4
5import { ThreadPullRequestLink } from "./threadPullRequest.ts";
6
7const decodeLinks = Schema.decodeUnknownEffect(Schema.Array(ThreadPullRequestLink));
8
9it.effect("decodes thread pull request links with snapshot and stack", () =>
10 Effect.gen(function* () {
11 const links = yield* decodeLinks([
12 {
13 host: "github.com",
14 repository: "pingdotgg/t3code",
15 number: 42,
16 url: "https://github.com/pingdotgg/t3code/pull/42",
17 source: "agent",
18 linkedAt: "2026-01-01T00:00:00.000Z",
19 snapshot: null,
20 stack: null,
21 },
22 {
23 host: "github.com",
24 repository: "pingdotgg/t3code",
25 number: 43,
26 url: "https://github.com/pingdotgg/t3code/pull/43",
27 source: "stack",
28 linkedAt: "2026-01-01T00:01:00.000Z",
29 snapshot: {
30 state: "open",
31 title: "Layer two",
32 headBranch: "feature/stack-2",
33 baseBranch: "feature/stack-1",
34 isDraft: false,
35 updatedAt: "2026-01-01T00:02:00.000Z",
36 syncedAt: "2026-01-01T00:03:00.000Z",
37 },
38 stack: {
39 kind: "native",
40 id: "7",
41 number: 3,
42 url: "https://github.com/pingdotgg/t3code/stacks/3",
43 base: "main",
44 layers: [
45 { number: 42, headBranch: "feature/stack-1", state: "open" },
46 { number: 43, headBranch: "feature/stack-2", state: "open" },
47 ],
48 },
49 },
50 ]);
51
52 assert.strictEqual(links.length, 2);
53 assert.strictEqual(links[1]?.stack?.layers.length, 2);
54 assert.strictEqual(links[1]?.snapshot?.state, "open");
55 }),
56);
57
58it.effect("decodes a watch saved before passed checks were recorded", () =>
59 Effect.gen(function* () {
60 const [link] = yield* decodeLinks([
61 {
62 host: "github.com",
63 repository: "pingdotgg/t3code",
64 number: 42,
65 url: "https://github.com/pingdotgg/t3code/pull/42",
66 source: "agent",
67 linkedAt: "2026-01-01T00:00:00.000Z",
68 snapshot: null,
69 stack: null,
70 watch: {
71 startedAt: "2026-01-01T00:00:00.000Z",
72 headSha: "abc123",
73 failedChecks: [],
74 passed: true,
75 remarksThrough: "2026-01-01T00:00:00.000Z",
76 remarkIds: [],
77 conflicting: false,
78 wakes: 0,
79 },
80 },
81 ]);
82
83 assert.deepStrictEqual(link?.watch?.passedChecks, []);
84 }),
85);