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

Function TestSpawnComputerUseAgent_SystemPromptFormat

coderd/x/chatd/subagent_test.go:74–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

72}
73
74func TestSpawnComputerUseAgent_SystemPromptFormat(t *testing.T) {
75 t.Parallel()
76
77 db, ps := dbtestutil.NewDB(t)
78 server := newTestServer(t, db, ps, uuid.New())
79 ctx := testutil.Context(t, testutil.WaitLong)
80 user, org, model := seedChatDependencies(t, db)
81
82 parent, err := server.CreateChat(ctx, chatd.CreateOptions{
83 OrganizationID: org.ID,
84 OwnerID: user.ID,
85 Title: "parent",
86 ModelConfigID: model.ID,
87 InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")},
88 })
89 require.NoError(t, err)
90
91 prompt := "Navigate to settings page"
92 systemPrompt := "Computer use instructions\n\n" + prompt
93
94 child, err := server.CreateChat(ctx, chatd.CreateOptions{
95 OrganizationID: org.ID,
96 OwnerID: parent.OwnerID,
97 ParentChatID: uuid.NullUUID{
98 UUID: parent.ID,
99 Valid: true,
100 },
101 RootChatID: uuid.NullUUID{
102 UUID: parent.ID,
103 Valid: true,
104 },
105 ModelConfigID: model.ID,
106 Title: "computer-use-format",
107 ChatMode: database.NullChatMode{ChatMode: database.ChatModeComputerUse, Valid: true},
108 SystemPrompt: systemPrompt,
109 InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText(prompt)},
110 })
111 require.NoError(t, err)
112
113 messages, err := db.GetChatMessagesForPromptByChatID(ctx, child.ID)
114 require.NoError(t, err)
115
116 // The system message raw content is a JSON-encoded string.
117 // It should contain the system prompt with the user prompt.
118 var foundPrompt bool
119 for _, msg := range messages {
120 if msg.Role != "system" {
121 continue
122 }
123 if msg.Content.Valid && strings.Contains(string(msg.Content.RawMessage), prompt) {
124 foundPrompt = true
125 break
126 }
127 }
128
129 assert.True(t, foundPrompt,
130 "at least one system message should contain the user prompt")
131}

Callers

nothing calls this directly

Calls 9

NewDBFunction · 0.92
ContextFunction · 0.92
ChatMessageTextFunction · 0.92
newTestServerFunction · 0.70
seedChatDependenciesFunction · 0.70
NewMethod · 0.65
CreateChatMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected