(t *testing.T)
| 201 | } |
| 202 | |
| 203 | func TestFormatSystemInstructions(t *testing.T) { |
| 204 | t.Parallel() |
| 205 | |
| 206 | t.Run("HomeAndPwdWithAgentContext", func(t *testing.T) { |
| 207 | t.Parallel() |
| 208 | got := formatSystemInstructions("linux", "/home/coder/project", []codersdk.ChatMessagePart{ |
| 209 | {Type: codersdk.ChatMessagePartTypeContextFile, ContextFileContent: "home rules", ContextFilePath: "/home/coder/.coder/AGENTS.md"}, |
| 210 | {Type: codersdk.ChatMessagePartTypeContextFile, ContextFileContent: "project rules", ContextFilePath: "/home/coder/project/AGENTS.md"}, |
| 211 | }) |
| 212 | require.Contains(t, got, "Operating System: linux") |
| 213 | require.Contains(t, got, "Working Directory: /home/coder/project") |
| 214 | require.Contains(t, got, "Source: /home/coder/.coder/AGENTS.md") |
| 215 | require.Contains(t, got, "home rules") |
| 216 | require.Contains(t, got, "Source: /home/coder/project/AGENTS.md") |
| 217 | require.Contains(t, got, "project rules") |
| 218 | require.True(t, strings.HasPrefix(got, "<workspace-context>")) |
| 219 | require.True(t, strings.HasSuffix(got, "</workspace-context>")) |
| 220 | }) |
| 221 | |
| 222 | t.Run("OnlyPwdFile", func(t *testing.T) { |
| 223 | t.Parallel() |
| 224 | got := formatSystemInstructions("", "/home/coder/project", []codersdk.ChatMessagePart{ |
| 225 | {Type: codersdk.ChatMessagePartTypeContextFile, ContextFileContent: "project rules", ContextFilePath: "/home/coder/project/AGENTS.md"}, |
| 226 | }) |
| 227 | require.Contains(t, got, "project rules") |
| 228 | require.Contains(t, got, "Source: /home/coder/project/AGENTS.md") |
| 229 | require.NotContains(t, got, ".coder/AGENTS.md") |
| 230 | }) |
| 231 | |
| 232 | t.Run("OnlyAgentContext", func(t *testing.T) { |
| 233 | t.Parallel() |
| 234 | got := formatSystemInstructions("darwin", "/Users/dev/repo", nil) |
| 235 | require.Contains(t, got, "Operating System: darwin") |
| 236 | require.Contains(t, got, "Working Directory: /Users/dev/repo") |
| 237 | require.NotContains(t, got, "Source:") |
| 238 | require.True(t, strings.HasPrefix(got, "<workspace-context>")) |
| 239 | require.True(t, strings.HasSuffix(got, "</workspace-context>")) |
| 240 | }) |
| 241 | |
| 242 | t.Run("OnlyHomeFile", func(t *testing.T) { |
| 243 | t.Parallel() |
| 244 | got := formatSystemInstructions("", "", []codersdk.ChatMessagePart{ |
| 245 | {Type: codersdk.ChatMessagePartTypeContextFile, ContextFileContent: "home rules", ContextFilePath: "~/.coder/AGENTS.md"}, |
| 246 | }) |
| 247 | require.Contains(t, got, "Source: ~/.coder/AGENTS.md") |
| 248 | require.Contains(t, got, "home rules") |
| 249 | require.NotContains(t, got, "Operating System:") |
| 250 | require.NotContains(t, got, "Working Directory:") |
| 251 | }) |
| 252 | |
| 253 | t.Run("Empty", func(t *testing.T) { |
| 254 | t.Parallel() |
| 255 | got := formatSystemInstructions("", "", nil) |
| 256 | require.Empty(t, got) |
| 257 | }) |
| 258 | |
| 259 | t.Run("TruncatedFile", func(t *testing.T) { |
| 260 | t.Parallel() |
nothing calls this directly
no test coverage detected