fix(coderd/x/chatd): avoid request recorder race (#27525)

`TestActiveServer_BasicAssistantGenerationAndPromptPreparation` could
race by reassigning a request recorder captured by concurrent callbacks.
Keep the recorder immutable across both scenarios.

Closes https://github.com/coder/internal/issues/1626
This commit is contained in:
Hugo Dutka
2026-07-27 14:16:21 +02:00
committed by GitHub
parent dba45cede7
commit b67e1b24f9
+4 -4
View File
@@ -6343,7 +6343,6 @@ func TestActiveServer_BasicAssistantGenerationAndPromptPreparation(t *testing.T)
require.GreaterOrEqual(t, last.RuntimeMs.Int64, int64(0))
requireTextPart(t, last, "done")
requests = newAnthropicRequestRecorder()
server = newActiveTestServer(t, db, ps, func(cfg *chatd.Config) {
cfg.AIBridgeTransportFactory = chatAIGatewayTransportFactoryPointer(chattest.NewMockAIBridgeTransport(t, anthropicURL, chattest.WithPreservePath()))
})
@@ -6358,9 +6357,10 @@ func TestActiveServer_BasicAssistantGenerationAndPromptPreparation(t *testing.T)
require.NoError(t, err)
waitForChatStatus(ctx, t, db, planChat.ID, database.ChatStatusWaiting)
planRequests := filterAnthropicStreamingRequests(requests.all())
require.Len(t, planRequests, 1)
toolNames = anthropicRequestToolNames(planRequests[0])
allGenerationRequests := filterAnthropicStreamingRequests(requests.all())
require.Len(t, allGenerationRequests, len(generationRequests)+1)
planRequest := allGenerationRequests[len(generationRequests)]
toolNames = anthropicRequestToolNames(planRequest)
require.Contains(t, toolNames, "read_file")
require.NotContains(t, toolNames, "write_file")
}