secert updated
This commit is contained in:
@@ -131,3 +131,78 @@ func TestTheEnvironmentsOwnFileBeatsTheSharedOne(t *testing.T) {
|
||||
t.Fatalf("the environment's own file does not take precedence: %v", order)
|
||||
}
|
||||
}
|
||||
|
||||
// One variable, not four.
|
||||
//
|
||||
// The assistant sat switched off for days because `ASSISTANT_PROVIDER` had not
|
||||
// been typed into a hosting platform's environment tab — a variable whose only
|
||||
// correct value is "openai", because every endpoint this server speaks is
|
||||
// OpenAI-compatible. The base URL and the model had one right answer too.
|
||||
//
|
||||
// So three of the four are constants now. The key is the only one that varies
|
||||
// between deployments and the only one that cannot live in the repository.
|
||||
func TestTheKeyAloneSwitchesTheAssistantOn(t *testing.T) {
|
||||
for _, name := range []string{
|
||||
"ASSISTANT_PROVIDER", "ASSISTANT_BASE_URL", "ASSISTANT_MODEL",
|
||||
"ASSISTANT_MODEL_BALANCED", "ASSISTANT_MODEL_FAST", "ASSISTANT_MODEL_DEEP",
|
||||
} {
|
||||
t.Setenv(name, "")
|
||||
}
|
||||
t.Setenv("ASSISTANT_API_KEY", "gsk_not-a-real-key")
|
||||
|
||||
cfg := AssistantConfig{
|
||||
Provider: assistantProvider(),
|
||||
BaseURL: env("ASSISTANT_BASE_URL", defaultAssistantBaseURL),
|
||||
APIKey: env("ASSISTANT_API_KEY", ""),
|
||||
Balanced: env("ASSISTANT_MODEL_BALANCED", env("ASSISTANT_MODEL", defaultAssistantModel)),
|
||||
}
|
||||
|
||||
if !cfg.Enabled() {
|
||||
t.Fatalf("the key alone did not switch it on: %s", cfg.Why())
|
||||
}
|
||||
if cfg.Provider != "openai" {
|
||||
t.Fatalf("provider defaulted to %q", cfg.Provider)
|
||||
}
|
||||
if cfg.ModelFor("fast") != defaultAssistantModel {
|
||||
t.Fatalf("the fast tier fell through to %q", cfg.ModelFor("fast"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoKeyIsStillOffAndSaysWhich(t *testing.T) {
|
||||
// The defaults must not make an unconfigured deployment look ready. Without
|
||||
// a key every question would reach Groq and come back 401, which reads as
|
||||
// the assistant being broken rather than as not being set up.
|
||||
cfg := AssistantConfig{
|
||||
Provider: defaultAssistantProvider,
|
||||
BaseURL: defaultAssistantBaseURL,
|
||||
Balanced: defaultAssistantModel,
|
||||
}
|
||||
if cfg.Enabled() {
|
||||
t.Fatal("reported ready with no key")
|
||||
}
|
||||
if !strings.Contains(cfg.Why(), "ASSISTANT_API_KEY") {
|
||||
t.Fatalf("did not name the one variable left to set: %q", cfg.Why())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEachDefaultIsStillOverridable(t *testing.T) {
|
||||
// Running against Ollama on a laptop must not need a code change.
|
||||
t.Setenv("ASSISTANT_PROVIDER", "ollama")
|
||||
t.Setenv("ASSISTANT_BASE_URL", "http://localhost:11434/v1")
|
||||
t.Setenv("ASSISTANT_MODEL", "llama3")
|
||||
|
||||
cfg := AssistantConfig{
|
||||
Provider: assistantProvider(),
|
||||
BaseURL: env("ASSISTANT_BASE_URL", defaultAssistantBaseURL),
|
||||
APIKey: env("ASSISTANT_API_KEY", ""),
|
||||
Balanced: env("ASSISTANT_MODEL_BALANCED", env("ASSISTANT_MODEL", defaultAssistantModel)),
|
||||
}
|
||||
|
||||
if cfg.Provider != "ollama" || cfg.Balanced != "llama3" {
|
||||
t.Fatalf("an override was ignored: %+v", cfg)
|
||||
}
|
||||
// Local endpoints need no key, so this must be on without one.
|
||||
if !cfg.Enabled() {
|
||||
t.Fatalf("a local model was refused: %s", cfg.Why())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user