test: migrate chatd tests to AI Gateway routing (#26658)

Refs CODAGT-681

Migrates all chatd tests from `AIGatewayRoutingEnabled = false` (direct
routing) to AI Gateway routing using the test helpers extracted in
#26639.

- `coderd/x/chatd/chatd_test.go` — 6 full-server tests migrated to
`NewWithAPI` + daemon, `directChatRoutingDeploymentValues` helper
deleted, 3 bare-chatd tests renamed
- `coderd/x/chatd/context_integration_test.go` — 2 tests migrated
- `coderd/exp_chats_test.go` — `chatDeploymentValues` helper deleted,
all 5 helper functions now use `NewWithAPI` + daemon internally (no call
site changes)
- `coderd/exp_chats_acl_test.go` — stale `chatDeploymentValues`
reference replaced
- `enterprise/coderd/exp_chats_test.go` — 9 sites across 5
`TestChatStreamRelay` subtests migrated
- `cli/exp_scaletest_chat_test.go` — 1 test migrated
- `coderd/x/chatd/model_routing_internal_test.go` — 1 direct-only test
removed
- `coderd/x/chatd/chatd_internal_test.go` — 1 direct-only test removed

> 🤖
This commit is contained in:
Cian Johnston
2026-06-30 12:17:42 +01:00
committed by GitHub
parent 33780758c1
commit e5b7e74847
8 changed files with 210 additions and 182 deletions
+53 -53
View File
@@ -11,6 +11,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/aibridgedtest"
"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -66,20 +67,24 @@ func createOpenAIModelConfigForTest(
}
func TestChatStreamRelay(t *testing.T) {
// OpenAI Responses streaming events are buffered (not relayed) under AI
// Gateway routing while the agentic inner loop exists; see
// https://github.com/coder/aibridge/issues/223. Unskip once the
// reverse-proxy refactor lands and the follow-up tracking ticket is
// resolved.
t.Parallel()
t.Skip("chat stream relay buffers events under AI Gateway routing; see CODAGT-734 and https://github.com/coder/aibridge/issues/223")
t.Run("RelayMessagePartsAcrossReplicas", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
db, pubsub := dbtestutil.NewDB(t)
firstClient, firstUser := coderdenttest.New(t, &coderdenttest.Options{
firstClient, _, firstAPI, firstUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
@@ -87,18 +92,18 @@ func TestChatStreamRelay(t *testing.T) {
},
},
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, firstAPI.AGPL, nil)
secondClient, _ := coderdenttest.New(t, &coderdenttest.Options{
secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
DontAddLicense: true,
DontAddFirstUser: true,
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, secondAPI.AGPL, nil)
secondClient.SetSessionToken(firstClient.SessionToken())
// Verify we have two replicas
@@ -220,14 +225,12 @@ func TestChatStreamRelay(t *testing.T) {
certificates := []tls.Certificate{testutil.GenerateTLSCertificate(t, "localhost")}
db, pubsub := dbtestutil.NewDB(t)
firstClient, firstUser := coderdenttest.New(t, &coderdenttest.Options{
firstClient, _, firstAPI, firstUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
TLSCertificates: certificates,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
TLSCertificates: certificates,
DeploymentValues: coderdtest.DeploymentValues(t),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
@@ -235,19 +238,19 @@ func TestChatStreamRelay(t *testing.T) {
},
},
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, firstAPI.AGPL, nil)
secondClient, _ := coderdenttest.New(t, &coderdenttest.Options{
secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
TLSCertificates: certificates,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
TLSCertificates: certificates,
DeploymentValues: coderdtest.DeploymentValues(t),
},
DontAddLicense: true,
DontAddFirstUser: true,
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, secondAPI.AGPL, nil)
// Authenticate the second client using cookies only, simulating
// browser WebSocket behavior. Browsers cannot set custom
@@ -406,13 +409,11 @@ func TestChatStreamRelay(t *testing.T) {
ctx := testutil.Context(t, testutil.WaitLong)
db, pubsub := dbtestutil.NewDB(t)
firstClient, firstUser := coderdenttest.New(t, &coderdenttest.Options{
firstClient, _, firstAPI, firstUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
@@ -420,18 +421,18 @@ func TestChatStreamRelay(t *testing.T) {
},
},
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, firstAPI.AGPL, nil)
secondClient, _ := coderdenttest.New(t, &coderdenttest.Options{
secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
DontAddLicense: true,
DontAddFirstUser: true,
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, secondAPI.AGPL, nil)
//nolint:gocritic // Test uses owner client session token for cookie-based relay auth.
sessionToken := firstClient.SessionToken()
@@ -562,11 +563,10 @@ func TestChatStreamRelay(t *testing.T) {
db, pubsub := dbtestutil.NewDB(t)
hostPrefixValues := coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
dv.HTTPCookies.EnableHostPrefix = true
dv.HTTPCookies.Secure = true
})
firstClient, firstUser := coderdenttest.New(t, &coderdenttest.Options{
firstClient, _, firstAPI, firstUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
@@ -578,8 +578,9 @@ func TestChatStreamRelay(t *testing.T) {
},
},
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, firstAPI.AGPL, nil)
secondClient, _ := coderdenttest.New(t, &coderdenttest.Options{
secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
@@ -588,6 +589,7 @@ func TestChatStreamRelay(t *testing.T) {
DontAddLicense: true,
DontAddFirstUser: true,
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, secondAPI.AGPL, nil)
//nolint:gocritic // Test uses owner client session token for cookie-based relay auth.
sessionToken := firstClient.SessionToken()
@@ -711,13 +713,11 @@ func TestChatStreamRelay(t *testing.T) {
ctx := testutil.Context(t, testutil.WaitLong)
db, pubsub := dbtestutil.NewDB(t)
firstClient, firstUser := coderdenttest.New(t, &coderdenttest.Options{
firstClient, _, firstAPI, firstUser := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
@@ -725,18 +725,18 @@ func TestChatStreamRelay(t *testing.T) {
},
},
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, firstAPI.AGPL, nil)
secondClient, _ := coderdenttest.New(t, &coderdenttest.Options{
secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
require.NoError(t, dv.AI.Chat.AIGatewayRoutingEnabled.Set("false"))
}),
Database: db,
Pubsub: pubsub,
DeploymentValues: coderdtest.DeploymentValues(t),
},
DontAddLicense: true,
DontAddFirstUser: true,
})
aibridgedtest.StartTestAIBridgeDaemon(t.Context(), t, secondAPI.AGPL, nil)
secondClient.SetSessionToken(firstClient.SessionToken())
// Verify we have two replicas.