@@ -422,4 +422,157 @@ class CatalogPruningTest {
422422 )
423423 kotlin.test.assertEquals(" /absolute/examples" , config.examplesPath)
424424 }
425+
426+ @Test
427+ fun loadsExamplesWithGlob () {
428+ val tempDir = java.nio.file.Files .createTempDirectory(" examples" ).toFile()
429+ try {
430+ val nestedDir = java.io.File (tempDir, " nested" )
431+ nestedDir.mkdir()
432+
433+ java.io
434+ .File (tempDir, " top.json" )
435+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" top\" }}]" )
436+ java.io
437+ .File (nestedDir, " deep.json" )
438+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" deep\" }}]" )
439+ java.io.File (tempDir, " ignored.txt" ).writeText(" not json" )
440+
441+ val catalog =
442+ A2uiCatalog (
443+ version = A2uiVersion .VERSION_0_8 ,
444+ name = " basic" ,
445+ serverToClientSchema = JsonObject (emptyMap()),
446+ commonTypesSchema = JsonObject (emptyMap()),
447+ catalogSchema = JsonObject (mapOf (A2uiConstants .CATALOG_ID_KEY to JsonPrimitive (" basic" ))),
448+ )
449+
450+ // Match only top-level using a specific glob
451+ val examplesTop = catalog.loadExamples(" ${tempDir.path} /*.json" )
452+ assertTrue(examplesTop.contains(" ---BEGIN top---" ))
453+ assertFalse(examplesTop.contains(" ---BEGIN deep---" ))
454+
455+ // Match recursively using globstar
456+ val examplesAll = catalog.loadExamples(" ${tempDir.path} /**/*.json" )
457+ assertTrue(examplesAll.contains(" ---BEGIN top---" ))
458+ assertTrue(examplesAll.contains(" ---BEGIN deep---" ))
459+ } finally {
460+ tempDir.deleteRecursively()
461+ }
462+ }
463+
464+ @Test
465+ fun loadsExamplesWithGlobPrefixSuffix () {
466+ val tempDir = java.nio.file.Files .createTempDirectory(" examples" ).toFile()
467+ try {
468+ java.io
469+ .File (tempDir, " user_profile.json" )
470+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" user\" }}]" )
471+ java.io
472+ .File (tempDir, " user_settings.json" )
473+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" settings\" }}]" )
474+ java.io
475+ .File (tempDir, " admin_profile.json" )
476+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" admin\" }}]" )
477+
478+ val catalog =
479+ A2uiCatalog (
480+ version = A2uiVersion .VERSION_0_8 ,
481+ name = " basic" ,
482+ serverToClientSchema = JsonObject (emptyMap()),
483+ commonTypesSchema = JsonObject (emptyMap()),
484+ catalogSchema = JsonObject (mapOf (A2uiConstants .CATALOG_ID_KEY to JsonPrimitive (" basic" ))),
485+ )
486+
487+ // Filter by prefix: user_*.json
488+ val userExamples = catalog.loadExamples(" ${tempDir.path} /user_*.json" )
489+ assertTrue(userExamples.contains(" ---BEGIN user_profile---" ))
490+ assertTrue(userExamples.contains(" ---BEGIN user_settings---" ))
491+ assertFalse(userExamples.contains(" ---BEGIN admin_profile---" ))
492+
493+ // Filter by suffix: *_profile.json
494+ val profileExamples = catalog.loadExamples(" ${tempDir.path} /*_profile.json" )
495+ assertTrue(profileExamples.contains(" ---BEGIN user_profile---" ))
496+ assertTrue(profileExamples.contains(" ---BEGIN admin_profile---" ))
497+ assertFalse(profileExamples.contains(" ---BEGIN user_settings---" ))
498+ } finally {
499+ tempDir.deleteRecursively()
500+ }
501+ }
502+
503+ @Test
504+ fun loadsExamplesWithGlobAdvancedCases () {
505+ val tempDir = java.nio.file.Files .createTempDirectory(" examples" ).toFile()
506+ try {
507+ java.io
508+ .File (tempDir, " step1.json" )
509+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" 1\" }}]" )
510+ java.io
511+ .File (tempDir, " step2.json" )
512+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" 2\" }}]" )
513+ java.io
514+ .File (tempDir, " step3.json" )
515+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" 3\" }}]" )
516+
517+ val fakeJsonDir = java.io.File (tempDir, " directory.json" )
518+ fakeJsonDir.mkdir()
519+
520+ val catalog =
521+ A2uiCatalog (
522+ version = A2uiVersion .VERSION_0_8 ,
523+ name = " basic" ,
524+ serverToClientSchema = JsonObject (emptyMap()),
525+ commonTypesSchema = JsonObject (emptyMap()),
526+ catalogSchema = JsonObject (mapOf (A2uiConstants .CATALOG_ID_KEY to JsonPrimitive (" basic" ))),
527+ )
528+
529+ // Test character range matching
530+ val rangeExamples = catalog.loadExamples(" ${tempDir.path} /step[1-2].json" )
531+ assertTrue(rangeExamples.contains(" ---BEGIN step1---" ))
532+ assertTrue(rangeExamples.contains(" ---BEGIN step2---" ))
533+ assertFalse(rangeExamples.contains(" ---BEGIN step3---" ))
534+
535+ // Test that directory matching *.json is skipped correctly
536+ val allExamples = catalog.loadExamples(" ${tempDir.path} /*.json" )
537+ assertTrue(allExamples.contains(" ---BEGIN step1---" ))
538+ assertFalse(allExamples.contains(" directory" ))
539+
540+ // Test zero matches returns empty string
541+ kotlin.test.assertEquals(
542+ expected = " " ,
543+ actual = catalog.loadExamples(" ${tempDir.path} /*.yaml" ),
544+ )
545+ } finally {
546+ tempDir.deleteRecursively()
547+ }
548+ }
549+
550+ @Test
551+ fun loadsExamplesWithGlobNegation () {
552+ val tempDir = java.nio.file.Files .createTempDirectory(" examples" ).toFile()
553+ try {
554+ java.io
555+ .File (tempDir, " visible.json" )
556+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" visible\" }}]" )
557+ java.io
558+ .File (tempDir, " index.json" )
559+ .writeText(" [{\" beginRendering\" : {\" surfaceId\" : \" index\" }}]" )
560+
561+ val catalog =
562+ A2uiCatalog (
563+ version = A2uiVersion .VERSION_0_8 ,
564+ name = " basic" ,
565+ serverToClientSchema = JsonObject (emptyMap()),
566+ commonTypesSchema = JsonObject (emptyMap()),
567+ catalogSchema = JsonObject (mapOf (A2uiConstants .CATALOG_ID_KEY to JsonPrimitive (" basic" ))),
568+ )
569+
570+ // Test negation to exclude files starting with 'i' (like index.json)
571+ val negationExamples = catalog.loadExamples(" ${tempDir.path} /[!i]*.json" )
572+ assertTrue(negationExamples.contains(" ---BEGIN visible---" ))
573+ assertFalse(negationExamples.contains(" ---BEGIN index---" ))
574+ } finally {
575+ tempDir.deleteRecursively()
576+ }
577+ }
425578}
0 commit comments