|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "encoding/json" |
| 6 | + "os" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +// TestLegacyPrintConfigDefaults_NoNewFlags ensures that a minimal invocation |
| 12 | +// without new flags produces the same resolved config baseline. |
| 13 | +func TestLegacyPrintConfigDefaults_NoNewFlags(t *testing.T) { |
| 14 | + // Ensure env does not influence defaults |
| 15 | + t.Setenv("OAI_BASE_URL", "") |
| 16 | + t.Setenv("OAI_MODEL", "") |
| 17 | + t.Setenv("OAI_HTTP_TIMEOUT", "") |
| 18 | + t.Setenv("OAI_IMAGE_MODEL", "") |
| 19 | + |
| 20 | + var out, err bytes.Buffer |
| 21 | + code := cliMain([]string{"-prompt", "p", "-print-config"}, &out, &err) |
| 22 | + if code != 0 { |
| 23 | + t.Fatalf("print-config exit=%d, stderr=%s", code, err.String()) |
| 24 | + } |
| 25 | + // Parse JSON |
| 26 | + var payload map[string]any |
| 27 | + if jerr := json.Unmarshal(out.Bytes(), &payload); jerr != nil { |
| 28 | + t.Fatalf("unmarshal print-config: %v; got %s", jerr, out.String()) |
| 29 | + } |
| 30 | + // Top-level expectations |
| 31 | + if got, ok := payload["model"].(string); !ok || got != "oss-gpt-20b" { |
| 32 | + t.Fatalf("model=%v; want oss-gpt-20b", payload["model"]) |
| 33 | + } |
| 34 | + if got, ok := payload["baseURL"].(string); !ok || got != "https://api.openai.com/v1" { |
| 35 | + t.Fatalf("baseURL=%v; want https://api.openai.com/v1", payload["baseURL"]) |
| 36 | + } |
| 37 | + if got, ok := payload["httpTimeout"].(string); !ok || got != "30s" { |
| 38 | + t.Fatalf("httpTimeout=%v; want 30s", payload["httpTimeout"]) |
| 39 | + } |
| 40 | + // Image block expectations |
| 41 | + img, ok := payload["image"].(map[string]any) |
| 42 | + if !ok { |
| 43 | + t.Fatalf("missing image block in print-config") |
| 44 | + } |
| 45 | + if got, ok := img["model"].(string); !ok || got != "gpt-image-1" { |
| 46 | + t.Fatalf("image.model=%v; want gpt-image-1", img["model"]) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestConflictingPromptSources_ErrorMessage(t *testing.T) { |
| 51 | + var out, err bytes.Buffer |
| 52 | + code := cliMain([]string{"-prompt", "p", "-prompt-file", os.DevNull}, &out, &err) |
| 53 | + if code != 2 { |
| 54 | + t.Fatalf("exit=%d; want 2", code) |
| 55 | + } |
| 56 | + if !strings.Contains(err.String(), "-prompt and -prompt-file are mutually exclusive") { |
| 57 | + t.Fatalf("stderr did not contain conflict message; got: %s", err.String()) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +func TestConflictingSystemSources_ErrorMessage(t *testing.T) { |
| 62 | + var out, err bytes.Buffer |
| 63 | + // Provide both -system (non-default) and -system-file |
| 64 | + code := cliMain([]string{"-prompt", "p", "-system", "X", "-system-file", os.DevNull}, &out, &err) |
| 65 | + if code != 2 { |
| 66 | + t.Fatalf("exit=%d; want 2", code) |
| 67 | + } |
| 68 | + if !strings.Contains(err.String(), "-system and -system-file are mutually exclusive") { |
| 69 | + t.Fatalf("stderr did not contain system conflict message; got: %s", err.String()) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func TestLoadMessagesWithPromptConflict_ErrorMessage(t *testing.T) { |
| 74 | + var out, err bytes.Buffer |
| 75 | + code := cliMain([]string{"-load-messages", os.DevNull, "-prompt", "p"}, &out, &err) |
| 76 | + if code != 2 { |
| 77 | + t.Fatalf("exit=%d; want 2", code) |
| 78 | + } |
| 79 | + if !strings.Contains(err.String(), "-load-messages cannot be combined with -prompt or -prompt-file") { |
| 80 | + t.Fatalf("stderr did not contain load/prompt conflict message; got: %s", err.String()) |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +func TestSaveAndLoadMessagesConflict_ErrorMessage(t *testing.T) { |
| 85 | + var out, err bytes.Buffer |
| 86 | + code := cliMain([]string{"-prompt", "p", "-save-messages", os.DevNull, "-load-messages", os.DevNull}, &out, &err) |
| 87 | + if code != 2 { |
| 88 | + t.Fatalf("exit=%d; want 2", code) |
| 89 | + } |
| 90 | + if !strings.Contains(err.String(), "-save-messages and -load-messages are mutually exclusive") { |
| 91 | + t.Fatalf("stderr did not contain save/load conflict message; got: %s", err.String()) |
| 92 | + } |
| 93 | +} |
0 commit comments