diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-08 11:14:36 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-08 11:14:36 +0200 |
| commit | 5e825543dc55a2c649e68dce6341844ad71fa217 (patch) | |
| tree | f7aae1c1d130f08c383f95a23413bdde7843dc0f /internal/tmuxedit/pane_test.go | |
| parent | 023ed82e612451caa38ec46106ed9d148ab9a595 (diff) | |
add hexai-tmux-edit: tmux popup editor for AI agent prompts
New tool that opens $EDITOR in a tmux popup for composing longer prompts
when working with AI CLI agents (Claude Code, Cursor, Amp, Aider, etc.).
Captures existing prompt text from the target pane, pre-fills the editor,
and sends edited text back via tmux send-keys. Config-driven agent
detection via regex patterns in [tmux_edit] config section.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tmuxedit/pane_test.go')
| -rw-r--r-- | internal/tmuxedit/pane_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/tmuxedit/pane_test.go b/internal/tmuxedit/pane_test.go new file mode 100644 index 0000000..5b6f1b6 --- /dev/null +++ b/internal/tmuxedit/pane_test.go @@ -0,0 +1,83 @@ +package tmuxedit + +import ( + "fmt" + "testing" +) + +func TestResolveTargetPane_FlagWins(t *testing.T) { + old := runCommand + defer func() { runCommand = old }() + runCommand = func(string, ...string) ([]byte, error) { + return []byte("%99"), nil + } + t.Setenv("HEXAI_TMUX_PANE", "%10") + got, err := resolveTargetPane("%5") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if got != "%5" { + t.Errorf("got %q, want %%5 (flag should win)", got) + } +} + +func TestResolveTargetPane_EnvFallback(t *testing.T) { + old := runCommand + defer func() { runCommand = old }() + runCommand = func(string, ...string) ([]byte, error) { + return []byte("%99"), nil + } + t.Setenv("HEXAI_TMUX_PANE", "%10") + got, err := resolveTargetPane("") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if got != "%10" { + t.Errorf("got %q, want %%10 (env fallback)", got) + } +} + +func TestResolveTargetPane_TmuxQuery(t *testing.T) { + old := runCommand + defer func() { runCommand = old }() + runCommand = func(name string, args ...string) ([]byte, error) { + if name == "tmux" && len(args) > 0 && args[0] == "display-message" { + return []byte("%42\n"), nil + } + return nil, fmt.Errorf("unexpected command: %s", name) + } + t.Setenv("HEXAI_TMUX_PANE", "") + got, err := resolveTargetPane("") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if got != "%42" { + t.Errorf("got %q, want %%42 (tmux query)", got) + } +} + +func TestResolveTargetPane_TmuxError(t *testing.T) { + old := runCommand + defer func() { runCommand = old }() + runCommand = func(string, ...string) ([]byte, error) { + return nil, fmt.Errorf("tmux not available") + } + t.Setenv("HEXAI_TMUX_PANE", "") + _, err := resolveTargetPane("") + if err == nil { + t.Fatal("expected error when tmux fails") + } +} + +func TestResolveTargetPane_TmuxEmptyOutput(t *testing.T) { + old := runCommand + defer func() { runCommand = old }() + runCommand = func(string, ...string) ([]byte, error) { + return []byte(" \n"), nil + } + t.Setenv("HEXAI_TMUX_PANE", "") + _, err := resolveTargetPane("") + if err == nil { + t.Fatal("expected error for empty tmux output") + } +} |
