Skip to content

Commit cd87fac

Browse files
committed
fix(contracts): accept legacy pull request checkout results
1 parent 994372b commit cd87fac

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/contracts/src/git.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Schema from "effect/Schema";
44
import {
55
VcsCreateWorktreeInput,
66
GitPreparePullRequestThreadInput,
7+
GitPreparePullRequestThreadResult,
78
GitRunStackedActionResult,
89
GitRunStackedActionInput,
910
GitResolvePullRequestResult,
@@ -13,6 +14,9 @@ const decodeCreateWorktreeInput = Schema.decodeUnknownSync(VcsCreateWorktreeInpu
1314
const decodePreparePullRequestThreadInput = Schema.decodeUnknownSync(
1415
GitPreparePullRequestThreadInput,
1516
);
17+
const decodePreparePullRequestThreadResult = Schema.decodeUnknownSync(
18+
GitPreparePullRequestThreadResult,
19+
);
1620
const decodeRunStackedActionInput = Schema.decodeUnknownSync(GitRunStackedActionInput);
1721
const decodeRunStackedActionResult = Schema.decodeUnknownSync(GitRunStackedActionResult);
1822
const decodeResolvePullRequestResult = Schema.decodeUnknownSync(GitResolvePullRequestResult);
@@ -55,6 +59,43 @@ describe("GitPreparePullRequestThreadInput", () => {
5559
});
5660
});
5761

62+
describe("GitPreparePullRequestThreadResult", () => {
63+
it("defaults legacy responses to the pull request head", () => {
64+
const parsed = decodePreparePullRequestThreadResult({
65+
pullRequest: {
66+
number: 42,
67+
title: "PR threads",
68+
url: "https://github.com/pingdotgg/codething-mvp/pull/42",
69+
baseBranch: "main",
70+
headBranch: "feature/pr-threads",
71+
state: "open",
72+
},
73+
branch: "feature/pr-threads",
74+
worktreePath: "/tmp/pr-threads",
75+
});
76+
77+
expect(parsed.isOnPullRequestHead).toBe(true);
78+
});
79+
80+
it("preserves an explicit stale pull request checkout result", () => {
81+
const parsed = decodePreparePullRequestThreadResult({
82+
pullRequest: {
83+
number: 42,
84+
title: "PR threads",
85+
url: "https://github.com/pingdotgg/codething-mvp/pull/42",
86+
baseBranch: "main",
87+
headBranch: "feature/pr-threads",
88+
state: "open",
89+
},
90+
branch: "feature/pr-threads",
91+
worktreePath: "/tmp/pr-threads",
92+
isOnPullRequestHead: false,
93+
});
94+
95+
expect(parsed.isOnPullRequestHead).toBe(false);
96+
});
97+
});
98+
5899
describe("GitResolvePullRequestResult", () => {
59100
it("decodes resolved pull request metadata", () => {
60101
const parsed = decodeResolvePullRequestResult({

‎packages/contracts/src/git.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as Effect from "effect/Effect";
12
import * as Schema from "effect/Schema";
23
import { NonNegativeInt, PositiveInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
34
import { SourceControlProviderError, SourceControlProviderInfo } from "./sourceControl.ts";
@@ -289,7 +290,7 @@ export const GitPreparePullRequestThreadResult = Schema.Struct({
289290
* holding local commits or uncommitted changes keeps its own state, so the code being handed
290291
* over is older than the pull request.
291292
*/
292-
isOnPullRequestHead: Schema.Boolean,
293+
isOnPullRequestHead: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true))),
293294
});
294295
export type GitPreparePullRequestThreadResult = typeof GitPreparePullRequestThreadResult.Type;
295296

0 commit comments

Comments
 (0)