fix: wait on bash prompt ready marker before sending in keystrokes

This commit is contained in:
2026-03-21 20:54:24 +00:00
parent cc696bb4be
commit fe42c40d1e
4 changed files with 159 additions and 2 deletions
+29
View File
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"testing"
"time"
)
func TestRecordCopiesInputAndOutput(t *testing.T) {
@@ -64,3 +65,31 @@ func TestReplayCapturesOutput(t *testing.T) {
t.Fatalf("output log = %q, want marker + line:hello", got)
}
}
func TestReplayWaitsForInputReadySignal(t *testing.T) {
cmd := exec.Command("sh", "-c", `IFS= read -r line; printf 'line:%s\n' "$line"`)
ready := make(chan struct{})
var outputLog bytes.Buffer
start := time.Now()
go func() {
time.Sleep(100 * time.Millisecond)
close(ready)
}()
if err := Replay(ReplayRequest{
Cmd: cmd,
Input: []byte("hello\n"),
InputReady: ready,
OutputLog: &outputLog,
}); err != nil {
t.Fatalf("Replay() error = %v", err)
}
if elapsed := time.Since(start); elapsed < 100*time.Millisecond {
t.Fatalf("Replay() elapsed = %v, want >= %v", elapsed, 100*time.Millisecond)
}
if !bytes.Contains(outputLog.Bytes(), []byte("line:hello")) {
t.Fatalf("output log = %q, want line:hello", outputLog.String())
}
}