more env fixes

This commit is contained in:
Luxferre
2026-09-10 12:28:00 +03:00
parent b0a16e99e1
commit d9c7bb4407
4 changed files with 157 additions and 65 deletions
+69 -2
View File
@@ -420,7 +420,8 @@ func TestGetCfgEnvOverriddenByFile(t *testing.T) {
t.Setenv("BANTAM_TOOLS_DIR", "/env/tools")
t.Setenv("BANTAM_SKILLS_DIR", "/env/skills")
p := writeCfg(t, strings.Join([]string{
p := filepath.Join(t.TempDir(), ".bantam.cfg")
if err := os.WriteFile(p, []byte(strings.Join([]string{
"endpoint=http://file-endpoint/v1",
"model=file-model",
"temperature=0.1",
@@ -433,7 +434,9 @@ func TestGetCfgEnvOverriddenByFile(t *testing.T) {
"reasoning_effort=high",
"bantam_tools_dir=/file/tools",
"bantam_skills_dir=/file/skills",
}, "\n"))
}, "\n")), 0644); err != nil {
t.Fatal(err)
}
cfg := getCfg(p)
if cfg.Endpoint != "http://file-endpoint/v1" {
t.Errorf("endpoint: got %q, want file value", cfg.Endpoint)
@@ -512,6 +515,70 @@ func TestGetCfgEnvFallbackWhenNoFile(t *testing.T) {
}
}
func TestGetCfgModelCfgOverriddenByEnvWhenBantamCfgAbsent(t *testing.T) {
clearBantamEnv(t)
t.Setenv("BANTAM_ENDPOINT", "http://env-endpoint/v1")
t.Setenv("BANTAM_MODEL", "env-model")
t.Setenv("BANTAM_TEMP", "0.9")
t.Setenv("BANTAM_TOOLS_DIR", "/env/tools")
t.Setenv("BANTAM_SKILLS_DIR", "/env/skills")
dir := t.TempDir()
modelCfg := filepath.Join(dir, "model.cfg")
if err := os.WriteFile(modelCfg, []byte("endpoint=http://file-endpoint/v1\nmodel=file-model\ntemperature=0.1\nbantam_tools_dir=/file/tools\nbantam_skills_dir=/file/skills\n"), 0644); err != nil {
t.Fatal(err)
}
// When .bantam.cfg is absent, model.cfg yields to existing BANTAM_* env vars:
cfg := getCfg(modelCfg)
if cfg.Endpoint != "http://env-endpoint/v1" {
t.Errorf("endpoint: got %q, want env value", cfg.Endpoint)
}
if cfg.Model != "env-model" {
t.Errorf("model: got %q, want env value", cfg.Model)
}
if cfg.Temperature != 0.9 {
t.Errorf("temperature: got %v, want env value", cfg.Temperature)
}
if toolsDir(&cfg) != "/env/tools" {
t.Errorf("toolsDir: got %q, want /env/tools", toolsDir(&cfg))
}
if skillsDir(&cfg) != "/env/skills" {
t.Errorf("skillsDir: got %q, want /env/skills", skillsDir(&cfg))
}
}
func TestGetCfgBantamCfgOverridesEnvAndModelCfg(t *testing.T) {
clearBantamEnv(t)
t.Setenv("BANTAM_ENDPOINT", "http://env-endpoint/v1")
t.Setenv("BANTAM_MODEL", "env-model")
t.Setenv("BANTAM_TEMP", "0.9")
dir := t.TempDir()
modelCfg := filepath.Join(dir, "model.cfg")
if err := os.WriteFile(modelCfg, []byte("endpoint=http://model-endpoint/v1\nmodel=model-model\ncolor=never\n"), 0644); err != nil {
t.Fatal(err)
}
bantamCfg := filepath.Join(dir, ".bantam.cfg")
if err := os.WriteFile(bantamCfg, []byte("model=bantam-model\n"), 0644); err != nil {
t.Fatal(err)
}
cfg := getCfg(bantamCfg)
// bantam.cfg overrides env and model.cfg for model:
if cfg.Model != "bantam-model" {
t.Errorf("model: got %q, want bantam-model", cfg.Model)
}
// endpoint falls back to env:
if cfg.Endpoint != "http://env-endpoint/v1" {
t.Errorf("endpoint: got %q, want env-endpoint", cfg.Endpoint)
}
// color falls back to model.cfg since not in bantam.cfg or env:
if cfg.Color != "never" {
t.Errorf("color: got %q, want never from model.cfg", cfg.Color)
}
}
func TestAtoiD(t *testing.T) {
cases := []struct {
s string