(t *testing.T)
| 636 | } |
| 637 | |
| 638 | func TestExploreSubagentIsReadOnly(t *testing.T) { |
| 639 | t.Parallel() |
| 640 | |
| 641 | ctx := testutil.Context(t, testutil.WaitLong) |
| 642 | deploymentValues := directChatRoutingDeploymentValues(t) |
| 643 | client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{ |
| 644 | DeploymentValues: deploymentValues, |
| 645 | IncludeProvisionerDaemon: true, |
| 646 | }) |
| 647 | user := coderdtest.CreateFirstUser(t, client) |
| 648 | expClient := codersdk.NewExperimentalClient(client) |
| 649 | |
| 650 | agentToken := uuid.NewString() |
| 651 | version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{ |
| 652 | Parse: echo.ParseComplete, |
| 653 | ProvisionPlan: echo.PlanComplete, |
| 654 | ProvisionApply: echo.ApplyComplete, |
| 655 | ProvisionGraph: echo.ProvisionGraphWithAgent(agentToken), |
| 656 | }) |
| 657 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 658 | template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) |
| 659 | workspace := coderdtest.CreateWorkspace(t, client, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) { |
| 660 | cwr.AutomaticUpdates = codersdk.AutomaticUpdatesNever |
| 661 | }) |
| 662 | coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 663 | _ = agenttest.New(t, client.URL, agentToken) |
| 664 | coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait() |
| 665 | |
| 666 | var toolsMu sync.Mutex |
| 667 | toolsByCall := make([][]string, 0, 2) |
| 668 | requestsByCall := make([]recordedOpenAIRequest, 0, 2) |
| 669 | |
| 670 | var callCount atomic.Int32 |
| 671 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 672 | if !req.Stream { |
| 673 | return chattest.OpenAINonStreamingResponse("ok") |
| 674 | } |
| 675 | |
| 676 | names := make([]string, 0, len(req.Tools)) |
| 677 | for _, tool := range req.Tools { |
| 678 | names = append(names, tool.Function.Name) |
| 679 | } |
| 680 | toolsMu.Lock() |
| 681 | toolsByCall = append(toolsByCall, names) |
| 682 | requestsByCall = append(requestsByCall, recordOpenAIRequest(req)) |
| 683 | toolsMu.Unlock() |
| 684 | |
| 685 | if callCount.Add(1) == 1 { |
| 686 | return chattest.OpenAIStreamingResponse( |
| 687 | chattest.OpenAIToolCallChunk("spawn_agent", `{"type":"explore","prompt":"investigate the codebase","title":"sub"}`), |
| 688 | ) |
| 689 | } |
| 690 | return chattest.OpenAIStreamingResponse( |
| 691 | chattest.OpenAITextChunks("done")..., |
| 692 | ) |
| 693 | }) |
| 694 | |
| 695 | coderdtest.CreateOpenAICompatChatModelConfig(t, expClient, openAIURL) |
nothing calls this directly
no test coverage detected