mirror of
https://github.com/patriceckhart/zot.git
synced 2026-06-28 06:13:42 +02:00
Add built-in provider catalog and support for additional provider backends, including Bedrock, Vertex, Azure OpenAI, GitHub Copilot, OpenAI Responses, and extra user-configured providers/models. Improve TUI session resume by restoring last-turn context usage and tail-rendering long transcripts for faster first paint. Handle Gemini image models without tools, persist generated images to the working directory, and make Anthropic transcript replay tolerate assistant-side image artifacts.
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestValidateAndRepairConfig_MismatchedPair simulates the bug from a
|
|
// stale /model switch: provider=anthropic but model=kimi-for-coding
|
|
// (which belongs to provider=kimi). The validator should rewrite the
|
|
// model to anthropic's default and persist.
|
|
func TestValidateAndRepairConfig_MismatchedPair(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ZOT_HOME", home)
|
|
|
|
must := func(c Config) {
|
|
t.Helper()
|
|
b, _ := json.Marshal(c)
|
|
if err := os.WriteFile(filepath.Join(home, "config.json"), b, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
must(Config{Provider: "anthropic", Model: "kimi-for-coding"})
|
|
|
|
ValidateAndRepairConfig()
|
|
|
|
out, err := LoadConfig()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out.Provider != "anthropic" {
|
|
t.Errorf("provider not preserved: %q", out.Provider)
|
|
}
|
|
if out.Model == "kimi-for-coding" {
|
|
t.Errorf("model not repaired; still %q", out.Model)
|
|
}
|
|
if out.Model == "" {
|
|
t.Errorf("model not set; expected anthropic default")
|
|
}
|
|
}
|
|
|
|
// TestValidateAndRepairConfig_UnknownProvider resets to anthropic and
|
|
// clears the model when the saved provider id isn't recognised
|
|
// (e.g. user removed it from a previous build).
|
|
func TestValidateAndRepairConfig_UnknownProvider(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ZOT_HOME", home)
|
|
|
|
b, _ := json.Marshal(Config{Provider: "made-up-provider", Model: "some-model"})
|
|
_ = os.WriteFile(filepath.Join(home, "config.json"), b, 0o644)
|
|
|
|
ValidateAndRepairConfig()
|
|
|
|
out, _ := LoadConfig()
|
|
if out.Provider != "anthropic" {
|
|
t.Errorf("provider not reset: %q", out.Provider)
|
|
}
|
|
if out.Model != "" {
|
|
t.Errorf("model not cleared: %q", out.Model)
|
|
}
|
|
}
|
|
|
|
// TestValidateAndRepairConfig_UnknownModel keeps the provider but
|
|
// snaps the model to that provider's default when the saved id is no
|
|
// longer in the catalog.
|
|
func TestValidateAndRepairConfig_UnknownModel(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ZOT_HOME", home)
|
|
|
|
b, _ := json.Marshal(Config{Provider: "anthropic", Model: "claude-deleted-model"})
|
|
_ = os.WriteFile(filepath.Join(home, "config.json"), b, 0o644)
|
|
|
|
ValidateAndRepairConfig()
|
|
|
|
out, _ := LoadConfig()
|
|
if out.Provider != "anthropic" {
|
|
t.Errorf("provider changed: %q", out.Provider)
|
|
}
|
|
if out.Model == "" || out.Model == "claude-deleted-model" {
|
|
t.Errorf("model not repaired: %q", out.Model)
|
|
}
|
|
}
|
|
|
|
// TestValidateAndRepairConfig_HappyPath leaves a valid config alone.
|
|
func TestValidateAndRepairConfig_HappyPath(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("ZOT_HOME", home)
|
|
|
|
b, _ := json.Marshal(Config{Provider: "anthropic", Model: "claude-sonnet-4-5"})
|
|
_ = os.WriteFile(filepath.Join(home, "config.json"), b, 0o644)
|
|
|
|
ValidateAndRepairConfig()
|
|
|
|
out, _ := LoadConfig()
|
|
if out.Provider != "anthropic" {
|
|
t.Errorf("provider mutated: %q", out.Provider)
|
|
}
|
|
if out.Model != "claude-sonnet-4-5" {
|
|
t.Errorf("model mutated: %q", out.Model)
|
|
}
|
|
}
|