MCPcopy Index your code
hub / github.com/coder/coder / TestStartWorkspaceTool_EndToEnd

Function TestStartWorkspaceTool_EndToEnd

coderd/x/chatd/chatd_test.go:5192–5335  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5190}
5191
5192func TestStartWorkspaceTool_EndToEnd(t *testing.T) {
5193 t.Parallel()
5194
5195 ctx := testutil.Context(t, testutil.WaitSuperLong)
5196 deploymentValues := directChatRoutingDeploymentValues(t)
5197 client := coderdtest.New(t, &coderdtest.Options{
5198 DeploymentValues: deploymentValues,
5199 IncludeProvisionerDaemon: true,
5200 })
5201 user := coderdtest.CreateFirstUser(t, client)
5202 expClient := codersdk.NewExperimentalClient(client)
5203
5204 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
5205 Parse: echo.ParseComplete,
5206 ProvisionPlan: echo.PlanComplete,
5207 ProvisionApply: echo.ApplyComplete,
5208 })
5209 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
5210 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
5211
5212 // Create a workspace, then stop it so start_workspace has
5213 // something to start. We intentionally skip starting a test
5214 // agent. The echo provisioner creates new agent rows for each
5215 // build, so an agent started for build 1 cannot serve build 3.
5216 // The tool handles the no-agent case gracefully.
5217 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
5218 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
5219 workspace = coderdtest.MustTransitionWorkspace(
5220 t, client, workspace.ID,
5221 codersdk.WorkspaceTransitionStart, codersdk.WorkspaceTransitionStop,
5222 )
5223
5224 var streamedCallCount atomic.Int32
5225 var streamedCallsMu sync.Mutex
5226 streamedCalls := make([][]chattest.OpenAIMessage, 0, 2)
5227
5228 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
5229 if !req.Stream {
5230 return chattest.OpenAINonStreamingResponse("Start workspace test")
5231 }
5232
5233 streamedCallsMu.Lock()
5234 streamedCalls = append(streamedCalls, append([]chattest.OpenAIMessage(nil), req.Messages...))
5235 streamedCallsMu.Unlock()
5236
5237 if streamedCallCount.Add(1) == 1 {
5238 return chattest.OpenAIStreamingResponse(
5239 chattest.OpenAIToolCallChunk("start_workspace", "{}"),
5240 )
5241 }
5242 return chattest.OpenAIStreamingResponse(
5243 chattest.OpenAITextChunks("Workspace started and ready.")...,
5244 )
5245 })
5246
5247 coderdtest.CreateOpenAICompatChatModelConfig(t, expClient, openAIURL)
5248
5249 // Create a chat with the stopped workspace pre-associated.

Callers

nothing calls this directly

Calls 15

CreateChatMethod · 0.95
GetChatMethod · 0.95
GetChatMessagesMethod · 0.95
ContextFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewExperimentalClientFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92

Tested by

no test coverage detected