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 <noreply@swe-agent.ai>
This commit is contained in:
cexll
2026-01-13 22:56:05 +08:00
parent c8f75faf84
commit f7aeaa5c7e

View File

@@ -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)