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

Function TestAgentContextFilesAndSkillsLoadedIntoChat

coderd/x/chatd/chatd_test.go:8724–8873  ·  view source on GitHub ↗

TestAgentContextFilesAndSkillsLoadedIntoChat verifies the full end-to-end path: the workspace agent reads instruction files and discovers skills from the filesystem, chatd fetches them via a real tailnet agent connection, and both the block and index appear in

(t *testing.T)

Source from the content-addressed store, hash-verified

8722// This test is NOT parallel because it sets process-wide environment
8723// variables via t.Setenv to configure the agent's context config.
8724func TestAgentContextFilesAndSkillsLoadedIntoChat(t *testing.T) {
8725 fakeHome := t.TempDir()
8726 t.Setenv("HOME", fakeHome)
8727 t.Setenv("USERPROFILE", fakeHome)
8728
8729 instructionsDir := filepath.Join(fakeHome, ".coder")
8730 skillsDir := filepath.Join(fakeHome, ".coder", "skills")
8731 require.NoError(t, os.MkdirAll(instructionsDir, 0o755))
8732 require.NoError(t, os.MkdirAll(skillsDir, 0o755))
8733
8734 t.Setenv(agentcontextconfig.EnvInstructionsDirs, instructionsDir)
8735 t.Setenv(agentcontextconfig.EnvInstructionsFile, "AGENTS.md")
8736 t.Setenv(agentcontextconfig.EnvSkillsDirs, skillsDir)
8737 t.Setenv(agentcontextconfig.EnvSkillMetaFile, "SKILL.md")
8738 t.Setenv(agentcontextconfig.EnvMCPConfigFiles, filepath.Join(fakeHome, "nonexistent-mcp.json"))
8739
8740 require.NoError(t, os.WriteFile(
8741 filepath.Join(instructionsDir, "AGENTS.md"),
8742 []byte("# Project Rules\nAlways write tests."),
8743 0o600,
8744 ))
8745
8746 skillDir := filepath.Join(skillsDir, "my-cool-skill")
8747 require.NoError(t, os.MkdirAll(skillDir, 0o755))
8748 require.NoError(t, os.WriteFile(
8749 filepath.Join(skillDir, "SKILL.md"),
8750 []byte("---\nname: my-cool-skill\ndescription: A test skill\n---\nDo the cool thing.\n"),
8751 0o600,
8752 ))
8753
8754 ctx := testutil.Context(t, testutil.WaitSuperLong)
8755 deploymentValues := directChatRoutingDeploymentValues(t)
8756 client := coderdtest.New(t, &coderdtest.Options{
8757 DeploymentValues: deploymentValues,
8758 IncludeProvisionerDaemon: true,
8759 ChatdInstructionLookupTimeout: testutil.WaitLong,
8760 })
8761 user := coderdtest.CreateFirstUser(t, client)
8762 expClient := codersdk.NewExperimentalClient(client)
8763
8764 agentToken := uuid.NewString()
8765 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
8766 Parse: echo.ParseComplete,
8767 ProvisionPlan: echo.PlanComplete,
8768 ProvisionApply: echo.ApplyComplete,
8769 ProvisionGraph: echo.ProvisionGraphWithAgent(agentToken),
8770 })
8771 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
8772 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
8773 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
8774 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
8775
8776 _ = agenttest.New(t, client.URL, agentToken, agenttest.WithContextConfigFromEnv())
8777 coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
8778
8779 // Capture LLM requests so we can inspect the system prompt.
8780 var streamedCallsMu sync.Mutex
8781 streamedCalls := make([][]chattest.OpenAIMessage, 0, 2)

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected