From a9c750365df5f5464c185ac02610574a99edcf59 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Fri, 30 Oct 2026 02:36:53 -0500 Subject: [PATCH] mcpx tests: poll the stats postcondition in the hooks firing test (#2609) The payload wait fixed the first race; the full-system build then exposed a second one in the same test: the runner records its stats asynchronously after the hook process finishes, so the immediate Stats() assertion read Fired:0 under load. Poll the postcondition with the same waitFor helper. Test-only; assertions unchanged. --- pkgs/mcpx/internal/hooks/runner_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/mcpx/internal/hooks/runner_test.go b/pkgs/mcpx/internal/hooks/runner_test.go index 1a07fc8c7a..c5e3acdbe6 100644 --- a/pkgs/mcpx/internal/hooks/runner_test.go +++ b/pkgs/mcpx/internal/hooks/runner_test.go @@ -56,10 +56,14 @@ func TestDeclaredHookFiresOnMatchingKindsOnly(t *testing.T) { !strings.Contains(string(body), `"hook":"rec"`) { t.Fatalf("hook stdin payload wrong: %s", body) } - st := r.Stats() - if len(st) != 1 || st[0].Fired != 1 || st[0].Failed != 0 { - t.Fatalf("stats wrong: %+v", st) - } + // The stats counter is recorded asynchronously after the hook + // process finishes; asserting it immediately races the recording + // under load (the second #2609 flake, seen in the full-system + // build). Poll the real postcondition. + waitFor(t, "hook stats to record the firing", func() bool { + st := r.Stats() + return len(st) == 1 && st[0].Fired == 1 && st[0].Failed == 0 + }) } func TestPythonModuleHookRuns(t *testing.T) {