返回 DeepSeek-Reasonix
statusline_scope_test.go
根目录 / internal / cli / statusline_scope_test.go
1 package cli
2
3 import (
4 "context"
5 "os"
6 "path/filepath"
7 "runtime"
8 "testing"
9 "time"
10
11 "reasonix/internal/config"
12 "reasonix/internal/control"
13 "reasonix/internal/event"
14 "reasonix/internal/hook"
15 )
16
17 // A project's configuration cannot choose commands the TUI runs: the footer
18 // reads the statusline from config.Load, as the interactive session does.
19 func TestProjectStatuslineCommandNeverRunsFromTheTUI(t *testing.T) {
20 if runtime.GOOS == "windows" {
21 t.Skip("marker command is POSIX shell")
22 }
23 isolateUserConfig(t)
24 repo := t.TempDir()
25 marker := filepath.Join(repo, "statusline-ran")
26 if err := os.WriteFile(filepath.Join(repo, "reasonix.toml"), []byte("[statusline]\ncommand = \"touch "+marker+"\"\n"), 0o600); err != nil {
27 t.Fatal(err)
28 }
29 t.Chdir(repo)
30 cfg, err := config.Load()
31 if err != nil {
32 t.Fatal(err)
33 }
34 m := newChatTUI(newOwnedTestController(t, control.Options{Label: "m"}), "", make(chan event.Event, 1), 80)
35 m.statuslineCmd = cfg.Statusline.Command
36 if cmd := m.runStatusline(); cmd != nil {
37 cmd()
38 }
39 if _, err := os.Stat(marker); err == nil {
40 t.Fatalf("project statusline command %q ran", cfg.Statusline.Command)
41 }
42 }
43
44 func TestStatuslineSpawnDisablesCwdExecutableSearch(t *testing.T) {
45 var got hook.SpawnInput
46 spawn := func(_ context.Context, in hook.SpawnInput) hook.SpawnResult {
47 got = in
48 return hook.SpawnResult{Stdout: "row\n"}
49 }
50 if out := runStatuslineCmdWith(spawn, "status", "{}", time.Second); out != "row" {
51 t.Fatalf("statusline output = %q, want row", out)
52 }
53 if got.Env[hook.NoCwdCommandSearchEnv] != "1" {
54 t.Fatalf("statusline spawned with env %v, want %s=1", got.Env, hook.NoCwdCommandSearchEnv)
55 }
56 }
57
57 lines GO