@@ -208,52 +208,33 @@ describe("manifest", () => {
208208 await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
209209 } ) ;
210210
211- it ( "throws when manifest from GitHub is invalid" , async ( ) => {
212- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
213- global . fetch = mock (
214- async ( ) =>
211+ const invalidManifestCases : Array < {
212+ label : string ;
213+ fetchImpl : ( ) => Promise < Response > ;
214+ } > = [
215+ {
216+ label : "non-manifest shape" ,
217+ fetchImpl : async ( ) =>
215218 new Response (
216219 JSON . stringify ( {
217220 not : "a manifest" ,
218221 } ) ,
219222 ) ,
220- ) ;
221-
222- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
223- if ( existsSync ( cacheFile ) ) {
224- rmSync ( cacheFile ) ;
225- }
226-
227- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
228- consoleSpy . mockRestore ( ) ;
229- } ) ;
230-
231- it ( "rejects manifest with string agents field" , async ( ) => {
232- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
233- global . fetch = mock (
234- async ( ) =>
223+ } ,
224+ {
225+ label : "string agents field" ,
226+ fetchImpl : async ( ) =>
235227 new Response (
236228 JSON . stringify ( {
237229 agents : "claude" ,
238230 clouds : { } ,
239231 matrix : { } ,
240232 } ) ,
241233 ) ,
242- ) ;
243-
244- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
245- if ( existsSync ( cacheFile ) ) {
246- rmSync ( cacheFile ) ;
247- }
248-
249- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
250- consoleSpy . mockRestore ( ) ;
251- } ) ;
252-
253- it ( "rejects manifest with array clouds field" , async ( ) => {
254- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
255- global . fetch = mock (
256- async ( ) =>
234+ } ,
235+ {
236+ label : "array clouds field" ,
237+ fetchImpl : async ( ) =>
257238 new Response (
258239 JSON . stringify ( {
259240 agents : { } ,
@@ -264,53 +245,38 @@ describe("manifest", () => {
264245 matrix : { } ,
265246 } ) ,
266247 ) ,
267- ) ;
268-
269- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
270- if ( existsSync ( cacheFile ) ) {
271- rmSync ( cacheFile ) ;
272- }
273-
274- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
275- consoleSpy . mockRestore ( ) ;
276- } ) ;
277-
278- it ( "rejects manifest with numeric matrix field" , async ( ) => {
279- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
280- global . fetch = mock (
281- async ( ) =>
248+ } ,
249+ {
250+ label : "numeric matrix field" ,
251+ fetchImpl : async ( ) =>
282252 new Response (
283253 JSON . stringify ( {
284254 agents : { } ,
285255 clouds : { } ,
286256 matrix : 42 ,
287257 } ) ,
288258 ) ,
289- ) ;
290-
291- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
292- if ( existsSync ( cacheFile ) ) {
293- rmSync ( cacheFile ) ;
294- }
295-
296- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
297- consoleSpy . mockRestore ( ) ;
298- } ) ;
299-
300- it ( "throws when network errors occur and no cache exists" , async ( ) => {
301- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
302- global . fetch = mock ( async ( ) => {
303- throw new Error ( "Network timeout" ) ;
259+ } ,
260+ {
261+ label : "network error" ,
262+ fetchImpl : async ( ) => {
263+ throw new Error ( "Network timeout" ) ;
264+ } ,
265+ } ,
266+ ] ;
267+
268+ for ( const { label, fetchImpl } of invalidManifestCases ) {
269+ it ( `rejects invalid manifest (${ label } )` , async ( ) => {
270+ const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
271+ global . fetch = mock ( fetchImpl ) ;
272+ const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
273+ if ( existsSync ( cacheFile ) ) {
274+ rmSync ( cacheFile ) ;
275+ }
276+ await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
277+ consoleSpy . mockRestore ( ) ;
304278 } ) ;
305-
306- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
307- if ( existsSync ( cacheFile ) ) {
308- rmSync ( cacheFile ) ;
309- }
310-
311- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
312- consoleSpy . mockRestore ( ) ;
313- } ) ;
279+ }
314280 } ) ;
315281} ) ;
316282
0 commit comments