From f7aeaa5c7e91807170b014b7530afaddec01a01d Mon Sep 17 00:00:00 2001 From: cexll Date: Tue, 13 Jan 2026 22:56:05 +0800 Subject: [PATCH] fix(codeagent-wrapper): add sleep in fake script to prevent CI race condition Add 50ms sleep in createFakeCodexScript to ensure parser goroutine has time to read stdout before the process exits. Fixes TestRun_ExplicitStdinSuccess flaky failure on Linux CI where fast shell execution closes pipe prematurely. Generated with SWE-Agent.ai Co-Authored-By: SWE-Agent.ai --- codeagent-wrapper/main_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codeagent-wrapper/main_test.go b/codeagent-wrapper/main_test.go index e59e5e9..f7c3595 100644 --- a/codeagent-wrapper/main_test.go +++ b/codeagent-wrapper/main_test.go @@ -637,9 +637,13 @@ func (f *fakeCmd) StdinContents() string { func createFakeCodexScript(t *testing.T, threadID, message string) string { t.Helper() scriptPath := filepath.Join(t.TempDir(), "codex.sh") + // Add small sleep to ensure parser goroutine has time to read stdout before + // the process exits and closes the pipe. This prevents race conditions in CI + // where fast shell script execution can close stdout before parsing completes. script := fmt.Sprintf(`#!/bin/sh printf '%%s\n' '{"type":"thread.started","thread_id":"%s"}' printf '%%s\n' '{"type":"item.completed","item":{"type":"agent_message","text":"%s"}}' +sleep 0.05 `, threadID, message) if err := os.WriteFile(scriptPath, []byte(script), 0o755); err != nil { t.Fatalf("failed to create fake codex script: %v", err)