diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-07 11:26:10 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-07 11:26:10 +0300 |
| commit | 8889949ad3851bfbf36ff5b73128286d67c88201 (patch) | |
| tree | 0f515ae6ee3da898dea113799c09e943f3e3f8fb /internal | |
| parent | 7c0266e94378f6121719939c6d53915eb72eed3e (diff) | |
tiding up
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/appconfig/config_test.go | 31 | ||||
| -rw-r--r-- | internal/hexaiaction/tui_test.go | 21 |
2 files changed, 45 insertions, 7 deletions
diff --git a/internal/appconfig/config_test.go b/internal/appconfig/config_test.go index d708542..5cb79a0 100644 --- a/internal/appconfig/config_test.go +++ b/internal/appconfig/config_test.go @@ -22,6 +22,20 @@ func writeFile(t *testing.T, path, content string) { } } +// clearHexaiEnv removes any HEXAI_* variables to prevent environment leakage +// into tests that expect file-only configuration. +func clearHexaiEnv(t *testing.T) { + t.Helper() + for _, e := range os.Environ() { + if strings.HasPrefix(e, "HEXAI_") { + kv := strings.SplitN(e, "=", 2) + if len(kv) > 0 { + t.Setenv(kv[0], "") + } + } + } +} + func withEnv(t *testing.T, k, v string) { t.Helper() old := os.Getenv(k) @@ -40,9 +54,10 @@ func TestLoad_Defaults_NoLogger(t *testing.T) { } func TestLoad_Defaults_WithLogger_NoFile_NoEnv(t *testing.T) { - t.Setenv("XDG_CONFIG_HOME", t.TempDir()) - logger := newLogger() - cfg := Load(logger) + clearHexaiEnv(t) + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) + logger := newLogger() + cfg := Load(logger) def := newDefaultConfig() if cfg.MaxTokens != def.MaxTokens || cfg.ContextMode != def.ContextMode || cfg.ContextWindowLines != def.ContextWindowLines { t.Fatalf("expected defaults; got %+v want %+v", cfg, def) @@ -192,8 +207,9 @@ func TestLoadFromFile_InvalidTOML(t *testing.T) { } func TestLoad_FileTables_Sectioned(t *testing.T) { - dir := t.TempDir() - t.Setenv("XDG_CONFIG_HOME", dir) + clearHexaiEnv(t) + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) cfgPath := filepath.Join(dir, "hexai", "config.toml") content := ` [general] @@ -274,8 +290,9 @@ temperature = 0.0 } func TestLoad_FileTables_Prompts_AllSections(t *testing.T) { - dir := t.TempDir() - t.Setenv("XDG_CONFIG_HOME", dir) + clearHexaiEnv(t) + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) cfgPath := filepath.Join(dir, "hexai", "config.toml") content := ` [prompts.completion] diff --git a/internal/hexaiaction/tui_test.go b/internal/hexaiaction/tui_test.go index 0f7d091..6f1debc 100644 --- a/internal/hexaiaction/tui_test.go +++ b/internal/hexaiaction/tui_test.go @@ -34,3 +34,24 @@ func TestHandleKey_JumpEndWithG(t *testing.T) { } } +func TestItemMethods(t *testing.T) { + it := item{title: "T", desc: "D", kind: ActionRewrite, hotkey: 'r'} + if it.Title() != "T" || it.Description() != "D" || it.FilterValue() != "T" { + t.Fatalf("item methods wrong: %+v", it) + } +} + +func TestModelInitAndViewAndUpdate(t *testing.T) { + m := newModel() + if m.Init() != nil { + t.Fatalf("Init should return nil cmd") + } + if v := m.View(); v == "" { + t.Fatalf("View should not be empty before done") + } + // Window resize + nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) + if _, ok := nm.(model); !ok { + t.Fatalf("expected model after WindowSizeMsg") + } +} |
