Open History to see the last commit
1import { describe, expect, it } from "vitest";
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
33describe("GitPreparePullRequestThreadInput", () => {
34 it("accepts pull request references and mode", () => {
35 const parsed = decodePreparePullRequestThreadInput({
36 cwd: "/repo",
37 reference: "#42",
38 mode: "worktree",
39 });
40
41 expect(parsed.reference).toBe("#42");
42 expect(parsed.mode).toBe("worktree");
43 });
44});
45
46describe("GitResolvePullRequestResult", () => {
47 it("decodes resolved pull request metadata", () => {
48 const parsed = decodeResolvePullRequestResult({
49 pullRequest: {
50 number: 42,
51 title: "PR threads",
52 url: "https://github.com/pingdotgg/codething-mvp/pull/42",
53 baseBranch: "main",
54 headBranch: "feature/pr-threads",
55 state: "open",
56 },
57 });
58
59 expect(parsed.pullRequest.number).toBe(42);
60 expect(parsed.pullRequest.headBranch).toBe("feature/pr-threads");
61 });
62});
63
64describe("GitRunStackedActionInput", () => {
65 it("accepts explicit stacked actions and requires a client-provided actionId", () => {
66 const parsed = decodeRunStackedActionInput({
67 actionId: "action-1",
68 cwd: "/repo",
69 action: "create_pr",
70 });
71
72 expect(parsed.actionId).toBe("action-1");
73 expect(parsed.action).toBe("create_pr");
74 });
75});
76
77describe("GitRunStackedActionResult", () => {
78 it("decodes a server-authored completion toast", () => {
79 const parsed = decodeRunStackedActionResult({
80 action: "commit_push",
81 branch: {
82 status: "created",
83 name: "feature/server-owned-toast",
84 },
85 commit: {
86 status: "created",
87 commitSha: "89abcdef01234567",
88 subject: "feat: move toast state into git manager",
89 },
90 push: {
91 status: "pushed",
92 branch: "feature/server-owned-toast",
93 upstreamBranch: "origin/feature/server-owned-toast",
94 },
95 pr: {
96 status: "skipped_not_requested",
97 },
98 toast: {
99 title: "Pushed 89abcde to origin/feature/server-owned-toast",
100 description: "feat: move toast state into git manager",
101 cta: {
102 kind: "run_action",
103 label: "Create PR",
104 action: {
105 kind: "create_pr",
106 },
107 },
108 },
109 });
110
111 expect(parsed.toast.cta.kind).toBe("run_action");
112 if (parsed.toast.cta.kind === "run_action") {
113 expect(parsed.toast.cta.action.kind).toBe("create_pr");
114 }
115 });
116});