TestNewAdvisorRuntime covers the three defensive branches in newAdvisorRuntime that gate whether the runtime is created and with what bounds. Without this coverage a regression in any branch ships silently.
(t *testing.T)
| 543 | // newAdvisorRuntime that gate whether the runtime is created and with what |
| 544 | // bounds. Without this coverage a regression in any branch ships silently. |
| 545 | func TestNewAdvisorRuntime(t *testing.T) { |
| 546 | t.Parallel() |
| 547 | |
| 548 | logger := slog.Make() |
| 549 | fallbackModel := &chattest.FakeModel{ProviderName: "openai", ModelName: "gpt-4"} |
| 550 | fallbackCallConfig := codersdk.ChatModelCallConfig{} |
| 551 | |
| 552 | t.Run("ZeroMaxUsesDefaultsToMaxChatSteps", func(t *testing.T) { |
| 553 | t.Parallel() |
| 554 | ctx := testutil.Context(t, testutil.WaitShort) |
| 555 | store := &advisorOverrideStubStore{} |
| 556 | p := newAdvisorTestServer(ctx, t, store) |
| 557 | |
| 558 | rt := p.newAdvisorRuntimeOrFallback( |
| 559 | ctx, |
| 560 | database.Chat{}, |
| 561 | codersdk.AdvisorConfig{ |
| 562 | Enabled: true, |
| 563 | MaxUsesPerRun: 0, |
| 564 | MaxOutputTokens: 16384, |
| 565 | }, |
| 566 | fallbackModel, |
| 567 | fallbackCallConfig, |
| 568 | chatprovider.ProviderAPIKeys{}, |
| 569 | modelBuildOptions{}, |
| 570 | logger, |
| 571 | ) |
| 572 | require.NotNil(t, rt, "zero max uses must default rather than bail out") |
| 573 | require.Equal(t, maxChatSteps, rt.RemainingUses(), |
| 574 | "zero max uses must be replaced with maxChatSteps") |
| 575 | }) |
| 576 | |
| 577 | t.Run("NegativeMaxUsesReturnsNil", func(t *testing.T) { |
| 578 | t.Parallel() |
| 579 | ctx := testutil.Context(t, testutil.WaitShort) |
| 580 | store := &advisorOverrideStubStore{} |
| 581 | p := newAdvisorTestServer(ctx, t, store) |
| 582 | |
| 583 | rt := p.newAdvisorRuntimeOrFallback( |
| 584 | ctx, |
| 585 | database.Chat{}, |
| 586 | codersdk.AdvisorConfig{ |
| 587 | Enabled: true, |
| 588 | MaxUsesPerRun: -1, |
| 589 | MaxOutputTokens: 16384, |
| 590 | }, |
| 591 | fallbackModel, |
| 592 | fallbackCallConfig, |
| 593 | chatprovider.ProviderAPIKeys{}, |
| 594 | modelBuildOptions{}, |
| 595 | logger, |
| 596 | ) |
| 597 | require.Nil(t, rt, "negative max uses must disable the advisor") |
| 598 | }) |
| 599 | |
| 600 | t.Run("ZeroMaxOutputTokensDefaults", func(t *testing.T) { |
| 601 | t.Parallel() |
| 602 | ctx := testutil.Context(t, testutil.WaitShort) |
nothing calls this directly
no test coverage detected