fix: mire test failing is some command inside of bash failed
This commit is contained in:
+11
-5
@@ -265,21 +265,27 @@ func replayScenario(scenario testScenario, shellPath string, _ testIO, sandboxCo
|
||||
promptTimeout := time.AfterFunc(replayPromptReadyTimeout, promptWriter.release)
|
||||
defer promptTimeout.Stop()
|
||||
|
||||
if err := script.Replay(script.ReplayRequest{
|
||||
replayResult := script.Replay(script.ReplayRequest{
|
||||
Cmd: cmd,
|
||||
Input: input,
|
||||
InputReady: ready,
|
||||
OutputLog: promptWriter,
|
||||
}); err != nil {
|
||||
rawOutFile.Close()
|
||||
return fmt.Errorf("replay failed: %v", err)
|
||||
}
|
||||
})
|
||||
if err := rawOutFile.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close replay output: %v", err)
|
||||
}
|
||||
if !promptWriter.seen {
|
||||
if err := replayResult.Err(); err != nil {
|
||||
return fmt.Errorf("replay failed: %v", err)
|
||||
}
|
||||
return fmt.Errorf("replay shell never emitted %q; rerun `mire init` or refresh %q", compareOutputMarker, shellPath)
|
||||
}
|
||||
if replayResult.OutputErr != nil {
|
||||
return fmt.Errorf("replay failed: %v", replayResult.OutputErr)
|
||||
}
|
||||
if replayResult.InputErr != nil {
|
||||
return fmt.Errorf("replay failed: %v", replayResult.InputErr)
|
||||
}
|
||||
|
||||
got, err := loadRecordedOutput(rawOut)
|
||||
if err != nil {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user