| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestStepFunPresetsDeclareTheServedContextWindow(t *testing.T) { |
| 10 | for _, id := range stepfunPresetIDs { |
| 11 | preset, ok := CuratedProviderPreset(id) |
| 12 | if !ok || len(preset.Entries) != 1 { |
| 13 | t.Fatalf("missing %s preset", id) |
| 14 | } |
| 15 | if got := preset.Entries[0].ContextWindow; got != 262_144 { |
| 16 | t.Fatalf("%s context_window = %d, want 262144 (0 turns automatic compaction off)", id, got) |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func TestLoadForRootGivesInstalledStepFunPresetsTheirContextWindow(t *testing.T) { |
| 22 | home := t.TempDir() |
| 23 | t.Setenv("REASONIX_HOME", home) |
| 24 | t.Setenv("REASONIX_CREDENTIALS_STORE", "file") |
| 25 | body := `[[providers]] |
| 26 | name = "stepfun" |
| 27 | preset_id = "stepfun" |
| 28 | kind = "openai" |
| 29 | base_url = "https://api.stepfun.com/step_plan/v1" |
| 30 | models = ["step-3.7-flash", "step-3.5-flash", "step-3.5-flash-2603"] |
| 31 | default = "step-3.7-flash" |
| 32 | |
| 33 | [[providers]] |
| 34 | name = "stepfun-anthropic" |
| 35 | preset_id = "stepfun-anthropic" |
| 36 | kind = "anthropic" |
| 37 | base_url = "https://api.stepfun.ai/step_plan/" |
| 38 | models = ["step-3.5-flash"] |
| 39 | default = "step-3.5-flash" |
| 40 | |
| 41 | [[providers]] |
| 42 | name = "stepfun-api" |
| 43 | preset_id = "stepfun-api" |
| 44 | kind = "openai" |
| 45 | base_url = "https://api.stepfun.com/v1" |
| 46 | models = ["step-3.7-flash", "step-3.5-flash", "step-3.5-flash-2603"] |
| 47 | default = "step-3.7-flash" |
| 48 | context_window = 131072 |
| 49 | |
| 50 | [[providers]] |
| 51 | name = "stepfun-relay" |
| 52 | preset_id = "stepfun-responses" |
| 53 | kind = "responses" |
| 54 | base_url = "https://relay.example.com/v1" |
| 55 | models = ["step-3.7-flash"] |
| 56 | default = "step-3.7-flash" |
| 57 | |
| 58 | [[providers]] |
| 59 | name = "stepfun-responses" |
| 60 | preset_id = "stepfun-responses" |
| 61 | kind = "responses" |
| 62 | base_url = "https://api.stepfun.com/v1" |
| 63 | models = ["step-3.7-flash", "private-model"] |
| 64 | default = "step-3.7-flash" |
| 65 | ` |
| 66 | if err := os.WriteFile(filepath.Join(home, "config.toml"), []byte(body), 0o644); err != nil { |
| 67 | t.Fatal(err) |
| 68 | } |
| 69 | |
| 70 | c, err := LoadForRoot(t.TempDir()) |
| 71 | if err != nil { |
| 72 | t.Fatalf("LoadForRoot: %v", err) |
| 73 | } |
| 74 | for ref, want := range map[string]int{ |
| 75 | "stepfun/step-3.7-flash": 262_144, |
| 76 | "stepfun-anthropic/step-3.5-flash": 262_144, |
| 77 | "stepfun-api/step-3.7-flash": 131_072, |
| 78 | "stepfun-relay/step-3.7-flash": 0, |
| 79 | "stepfun-responses/step-3.7-flash": 0, |
| 80 | } { |
| 81 | entry, ok := c.ResolveModel(ref) |
| 82 | if !ok { |
| 83 | t.Fatalf("%s did not resolve", ref) |
| 84 | } |
| 85 | if entry.ContextWindow != want { |
| 86 | t.Fatalf("%s context_window = %d, want %d", ref, entry.ContextWindow, want) |
| 87 | } |
| 88 | } |
| 89 | edit := LoadForEdit(filepath.Join(home, "config.toml")) |
| 90 | if got, ok := edit.Provider("stepfun"); !ok || got.ContextWindow != 262_144 { |
| 91 | t.Fatalf("LoadForEdit stepfun = %+v, want context_window 262144", got) |
| 92 | } |
| 93 | } |
| 94 |