| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/config" |
| 9 | "reasonix/internal/control" |
| 10 | "reasonix/internal/event" |
| 11 | ) |
| 12 | |
| 13 | func TestBuildOfficialDeepSeekV4ProPrependsPersona(t *testing.T) { |
| 14 | ctrl := buildOfficialDeepSeekModel(t, "deepseek-v4-pro") |
| 15 | defer ctrl.Close() |
| 16 | |
| 17 | sys := systemMessage(ctrl.History()) |
| 18 | wantPrefix := config.OfficialDeepSeekV4ProPersona + "\n\n" |
| 19 | if !strings.HasPrefix(sys, wantPrefix) { |
| 20 | t.Fatalf("official V4 Pro system prompt must start with the DSH persona:\n%s", sys) |
| 21 | } |
| 22 | if !strings.Contains(sys, "BASE") { |
| 23 | t.Fatalf("persona must keep the configured system prompt, got:\n%s", sys) |
| 24 | } |
| 25 | |
| 26 | composed := ctrl.Compose("解释 AuthHandler 的 panic") |
| 27 | if strings.Contains(composed, "简体中文") { |
| 28 | t.Fatalf("official V4 Pro auto mode must not inject Chinese thinking: %q", composed) |
| 29 | } |
| 30 | if !strings.Contains(composed, "use English") { |
| 31 | t.Fatalf("official V4 Pro auto mode should pin English thinking, got %q", composed) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func TestBuildOfficialDeepSeekV4FlashDoesNotPrependPersona(t *testing.T) { |
| 36 | ctrl := buildOfficialDeepSeekModel(t, "deepseek-v4-flash") |
| 37 | defer ctrl.Close() |
| 38 | |
| 39 | sys := systemMessage(ctrl.History()) |
| 40 | if strings.Contains(sys, config.OfficialDeepSeekV4ProPersona) { |
| 41 | t.Fatalf("official V4 Flash must not load the Pro persona:\n%s", sys) |
| 42 | } |
| 43 | composed := ctrl.Compose("解释 AuthHandler 的 panic") |
| 44 | if !strings.Contains(composed, "简体中文") { |
| 45 | t.Fatalf("flash auto mode should still infer Chinese thinking, got %q", composed) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestBuildThirdPartyDeepSeekV4ProDoesNotPrependPersona(t *testing.T) { |
| 50 | isolateConfigHome(t) |
| 51 | const envName = "BOOT_THIRD_PARTY_V4_PRO_KEY" |
| 52 | if _, err := config.SetCredential(envName, "test-key"); err != nil { |
| 53 | t.Fatalf("store credential: %v", err) |
| 54 | } |
| 55 | dir := robustTempDir(t) |
| 56 | t.Chdir(dir) |
| 57 | writeFile(t, dir, "reasonix.toml", ` |
| 58 | default_model = "novita/deepseek-v4-pro" |
| 59 | |
| 60 | [agent] |
| 61 | system_prompt = "BASE" |
| 62 | |
| 63 | [[providers]] |
| 64 | name = "novita" |
| 65 | kind = "openai" |
| 66 | base_url = "https://api.novita.ai/openai" |
| 67 | model = "deepseek-v4-pro" |
| 68 | api_key_env = "`+envName+`" |
| 69 | `) |
| 70 | |
| 71 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 72 | if err != nil { |
| 73 | t.Fatalf("Build: %v", err) |
| 74 | } |
| 75 | defer ctrl.Close() |
| 76 | |
| 77 | sys := systemMessage(ctrl.History()) |
| 78 | if strings.Contains(sys, config.OfficialDeepSeekV4ProPersona) { |
| 79 | t.Fatalf("third-party V4 Pro must not load the official persona:\n%s", sys) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func buildOfficialDeepSeekModel(t *testing.T, model string) *control.Controller { |
| 84 | t.Helper() |
| 85 | isolateConfigHome(t) |
| 86 | const envName = "BOOT_OFFICIAL_V4_PRO_PERSONA_KEY" |
| 87 | if _, err := config.SetCredential(envName, "test-key"); err != nil { |
| 88 | t.Fatalf("store credential: %v", err) |
| 89 | } |
| 90 | dir := robustTempDir(t) |
| 91 | t.Chdir(dir) |
| 92 | writeFile(t, dir, "reasonix.toml", ` |
| 93 | default_model = "deepseek/`+model+`" |
| 94 | |
| 95 | [agent] |
| 96 | system_prompt = "BASE" |
| 97 | |
| 98 | [[providers]] |
| 99 | name = "deepseek" |
| 100 | kind = "openai" |
| 101 | base_url = "https://api.deepseek.com" |
| 102 | models = ["deepseek-v4-flash", "deepseek-v4-pro"] |
| 103 | default = "deepseek-v4-flash" |
| 104 | api_key_env = "`+envName+`" |
| 105 | `) |
| 106 | ctrl, err := Build(context.Background(), Options{Sink: event.Discard}) |
| 107 | if err != nil { |
| 108 | t.Fatalf("Build %s: %v", model, err) |
| 109 | } |
| 110 | return ctrl |
| 111 | } |
| 112 |