From 3efa123b23a9643012531af4aa6a4f0327b2419c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Wed, 2 Dec 2026 00:50:44 +0000 Subject: [PATCH] test(cli): keep polling while the pre-run PID file is still being written TestDefaultPreRunCommandKillsGrandchildOnDeadline failed on main CI (run for 4a0df0c) with "grandchild did not start" after 0.01s. The helper writes the grandchild PID with os.WriteFile, which creates the file before writing it; a poll that landed between the two read an empty file, parsed PID 0 and stopped polling. Reproduced by widening that window in the helper. The loop now waits until the file holds a valid PID. Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/cli/root_prerun_backup_linux_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/go-cli/internal/cli/root_prerun_backup_linux_test.go b/app/go-cli/internal/cli/root_prerun_backup_linux_test.go index c85c9e6..37b9a93 100644 --- a/app/go-cli/internal/cli/root_prerun_backup_linux_test.go +++ b/app/go-cli/internal/cli/root_prerun_backup_linux_test.go @@ -492,9 +492,11 @@ func TestDefaultPreRunCommandKillsGrandchildOnDeadline(t *testing.T) { go func() { done <- command.Run() }() var childPID int for time.Now().Before(started.Add(4 * time.Second)) { + // os.WriteFile creates the file before writing it: an empty or partial + // read means the helper has not finished, so keep polling. body, err := os.ReadFile(preRunTestPIDPath) - if err == nil { - childPID, _ = strconv.Atoi(string(body)) + if pid, parseErr := strconv.Atoi(string(body)); err == nil && parseErr == nil && pid > 0 { + childPID = pid break } time.Sleep(10 * time.Millisecond)