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

Function TestInstructionFromContextFiles

coderd/x/chatd/instruction_internal_test.go:294–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

292}
293
294func TestInstructionFromContextFiles(t *testing.T) {
295 t.Parallel()
296
297 makeMsg := func(parts []codersdk.ChatMessagePart) database.ChatMessage {
298 raw, _ := json.Marshal(parts)
299 return database.ChatMessage{
300 Content: pqtype.NullRawMessage{RawMessage: raw, Valid: true},
301 }
302 }
303
304 t.Run("EmptyMessages", func(t *testing.T) {
305 t.Parallel()
306 got := instructionFromContextFiles(nil)
307 require.Empty(t, got)
308 })
309
310 t.Run("NoContextFileParts", func(t *testing.T) {
311 t.Parallel()
312 msgs := []database.ChatMessage{
313 makeMsg([]codersdk.ChatMessagePart{
314 {
315 Type: codersdk.ChatMessagePartTypeSkill,
316 SkillName: "test",
317 SkillDescription: "test skill",
318 },
319 }),
320 }
321 got := instructionFromContextFiles(msgs)
322 require.Empty(t, got)
323 })
324
325 t.Run("ReconstructsFromContextFileParts", func(t *testing.T) {
326 t.Parallel()
327 msgs := []database.ChatMessage{
328 makeMsg([]codersdk.ChatMessagePart{
329 {
330 Type: codersdk.ChatMessagePartTypeContextFile,
331 ContextFileOS: "linux",
332 ContextFileDirectory: "/home/coder/project",
333 ContextFileContent: "project rules",
334 ContextFilePath: "/home/coder/project/AGENTS.md",
335 },
336 }),
337 }
338 got := instructionFromContextFiles(msgs)
339 require.Contains(t, got, "Operating System: linux")
340 require.Contains(t, got, "Working Directory: /home/coder/project")
341 require.Contains(t, got, "Source: /home/coder/project/AGENTS.md")
342 require.Contains(t, got, "project rules")
343 })
344}

Callers

nothing calls this directly

Calls 6

makeMsgFunction · 0.85
RunMethod · 0.65
MarshalMethod · 0.45
EmptyMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected