@@ -217,52 +217,33 @@ describe("manifest", () => {
217217 await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
218218 } ) ;
219219
220- it ( "throws when manifest from GitHub is invalid" , async ( ) => {
221- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
222- global . fetch = mock (
223- async ( ) =>
220+ const invalidManifestCases : Array < {
221+ label : string ;
222+ fetchImpl : ( ) => Promise < Response > ;
223+ } > = [
224+ {
225+ label : "non-manifest shape" ,
226+ fetchImpl : async ( ) =>
224227 new Response (
225228 JSON . stringify ( {
226229 not : "a manifest" ,
227230 } ) ,
228231 ) ,
229- ) ;
230-
231- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
232- if ( existsSync ( cacheFile ) ) {
233- rmSync ( cacheFile ) ;
234- }
235-
236- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
237- consoleSpy . mockRestore ( ) ;
238- } ) ;
239-
240- it ( "rejects manifest with string agents field" , async ( ) => {
241- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
242- global . fetch = mock (
243- async ( ) =>
232+ } ,
233+ {
234+ label : "string agents field" ,
235+ fetchImpl : async ( ) =>
244236 new Response (
245237 JSON . stringify ( {
246238 agents : "claude" ,
247239 clouds : { } ,
248240 matrix : { } ,
249241 } ) ,
250242 ) ,
251- ) ;
252-
253- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
254- if ( existsSync ( cacheFile ) ) {
255- rmSync ( cacheFile ) ;
256- }
257-
258- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
259- consoleSpy . mockRestore ( ) ;
260- } ) ;
261-
262- it ( "rejects manifest with array clouds field" , async ( ) => {
263- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
264- global . fetch = mock (
265- async ( ) =>
243+ } ,
244+ {
245+ label : "array clouds field" ,
246+ fetchImpl : async ( ) =>
266247 new Response (
267248 JSON . stringify ( {
268249 agents : { } ,
@@ -273,53 +254,38 @@ describe("manifest", () => {
273254 matrix : { } ,
274255 } ) ,
275256 ) ,
276- ) ;
277-
278- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
279- if ( existsSync ( cacheFile ) ) {
280- rmSync ( cacheFile ) ;
281- }
282-
283- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
284- consoleSpy . mockRestore ( ) ;
285- } ) ;
286-
287- it ( "rejects manifest with numeric matrix field" , async ( ) => {
288- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
289- global . fetch = mock (
290- async ( ) =>
257+ } ,
258+ {
259+ label : "numeric matrix field" ,
260+ fetchImpl : async ( ) =>
291261 new Response (
292262 JSON . stringify ( {
293263 agents : { } ,
294264 clouds : { } ,
295265 matrix : 42 ,
296266 } ) ,
297267 ) ,
298- ) ;
299-
300- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
301- if ( existsSync ( cacheFile ) ) {
302- rmSync ( cacheFile ) ;
303- }
304-
305- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
306- consoleSpy . mockRestore ( ) ;
307- } ) ;
308-
309- it ( "throws when network errors occur and no cache exists" , async ( ) => {
310- const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
311- global . fetch = mock ( async ( ) => {
312- throw new Error ( "Network timeout" ) ;
268+ } ,
269+ {
270+ label : "network error" ,
271+ fetchImpl : async ( ) => {
272+ throw new Error ( "Network timeout" ) ;
273+ } ,
274+ } ,
275+ ] ;
276+
277+ for ( const { label, fetchImpl } of invalidManifestCases ) {
278+ it ( `rejects invalid manifest (${ label } )` , async ( ) => {
279+ const consoleSpy = spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
280+ global . fetch = mock ( fetchImpl ) ;
281+ const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
282+ if ( existsSync ( cacheFile ) ) {
283+ rmSync ( cacheFile ) ;
284+ }
285+ await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
286+ consoleSpy . mockRestore ( ) ;
313287 } ) ;
314-
315- const cacheFile = join ( env . testDir , "spawn" , "manifest.json" ) ;
316- if ( existsSync ( cacheFile ) ) {
317- rmSync ( cacheFile ) ;
318- }
319-
320- await expect ( loadManifest ( true ) ) . rejects . toThrow ( "Cannot load manifest" ) ;
321- consoleSpy . mockRestore ( ) ;
322- } ) ;
288+ }
323289 } ) ;
324290} ) ;
325291
0 commit comments