env var updates
This commit is contained in:
+40
-4
@@ -263,7 +263,7 @@ func TestDefaultSystemPrompt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCfgDefaults(t *testing.T) {
|
||||
t.Setenv("OPENAI_API_KEY", "")
|
||||
t.Setenv("BANTAM_API_KEY", "")
|
||||
cfg := getCfg(filepath.Join(t.TempDir(), "missing.cfg"))
|
||||
if cfg.Endpoint != defCfg.Endpoint || cfg.Model != defCfg.Model || cfg.APIKey != defCfg.APIKey {
|
||||
t.Errorf("defaults mismatch: %+v", cfg)
|
||||
@@ -359,7 +359,7 @@ func TestGetCfgStreamTruthyVariants(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCfgAPIKeyEnvFallback(t *testing.T) {
|
||||
t.Setenv("OPENAI_API_KEY", "sk-env")
|
||||
t.Setenv("BANTAM_API_KEY", "sk-env")
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
|
||||
// no api_key line at all -> env fallback (documented behavior)
|
||||
@@ -379,7 +379,7 @@ func TestGetCfgAPIKeyEnvFallback(t *testing.T) {
|
||||
t.Errorf("explicit api_key: got %q, want real", got)
|
||||
}
|
||||
// no env and no key -> stays "-"
|
||||
t.Setenv("OPENAI_API_KEY", "")
|
||||
t.Setenv("BANTAM_API_KEY", "")
|
||||
if got := getCfg(writeCfg(t, "api_key=-\n")).APIKey; got != "-" {
|
||||
t.Errorf("api_key=- without env: got %q, want -", got)
|
||||
}
|
||||
@@ -388,6 +388,42 @@ func TestGetCfgAPIKeyEnvFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCfgEnvOverriddenByFile(t *testing.T) {
|
||||
// New env vars BANTAM_ENDPOINT / BANTAM_MODEL / BANTAM_TEMP act as fallbacks
|
||||
// that must yield to any value set in the config file (.bantam.cfg).
|
||||
t.Setenv("BANTAM_ENDPOINT", "http://env-endpoint/v1")
|
||||
t.Setenv("BANTAM_MODEL", "env-model")
|
||||
t.Setenv("BANTAM_TEMP", "0.9")
|
||||
t.Setenv("BANTAM_API_KEY", "")
|
||||
p := writeCfg(t, strings.Join([]string{
|
||||
"endpoint=http://file-endpoint/v1",
|
||||
"model=file-model",
|
||||
"temperature=0.1",
|
||||
}, "\n"))
|
||||
cfg := getCfg(p)
|
||||
if cfg.Endpoint != "http://file-endpoint/v1" {
|
||||
t.Errorf("endpoint: got %q, want file value", cfg.Endpoint)
|
||||
}
|
||||
if cfg.Model != "file-model" {
|
||||
t.Errorf("model: got %q, want file value", cfg.Model)
|
||||
}
|
||||
if cfg.Temperature != 0.1 {
|
||||
t.Errorf("temperature: got %v, want file value", cfg.Temperature)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCfgEnvFallbackWhenNoFile(t *testing.T) {
|
||||
// Without a config file the new env vars supply the values.
|
||||
t.Setenv("BANTAM_ENDPOINT", "http://env-endpoint/v1")
|
||||
t.Setenv("BANTAM_MODEL", "env-model")
|
||||
t.Setenv("BANTAM_TEMP", "0.42")
|
||||
t.Setenv("BANTAM_API_KEY", "")
|
||||
cfg := getCfg(filepath.Join(t.TempDir(), "missing.cfg"))
|
||||
if cfg.Endpoint != "http://env-endpoint/v1" || cfg.Model != "env-model" || cfg.Temperature != 0.42 {
|
||||
t.Errorf("env fallback mismatch: %+v", cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAtoiD(t *testing.T) {
|
||||
cases := []struct {
|
||||
s string
|
||||
@@ -2538,7 +2574,7 @@ func TestSkills(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// skillsDir prefers the env var, then the config key.
|
||||
// skillsDir prefers the config key, then the environment variable.
|
||||
t.Setenv("BANTAM_SKILLS_DIR", skillDir)
|
||||
if got := skillsDir(&Cfg{}); got != skillDir {
|
||||
t.Errorf("skillsDir() with env = %q, want %q", got, skillDir)
|
||||
|
||||
Reference in New Issue
Block a user