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

Function TestCreateWorkspaceTool_EndToEnd

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

Source from the content-addressed store, hash-verified

5025}
5026
5027func TestCreateWorkspaceTool_EndToEnd(t *testing.T) {
5028 t.Parallel()
5029
5030 ctx := testutil.Context(t, testutil.WaitLong)
5031 deploymentValues := directChatRoutingDeploymentValues(t)
5032 client := coderdtest.New(t, &coderdtest.Options{
5033 DeploymentValues: deploymentValues,
5034 IncludeProvisionerDaemon: true,
5035 })
5036 user := coderdtest.CreateFirstUser(t, client)
5037 expClient := codersdk.NewExperimentalClient(client)
5038
5039 agentToken := uuid.NewString()
5040 // Add a startup script so the agent spends time in the
5041 // "starting" lifecycle state. This lets us verify that
5042 // create_workspace waits for scripts to finish.
5043 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
5044 Parse: echo.ParseComplete,
5045 ProvisionPlan: echo.PlanComplete,
5046 ProvisionApply: echo.ApplyComplete,
5047 ProvisionGraph: echo.ProvisionGraphWithAgent(agentToken, func(g *proto.GraphComplete) {
5048 g.Resources[0].Agents[0].Scripts = []*proto.Script{{
5049 DisplayName: "setup",
5050 Script: "sleep 5",
5051 RunOnStart: true,
5052 }}
5053 }),
5054 })
5055 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
5056 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
5057
5058 // Start the test workspace agent so create_workspace can wait for
5059 // the agent to become reachable before returning.
5060 _ = agenttest.New(t, client.URL, agentToken)
5061
5062 workspaceName := "chat-ws-" + strings.ReplaceAll(uuid.NewString(), "-", "")[:8]
5063 createWorkspaceArgs := fmt.Sprintf(
5064 `{"template_id":%q,"name":%q}`,
5065 template.ID.String(),
5066 workspaceName,
5067 )
5068
5069 var streamedCallCount atomic.Int32
5070 var streamedCallsMu sync.Mutex
5071 streamedCalls := make([][]chattest.OpenAIMessage, 0, 2)
5072
5073 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
5074 if !req.Stream {
5075 return chattest.OpenAINonStreamingResponse("Create workspace test")
5076 }
5077
5078 streamedCallsMu.Lock()
5079 streamedCalls = append(streamedCalls, append([]chattest.OpenAIMessage(nil), req.Messages...))
5080 streamedCallsMu.Unlock()
5081
5082 if streamedCallCount.Add(1) == 1 {
5083 return chattest.OpenAIStreamingResponse(
5084 chattest.OpenAIToolCallChunk("create_workspace", createWorkspaceArgs),

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
ProvisionGraphWithAgentFunction · 0.92
CreateTemplateFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected