Skip to content

Fix flaky C# permission E2E assertions#1827

Merged
roji merged 1 commit into
mainfrom
roji-fix-permission-flake
Jun 29, 2026
Merged

Fix flaky C# permission E2E assertions#1827
roji merged 1 commit into
mainfrom
roji-fix-permission-flake

Conversation

@roji

@roji roji commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

These C# permission E2E tests could flake because they asserted tool completion from live SessionEvent callbacks after the turn had already completed. This changes the final assertions to use persisted session events from GetEventsAsync(), avoiding callback-dispatch races while preserving the permission coverage.

Summary

  • Keep the slow-handler pre-release check that verifies the target tool has not completed before permission is released.
  • Verify final slow-handler tool start/complete ordering from the persisted event stream after SendAndWaitAsync completes.
  • Verify approve-all short-circuits the SDK handler and still produces a successful shell tool completion via persisted events instead of a live-event-only TaskCompletionSource.

Testing

  • dotnet format test/GitHub.Copilot.SDK.Test.csproj --include test/E2E/PermissionE2ETests.cs --verify-no-changes
  • DOTNET_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"

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>
@roji roji requested a review from a team as a code owner June 29, 2026 17:45
Copilot AI review requested due to automatic review settings June 29, 2026 17:45
@roji roji enabled auto-merge June 29, 2026 17:46
@github-actions

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

This PR only modifies dotnet/test/E2E/PermissionE2ETests.cs — a single test file fixing flaky race conditions in permission test assertions.

No cross-SDK consistency issues found. Specifically:

  • No new public API surface is introduced. The PR relies entirely on existing .NET SDK public APIs (SendAndWaitAsync, GetEventsAsync) that were already present in dotnet/src/Session.cs.
  • The helper methods added (WaitForPersistedEventsAsync, DescribeEvent, ToolCompleteContains) are all private static test utilities scoped to PermissionE2ETests.
  • The pattern shift (from live TaskCompletionSource callbacks to persisted event stream assertions) is a .NET test-internal improvement and does not affect any other SDK's behavior or API contract.

Optional follow-up: Other SDKs with permission E2E tests (e.g., go/internal/e2e/permissions_e2e_test.go) could be audited for similar callback-race patterns, but that's out of scope for this PR.

Generated by SDK Consistency Review Agent for issue #1827 · sonnet46 535.2K ·

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SendAndWaitAsync and then assert tool start/complete ordering using persisted events.
  • Reworked the approve-all test to assert successful shell tool completion using persisted ToolExecutionCompleteEvent rather than a callback-driven TaskCompletionSource.
  • 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

Comment on lines +380 to 383
var sendTask = session.SendAndWaitAsync(new MessageOptions
{
Prompt = "Run 'echo slow_handler_test'"
});
Comment on lines 419 to +421
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}");
Comment on lines +772 to +780
List<SessionEvent> events = [];
await TestHelper.WaitForConditionAsync(
async () =>
{
events = (await session.GetEventsAsync()).ToList();
return condition(events);
},
timeoutMessage: timeoutMessage);
return events;
@roji roji added this pull request to the merge queue Jun 29, 2026
Merged via the queue into main with commit 07f849a Jun 29, 2026
19 of 20 checks passed
@roji roji deleted the roji-fix-permission-flake branch June 29, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants