// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Microsoft.Agents.AI.UnitTests.AgentSkills;
///
/// Test-only helpers that peek at the underlying resource list of a skill via reflection.
///
///
/// The public API exposes resources only through
/// .
/// These helpers exist purely to allow unit tests for and
/// to inspect the concrete enumerated list a skill carries.
///
internal static class AgentSkillTestExtensions
{
public static IReadOnlyList? GetTestResources(this AgentSkill skill)
{
// AgentFileSkill / AgentInlineSkill: private "_resources" field.
for (var type = skill.GetType(); type is not null; type = type.BaseType)
{
var field = type.GetField("_resources", BindingFlags.NonPublic | BindingFlags.Instance);
if (field is not null)
{
return UnwrapList(field.GetValue(skill));
}
}
return null;
}
private static IReadOnlyList? UnwrapList(object? value) =>
value switch
{
null => null,
IReadOnlyList list => list,
IEnumerable seq => seq.ToList(),
_ => null,
};
}