@@ -164,60 +164,73 @@ describe("exec approvals pending and resolve CLI", () => {
164164 expect ( call ?. [ 2 ] ) . toEqual ( { limit : 25 } ) ;
165165 } ) ;
166166
167- it . each ( [ "10junk" , "1.5" , "0" , "-1" ] ) (
168- "rejects malformed approval grant lifetime before resolving (%s)" ,
167+ it . each ( [ "10junk" , "1.5" , "1e3" , "" , " 0", "-1" , "3651 "] ) (
168+ "rejects an invalid grant lifetime without resolving the approval (%s)" ,
169169 async ( expiresInDays ) => {
170- callGatewayFromCli . mockResolvedValueOnce ( pendingApprovalSnapshot ( { id : "approval-expiry" } ) ) ;
170+ callGatewayFromCli . mockImplementation ( async ( method : string ) =>
171+ method === "approval.get"
172+ ? pendingApprovalSnapshot ( { id : "lifetime-invalid" } )
173+ : {
174+ applied : true ,
175+ approval : terminalApprovalSnapshot ( {
176+ id : "lifetime-invalid" ,
177+ decision : "allow-always" ,
178+ } ) ,
179+ } ,
180+ ) ;
171181
172182 await expect (
173183 runApprovalsCommand ( [
174184 "approvals" ,
175185 "resolve" ,
176- "approval-expiry " ,
186+ "lifetime-invalid " ,
177187 "allow-always" ,
178188 "--expires-in-days" ,
179189 expiresInDays ,
180190 ] ) ,
181191 ) . rejects . toThrow ( "__exit__:1" ) ;
182192
183- expect ( callGatewayFromCli ) . toHaveBeenCalledTimes ( 1 ) ;
184- expect ( runtimeErrors [ 0 ] ) . toContain (
193+ expect ( runtimeErrors ) . toEqual ( [
185194 "--expires-in-days must be a whole number of days between 1 and 3650." ,
186- ) ;
195+ ] ) ;
196+ expect ( callGatewayFromCli . mock . calls . map ( ( [ method ] ) => method ) ) . toEqual ( [ "approval.get" ] ) ;
187197 } ,
188198 ) ;
189199
190- it ( "forwards a valid approval grant lifetime as a number" , async ( ) => {
191- callGatewayFromCli . mockImplementation ( async ( method : string ) => {
192- if ( method === "approval.get" ) {
193- return pendingApprovalSnapshot ( { id : "approval-expiry-valid" } ) ;
194- }
195- return {
196- applied : true ,
197- approval : terminalApprovalSnapshot ( {
198- id : "approval-expiry-valid" ,
199- decision : "allow-always" ,
200- } ) ,
201- } ;
202- } ) ;
203-
204- await runApprovalsCommand ( [
205- "approvals" ,
206- "resolve" ,
207- "approval-expiry-valid" ,
208- "allow-always" ,
209- "--expires-in-days" ,
210- "30" ,
211- "--json" ,
212- ] ) ;
200+ it . each ( [ undefined , "1" , "30" , "3650" ] ) (
201+ "preserves the numeric or absent grant lifetime (%s)" ,
202+ async ( expiresInDays ) => {
203+ callGatewayFromCli . mockImplementation ( async ( method : string ) =>
204+ method === "approval.get"
205+ ? pendingApprovalSnapshot ( { id : "lifetime-valid" } )
206+ : {
207+ applied : true ,
208+ approval : terminalApprovalSnapshot ( {
209+ id : "lifetime-valid" ,
210+ decision : "allow-always" ,
211+ } ) ,
212+ } ,
213+ ) ;
213214
214- expect ( callGatewayFromCli . mock . calls [ 1 ] ?. [ 2 ] ) . toEqual ( {
215- id : "approval-expiry-valid" ,
216- kind : "exec" ,
217- decision : "allow-always" ,
218- grantExpiresInDays : 30 ,
219- } ) ;
220- } ) ;
215+ await runApprovalsCommand ( [
216+ "approvals" ,
217+ "resolve" ,
218+ "lifetime-valid" ,
219+ "allow-always" ,
220+ ...( expiresInDays === undefined ? [ ] : [ "--expires-in-days" , expiresInDays ] ) ,
221+ "--json" ,
222+ ] ) ;
223+
224+ expect ( callGatewayFromCli . mock . calls [ 1 ] ?. [ 0 ] ) . toBe ( "approval.resolve" ) ;
225+ expect ( callGatewayFromCli . mock . calls [ 1 ] ?. [ 2 ] ) . toEqual ( {
226+ id : "lifetime-valid" ,
227+ kind : "exec" ,
228+ decision : "allow-always" ,
229+ ...( expiresInDays === undefined ? { } : { grantExpiresInDays : Number ( expiresInDays ) } ) ,
230+ } ) ;
231+ expect ( writtenJson ( ) ) . toMatchObject ( { applied : true , alreadyResolved : false } ) ;
232+ } ,
233+ ) ;
221234
222235 it ( "renders pending approvals from all three approval kinds" , async ( ) => {
223236 const now = Date . now ( ) ;
0 commit comments