(t *testing.T)
| 1395 | } |
| 1396 | |
| 1397 | func TestClient_MCPAuthInterestRegistration(t *testing.T) { |
| 1398 | t.Run("create skips MCP OAuth interest without auth handler", func(t *testing.T) { |
| 1399 | client, requests, cleanup := newInMemoryClient(t) |
| 1400 | defer cleanup() |
| 1401 | |
| 1402 | session, err := client.CreateSession(t.Context(), &SessionConfig{ |
| 1403 | OnPermissionRequest: PermissionHandler.ApproveAll, |
| 1404 | OnEvent: func(SessionEvent) {}, |
| 1405 | }) |
| 1406 | if err != nil { |
| 1407 | t.Fatalf("CreateSession failed: %v", err) |
| 1408 | } |
| 1409 | defer session.Disconnect() |
| 1410 | |
| 1411 | assertNoMCPAuthInterest(t, requests.snapshot()) |
| 1412 | assertRequestMethod(t, requests.snapshot(), "session.create") |
| 1413 | assertCreateRequestPermission(t, requests.snapshot()) |
| 1414 | }) |
| 1415 | |
| 1416 | t.Run("create registers MCP OAuth interest after local session create when auth handler is configured", func(t *testing.T) { |
| 1417 | client, requests, cleanup := newInMemoryClient(t) |
| 1418 | defer cleanup() |
| 1419 | |
| 1420 | session, err := client.CreateSession(t.Context(), &SessionConfig{ |
| 1421 | OnPermissionRequest: PermissionHandler.ApproveAll, |
| 1422 | OnMCPAuthRequest: func(MCPAuthRequest, MCPAuthInvocation) (*MCPAuthResult, error) { |
| 1423 | return MCPAuthResultCancelled(), nil |
| 1424 | }, |
| 1425 | }) |
| 1426 | if err != nil { |
| 1427 | t.Fatalf("CreateSession failed: %v", err) |
| 1428 | } |
| 1429 | defer session.Disconnect() |
| 1430 | |
| 1431 | snapshot := requests.snapshot() |
| 1432 | assertRequestMethod(t, snapshot, "session.eventLog.registerInterest") |
| 1433 | if snapshot[0].Method != "session.create" { |
| 1434 | t.Fatalf("expected session.create before MCP auth interest, got %s", snapshot[0].Method) |
| 1435 | } |
| 1436 | if snapshot[1].Method != "session.eventLog.registerInterest" { |
| 1437 | t.Fatalf("expected MCP auth interest after session.create, got %s", snapshot[1].Method) |
| 1438 | } |
| 1439 | assertMCPAuthInterest(t, snapshot[1]) |
| 1440 | assertCreateRequestPermission(t, snapshot) |
| 1441 | }) |
| 1442 | |
| 1443 | t.Run("cloud create registers MCP OAuth interest after server assigns id only when auth handler is configured", func(t *testing.T) { |
| 1444 | client, requests, cleanup := newInMemoryClient(t) |
| 1445 | defer cleanup() |
| 1446 | |
| 1447 | withoutAuth, err := client.CreateSession(t.Context(), &SessionConfig{ |
| 1448 | OnPermissionRequest: PermissionHandler.ApproveAll, |
| 1449 | Cloud: &CloudSessionOptions{ |
| 1450 | Repository: &CloudSessionRepository{Owner: "github", Name: "copilot-sdk", Branch: "main"}, |
| 1451 | }, |
| 1452 | }) |
| 1453 | if err != nil { |
| 1454 | t.Fatalf("CreateSession without auth failed: %v", err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…