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

main
ts 108 lines 3.44 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2 import * as Schema from "effect/Schema";
3
4 import {
5 GitCommandError,
6 GitPreparePullRequestThreadResult,
7 GitRunStackedActionInput,
8 } from "./git.ts";
9 import { PullRequestDiffFileContentsInput } from "./pullRequest.ts";
10 import { ReviewDiffFileContentsInput } from "./review.ts";
11
12 const decodeGitCommandError = Schema.decodeUnknownSync(Schema.toCodecJson(GitCommandError));
13 const decodePreparePullRequestThreadResult = Schema.decodeUnknownSync(
14 GitPreparePullRequestThreadResult,
15 );
16 const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
17 const encodeRunStackedActionInput = Schema.encodeUnknownSync(GitRunStackedActionInput);
18 const decodeReviewDiffFileContentsInput = Schema.decodeUnknownSync(ReviewDiffFileContentsInput);
19 const encodeReviewDiffFileContentsInput = Schema.encodeUnknownSync(ReviewDiffFileContentsInput);
20 const decodePullRequestDiffFileContentsInput = Schema.decodeUnknownSync(
21 PullRequestDiffFileContentsInput,
22 );
23 const encodePullRequestDiffFileContentsInput = Schema.encodeUnknownSync(
24 PullRequestDiffFileContentsInput,
25 );
26
27 describe("GitCommandError", () => {
28 it("decodes an unknown failure reason as absent", () => {
29 const error = decodeGitCommandError({
30 _tag: "GitCommandError",
31 operation: "GitVcsDriver.createWorktree",
32 command: "git",
33 cwd: "/repo",
34 detail: "git worktree add failed",
35 reason: "added_by_a_newer_server",
36 });
37
38 expect(error.reason).toBeUndefined();
39 expect(error.message).toBe(
40 "Git command failed in GitVcsDriver.createWorktree (/repo): git worktree add failed",
41 );
42 });
43 });
44
45 describe("GitPreparePullRequestThreadResult", () => {
46 it("defaults legacy responses to the pull request head", () => {
47 const parsed = decodePreparePullRequestThreadResult({
48 pullRequest: {
49 number: 42,
50 title: "PR threads",
51 url: "https://github.com/pingdotgg/codething-mvp/pull/42",
52 baseBranch: "main",
53 headBranch: "feature/pr-threads",
54 state: "open",
55 },
56 branch: "feature/pr-threads",
57 worktreePath: "/tmp/pr-threads",
58 });
59
60 expect(parsed.isOnPullRequestHead).toBe(true);
61 });
62 });
63
64 describe("Git file paths", () => {
65 it.each([
66 {
67 operation: "commit",
68 decode: decodeRunStackedActionInput,
69 encode: encodeRunStackedActionInput,
70 input: {
71 actionId: "action-1",
72 cwd: "/repo",
73 action: "commit",
74 filePaths: [" leading.txt", "trailing.txt "],
75 },
76 },
77 {
78 operation: "local diff expansion",
79 decode: decodeReviewDiffFileContentsInput,
80 encode: encodeReviewDiffFileContentsInput,
81 input: {
82 cwd: "/repo",
83 sourceKind: "working-tree",
84 changeType: "rename-changed",
85 baseRef: "HEAD",
86 headRef: null,
87 oldPath: " leading.txt",
88 newPath: "trailing.txt ",
89 },
90 },
91 {
92 operation: "pull request diff expansion",
93 decode: decodePullRequestDiffFileContentsInput,
94 encode: encodePullRequestDiffFileContentsInput,
95 input: {
96 projectId: "project-1",
97 repository: "owner/repo",
98 number: 1,
99 changeType: "rename-changed",
100 oldPath: " leading.txt",
101 newPath: "trailing.txt ",
102 },
103 },
104 ])("preserves leading and trailing whitespace for $operation", ({ decode, encode, input }) => {
105 expect(decode(input)).toEqual(input);
106 expect(encode(input)).toEqual(input);
107 });
108 });