Fix flaky C# permission E2E assertions#1827
Conversation
Assert final permission tool lifecycle from persisted session events instead of racing live event callbacks after turn completion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR only modifies No cross-SDK consistency issues found. Specifically:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the .NET/C# permission E2E tests to reduce flakiness by avoiding reliance on live SessionEvent callback ordering after a turn completes, instead validating tool lifecycle using the persisted event stream returned by GetEventsAsync().
Changes:
- Reworked the slow-permission-handler test to await
SendAndWaitAsyncand then assert tool start/complete ordering using persisted events. - Reworked the approve-all test to assert successful shell tool completion using persisted
ToolExecutionCompleteEventrather than a callback-drivenTaskCompletionSource. - Added local helpers for polling persisted events and formatting events for assertion diagnostics.
Show a summary per file
| File | Description |
|---|---|
| dotnet/test/E2E/PermissionE2ETests.cs | Switches flaky assertions from live callbacks to persisted event stream checks; adds helper methods to poll and inspect persisted events. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Low
| var sendTask = session.SendAndWaitAsync(new MessageOptions | ||
| { | ||
| Prompt = "Run 'echo slow_handler_test'" | ||
| }); |
| Assert.True( | ||
| permissionCompleteIndex < toolCompleteIndex, | ||
| $"Expected permission completion before target tool completion. Observed: {observedLifecycle}"); | ||
| permissionStartIndex < permissionCompleteIndex, | ||
| $"Expected permission handler to complete after it started. Observed: {observedLifecycle}"); |
| List<SessionEvent> events = []; | ||
| await TestHelper.WaitForConditionAsync( | ||
| async () => | ||
| { | ||
| events = (await session.GetEventsAsync()).ToList(); | ||
| return condition(events); | ||
| }, | ||
| timeoutMessage: timeoutMessage); | ||
| return events; |
These C# permission E2E tests could flake because they asserted tool completion from live
SessionEventcallbacks after the turn had already completed. This changes the final assertions to use persisted session events fromGetEventsAsync(), avoiding callback-dispatch races while preserving the permission coverage.Summary
SendAndWaitAsynccompletes.TaskCompletionSource.Testing
dotnet format test/GitHub.Copilot.SDK.Test.csproj --include test/E2E/PermissionE2ETests.cs --verify-no-changesDOTNET_ROLL_FORWARD=Major dotnet test test/GitHub.Copilot.SDK.Test.csproj --filter "FullyQualifiedName~PermissionE2ETests.Should_Wait_For_Slow_Permission_Handler|FullyQualifiedName~PermissionE2ETests.Should_Short_Circuit_Permission_Handler_When_Set_Approve_All_Enabled"