Skip to content

Commit 2ebf132

Browse files
Copilotpelikhan
andauthored
Fix CaptureStderr restoration timing in testutil to resolve CI unit test failure (#26687)
* Initial plan * chore: start CI failure investigation Agent-Logs-Url: https://github.com/github/gh-aw/sessions/005cb2c2-4d54-4e3b-94df-a47692cb3734 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * fix: restore os.Stderr immediately in CaptureStderr helper Agent-Logs-Url: https://github.com/github/gh-aw/sessions/005cb2c2-4d54-4e3b-94df-a47692cb3734 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * fix: close CaptureStderr reader after read completion Agent-Logs-Url: https://github.com/github/gh-aw/sessions/005cb2c2-4d54-4e3b-94df-a47692cb3734 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent fecca41 commit 2ebf132

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/testutil/tempdir.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,20 @@ func CaptureStderr(t *testing.T, fn func()) string {
8080

8181
origStderr := os.Stderr
8282
os.Stderr = w
83-
t.Cleanup(func() { os.Stderr = origStderr })
83+
defer func() { os.Stderr = origStderr }()
8484

8585
fn()
8686

87-
w.Close()
87+
if err = w.Close(); err != nil {
88+
t.Fatalf("CaptureStderr: failed to close writer pipe: %v", err)
89+
}
8890
var buf bytes.Buffer
8991
if _, err = buf.ReadFrom(r); err != nil {
9092
t.Fatalf("CaptureStderr: failed to read pipe: %v", err)
9193
}
94+
if err = r.Close(); err != nil {
95+
t.Logf("Warning: failed to close stderr capture reader: %v", err)
96+
}
9297
return buf.String()
9398
}
9499

0 commit comments

Comments
 (0)