summaryrefslogtreecommitdiff
path: root/internal/config/config_test.go
blob: e4f1a5d3d6c19a57b3e4bd2a3ce503c85e629cce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package config

import (
	"os"
	"path/filepath"
	"testing"
)

func TestDefault_EmptyHome_ReturnsError(t *testing.T) {
	t.Setenv("HOME", "")
	_, err := Default()
	if err == nil {
		t.Fatal("expected error when HOME is empty, got nil")
	}
}

func TestDefault_ValidHome_ReturnsConfig(t *testing.T) {
	t.Setenv("HOME", "/tmp/testhome")
	cfg, err := Default()
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if cfg.DataDir != "/tmp/testhome/.claudomator" {
		t.Errorf("DataDir = %q, want /tmp/testhome/.claudomator", cfg.DataDir)
	}
}

func TestLoadFile_OverridesDefaults(t *testing.T) {
	dir := t.TempDir()
	path := filepath.Join(dir, "config.toml")
	if err := os.WriteFile(path, []byte("server_addr = \":9191\"\n"), 0600); err != nil {
		t.Fatal(err)
	}
	t.Setenv("HOME", dir)

	cfg, err := LoadFile(path)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if cfg.ServerAddr != ":9191" {
		t.Errorf("ServerAddr = %q, want :9191", cfg.ServerAddr)
	}
	// Unset fields retain defaults.
	if cfg.MaxConcurrent != 3 {
		t.Errorf("MaxConcurrent = %d, want 3", cfg.MaxConcurrent)
	}
}

func TestLoadFile_MissingFile_ReturnsError(t *testing.T) {
	t.Setenv("HOME", t.TempDir())
	_, err := LoadFile("/nonexistent/config.toml")
	if err == nil {
		t.Fatal("expected error for missing file, got nil")
	}
}

func TestLocalModel_UseForElaborate_EmptyEndpoint(t *testing.T) {
	m := LocalModel{}
	if m.UseForElaborate() {
		t.Error("empty endpoint should never opt into elaborate")
	}
}

func TestLocalModel_UseForElaborate_DefaultTrue(t *testing.T) {
	m := LocalModel{Endpoint: "http://localhost:11434/v1"}
	if !m.UseForElaborate() {
		t.Error("endpoint set + default flag should opt in")
	}
}

func TestLocalModel_UseForElaborate_ExplicitFalse(t *testing.T) {
	f := false
	m := LocalModel{Endpoint: "http://localhost:11434/v1", PreferForElaborate: &f}
	if m.UseForElaborate() {
		t.Error("explicit false should opt out")
	}
}

func TestLocalModel_UseForElaborate_ExplicitTrue(t *testing.T) {
	tr := true
	m := LocalModel{Endpoint: "http://localhost:11434/v1", PreferForElaborate: &tr}
	if !m.UseForElaborate() {
		t.Error("explicit true should opt in")
	}
}