Skip to content

[dotnet-port-fixes] Cover implicit tool approval sessions #866

Description

@github-actions

Summary

Added regression coverage for the .NET tool-approval no-session fix by exercising Go's existing implicit-session behavior through a real agent run. The new tests verify that agent.prepareRun creates exactly one implicit session, threads it through tool-approval auto-approval re-entry, and still provides that session on a no-approval pass-through run.

Ported .NET PRs

Breaking Changes

No. This is a test-only parity update for behavior the Go SDK already implements.

Tests and Examples

  • go test ./agent/harness/toolapproval
  • Added focused tests for implicit session threading during tool-approval auto-approval re-entry and for single implicit-session creation when no approval request is returned

Notes

Go already aligned the runtime behavior before this change because agent.prepareRun injects an implicit session before middleware executes. This PR ports the upstream regression coverage so that alignment stays protected. Go uses a single streamed run path, so separate .NET non-streaming and streaming coverage collapses into these focused tests.

Generated by .NET to Go Fixes and Test Porting Agent · gpt54 · 229.6 AIC · ⌖ 11.7 AIC · ⊞ 24.2K ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch copilot/dotnet-port-fixes-toolapproval-implicit-session-684c84d4411d22d8.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (169 of 169 lines)
From a9aba78c4bedef81f692dd7042c1a5154b785801 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Wed, 19 Aug 2026 02:55:15 +0000
Subject: [PATCH] test: cover implicit tool approval sessions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 .../harness/toolapproval/toolapproval_test.go | 137 ++++++++++++++++++
 1 file changed, 137 insertions(+)

diff --git a/agent/harness/toolapproval/toolapproval_test.go b/agent/harness/toolapproval/toolapproval_test.go
index d078861fd..f1f4021ea 100644
--- a/agent/harness/toolapproval/toolapproval_test.go
+++ b/agent/harness/toolapproval/toolapproval_test.go
@@ -30,6 +30,15 @@ func collectUpdates(t *testing.T, mw agent.Middleware, next agent.RunFunc, messa
 	return updates
 }
 
+func sessionFromOptions(t *testing.T, opts ...agent.Option) *agent.Session {
+	t.Helper()
+	session, ok := agent.GetOption(opts, agent.WithSession)
+	if !ok || session == nil {
+		t.Fatal("expected run options to include a non-nil session")
+	}
+	return session
+}
+
 func TestToolApproval_PassthroughWithoutApprovalRequests(t *testing.T) {
 	runner := &agenttest.Runner{
 		Responses: agenttest.NewResponseBuilder().AddText("hello").Build(),
@@ -147,6 +156,134 @@ func TestToolApproval_SurfacesFirstApprovalRequest(t *testing.T) {
 	}
 }
 
+func TestToolApproval_AutoApprovalRuleWithoutExplicitSessionThreadsImplicitSession(t *testing.T) {
+	fcc := &message.FunctionCallContent{CallID: "c1", Name: "deploy", Arguments: `{"env":"prod"}`}
+
+	var createdSession *agent.Session
+	createSessionCalls := 0
+	capturedSessions := []*agent.Session{}
+
+	runner := &agenttest.Runner{
+		Responses: agenttest.NewResponseBuilder(
+			func(_ context.Context, _ []*message.Message, opts ...agent.Option) {
+				capturedSessions = append(capturedSessions, sessionFromOptions(t, opts...))
+			},
+		).
+			Add(&agent.ResponseUpdate{
+				Role: message.RoleAssistant,
+				Contents: []message.Content{
+					&mes
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions