Skip to content

Commit f6d8e00

Browse files
committed
fix(contracts): older clients still load PRs from newer servers
A server that offers a PR action an older client does not know, such as delete-branch, failed the client's whole pull request decode. Lists of actions, verdicts, merge methods, and update methods the server sends now decode with ForwardCompatibleArray, so unknown members are dropped.
1 parent 81493ef commit f6d8e00

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ describe("PullRequestCapabilities", () => {
276276
expect(decodeCapabilities(base).deleteBranch).toBeUndefined();
277277
expect(decodeCapabilities({ ...base, deleteBranch: true }).deleteBranch).toBe(true);
278278
});
279+
280+
it("drops actions and verdicts from a newer server instead of failing", () => {
281+
const decoded = decodeCapabilities({
282+
...base,
283+
actions: ["merge", "archive", "close"],
284+
review: { ...base.review, verdicts: ["approve", "block"] },
285+
});
286+
287+
expect(decoded.actions).toEqual(["merge", "close"]);
288+
expect(decoded.review.verdicts).toEqual(["approve"]);
289+
});
279290
});
280291

281292
describe("naming the reader as the author to narrow by", () => {

‎packages/contracts/src/pullRequest.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as HttpServerRespondable from "effect/http/HttpServerRespondable";
33
import * as HttpServerResponse from "effect/http/HttpServerResponse";
44

55
import {
6+
ForwardCompatibleArray,
67
IsoDateTime,
78
NonNegativeInt,
89
PositiveInt,
@@ -77,6 +78,10 @@ export type PullRequestMergeability = typeof PullRequestMergeability.Type;
7778
export const PullRequestMergeMethod = Schema.Literals(["merge", "squash", "rebase"]);
7879
export type PullRequestMergeMethod = typeof PullRequestMergeMethod.Type;
7980

81+
/**
82+
* Grows as hosts gain actions, so lists a server sends decode with `ForwardCompatibleArray`: an
83+
* older client drops an action it does not know instead of failing the whole pull request.
84+
*/
8085
export const PullRequestAction = Schema.Literals([
8186
"merge",
8287
"ready",
@@ -360,7 +365,7 @@ export const PullRequestReviewCapabilities = Schema.Struct({
360365
/** A thread can be marked resolved, and unresolved again. */
361366
resolve: Schema.Boolean,
362367
/** The verdicts a submitted review can carry. Empty means reviews cannot be submitted. */
363-
verdicts: Schema.Array(PullRequestReviewVerdict),
368+
verdicts: ForwardCompatibleArray(PullRequestReviewVerdict),
364369
});
365370
export type PullRequestReviewCapabilities = typeof PullRequestReviewCapabilities.Type;
366371

@@ -416,15 +421,15 @@ export const PullRequestCapabilities = Schema.Struct({
416421
/** A comment can be posted, and the conversation read back. */
417422
comment: Schema.Boolean,
418423
/** The actions this host can carry out; anything absent is never offered. */
419-
actions: Schema.Array(PullRequestAction),
424+
actions: ForwardCompatibleArray(PullRequestAction),
420425
/** Merge strategies the provider itself offers, before repository settings narrow them. */
421-
mergeMethods: Schema.Array(PullRequestMergeMethod),
426+
mergeMethods: ForwardCompatibleArray(PullRequestMergeMethod),
422427
deleteBranch: Schema.optional(Schema.Boolean),
423428
/**
424429
* How this host can bring a stale branch up to date. Absent where it cannot at all, which is
425430
* every host that has not said otherwise — so a provider that says nothing offers nothing.
426431
*/
427-
updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),
432+
updateMethods: Schema.optional(ForwardCompatibleArray(PullRequestUpdateMethod)),
428433
/**
429434
* The host can narrow a listing by free text. False means it answers unnarrowed and whoever
430435
* asked has to do the narrowing — which is a different promise, so the page is told rather
@@ -481,20 +486,20 @@ export const PullRequestViewerPermissions = Schema.Struct({
481486
/** May request remote stack rebases, including when this layer is already current. */
482487
stackRebase: Schema.optional(Schema.Boolean),
483488
/** Which of the actions this viewer may take; anything absent is theirs to look at only. */
484-
actions: Schema.Array(PullRequestAction),
489+
actions: ForwardCompatibleArray(PullRequestAction),
485490
/** This viewer may write a remark: a comment, a reply, or a note against a line. */
486491
comment: Schema.Boolean,
487492
/** This viewer may mark a review conversation resolved, and unresolved again. */
488493
resolve: Schema.Boolean,
489494
/** The verdicts this viewer may submit a review with. Empty means they may not review. */
490-
verdicts: Schema.Array(PullRequestReviewVerdict),
495+
verdicts: ForwardCompatibleArray(PullRequestReviewVerdict),
491496
/** This viewer may ask somebody for a review, and take the request back again. */
492497
requestReviewers: Schema.Boolean,
493498
/**
494499
* The ways this viewer may bring the branch up to date, narrowed from what the host offers.
495500
* Absent or empty means they may not, which is also what a host with no such action says.
496501
*/
497-
updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),
502+
updateMethods: Schema.optional(ForwardCompatibleArray(PullRequestUpdateMethod)),
498503
/**
499504
* This viewer may put a label on the change request, and take one off. Absent is granted, like
500505
* every permission here; the capability beside it is what decides whether a label can be
@@ -640,7 +645,7 @@ export const PullRequestProviderSummary = Schema.Struct({
640645
* The actions this host can carry out, so a row can offer them before its detail is read.
641646
* Absent from servers older than this field; clients then offer what they always did.
642647
*/
643-
actions: Schema.optional(Schema.Array(PullRequestAction)),
648+
actions: Schema.optional(ForwardCompatibleArray(PullRequestAction)),
644649
projectCount: PositiveInt,
645650
/** False when the provider's CLI or credentials are missing, with `detail` saying which. */
646651
configured: Schema.Boolean,

0 commit comments

Comments
 (0)