@@ -5,19 +5,23 @@ import { describe, expect, it } from "vite-plus/test";
55import {
66 PullRequestActionInput ,
77 PullRequestCapabilities ,
8+ PullRequestDetail ,
89 PullRequestFilesViewedResult ,
910 PullRequestListInput ,
1011 PullRequestListResult ,
1112 PullRequestReviewerRequestInput ,
1213 PullRequestSetFilesViewedInput ,
14+ PullRequestSubmitReviewInput ,
1315 pullRequestHostOf ,
1416 resolvePullRequestAuthorFilter ,
1517} from "./pullRequest.ts" ;
1618
17- const decodeListResult = Schema . decodeUnknownSync ( PullRequestListResult ) ;
19+ const decodeListResult = Schema . decodeUnknownSync ( Schema . toCodecJson ( PullRequestListResult ) ) ;
20+ const decodeDetail = Schema . decodeUnknownSync ( Schema . toCodecJson ( PullRequestDetail ) ) ;
1821const decodeListInput = Schema . decodeUnknownSync ( PullRequestListInput ) ;
1922const decodeReviewerRequest = Schema . decodeUnknownSync ( PullRequestReviewerRequestInput ) ;
20- const decodeAction = Schema . decodeUnknownSync ( PullRequestActionInput ) ;
23+ const decodeAction = Schema . decodeUnknownSync ( Schema . toCodecJson ( PullRequestActionInput ) ) ;
24+ const decodeReview = Schema . decodeUnknownSync ( Schema . toCodecJson ( PullRequestSubmitReviewInput ) ) ;
2125const decodeSetFilesViewed = Schema . decodeUnknownSync ( PullRequestSetFilesViewedInput ) ;
2226const decodeFilesViewed = Schema . decodeUnknownSync ( PullRequestFilesViewedResult ) ;
2327
@@ -102,6 +106,18 @@ describe("PullRequestListResult", () => {
102106 expect ( decoded ) . toStrictEqual ( LIST_RESULT ) ;
103107 } ) ;
104108
109+ it ( "loads a newer server's list response, dropping unknown provider actions in order" , ( ) => {
110+ const decoded = decodeListResult ( {
111+ ...LIST_RESULT ,
112+ providers : [ { ...LIST_RESULT . providers [ 0 ] , actions : [ "close" , "archive" , "merge" ] } ] ,
113+ } ) ;
114+
115+ expect ( decoded ) . toEqual ( {
116+ ...LIST_RESULT ,
117+ providers : [ { ...LIST_RESULT . providers [ 0 ] , actions : [ "close" , "merge" ] } ] ,
118+ } ) ;
119+ } ) ;
120+
105121 it ( "keys a viewer by host, so two hosts of one kind stay separate accounts" , ( ) => {
106122 const decoded = decodeListResult ( {
107123 ...LIST_RESULT ,
@@ -274,6 +290,63 @@ describe("PullRequestCapabilities", () => {
274290 expect ( decodeCapabilities ( base ) . deleteBranch ) . toBeUndefined ( ) ;
275291 expect ( decodeCapabilities ( { ...base , deleteBranch : true } ) . deleteBranch ) . toBe ( true ) ;
276292 } ) ;
293+
294+ it ( "loads a newer server's detail response, dropping unknown options in order" , ( ) => {
295+ const options = {
296+ actions : [ "close" , "archive" , "merge" ] ,
297+ verdicts : [ "request-changes" , "block" , "approve" ] ,
298+ updateMethods : [ "rebase" , "fast-forward" , "merge" ] ,
299+ } ;
300+ const detail = {
301+ ...LIST_RESULT . entries [ 0 ] ,
302+ workspaceRoot : "/workspace/t3code" ,
303+ body : "" ,
304+ changedFiles : 1 ,
305+ mergedAt : null ,
306+ closedAt : null ,
307+ reviewers : [ ] ,
308+ checks : [ ] ,
309+ mergeCapabilities : { merge : true , squash : true , rebase : true } ,
310+ capabilities : {
311+ ...base ,
312+ actions : options . actions ,
313+ mergeMethods : [ "squash" , "fast-forward" , "merge" ] ,
314+ updateMethods : options . updateMethods ,
315+ review : { ...base . review , verdicts : options . verdicts } ,
316+ } ,
317+ viewerPermissions : { ...options , comment : true , resolve : true , requestReviewers : true } ,
318+ } ;
319+ const decoded = decodeDetail ( detail ) ;
320+
321+ expect ( decoded . capabilities ) . toEqual ( {
322+ ...base ,
323+ actions : [ "close" , "merge" ] ,
324+ mergeMethods : [ "squash" , "merge" ] ,
325+ updateMethods : [ "rebase" , "merge" ] ,
326+ review : { ...base . review , verdicts : [ "request-changes" , "approve" ] } ,
327+ } ) ;
328+ expect ( decoded . viewerPermissions ) . toEqual ( {
329+ actions : [ "close" , "merge" ] ,
330+ verdicts : [ "request-changes" , "approve" ] ,
331+ updateMethods : [ "rebase" , "merge" ] ,
332+ comment : true ,
333+ resolve : true ,
334+ requestReviewers : true ,
335+ } ) ;
336+ expect ( decoded . title ) . toBe ( detail . title ) ;
337+ } ) ;
338+ } ) ;
339+
340+ describe ( "pull request mutation requests" , ( ) => {
341+ it ( "still rejects unknown actions, merge methods, and review verdicts on the wire" , ( ) => {
342+ const ref = { projectId : "project-1" , repository : "acme/web" , number : 7 } ;
343+
344+ expect ( ( ) => decodeAction ( { ...ref , action : "archive" } ) ) . toThrow ( ) ;
345+ expect ( ( ) => decodeAction ( { ...ref , action : "merge" , mergeMethod : "fast-forward" } ) ) . toThrow ( ) ;
346+ const review = { ...ref , body : "" , comments : [ ] , verdict : "approve" } ;
347+ expect ( decodeReview ( review ) . verdict ) . toBe ( "approve" ) ;
348+ expect ( ( ) => decodeReview ( { ...review , verdict : "block" } ) ) . toThrow ( ) ;
349+ } ) ;
277350} ) ;
278351
279352describe ( "naming the reader as the author to narrow by" , ( ) => {
0 commit comments