Skip to content

Commit 99b1679

Browse files
CopilotCopilot
andcommitted
Add test for null Data path in ConvertToAgentResponseUpdate (#4732)
Add a regression test covering the null-propagation path where AssistantMessageEvent.Data is null. The production code already handles this via ?. operators, but no test previously verified the behavior. Co-authored-by: Copilot <[email protected]>
1 parent 79b662a commit 99b1679

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,26 @@ public void ConvertToAgentResponseUpdate_AssistantMessageEventWhenNotStreaming_H
360360
Assert.Empty(result.Text);
361361
Assert.Contains(result.Contents, c => c is TextContent);
362362
}
363+
364+
[Fact]
365+
public void ConvertToAgentResponseUpdate_AssistantMessageEventWhenNotStreaming_HandlesNullData()
366+
{
367+
// Arrange
368+
var assistantMessage = new AssistantMessageEvent
369+
{
370+
Data = null!
371+
};
372+
CopilotClient copilotClient = new(new CopilotClientOptions());
373+
const string TestId = "agent-id";
374+
var agent = new GitHubCopilotAgent(copilotClient, ownsClient: false, id: TestId, tools: null);
375+
376+
// Act
377+
AgentResponseUpdate result = agent.ConvertToAgentResponseUpdate(assistantMessage, isStreaming: false);
378+
379+
// Assert - null Data should produce empty TextContent via null-propagation fallback.
380+
Assert.Empty(result.Text);
381+
Assert.Contains(result.Contents, c => c is TextContent);
382+
Assert.Null(result.MessageId);
383+
Assert.Null(result.ResponseId);
384+
}
363385
}

0 commit comments

Comments
 (0)