feat(config): internal/config (load/save atomik + validasi) — wiring bahasa/suara/animasi + doctor baca config
CI / test (push) Successful in 13m3s

This commit is contained in:
oxpoe committed 2026-10-15 13:27:16 +07:00
1 parent 36bc33f904
commit c65d2cb75d
8 files changed
+328 -15

No files matched your search

+62 -3
View File
@@ -58,7 +58,31 @@ type tui struct {
waited bool
}
func startTUI(t *testing.T) *tui { return startTUIEnv(t) }
// startTUI memakai TIA_LANG=id eksplisit — deterministik walau mesin
// pengembang/testing punya config.yaml sendiri.
func startTUI(t *testing.T) *tui { return startTUIEnv(t, "TIA_LANG=id") }
// envWith — gabung env proses + override tanpa duplikat key
// (Linux getenv memakai kemunculan pertama, jadi duplikat berbahaya).
func envWith(env []string) []string {
if len(env) == 0 {
return nil
}
overridden := map[string]bool{}
for _, kv := range env {
k, _, _ := strings.Cut(kv, "=")
overridden[k+"="] = true
}
out := make([]string, 0, len(os.Environ())+len(env))
for _, kv := range os.Environ() {
k, _, _ := strings.Cut(kv, "=")
if overridden[k+"="] {
continue
}
out = append(out, kv)
}
return append(out, env...)
}
func startTUIEnv(t *testing.T, env ...string) *tui {
t.Helper()
@@ -66,8 +90,8 @@ func startTUIEnv(t *testing.T, env ...string) *tui {
t.Skip("e2e pty tidak didukung di Windows")
}
cmd := exec.Command(binPath)
if len(env) > 0 {
cmd.Env = append(os.Environ(), env...)
if e := envWith(env); len(e) > 0 {
cmd.Env = e
}
ptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: rows, Cols: cols})
if err != nil {
@@ -216,6 +240,41 @@ func TestDoctorCommand(t *testing.T) {
}
}
func TestConfigFileRespected(t *testing.T) {
xdg := t.TempDir()
if err := os.MkdirAll(filepath.Join(xdg, "tia"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(xdg, "tia", "config.yaml"),
[]byte("version: 1\nui:\n language: en\n"), 0o644); err != nil {
t.Fatal(err)
}
u := startTUIEnv(t, "XDG_CONFIG_HOME="+xdg)
u.waitContains("· home", 5*time.Second)
u.send("q")
if code := u.waitExit(5 * time.Second); code != 0 {
t.Fatalf("exit code %d, mau 0", code)
}
}
func TestDoctorUsesConfigStacksDir(t *testing.T) {
xdg := t.TempDir()
if err := os.MkdirAll(filepath.Join(xdg, "tia"), 0o755); err != nil {
t.Fatal(err)
}
stacks := filepath.Join(xdg, "stacks-custom")
if err := os.WriteFile(filepath.Join(xdg, "tia", "config.yaml"),
[]byte("version: 1\nstacks_dir: "+stacks+"\n"), 0o644); err != nil {
t.Fatal(err)
}
cmd := exec.Command(binPath, "doctor")
cmd.Env = envWith([]string{"XDG_CONFIG_HOME=" + xdg})
out, _ := cmd.CombinedOutput()
if !strings.Contains(string(out), "stacks-custom") {
t.Fatalf("doctor tidak memakai stacks_dir dari config:\n%s", out)
}
}
func TestEnglishLanguage(t *testing.T) {
u := startTUIEnv(t, "TIA_LANG=en")
u.waitContains("· home", 5*time.Second)