summaryrefslogtreecommitdiff
path: root/cmd/hexai-tmux-edit
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/hexai-tmux-edit')
-rw-r--r--cmd/hexai-tmux-edit/main.go21
-rw-r--r--cmd/hexai-tmux-edit/main_test.go59
2 files changed, 74 insertions, 6 deletions
diff --git a/cmd/hexai-tmux-edit/main.go b/cmd/hexai-tmux-edit/main.go
index ea3330b..6d0e75e 100644
--- a/cmd/hexai-tmux-edit/main.go
+++ b/cmd/hexai-tmux-edit/main.go
@@ -21,6 +21,9 @@ import (
"codeberg.org/snonux/hexai/internal/tmuxedit"
)
+// runTmuxEdit is the seam for testing: override in tests to avoid real tmux.
+var runTmuxEdit = tmuxedit.Run
+
func main() {
defaultPath := appconfig.DefaultConfigPath()
configPath := flag.String("config", "", fmt.Sprintf("path to config file (default: %s)", defaultPath))
@@ -28,13 +31,19 @@ func main() {
pane := flag.String("pane", "", "tmux target pane ID (e.g. %%5)")
flag.Parse()
- opts := tmuxedit.Options{
- ConfigPath: strings.TrimSpace(*configPath),
- Agent: strings.TrimSpace(*agent),
- Pane: strings.TrimSpace(*pane),
- }
- if err := tmuxedit.Run(opts); err != nil {
+ opts := buildOptions(*configPath, *agent, *pane)
+ if err := runTmuxEdit(opts); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
+
+// buildOptions constructs tmuxedit.Options from the parsed flag values,
+// trimming whitespace from each field.
+func buildOptions(configPath, agent, pane string) tmuxedit.Options {
+ return tmuxedit.Options{
+ ConfigPath: strings.TrimSpace(configPath),
+ Agent: strings.TrimSpace(agent),
+ Pane: strings.TrimSpace(pane),
+ }
+}
diff --git a/cmd/hexai-tmux-edit/main_test.go b/cmd/hexai-tmux-edit/main_test.go
new file mode 100644
index 0000000..fc2364c
--- /dev/null
+++ b/cmd/hexai-tmux-edit/main_test.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "errors"
+ "testing"
+
+ "codeberg.org/snonux/hexai/internal/tmuxedit"
+)
+
+func TestBuildOptions_AllEmpty(t *testing.T) {
+ opts := buildOptions("", "", "")
+ if opts.ConfigPath != "" || opts.Agent != "" || opts.Pane != "" {
+ t.Fatalf("expected all empty, got %+v", opts)
+ }
+}
+
+func TestBuildOptions_TrimsWhitespace(t *testing.T) {
+ opts := buildOptions(" /tmp/cfg.toml ", " claude ", " %5 ")
+ if opts.ConfigPath != "/tmp/cfg.toml" {
+ t.Fatalf("expected trimmed config path, got %q", opts.ConfigPath)
+ }
+ if opts.Agent != "claude" {
+ t.Fatalf("expected trimmed agent, got %q", opts.Agent)
+ }
+ if opts.Pane != "%5" {
+ t.Fatalf("expected trimmed pane, got %q", opts.Pane)
+ }
+}
+
+func TestRunTmuxEdit_Success(t *testing.T) {
+ old := runTmuxEdit
+ t.Cleanup(func() { runTmuxEdit = old })
+
+ var gotOpts tmuxedit.Options
+ runTmuxEdit = func(opts tmuxedit.Options) error {
+ gotOpts = opts
+ return nil
+ }
+
+ opts := buildOptions("/tmp/cfg.toml", "cursor", "%3")
+ if err := runTmuxEdit(opts); err != nil {
+ t.Fatalf("runTmuxEdit: %v", err)
+ }
+ if gotOpts.ConfigPath != "/tmp/cfg.toml" || gotOpts.Agent != "cursor" || gotOpts.Pane != "%3" {
+ t.Fatalf("unexpected opts: %+v", gotOpts)
+ }
+}
+
+func TestRunTmuxEdit_Error(t *testing.T) {
+ old := runTmuxEdit
+ t.Cleanup(func() { runTmuxEdit = old })
+
+ wantErr := errors.New("tmux not found")
+ runTmuxEdit = func(_ tmuxedit.Options) error { return wantErr }
+
+ if err := runTmuxEdit(tmuxedit.Options{}); !errors.Is(err, wantErr) {
+ t.Fatalf("expected error, got: %v", err)
+ }
+}