From 175a9c3558484cb7e9e5cde37bd63d94d0259469 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 18:55:40 +0000 Subject: [PATCH] Add MessageMerger regression test skeleton Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/43f2a9ba-4aac-4491-89ba-8de379eefc2b Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../MessageMergerTests.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.cs index 09d83966aa..edd9967377 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.cs @@ -42,6 +42,47 @@ public class MessageMergerTests response.FinishReason.Should().BeNull(); } + [Fact] + public void Test_MessageMerger_PreservesFunctionCallOrderingWhenToolResultHasCreatedAt() + { + // Arrange + string responseId = Guid.NewGuid().ToString("N"); + string functionCallMessageId = Guid.NewGuid().ToString("N"); + string functionResultMessageId = Guid.NewGuid().ToString("N"); + string callId = Guid.NewGuid().ToString("N"); + DateTimeOffset toolResultCreatedAt = DateTimeOffset.UtcNow; + + MessageMerger merger = new(); + + merger.AddUpdate(new AgentResponseUpdate + { + ResponseId = responseId, + MessageId = functionCallMessageId, + AgentId = TestAgentId1, + Role = ChatRole.Assistant, + Contents = [new FunctionCallContent(callId, "handoff_to_TestAgent2")], + }); + merger.AddUpdate(new AgentResponseUpdate + { + ResponseId = responseId, + MessageId = functionResultMessageId, + AgentId = TestAgentId1, + CreatedAt = toolResultCreatedAt, + Role = ChatRole.Tool, + Contents = [new FunctionResultContent(callId, "Transferred.")], + }); + + // Act + AgentResponse response = merger.ComputeMerged(responseId); + + // Assert + response.Messages.Should().HaveCount(2); + response.Messages[0].Role.Should().Be(ChatRole.Assistant); + response.Messages[0].Contents.Should().ContainSingle().Which.Should().BeOfType(); + response.Messages[1].Role.Should().Be(ChatRole.Tool); + response.Messages[1].Contents.Should().ContainSingle().Which.Should().BeOfType(); + } + [Fact] public void Test_MessageMerger_PropagatesFinishReasonFromUpdates() {