@@ -8,7 +8,7 @@ import { describe, it } from "node:test";
88import assert from "node:assert/strict" ;
99
1010import { Run402 } from "../index.js" ;
11- import { ProjectNotFound , ApiError } from "../errors.js" ;
11+ import { ProjectNotFound , ApiError , LocalError } from "../errors.js" ;
1212import type { CredentialsProvider } from "../credentials.js" ;
1313
1414interface FetchCall {
@@ -403,6 +403,26 @@ describe("blobs.ls", () => {
403403 await sdk . blobs . ls ( "prj_known" ) ;
404404 assert . equal ( calls [ 0 ] ! . url , "https://api.example.test/storage/v1/blobs" ) ;
405405 } ) ;
406+
407+ it ( "throws LocalError and does not request for invalid limits" , async ( ) => {
408+ const invalidLimits = [ 0 , - 1 , 1.5 , Number . NaN , Number . MAX_SAFE_INTEGER + 1 ] ;
409+
410+ for ( const limit of invalidLimits ) {
411+ const { fetch, calls } = mockFetch ( ( ) => {
412+ throw new Error ( `unexpected fetch for limit ${ String ( limit ) } ` ) ;
413+ } ) ;
414+ const sdk = makeSdk ( fetch ) ;
415+
416+ await assert . rejects (
417+ sdk . blobs . ls ( "prj_known" , { limit } ) ,
418+ ( err : unknown ) =>
419+ err instanceof LocalError &&
420+ err . context === "listing blobs" &&
421+ / l i m i t .* p o s i t i v e s a f e i n t e g e r / i. test ( err . message ) ,
422+ ) ;
423+ assert . equal ( calls . length , 0 , `limit ${ String ( limit ) } should not request` ) ;
424+ }
425+ } ) ;
406426} ) ;
407427
408428describe ( "blobs.rm" , ( ) => {
@@ -923,4 +943,28 @@ describe("blobs.waitFresh", () => {
923943 ProjectNotFound ,
924944 ) ;
925945 } ) ;
946+
947+ it ( "throws LocalError and does not diagnose for invalid timeoutMs" , async ( ) => {
948+ const invalidTimeouts = [ 0 , - 1 , 1.5 , Number . NaN , Number . MAX_SAFE_INTEGER + 1 ] ;
949+
950+ for ( const timeoutMs of invalidTimeouts ) {
951+ const { fetch, calls } = mockFetch ( ( ) => {
952+ throw new Error ( `unexpected fetch for timeoutMs ${ String ( timeoutMs ) } ` ) ;
953+ } ) ;
954+ const sdk = makeSdk ( fetch ) ;
955+
956+ await assert . rejects (
957+ sdk . blobs . waitFresh ( "prj_known" , {
958+ url : "https://app.run402.com/_blob/k" ,
959+ sha256 : "ff" ,
960+ timeoutMs,
961+ } ) ,
962+ ( err : unknown ) =>
963+ err instanceof LocalError &&
964+ err . context === "waiting for CDN freshness" &&
965+ / t i m e o u t M s .* p o s i t i v e s a f e i n t e g e r / i. test ( err . message ) ,
966+ ) ;
967+ assert . equal ( calls . length , 0 , `timeoutMs ${ String ( timeoutMs ) } should not request` ) ;
968+ }
969+ } ) ;
926970} ) ;
0 commit comments