Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/HostedCodeInterpreterFileAgentSkillScriptExecutorTests.cs
T
SergeyMenshykh c9cd067be6 .NET: Support hosted code interpreter for skill script execution (#4192)
* support script execution by code interpretor

* improve the instruction prompt

* Add DefaultAzureCredential production warning to AgentSkills samples

Add the standard three-line WARNING comment about DefaultAzureCredential
production considerations to both AgentSkills sample Program.cs files,
matching the convention used in all other GettingStarted/Agents samples.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* address pr review comments

* address feedback

* rename Skill* types to FileAgentSkill* prefix for consistency

- Rename SkillFrontmatter -> FileAgentSkillFrontmatter
- Rename SkillScriptExecutor -> FileAgentSkillScriptExecutor
- Add FileAgentSkillScriptExecutionContext and FileAgentSkillScriptExecutionDetails
- Update sample, provider, loader, and tests accordingly

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* reorder usings

* use set for props initialization instead of init

* rename HostedCodeInterpreterSkillScriptExecutor

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-26 13:17:21 +00:00

73 lines
2.3 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Logging.Abstractions;
namespace Microsoft.Agents.AI.UnitTests.AgentSkills;
/// <summary>
/// Unit tests for <see cref="HostedCodeInterpreterFileAgentSkillScriptExecutor"/>.
/// </summary>
public sealed class HostedCodeInterpreterFileAgentSkillScriptExecutorTests
{
private static readonly FileAgentSkillScriptExecutionContext s_emptyContext = new(
new Dictionary<string, FileAgentSkill>(StringComparer.OrdinalIgnoreCase),
new FileAgentSkillLoader(NullLogger.Instance));
[Fact]
public void GetExecutionDetails_ReturnsScriptExecutionGuidance()
{
// Arrange
var executor = new HostedCodeInterpreterFileAgentSkillScriptExecutor();
// Act
var details = executor.GetExecutionDetails(s_emptyContext);
// Assert
Assert.NotNull(details.Instructions);
Assert.Contains("read_skill_resource", details.Instructions);
Assert.Contains("code interpreter", details.Instructions);
}
[Fact]
public void GetExecutionDetails_ReturnsSingleHostedCodeInterpreterTool()
{
// Arrange
var executor = new HostedCodeInterpreterFileAgentSkillScriptExecutor();
// Act
var details = executor.GetExecutionDetails(s_emptyContext);
// Assert
Assert.NotNull(details.Tools);
Assert.Single(details.Tools!);
Assert.IsType<HostedCodeInterpreterTool>(details.Tools![0]);
}
[Fact]
public void GetExecutionDetails_ReturnsSameInstanceOnMultipleCalls()
{
// Arrange
var executor = new HostedCodeInterpreterFileAgentSkillScriptExecutor();
// Act
var details1 = executor.GetExecutionDetails(s_emptyContext);
var details2 = executor.GetExecutionDetails(s_emptyContext);
// Assert — static details should be reused
Assert.Same(details1, details2);
}
[Fact]
public void FactoryMethod_ReturnsHostedCodeInterpreterFileAgentSkillScriptExecutor()
{
// Act
var executor = FileAgentSkillScriptExecutor.HostedCodeInterpreter();
// Assert
Assert.IsType<HostedCodeInterpreterFileAgentSkillScriptExecutor>(executor);
}
}