mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd): preseed AI providers for title tests (#27564)
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/coder/coder/v2/cli"
|
||||
"github.com/coder/coder/v2/coderd"
|
||||
"github.com/coder/coder/v2/coderd/aibridged"
|
||||
"github.com/coder/coder/v2/coderd/database/pubsub"
|
||||
)
|
||||
|
||||
// StartTestAIBridgeDaemon wires an in-process aibridged daemon onto the
|
||||
@@ -37,6 +38,21 @@ func StartTestAIBridgeDaemon(
|
||||
metrics *aibridged.Metrics,
|
||||
) {
|
||||
t.Helper()
|
||||
StartTestAIBridgeDaemonWithPubsub(ctx, t, api, metrics, api.Pubsub)
|
||||
}
|
||||
|
||||
// StartTestAIBridgeDaemonWithPubsub is StartTestAIBridgeDaemon with an
|
||||
// explicit pubsub for the provider-reload subscription. A pubsub that is
|
||||
// disconnected from api.Pubsub cuts the daemon off from provider change
|
||||
// events, leaving the initial synchronous load as its only route source.
|
||||
func StartTestAIBridgeDaemonWithPubsub(
|
||||
ctx context.Context,
|
||||
t testing.TB,
|
||||
api *coderd.API,
|
||||
metrics *aibridged.Metrics,
|
||||
ps pubsub.Pubsub,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
logger := api.Logger.Named("aibridged").Leveled(slog.LevelDebug)
|
||||
cfg := api.DeploymentValues.AI.BridgeConfig
|
||||
@@ -63,7 +79,7 @@ func StartTestAIBridgeDaemon(
|
||||
// The reloader fetches providers from coderd over srv's DRPC client; the
|
||||
// subscription drives an initial load and refreshes on change events.
|
||||
reloader := cli.NewPoolRPCReloader(pool, srv.ClientContext, cfg, logger.Named("reloader"), nil, metrics)
|
||||
unsubscribe, err := aibridged.SubscribeProviderReload(ctx, api.Pubsub, reloader, logger.Named("subscriber"))
|
||||
unsubscribe, err := aibridged.SubscribeProviderReload(ctx, ps, reloader, logger.Named("subscriber"))
|
||||
if err != nil {
|
||||
t.Fatalf("subscribe provider reload: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user