From 15a5bbab2143de899556aad96a0b90e0333d1a26 Mon Sep 17 00:00:00 2001 From: Jacob Alber Date: Mon, 20 Apr 2026 14:13:30 -0400 Subject: [PATCH] test: Add tests for failure when .AsAgent used on a non-ChatProtocol workflow --- .../WorkflowHostSmokeTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs index 3fa17a34bb..7b9b428871 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs @@ -206,6 +206,14 @@ internal sealed class TurnTrackingStartExecutor : ChatProtocolExecutor } } +public class NonChatProtocolExecutor() : Executor(nameof(NonChatProtocolExecutor)) +{ + public override ValueTask HandleAsync(string message, IWorkflowContext context, CancellationToken cancellationToken = default) + { + return default; + } +} + public class WorkflowHostSmokeTests : AIAgentHostingExecutorTestsBase { private sealed class AlwaysFailsAIAgent(bool failByThrowing) : AIAgent @@ -732,6 +740,25 @@ public class WorkflowHostSmokeTests : AIAgentHostingExecutorTestsBase .BeEmpty(); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Test_AsAgent_FailsWhenNotChatProtocolAsync(bool runAsync) + { + // Arrange + NonChatProtocolExecutor executor = new(); + executor.DescribeProtocol().IsChatProtocol().Should().BeFalse(); + + Workflow workflow = new WorkflowBuilder(executor).Build(); + AIAgent workflowAsAgent = workflow.AsAIAgent(); + + Func action = runAsync + ? () => workflowAsAgent.RunStreamingAsync().ToAgentResponseAsync() + : () => workflowAsAgent.RunAsync(); + + await action.Should().ThrowAsync(); + } + private async Task Run_AsAgent_OutgoingMessagesInHistoryAsync(Workflow workflow, bool runAsync) { // Arrange