Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import {
4 gitPullInputSchema,
5 gitPullResultSchema,
6 gitRunStackedActionInputSchema,
7 gitRunStackedActionResultSchema,
8 gitStackedActionSchema,
9 gitStatusInputSchema,
10 gitStatusResultSchema,
11} from "./git";
12
13describe("git contracts", () => {
14 it("parses git status input and trims cwd", () => {
15 const parsed = gitStatusInputSchema.parse({ cwd: " /tmp/repo " });
16 expect(parsed.cwd).toBe("/tmp/repo");
17 });
18
19 it("parses git pull input and trims cwd", () => {
20 const parsed = gitPullInputSchema.parse({ cwd: " /tmp/repo " });
21 expect(parsed.cwd).toBe("/tmp/repo");
22 });
23
24 it("parses git status result", () => {
25 const parsed = gitStatusResultSchema.parse({
26 branch: "feature/git-actions",
27 hasWorkingTreeChanges: true,
28 workingTree: {
29 files: [
30 { path: "src/git.ts", insertions: 8, deletions: 2 },
31 { path: "src/git.test.ts", insertions: 4, deletions: 1 },
32 ],
33 insertions: 12,
34 deletions: 3,
35 },
36 hasUpstream: false,
37 aheadCount: 0,
38 behindCount: 0,
39 openPr: null,
40 });
41 expect(parsed.branch).toBe("feature/git-actions");
42 expect(parsed.hasWorkingTreeChanges).toBe(true);
43 expect(parsed.workingTree.files[0]?.insertions).toBe(8);
44 expect(parsed.workingTree.files).toHaveLength(2);
45 });
46
47 it("accepts supported stacked actions", () => {
48 expect(gitStackedActionSchema.parse("commit")).toBe("commit");
49 expect(gitStackedActionSchema.parse("commit_push")).toBe("commit_push");
50 expect(gitStackedActionSchema.parse("commit_push_pr")).toBe("commit_push_pr");
51 });
52
53 it("parses stacked action input", () => {
54 const parsed = gitRunStackedActionInputSchema.parse({
55 cwd: "/tmp/repo",
56 action: "commit_push",
57 });
58 expect(parsed.action).toBe("commit_push");
59 });
60
61 it("accepts custom commit message input", () => {
62 const parsed = gitRunStackedActionInputSchema.parse({
63 cwd: "/tmp/repo",
64 action: "commit",
65 commitMessage: " chore: update git action modal ",
66 });
67 expect(parsed.commitMessage).toBe("chore: update git action modal");
68 });
69
70 it("parses stacked action result with metadata", () => {
71 const parsed = gitRunStackedActionResultSchema.parse({
72 action: "commit_push_pr",
73 commit: {
74 status: "created",
75 commitSha: "abc123",
76 subject: "Implement stacked git actions",
77 },
78 push: {
79 status: "pushed",
80 branch: "feature/git-actions",
81 upstreamBranch: "origin/feature/git-actions",
82 setUpstream: true,
83 },
84 pr: {
85 status: "created",
86 url: "https://github.com/pingdotgg/codething-mvp/pull/123",
87 number: 123,
88 baseBranch: "main",
89 headBranch: "feature/git-actions",
90 title: "Add stacked git actions workflow",
91 },
92 });
93
94 expect(parsed.commit.status).toBe("created");
95 expect(parsed.pr.number).toBe(123);
96 });
97
98 it("parses git pull result", () => {
99 const parsed = gitPullResultSchema.parse({
100 status: "pulled",
101 branch: "feature/my-branch",
102 upstreamBranch: "origin/feature/my-branch",
103 });
104 expect(parsed.status).toBe("pulled");
105 expect(parsed.branch).toBe("feature/my-branch");
106 });
107});