返回 DeepSeek-Reasonix
model_override_retention_test.go
根目录 / internal / config / model_override_retention_test.go
1 package config
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 func loadSingleProvider(t *testing.T, providerBody string) *ProviderEntry {
10 t.Helper()
11 dir := t.TempDir()
12 body := "default_model = \"relay\"\n\n[[providers]]\nname = \"relay\"\nkind = \"openai\"\nmodels = [\"a\", \"b\"]\ndefault = \"a\"\n" + providerBody + "\n"
13 if err := os.WriteFile(filepath.Join(dir, "reasonix.toml"), []byte(body), 0o644); err != nil {
14 t.Fatalf("write config: %v", err)
15 }
16 approveWorkspace(t, dir)
17 c, err := LoadForRootReadOnly(dir)
18 if err != nil {
19 t.Fatalf("load config: %v", err)
20 }
21 e, ok := c.ResolveModel("relay/a")
22 if !ok {
23 t.Fatal("ResolveModel did not resolve relay/a")
24 }
25 return e
26 }
27
28 // normalizedModelOverrides drops overrides it judges empty. Its emptiness test
29 // omitted MaxOutputTokens, so an override carrying only max_output_tokens was
30 // discarded at load and the documented key silently did nothing.
31 func TestMaxOutputTokensOnlyOverrideSurvivesLoad(t *testing.T) {
32 e := loadSingleProvider(t, `model_overrides = { "a" = { max_output_tokens = 32768 } }`)
33 if e.MaxOutputTokens != 32768 {
34 t.Fatalf("MaxOutputTokens = %d, want 32768 from the model override", e.MaxOutputTokens)
35 }
36 }
37
38 // A negative value is the documented way to force-omit optional wire limits, so
39 // it must survive the same pass rather than reading as an unset field.
40 func TestNegativeMaxOutputTokensOnlyOverrideSurvivesLoad(t *testing.T) {
41 e := loadSingleProvider(t, `model_overrides = { "a" = { max_output_tokens = -1 } }`)
42 if e.MaxOutputTokens != -1 {
43 t.Fatalf("MaxOutputTokens = %d, want -1 from the model override", e.MaxOutputTokens)
44 }
45 }
46
47 // An override with nothing set is still dropped, and an override aimed at a
48 // different model must not leak onto the resolved one.
49 func TestEmptyAndForeignModelOverridesStayInert(t *testing.T) {
50 e := loadSingleProvider(t, `model_overrides = { "a" = { }, "b" = { max_output_tokens = 4096 } }`)
51 if len(e.ModelOverrides) != 1 {
52 t.Fatalf("ModelOverrides = %+v, want only the non-empty entry for b", e.ModelOverrides)
53 }
54 if e.MaxOutputTokens == 4096 {
55 t.Fatal("an override for model b was applied to model a")
56 }
57 }
58
58 lines GO