From c8aebf8eabf60f75e4d118668d3cca4998a09d94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 28 May 2026 12:18:08 +0000 Subject: [PATCH] test: assert no subsequent tool call and exact agent invocation counts in coord/spec/coord ping-pong handoff --- .../HandoffOrchestrationTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffOrchestrationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffOrchestrationTests.cs index 2be2ea3015..ff71ef2be6 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffOrchestrationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/HandoffOrchestrationTests.cs @@ -411,6 +411,7 @@ public class HandoffOrchestrationTests // at the very end, breaking the contiguity of each step's block. int coordCallCount = 0; + int specCallCount = 0; var coord = new ChatClientAgent(new MockChatClient((messages, options) => { coordCallCount++; @@ -424,6 +425,9 @@ public class HandoffOrchestrationTests }; } + // Second (final) Coord turn: emit only assistant text - no tool call. + // The test asserts this turn does NOT emit a handoff_to_* FunctionCallContent + // and that the workflow terminates here (coordCallCount stays at 2). return new(new ChatMessage(ChatRole.Assistant, "Here are two fake Excel course recommendations") { MessageId = "coord-msg-2" }) { ResponseId = "resp-coord-2", @@ -432,6 +436,7 @@ public class HandoffOrchestrationTests var spec = new ChatClientAgent(new MockChatClient((messages, options) => { + specCallCount++; string? transferFuncName = options?.Tools?.FirstOrDefault(t => t.Name.StartsWith("handoff_to_", StringComparison.Ordinal))?.Name; Assert.NotNull(transferFuncName); @@ -492,6 +497,13 @@ public class HandoffOrchestrationTests Assert.Equal(ChatRole.Assistant, result[5].Role); Assert.Contains("Coord", result[5].AuthorName); Assert.Equal("Here are two fake Excel course recommendations", result[5].Text); + + // Final Coord turn must emit ONLY assistant text - no further handoff/tool call. + Assert.DoesNotContain(result[5].Contents, c => c is FunctionCallContent); + + // And the workflow must have terminated after that turn - no extra Coord/Spec re-invocations. + Assert.Equal(2, coordCallCount); + Assert.Equal(1, specCallCount); } [Fact]