@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, 03:37 UTC

main
ts 85 lines 2.92 KB
Raw
1 import type { ExecutionEnvironmentCapabilities } from "@t3tools/contracts";
2 import { ThreadId } from "@t3tools/contracts";
3 import { describe, expect, it } from "@effect/vitest";
4 import {
5 canStartThreadPullRequestWatch,
6 planThreadPullRequestMutation,
7 threadPullRequestLinkMode,
8 } from "./threadPullRequestCompatibility.ts";
9
10 const reference = {
11 host: "github.example",
12 repository: "team/repo",
13 number: 7,
14 url: "https://github.example/team/repo/pull/7",
15 };
16 const input = {
17 threadId: ThreadId.make("thread"),
18 reference,
19 linked: true,
20 };
21 const capabilities = { repositoryIdentity: true } satisfies ExecutionEnvironmentCapabilities;
22
23 describe("thread pull request capability negotiation", () => {
24 it.each([true, false])(
25 "preserves Forgejo ports in a multi-link mutation: linked=%s",
26 (linked) => {
27 const mutation = planThreadPullRequestMutation({
28 ...input,
29 linked,
30 capabilities,
31 reference: {
32 host: "forge.example",
33 repository: "team/repo",
34 number: 7,
35 url: "http://forge.example:3000/team/repo/pulls/7",
36 },
37 });
38 expect(mutation).toMatchObject({ input: { host: "forge.example:3000", number: 7 } });
39 },
40 );
41
42 it("does not dispatch before the server config loads", () => {
43 expect(threadPullRequestLinkMode(undefined)).toBe("unsupported");
44 expect(planThreadPullRequestMutation({ ...input, capabilities: undefined })).toBeNull();
45 });
46 it("plans link and unlink commands", () => {
47 expect(planThreadPullRequestMutation({ ...input, capabilities })).toEqual({
48 type: "thread.pull-request.link",
49 input: { threadId: input.threadId, ...reference, source: "manual" },
50 });
51 expect(planThreadPullRequestMutation({ ...input, capabilities, linked: false })).toEqual({
52 type: "thread.pull-request.unlink",
53 input: {
54 threadId: input.threadId,
55 host: reference.host,
56 repository: reference.repository,
57 number: reference.number,
58 },
59 });
60 });
61
62 it("offers a new watch only where the server accepts one", () => {
63 const active = {
64 archivedAt: null,
65 settledAt: null,
66 settledOverride: null,
67 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: input.threadId },
68 } as const;
69 expect(canStartThreadPullRequestWatch(active)).toBe(true);
70 expect(canStartThreadPullRequestWatch({ ...active, settledOverride: "active" })).toBe(true);
71 expect(canStartThreadPullRequestWatch({ ...active, settledOverride: "settled" })).toBe(false);
72 expect(canStartThreadPullRequestWatch({ ...active, settledAt: "2026-01-01T00:00:00Z" })).toBe(
73 false,
74 );
75 expect(canStartThreadPullRequestWatch({ ...active, archivedAt: "2026-01-01T00:00:00Z" })).toBe(
76 false,
77 );
78 expect(
79 canStartThreadPullRequestWatch({
80 ...active,
81 lineage: { ...active.lineage, relationshipToParent: "subagent" },
82 }),
83 ).toBe(false);
84 });
85 });