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

git.test.ts

128 lines3.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3​
4import {
5 VcsCreateWorktreeInput,
6 GitPreparePullRequestThreadInput,
7 GitRunStackedActionResult,
8 GitRunStackedActionInput,
9 GitResolvePullRequestResult,
10} from "./git.ts";
11​
12const decodeCreateWorktreeInput = Schema.decodeUnknownSync(VcsCreateWorktreeInput);
13const decodePreparePullRequestThreadInput = Schema.decodeUnknownSync(
14 GitPreparePullRequestThreadInput,
15);
16const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
17const decodeRunStackedActionResult = Schema.decodeUnknownSync(GitRunStackedActionResult);
18const decodeResolvePullRequestResult = Schema.decodeUnknownSync(GitResolvePullRequestResult);
19​
20describe("VcsCreateWorktreeInput", () => {
21 it("accepts omitted newRefName for existing-refName worktrees", () => {
22 const parsed = decodeCreateWorktreeInput({
23 cwd: "/repo",
24 refName: "feature/existing",
25 path: "/tmp/worktree",
26 });
27​
28 expect(parsed.newRefName).toBeUndefined();
29 expect(parsed.refName).toBe("feature/existing");
30 });
31​
32 it("accepts baseRefName metadata for a new worktree ref", () => {
33 const parsed = decodeCreateWorktreeInput({
34 cwd: "/repo",
35 refName: "0123456789abcdef",
36 newRefName: "feature/new",
37 baseRefName: "origin/main",
38 path: "/tmp/worktree",
39 });
40​
41 expect(parsed.baseRefName).toBe("origin/main");
42 });
43});
44​
45describe("GitPreparePullRequestThreadInput", () => {
46 it("accepts pull request references and mode", () => {
47 const parsed = decodePreparePullRequestThreadInput({
48 cwd: "/repo",
49 reference: "#42",
50 mode: "worktree",
51 });
52​
53 expect(parsed.reference).toBe("#42");
54 expect(parsed.mode).toBe("worktree");
55 });
56});
57​
58describe("GitResolvePullRequestResult", () => {
59 it("decodes resolved pull request metadata", () => {
60 const parsed = decodeResolvePullRequestResult({
61 pullRequest: {
62 number: 42,
63 title: "PR threads",
64 url: "https://github.com/pingdotgg/codething-mvp/pull/42",
65 baseBranch: "main",
66 headBranch: "feature/pr-threads",
67 state: "open",
68 },
69 });
70​
71 expect(parsed.pullRequest.number).toBe(42);
72 expect(parsed.pullRequest.headBranch).toBe("feature/pr-threads");
73 });
74});
75​
76describe("GitRunStackedActionInput", () => {
77 it("accepts explicit stacked actions and requires a client-provided actionId", () => {
78 const parsed = decodeRunStackedActionInput({
79 actionId: "action-1",
80 cwd: "/repo",
81 action: "create_pr",
82 });
83​
84 expect(parsed.actionId).toBe("action-1");
85 expect(parsed.action).toBe("create_pr");
86 });
87});
88​
89describe("GitRunStackedActionResult", () => {
90 it("decodes a server-authored completion toast", () => {
91 const parsed = decodeRunStackedActionResult({
92 action: "commit_push",
93 branch: {
94 status: "created",
95 name: "feature/server-owned-toast",
96 },
97 commit: {
98 status: "created",
99 commitSha: "89abcdef01234567",
100 subject: "feat: move toast state into git manager",
101 },
102 push: {
103 status: "pushed",
104 branch: "feature/server-owned-toast",
105 upstreamBranch: "origin/feature/server-owned-toast",
106 },
107 pr: {
108 status: "skipped_not_requested",
109 },
110 toast: {
111 title: "Pushed 89abcde to origin/feature/server-owned-toast",
112 description: "feat: move toast state into git manager",
113 cta: {
114 kind: "run_action",
115 label: "Create PR",
116 action: {
117 kind: "create_pr",
118 },
119 },
120 },
121 });
122​
123 expect(parsed.toast.cta.kind).toBe("run_action");
124 if (parsed.toast.cta.kind === "run_action") {
125 expect(parsed.toast.cta.action.kind).toBe("create_pr");
126 }
127 });
128});