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
|
package appconfig
import (
"path/filepath"
"strings"
"testing"
)
func TestCustomActions_MissingFields(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
cfgPath := filepath.Join(dir, "hexai", "config.toml")
writeFile(t, cfgPath, `
[prompts.code_action]
[[prompts.code_action.custom]]
title = "No ID"
instruction = "x"
[[prompts.code_action.custom]]
id = "no-title"
instruction = "x"
`)
cfg := Load(newLogger())
if err := cfg.Validate(); err == nil || (!strings.Contains(err.Error(), "missing required field id") && !strings.Contains(err.Error(), "missing required field title")) {
t.Fatalf("expected missing field error, got %v", err)
}
}
func TestCustomActions_InvalidHotkeys(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", dir)
cfgPath := filepath.Join(dir, "hexai", "config.toml")
writeFile(t, cfgPath, `
[prompts.code_action]
[[prompts.code_action.custom]]
id = "a"
title = "A"
instruction = "x"
hotkey = "too"
[tmux]
custom_menu_hotkey = "ab"
`)
cfg := Load(newLogger())
if err := cfg.Validate(); err == nil || (!strings.Contains(err.Error(), "hotkey must be a single character") && !strings.Contains(err.Error(), "invalid tmux.custom_menu_hotkey")) {
t.Fatalf("expected invalid hotkey error, got %v", err)
}
}
|