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

Function TestAwaitSubagentCompletion

coderd/x/chatd/subagent_internal_test.go:3253–3602  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3251}
3252
3253func TestAwaitSubagentCompletion(t *testing.T) {
3254 t.Parallel()
3255
3256 // Shared fixtures for subtests that use a real clock. Each
3257 // subtest creates its own parent+child chats (unique IDs)
3258 // so they don't collide. Mock-clock subtests need their own
3259 // DB and server because the Server's background tickers
3260 // also use the mock clock.
3261 db, ps := dbtestutil.NewDB(t)
3262 server := newInternalTestServer(t, db, ps, chatprovider.ProviderAPIKeys{})
3263 user, org, model := seedInternalChatDeps(t, db)
3264
3265 t.Run("NotDescendant", func(t *testing.T) {
3266 t.Parallel()
3267 ctx := chatdTestContext(t)
3268
3269 parent, _ := createParentChildChats(ctx, t, server, user, org, model)
3270
3271 unrelated, err := server.CreateChat(ctx, CreateOptions{
3272 OrganizationID: org.ID,
3273 OwnerID: user.ID,
3274 Title: "unrelated",
3275 ModelConfigID: model.ID,
3276 InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("other")},
3277 })
3278 require.NoError(t, err)
3279
3280 _, _, err = server.awaitSubagentCompletion(
3281 ctx, parent.ID, unrelated.ID, time.Second,
3282 )
3283 require.ErrorIs(t, err, ErrSubagentNotDescendant)
3284 })
3285
3286 t.Run("AlreadyWaiting", func(t *testing.T) {
3287 t.Parallel()
3288 ctx := chatdTestContext(t)
3289
3290 parent, child := createParentChildChats(ctx, t, server, user, org, model)
3291
3292 setChatStatus(ctx, t, db, child.ID, database.ChatStatusWaiting, "")
3293 insertAssistantMessage(t, db, child.ID, model.ID, "task complete")
3294
3295 gotChat, report, err := server.awaitSubagentCompletion(
3296 ctx, parent.ID, child.ID, time.Second,
3297 )
3298 require.NoError(t, err)
3299 assert.Equal(t, child.ID, gotChat.ID)
3300 assert.Equal(t, database.ChatStatusWaiting, gotChat.Status)
3301 assert.Equal(t, "task complete", report)
3302 })
3303
3304 t.Run("AlreadyError", func(t *testing.T) {
3305 t.Parallel()
3306 ctx := chatdTestContext(t)
3307
3308 parent, child := createParentChildChats(ctx, t, server, user, org, model)
3309
3310 setChatStatus(ctx, t, db, child.ID, database.ChatStatusError, "something broke")

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
ChatMessageTextFunction · 0.92
EventuallyFunction · 0.92
RequireReceiveFunction · 0.92
newInternalTestServerFunction · 0.85
seedInternalChatDepsFunction · 0.85
chatdTestContextFunction · 0.85
createParentChildChatsFunction · 0.85
insertAssistantMessageFunction · 0.85
drainInflightMethod · 0.80

Tested by

no test coverage detected