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

Function TestResolve

agent/agentcontextconfig/api_test.go:163–498  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

161}
162
163func TestResolve(t *testing.T) {
164 //nolint:paralleltest // Uses t.Setenv to mutate process-wide environment.
165 t.Run("Defaults", func(t *testing.T) {
166 setupConfigTestEnv(t, nil)
167
168 workDir := platformAbsPath("work")
169 cfg, mcpFiles := agentcontextconfig.Resolve(workDir, agentcontextconfig.ReadEnvConfig())
170
171 // Parts is always non-nil.
172 require.NotNil(t, cfg.Parts)
173 // Default MCP config file is ".mcp.json" (relative),
174 // resolved against the working directory.
175 require.Equal(t, []string{filepath.Join(workDir, ".mcp.json")}, mcpFiles)
176 })
177
178 //nolint:paralleltest // Uses t.Setenv to mutate process-wide environment.
179 t.Run("CustomEnvVars", func(t *testing.T) {
180 optInstructions := t.TempDir()
181 optSkills := t.TempDir()
182 optMCP := platformAbsPath("opt", "mcp.json")
183 setupConfigTestEnv(t, map[string]string{
184 agentcontextconfig.EnvInstructionsDirs: optInstructions,
185 agentcontextconfig.EnvInstructionsFile: "CUSTOM.md",
186 agentcontextconfig.EnvSkillsDirs: optSkills,
187 agentcontextconfig.EnvSkillMetaFile: "META.yaml",
188 agentcontextconfig.EnvMCPConfigFiles: optMCP,
189 })
190
191 // Create files matching the custom names so we can
192 // verify the env vars actually change lookup behavior.
193 require.NoError(t, os.WriteFile(filepath.Join(optInstructions, "CUSTOM.md"), []byte("custom instructions"), 0o600))
194 skillDir := filepath.Join(optSkills, "my-skill")
195 require.NoError(t, os.MkdirAll(skillDir, 0o755))
196 require.NoError(t, os.WriteFile(
197 filepath.Join(skillDir, "META.yaml"),
198 []byte("---\nname: my-skill\ndescription: custom meta\n---\n"),
199 0o600,
200 ))
201
202 workDir := platformAbsPath("work")
203 cfg, mcpFiles := agentcontextconfig.Resolve(workDir, agentcontextconfig.ReadEnvConfig())
204
205 require.Equal(t, []string{optMCP}, mcpFiles)
206 ctxFiles := filterParts(cfg.Parts, codersdk.ChatMessagePartTypeContextFile)
207 require.Len(t, ctxFiles, 1)
208 require.Equal(t, "custom instructions", ctxFiles[0].ContextFileContent)
209 skillParts := filterParts(cfg.Parts, codersdk.ChatMessagePartTypeSkill)
210 require.Len(t, skillParts, 1)
211 require.Equal(t, "my-skill", skillParts[0].SkillName)
212 require.Equal(t, "META.yaml", skillParts[0].ContextFileSkillMetaFile)
213 })
214
215 //nolint:paralleltest // Uses t.Setenv to mutate process-wide environment.
216 t.Run("WhitespaceInFileNames", func(t *testing.T) {
217 fakeHome := setupConfigTestEnv(t, map[string]string{
218 agentcontextconfig.EnvInstructionsFile: " CLAUDE.md ",
219 })
220 t.Setenv(agentcontextconfig.EnvInstructionsDirs, fakeHome)

Callers

nothing calls this directly

Calls 15

ResolveFunction · 0.92
ReadEnvConfigFunction · 0.92
setupConfigTestEnvFunction · 0.85
filterPartsFunction · 0.85
writeSkillMetaFileInRootFunction · 0.85
writeSkillMetaFileFunction · 0.85
MkdirAllMethod · 0.80
SetenvMethod · 0.80
platformAbsPathFunction · 0.70
RunMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected