fix: mire test failing is some command inside of bash failed

This commit is contained in:
2026-03-22 20:25:29 +00:00
parent 19d7c2bb3e
commit 12cb12991a
3 changed files with 35 additions and 15 deletions
+18 -4
View File
@@ -49,6 +49,16 @@ type ReplayRequest struct {
OutputLog io.Writer
}
type ReplayResult struct {
ProcessErr error
OutputErr error
InputErr error
}
func (r ReplayResult) Err() error {
return firstErr(r.ProcessErr, r.OutputErr, r.InputErr)
}
// Record runs a live PTY session so we can mirror interactive output while capturing stable input and output logs.
func Record(req RecordRequest) error {
if req.Cmd == nil {
@@ -98,14 +108,14 @@ func Record(req RecordRequest) error {
}
// Replay feeds recorded keystrokes back into a fresh PTY session to verify behavior against captured output.
func Replay(req ReplayRequest) error {
func Replay(req ReplayRequest) ReplayResult {
if req.Cmd == nil {
return errors.New("replay session command is required")
return ReplayResult{ProcessErr: errors.New("replay session command is required")}
}
ptmx, err := pty.StartWithSize(req.Cmd, sessionSize(nil))
if err != nil {
return err
return ReplayResult{ProcessErr: err}
}
defer ptmx.Close()
@@ -120,7 +130,11 @@ func Replay(req ReplayRequest) error {
outputErr := <-outputDone
inputErr := <-inputDone
return firstErr(waitErr, outputErr, inputErr)
return ReplayResult{
ProcessErr: waitErr,
OutputErr: outputErr,
InputErr: inputErr,
}
}
// combineWriters skips nil destinations so callers can fan out conditionally without repeated nil checks.
+6 -6
View File
@@ -52,12 +52,12 @@ func TestReplayCapturesOutput(t *testing.T) {
cmd := exec.Command("sh", "-c", `read line; printf '__MIRE_E2E_BEGIN__\nline:%s\n' "$line"`)
var outputLog bytes.Buffer
if err := Replay(ReplayRequest{
if result := Replay(ReplayRequest{
Cmd: cmd,
Input: []byte("hello\n"),
OutputLog: &outputLog,
}); err != nil {
t.Fatalf("Replay() error = %v", err)
}); result.Err() != nil {
t.Fatalf("Replay() error = %v", result.Err())
}
got := outputLog.String()
@@ -77,13 +77,13 @@ func TestReplayWaitsForInputReadySignal(t *testing.T) {
close(ready)
}()
if err := Replay(ReplayRequest{
if result := Replay(ReplayRequest{
Cmd: cmd,
Input: []byte("hello\n"),
InputReady: ready,
OutputLog: &outputLog,
}); err != nil {
t.Fatalf("Replay() error = %v", err)
}); result.Err() != nil {
t.Fatalf("Replay() error = %v", result.Err())
}
if elapsed := time.Since(start); elapsed < 100*time.Millisecond {