1import { describe, expect, it } from "vite-plus/test";
2import * as Schema from "effect/Schema";
3
4import {
5 GitCommandError,
6 GitPreparePullRequestThreadResult,
7 GitRunStackedActionInput,
8} from "./git.ts";
9
10const decodeGitCommandError = Schema.decodeUnknownSync(Schema.toCodecJson(GitCommandError));
11const decodePreparePullRequestThreadResult = Schema.decodeUnknownSync(
12 GitPreparePullRequestThreadResult,
13);
14const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
15
16describe("GitCommandError", () => {
17 it("decodes an unknown failure reason as absent", () => {
18 const error = decodeGitCommandError({
19 _tag: "GitCommandError",
20 operation: "GitVcsDriver.createWorktree",
21 command: "git",
22 cwd: "/repo",
23 detail: "git worktree add failed",
24 reason: "added_by_a_newer_server",
25 });
26
27 expect(error.reason).toBeUndefined();
28 expect(error.message).toBe(
29 "Git command failed in GitVcsDriver.createWorktree (/repo): git worktree add failed",
30 );
31 });
32});
33
34describe("GitPreparePullRequestThreadResult", () => {
35 it("defaults legacy responses to the pull request head", () => {
36 const parsed = decodePreparePullRequestThreadResult({
37 pullRequest: {
38 number: 42,
39 title: "PR threads",
40 url: "https://github.com/pingdotgg/codething-mvp/pull/42",
41 baseBranch: "main",
42 headBranch: "feature/pr-threads",
43 state: "open",
44 },
45 branch: "feature/pr-threads",
46 worktreePath: "/tmp/pr-threads",
47 });
48
49 expect(parsed.isOnPullRequestHead).toBe(true);
50 });
51});
52
53describe("GitRunStackedActionInput", () => {
54 it("preserves leading and trailing whitespace in file paths", () => {
55 const parsed = decodeRunStackedActionInput({
56 actionId: "action-1",
57 cwd: "/repo",
58 action: "commit",
59 filePaths: [" leading.txt", "trailing.txt "],
60 });
61
62 expect(parsed.filePaths).toEqual([" leading.txt", "trailing.txt "]);
63 });
64});