diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-18 08:05:32 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-18 08:05:32 +0300 |
| commit | a80ad2b4691d0df63f68c6977ee18444e7bb752f (patch) | |
| tree | 6edc47fcc3c929856826432cf3df3394a14934e8 /internal/tmuxedit | |
| parent | 4ffb22e7f69f1c9c79b095d4e60bad3d97aac55b (diff) | |
ik0 replace remaining test seams with DI
Diffstat (limited to 'internal/tmuxedit')
| -rw-r--r-- | internal/tmuxedit/agentutil.go | 12 | ||||
| -rw-r--r-- | internal/tmuxedit/agentutil_test.go | 7 | ||||
| -rw-r--r-- | internal/tmuxedit/pane.go | 15 | ||||
| -rw-r--r-- | internal/tmuxedit/send_test.go | 2 |
4 files changed, 26 insertions, 10 deletions
diff --git a/internal/tmuxedit/agentutil.go b/internal/tmuxedit/agentutil.go index 0f4f38e..bf1a723 100644 --- a/internal/tmuxedit/agentutil.go +++ b/internal/tmuxedit/agentutil.go @@ -11,6 +11,8 @@ import ( "time" ) +const escapeKeyDelay = 150 * time.Millisecond + // promptMatch holds a regex match result with its line number in the pane. type promptMatch struct { lineNum int @@ -124,12 +126,20 @@ func (d tmuxEditDeps) sendClearSequence(paneID, clearKeys string) error { } // Add delay after Escape to let Vim-based agents exit INSERT mode if key == "Escape" { - time.Sleep(150 * time.Millisecond) + d.sleepEscape() } } return nil } +func (d tmuxEditDeps) sleepEscape() { + if d.sleepAfterEscape != nil { + d.sleepAfterEscape() + return + } + time.Sleep(escapeKeyDelay) +} + // parseKeyRepeat splits "Key*N" into (Key, N). Returns (token, 1) if no // repeat suffix is present or the suffix is invalid. func parseKeyRepeat(token string) (string, int) { diff --git a/internal/tmuxedit/agentutil_test.go b/internal/tmuxedit/agentutil_test.go index eed245c..3cafb3b 100644 --- a/internal/tmuxedit/agentutil_test.go +++ b/internal/tmuxedit/agentutil_test.go @@ -199,13 +199,15 @@ func TestParseKeyRepeat(t *testing.T) { func TestSendClearSequence_EscapeKey(t *testing.T) { var calls []string + var escapeSleeps int deps := tmuxEditDeps{sendKeys: func(paneID string, keys ...string) error { calls = append(calls, strings.Join(keys, ",")) return nil + }, sleepAfterEscape: func() { + escapeSleeps++ }} // sendClearSequence with "Escape" should succeed and send the key. - // The 150ms Escape delay is real but acceptable in tests. err := deps.sendClearSequence("%1", "Escape C-k") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -219,6 +221,9 @@ func TestSendClearSequence_EscapeKey(t *testing.T) { t.Errorf("call[%d] = %q, want %q", i, calls[i], w) } } + if escapeSleeps != 1 { + t.Fatalf("escape sleeps = %d, want 1", escapeSleeps) + } } func TestSendClearSequence_SingleKeyError(t *testing.T) { diff --git a/internal/tmuxedit/pane.go b/internal/tmuxedit/pane.go index 0b6be93..2713994 100644 --- a/internal/tmuxedit/pane.go +++ b/internal/tmuxedit/pane.go @@ -8,13 +8,14 @@ import ( ) type tmuxEditDeps struct { - runCommand func(string, ...string) ([]byte, error) - capturePane func(string) (string, error) - openEditorPopup func(string, string, string) (string, error) - sendKeys func(string, ...string) error - sendRepeatedKey func(string, string, int) error - sleepAfterClear func() - launchPopup func(string, string, string, string) error + runCommand func(string, ...string) ([]byte, error) + capturePane func(string) (string, error) + openEditorPopup func(string, string, string) (string, error) + sendKeys func(string, ...string) error + sendRepeatedKey func(string, string, int) error + sleepAfterClear func() + sleepAfterEscape func() + launchPopup func(string, string, string, string) error } func (d tmuxEditDeps) command(name string, args ...string) ([]byte, error) { diff --git a/internal/tmuxedit/send_test.go b/internal/tmuxedit/send_test.go index 3fdd27b..64e1d36 100644 --- a/internal/tmuxedit/send_test.go +++ b/internal/tmuxedit/send_test.go @@ -7,7 +7,7 @@ import ( ) func noSleepDeps() tmuxEditDeps { - return tmuxEditDeps{sleepAfterClear: func() {}} + return tmuxEditDeps{sleepAfterClear: func() {}, sleepAfterEscape: func() {}} } func TestDeduplicateText(t *testing.T) { |
