// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Agents.AI.UnitTests.AgentSkills;
///
/// Unit tests for , focusing on the structure of the
/// emitted <available_resources> and <available_scripts> blocks.
///
public sealed class AgentInlineSkillContentBuilderTests
{
[Fact]
public void Build_NullResourcesAndScripts_EmitsSelfClosingTags()
{
// Act
var content = AgentInlineSkillContentBuilder.Build("my-skill", "A skill.", "Instructions.", resources: null, scripts: null);
// Assert — explicit empty elements signal "none available" so the model does not hallucinate names
Assert.Contains("", content);
Assert.Contains("", content);
Assert.DoesNotContain("", content);
Assert.DoesNotContain("", content);
}
[Fact]
public void Build_EmptyResourcesAndScripts_EmitsSelfClosingTags()
{
// Act
var content = AgentInlineSkillContentBuilder.Build(
"my-skill",
"A skill.",
"Instructions.",
resources: Array.Empty(),
scripts: Array.Empty());
// Assert
Assert.Contains("", content);
Assert.Contains("", content);
}
[Fact]
public void Build_ResourcesOnly_EmitsResourceEntriesAndSelfClosingScripts()
{
// Arrange
var resources = new AgentSkillResource[]
{
new AgentInlineSkillResource("config", "value", "A described resource."),
new AgentInlineSkillResource("table", "value"),
};
// Act
var content = AgentInlineSkillContentBuilder.Build("my-skill", "A skill.", "Instructions.", resources, scripts: null);
// Assert — resources are listed by name with optional description, scripts are an empty element
Assert.Contains("", content);
Assert.Contains("", content);
Assert.Contains("", content);
Assert.Contains("", content);
Assert.Contains("", content);
}
[Fact]
public void Build_ScriptsOnly_EmitsSelfClosingResourcesAndScriptsBlock()
{
// Arrange
var scripts = new AgentSkillScript[] { new FakeScript("run", ParseSchema("{\"type\":\"object\"}")) };
// Act
var content = AgentInlineSkillContentBuilder.Build("my-skill", "A skill.", "Instructions.", resources: null, scripts);
// Assert
Assert.Contains("", content);
Assert.Contains("", content);
Assert.Contains("", block);
Assert.DoesNotContain("&\"c", parametersSchema: null) };
// Act
var block = AgentInlineSkillContentBuilder.BuildAvailableScriptsBlock(scripts);
// Assert
Assert.Contains("