Skip to content

test: migrate chatd tests to AI Gateway routing#26658

Draft
johnstcn wants to merge 4 commits into
cian/ai-gateway-routing-mock-factoryfrom
cian/codagt-681-migrate-chatd-tests
Draft

test: migrate chatd tests to AI Gateway routing#26658
johnstcn wants to merge 4 commits into
cian/ai-gateway-routing-mock-factoryfrom
cian/codagt-681-migrate-chatd-tests

Conversation

@johnstcn

@johnstcn johnstcn commented Jun 24, 2026

Copy link
Copy Markdown
Member

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

Full-server tests now call aibridgedtest.StartTestAIBridgeDaemon to wire a real in-process aibridged daemon. The coderdtest and coderdenttest helpers are switched to NewWithAPI so the daemon can be started after server creation.

Bare-chatd tests already use chattest.NewMockAIBridgeTransport from #26639. The chatd.Config.AIGatewayRoutingEnabled = true assignment is kept (plain bool, zero value false).

Two direct-branch-only internal tests are removed:

  • TestDirectModelBuildDoesNotRequireActiveAPIKeyID
  • TestResolveComputerUseModel_OpenAIMissingCredentials

No production code changes. The AIGatewayRoutingEnabled flag and direct routing code remain untouched until PR 3.

Depends on #26639

Refs https://linear.app/codercom/issue/CODAGT-681/migrate-chatd-tests-to-ai-gateway-routing

Implementation plan

Three layers of defaults with different semantics:

Layer Type Zero/default Migration action
codersdk.DeploymentValues.AI.Chat.AIGatewayRoutingEnabled serpent.Bool "true" (already) Remove Set("false") calls
chatd.Config.AIGatewayRoutingEnabled bool false Keep = true (plain bool, zero value false)
chatd.Server.aiGatewayRoutingEnabled bool false Keep : true (defer to PR 3)

Internal test = true cleanup is deferred to PR 3 when the field is removed entirely.

Files changed (8 test files, no production code):

  • 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.gochatDeploymentValues 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

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

Full-server tests now call aibridgedtest.StartTestAIBridgeDaemon to
wire a real in-process aibridged daemon. The coderdtest and
coderdenttest helpers that return *coderd.API are switched to
NewWithAPI so the daemon can be started after server creation.

Bare-chatd tests already use chattest.NewMockAIBridgeTransport from
PR #26639. The chatd.Config.AIGatewayRoutingEnabled=true assignment
is kept (plain bool, zero value false).

Two direct-branch-only internal tests are removed:
- TestDirectModelBuildDoesNotRequireActiveAPIKeyID
- TestResolveComputerUseModel_OpenAIMissingCredentials

No production code changes. The AIGatewayRoutingEnabled flag and
direct routing code remain untouched until PR 3.
@linear-code

linear-code Bot commented Jun 24, 2026

Copy link
Copy Markdown

CODAGT-681

Replace the deleted TestResolveComputerUseModel_OpenAIMissingCredentials
(direct routing error path) with TestResolveComputerUseModel_AIGatewayMissingAPIKeyID
which tests the same computer use error wrapping through the AI Gateway
routing path.
Comment on lines -144 to -170
func TestResolveComputerUseModel_OpenAIMissingCredentials(t *testing.T) {
t.Parallel()

server := &Server{}
provider := chattool.ComputerUseProviderOpenAI
modelProvider, modelName, ok := chattool.DefaultComputerUseModel(provider)
require.True(t, ok)

model, debugEnabled, resolvedProvider, resolvedModel, err := server.resolveComputerUseModel(
context.Background(),
database.Chat{ID: uuid.New(), OwnerID: uuid.New()},
newDirectModelRoute(modelProvider, chatprovider.ProviderAPIKeys{}),
provider,
modelProvider,
modelName,
modelBuildOptions{},
)
require.Error(t, err)
require.Nil(t, model)
require.False(t, debugEnabled)
require.Empty(t, resolvedProvider)
require.Empty(t, resolvedModel)
require.Contains(t, err.Error(), `provider "openai" model "gpt-5.5"`)
require.Contains(t, err.Error(), "OPENAI_API_KEY is not set")
require.NotContains(t, err.Error(), "ANTHROPIC_API_KEY")
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced by TestResolveComputerUseModel_AIGatewayMissingAPIKeyID

johnstcn added 2 commits June 24, 2026 12:13
- Change newChatClient* helper signatures from testing.TB to *testing.T
  to eliminate 5 t.(*testing.T) type assertions
- Replace closer/closer2 variables with _ in enterprise TestChatStreamRelay
  subtests (the closer is handled by t.Cleanup inside NewWithAPI)
- Reuse existing ctx where the daemon timeout matches the test's
  context timeout
The daemon context was created with testutil.Context(t, testutil.WaitLong)
which has a 25s deadline. Under CI load, tests that take >25s would see
the daemon shut down mid-test. Use t.Context() (no deadline, tied to
test lifetime) instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant