@@ -833,8 +833,10 @@ public async Task StructuredOutput_WithDuplicateTypeRefs_RewritesRefPointers()
833833 // (confirming the rewrite happened).
834834 string schemaJson = tool . ProtocolTool . OutputSchema . Value . GetRawText ( ) ;
835835 var schemaNode = JsonNode . Parse ( schemaJson ) ! ;
836- AssertAllRefsStartWith ( schemaNode , "#/properties/result" ) ;
837- AssertAllRefsResolvable ( schemaNode , schemaNode ) ;
836+ int refCount = AssertAllRefsStartWith ( schemaNode , "#/properties/result" ) ;
837+ Assert . True ( refCount > 0 , "Expected at least one $ref in the schema to validate the rewrite, but none were found." ) ;
838+ int resolvableCount = AssertAllRefsResolvable ( schemaNode , schemaNode ) ;
839+ Assert . True ( resolvableCount > 0 , "Expected at least one resolvable $ref in the schema, but none were found." ) ;
838840 }
839841
840842 [ Fact ]
@@ -871,39 +873,46 @@ public async Task StructuredOutput_WithRecursiveTypeRefs_RewritesRefPointers()
871873
872874 string schemaJson = tool . ProtocolTool . OutputSchema . Value . GetRawText ( ) ;
873875 var schemaNode = JsonNode . Parse ( schemaJson ) ! ;
874- AssertAllRefsStartWith ( schemaNode , "#/properties/result" ) ;
875- AssertAllRefsResolvable ( schemaNode , schemaNode ) ;
876+ int refCount = AssertAllRefsStartWith ( schemaNode , "#/properties/result" ) ;
877+ Assert . True ( refCount > 0 , "Expected at least one $ref in the schema to validate the rewrite, but none were found." ) ;
878+ int resolvableCount = AssertAllRefsResolvable ( schemaNode , schemaNode ) ;
879+ Assert . True ( resolvableCount > 0 , "Expected at least one resolvable $ref in the schema, but none were found." ) ;
876880 }
877881
878- private static void AssertAllRefsStartWith ( JsonNode ? node , string expectedPrefix )
882+ private static int AssertAllRefsStartWith ( JsonNode ? node , string expectedPrefix )
879883 {
884+ int count = 0 ;
880885 if ( node is JsonObject obj )
881886 {
882887 if ( obj . TryGetPropertyValue ( "$ref" , out JsonNode ? refNode ) &&
883888 refNode ? . GetValue < string > ( ) is string refValue )
884889 {
885890 Assert . StartsWith ( expectedPrefix , refValue ) ;
891+ count ++ ;
886892 }
887893
888894 foreach ( var property in obj )
889895 {
890- AssertAllRefsStartWith ( property . Value , expectedPrefix ) ;
896+ count += AssertAllRefsStartWith ( property . Value , expectedPrefix ) ;
891897 }
892898 }
893899 else if ( node is JsonArray arr )
894900 {
895901 foreach ( var item in arr )
896902 {
897- AssertAllRefsStartWith ( item , expectedPrefix ) ;
903+ count += AssertAllRefsStartWith ( item , expectedPrefix ) ;
898904 }
899905 }
906+
907+ return count ;
900908 }
901909
902910 /// <summary>
903911 /// Walks the JSON tree and verifies that every <c>$ref</c> pointer resolves to a valid node.
904912 /// </summary>
905- private static void AssertAllRefsResolvable ( JsonNode root , JsonNode ? node )
913+ private static int AssertAllRefsResolvable ( JsonNode root , JsonNode ? node )
906914 {
915+ int count = 0 ;
907916 if ( node is JsonObject obj )
908917 {
909918 if ( obj . TryGetPropertyValue ( "$ref" , out JsonNode ? refNode ) &&
@@ -912,20 +921,23 @@ private static void AssertAllRefsResolvable(JsonNode root, JsonNode? node)
912921 {
913922 var resolved = ResolveJsonPointer ( root , refValue ) ;
914923 Assert . True ( resolved is not null , $ "$ref \" { refValue } \" does not resolve to a valid node in the schema.") ;
924+ count ++ ;
915925 }
916926
917927 foreach ( var property in obj )
918928 {
919- AssertAllRefsResolvable ( root , property . Value ) ;
929+ count += AssertAllRefsResolvable ( root , property . Value ) ;
920930 }
921931 }
922932 else if ( node is JsonArray arr )
923933 {
924934 foreach ( var item in arr )
925935 {
926- AssertAllRefsResolvable ( root , item ) ;
936+ count += AssertAllRefsResolvable ( root , item ) ;
927937 }
928938 }
939+
940+ return count ;
929941 }
930942
931943 /// <summary>
0 commit comments