From e39ecfec8d24265f0fe28ffc6c4d0fedebb1b889 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 10 Nov 2026 17:44:34 +0800 Subject: [PATCH] plugin: the hook-chain test leaves the first hook room for the host's start TestGatewayHookChainStillTenSeconds gave each of two hooks 8s and had both sleep 6s. On macOS CI at 286e3b6d5 (run 42784088261) the first one ran past its 8s with the host's start counted and was dropped: "the chain's 10s changed: {"note":"original"}". The first now sleeps 4s (4s to spare), the second 7s: inside its own 8s, past the ~6s the chain has left, so only the chain's 10s cuts it. Run on magpie-desktop: go test -tags nogui -count=3 -run TestGatewayHook ./internal/plugin ok. Broken by hand (chain budget 20s in host.js and gateway.go): red, "first":true,"second":true kept. --- internal/plugin/gateway_budget_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/plugin/gateway_budget_test.go b/internal/plugin/gateway_budget_test.go index 4a692e4a9..c1198fba7 100644 --- a/internal/plugin/gateway_budget_test.go +++ b/internal/plugin/gateway_budget_test.go @@ -7,6 +7,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "strconv" "strings" "testing" "time" @@ -91,14 +92,20 @@ func TestGatewayHookDefaultBudgetStillCuts(t *testing.T) { } // TestGatewayHookChainStillTenSeconds: hooks of 10000 or less share the -// chain's 10s as before. Two of 8000 that take 6s each: the first is kept, -// the second is cut when the chain's 10s are up. +// chain's 10s as before. Two of 8000: the first takes 4s and is kept (4s +// to spare for the host's start on a busy CI machine, where 6s of 8 ran +// out), the second takes 7s, inside its own 8s but past the ~6s the chain +// has left, so only the chain's 10s can cut it. func TestGatewayHookChainStillTenSeconds(t *testing.T) { sandbox(t) var specs []string - for _, name := range []string{"first", "second"} { + for _, h := range []struct { + name string + ms int + }{{"first", 4000}, {"second", 7000}} { + name := h.name spec := gatewayFixture(t, `export async function onRequest(body) { - await new Promise(resolve => setTimeout(resolve, 6000)); + await new Promise(resolve => setTimeout(resolve, `+strconv.Itoa(h.ms)+`)); return {...body, `+name+`: true}; }`) if err := SetOptions(spec, map[string]any{"gatewayTimeoutMs": 8000}); err != nil {