Skip to content

Commit ce36a4f

Browse files
authored
Add InheritedDescriptionAttributes test from PR #7599
Includes AIFunctionFactory_InheritedDescriptionAttributes_OnOverride test that validates inherited Description attributes on overridden methods, including parameter descriptions and return value descriptions. Covers both modern .NET and .NET Framework behavior differences.
1 parent 0652e52 commit ce36a4f

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/Libraries/Microsoft.Extensions.AI.Tests/Functions/AIFunctionFactoryTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,28 @@ public void AIFunctionNameAttribute_DisplayNameAttribute_StillHonoredWhenNoAIFun
510510
Assert.Equal("from-display-name", func.Name);
511511
}
512512

513+
[Fact]
514+
public void AIFunctionFactory_InheritedDescriptionAttributes_OnOverride()
515+
{
516+
MethodInfo overrideMethod = typeof(DerivedDescribed).GetMethod(nameof(DerivedDescribed.Compute))!;
517+
AIFunction f = AIFunctionFactory.Create(overrideMethod, new DerivedDescribed());
518+
519+
Assert.Equal("The compute method", f.Description);
520+
521+
JsonElement valueParam = f.JsonSchema.GetProperty("properties").GetProperty("value");
522+
Assert.Equal("The input value", valueParam.GetProperty("description").GetString());
523+
524+
Assert.NotNull(f.ReturnJsonSchema);
525+
Assert.Equal("integer", f.ReturnJsonSchema!.Value.GetProperty("type").GetString());
526+
#if NET
527+
// On modern .NET the return-parameter inheritance walk is fixed, so the inherited description is read.
528+
Assert.Equal("The computed result", f.ReturnJsonSchema!.Value.GetProperty("description").GetString());
529+
#else
530+
// On .NET Framework the inherited return-parameter description cannot be read and is silently dropped.
531+
Assert.False(f.ReturnJsonSchema!.Value.TryGetProperty("description", out _));
532+
#endif
533+
}
534+
513535
[Fact]
514536
public void AIFunctionFactoryCreateOptions_ValuesPropagateToAIFunction()
515537
{
@@ -1802,4 +1824,16 @@ private sealed class AIParameterNameAttributeRecursiveNode
18021824
{
18031825
public AIParameterNameAttributeRecursiveNode? Next { get; set; }
18041826
}
1827+
1828+
private abstract class BaseDescribed
1829+
{
1830+
[Description("The compute method")]
1831+
[return: Description("The computed result")]
1832+
public abstract int Compute([Description("The input value")] int value);
1833+
}
1834+
1835+
private sealed class DerivedDescribed : BaseDescribed
1836+
{
1837+
public override int Compute(int value) => value;
1838+
}
18051839
}

0 commit comments

Comments
 (0)