Skip to content

Add PermissionRequestResultKind type for .NET and Go SDKs#631

Draft
stephentoub wants to merge 3 commits intogithub:mainfrom
stephentoub:stoub/permission-result-kind-type
Draft

Add PermissionRequestResultKind type for .NET and Go SDKs#631
stephentoub wants to merge 3 commits intogithub:mainfrom
stephentoub:stoub/permission-result-kind-type

Conversation

@stephentoub
Copy link
Collaborator

Summary

Replace magic strings for permission request result kinds with strongly-typed values in the .NET and Go SDKs.

Problem

The PermissionRequestResult.Kind field was typed as a plain string in both .NET and Go, requiring developers to use undiscoverable magic strings like "approved" or "denied-interactively-by-user". Node.js and Python already constrain these via union/literal types.

Solution

C# (.NET): Add a PermissionRequestResultKind readonly struct following the ChatRole pattern from Microsoft.Extensions.AI:

  • IEquatable<T>, case-insensitive equality, custom JsonConverter
  • Static properties: Approved, DeniedByRules, DeniedCouldNotRequestFromUser, DeniedInteractivelyByUser
  • Extensible via constructor for custom values

Go: Add a PermissionRequestResultKind typed string with constants, following the existing ConnectionState pattern:

  • PermissionKindApproved, PermissionKindDeniedByRules, PermissionKindDeniedCouldNotRequestFromUser, PermissionKindDeniedInteractivelyByUser

Both SDKs include unit tests covering value correctness, equality, and JSON serialization round-trips. All existing magic string usages in source and test files have been replaced with the new constants.

Replace magic strings for permission request result kinds with
strongly-typed values. .NET uses a readonly struct following the
ChatRole pattern from Microsoft.Extensions.AI. Go uses a typed
string constant block following the existing ConnectionState pattern.

Both remain extensible for custom values while making the well-known
kinds (approved, denied-by-rules, denied-interactively-by-user,
denied-no-approval-rule-and-could-not-request-from-user) discoverable
via IntelliSense/autocomplete.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub requested a review from a team as a code owner March 2, 2026 16:43
Copilot AI review requested due to automatic review settings March 2, 2026 16:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds strongly-typed permission request result kinds to the Go and .NET SDKs to replace previously required “magic string” values, aligning these SDKs with the more constrained typing already present in other languages.

Changes:

  • Go: Introduces PermissionRequestResultKind (typed string) with exported constants, updates SDK and e2e tests to use them.
  • .NET: Introduces PermissionRequestResultKind (readonly struct + JsonConverter), updates SDK code and tests to use it.
  • Adds new unit tests validating constants and JSON round-trips in both SDKs.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
go/types.go Adds PermissionRequestResultKind and updates PermissionRequestResult.Kind to use it.
go/types_test.go New unit tests for Go constants and JSON serialization/deserialization.
go/session.go Replaces denial magic string with the new Go constant.
go/permissions.go Updates ApproveAll handler to use the new Go constant.
go/client.go Updates fallback denial kind to use the new Go constant.
go/internal/e2e/tools_test.go Updates e2e permission handler returns to use new Go constants.
go/internal/e2e/permissions_test.go Updates e2e permission handler returns to use new Go constants.
dotnet/src/Types.cs Adds PermissionRequestResultKind struct + converter and updates PermissionRequestResult.Kind type.
dotnet/src/Session.cs Updates default denial to use PermissionRequestResultKind.
dotnet/src/PermissionHandlers.cs Updates ApproveAll to use PermissionRequestResultKind.
dotnet/src/Client.cs Updates fallback denial to use PermissionRequestResultKind.
dotnet/test/ToolsTests.cs Updates tests to return typed kinds.
dotnet/test/PermissionTests.cs Updates tests to return typed kinds.
dotnet/test/PermissionRequestResultKindTests.cs New unit tests for value correctness, equality, and JSON round-trips.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub marked this pull request as draft March 2, 2026 18:15
The 'forwards clientName in session.resume request' test calls through to
the real CLI, which requires COPILOT_HMAC_KEY for authentication. This
secret is unavailable to fork PRs, causing CI failures. Mock the
sendRequest return value since the test only verifies parameter forwarding.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants