From 0659dc66fa20c46342e3c40c6215f12dde1f8725 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 10 Nov 2026 22:37:25 +0800 Subject: [PATCH] plugin: the default-budget hook test starts the host before it measures TestGatewayHookDefaultBudgetStillCuts/10000 was red on macOS CI at c2c2c82ca (run 42819148533): the hook was cut at 9.3s as "cancelled", not by its own 10s timer as "timeout". The RPC's 11s (gatewayWait) counts the host's start too, so a start past a second on a busy machine lets the RPC's deadline land first. Same class as e39ecfec8's chain test. Now the fixture's first request returns at once and only starts the host; the second one is measured, with the host's start out of its margin. The product is unchanged. Ran on WSL magpie-desktop, go test -tags nogui ./internal/plugin -run TestGatewayHook: ok. Broken by hand: - a 2.5s top-level wait in the fixture (a slow host start): the old test fails ("wasn't cut by its own budget"), the new one passes; - the 10000 case given 20000: the new test fails ("a hook past its default budget was kept"). Not tried: macOS CI itself, until this push's run. --- internal/plugin/gateway_budget_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/plugin/gateway_budget_test.go b/internal/plugin/gateway_budget_test.go index c1198fba7..45855ad65 100644 --- a/internal/plugin/gateway_budget_test.go +++ b/internal/plugin/gateway_budget_test.go @@ -60,7 +60,8 @@ export async function onResponse(reply, ctx) { // TestGatewayHookDefaultBudgetStillCuts: without a longer timeout a slow // hook is cut where it always was, by the host's own timer ("timeout", not // the RPC's deadline, which would read "cancelled"): at the default second, -// and at 10s for the 10000 every host took. +// and at 10s for the 10000 every host took. A first, quick request starts +// the host, so the start doesn't eat the second's margin. func TestGatewayHookDefaultBudgetStillCuts(t *testing.T) { for _, tc := range []struct { name string @@ -69,7 +70,13 @@ func TestGatewayHookDefaultBudgetStillCuts(t *testing.T) { }{{"default", nil, 8000}, {"10000", map[string]any{"gatewayTimeoutMs": 10000}, 0}} { t.Run(tc.name, func(t *testing.T) { sandbox(t) - spec := gatewayFixture(t, `export async function onRequest(body) { + // The first request only starts the host: the RPC's 11s counts + // the host's start too, and on a busy CI machine a start past a + // second let it cut the 10000 hook first ("cancelled", run + // 42819148533 on macOS). The second request is the one measured. + spec := gatewayFixture(t, `let seen = 0; +export async function onRequest(body) { + if (seen++ === 0) return body; await new Promise(resolve => setTimeout(resolve, 12000)); return {...body, note: "recalled"}; }`) @@ -80,6 +87,9 @@ func TestGatewayHookDefaultBudgetStillCuts(t *testing.T) { } ctx, cancel := context.WithTimeout(t.Context(), 40*time.Second) defer cancel() + if out := gatewayRequest(ctx, []byte(`{"note":"original"}`), GatewayContext{}); string(out) != `{"note":"original"}` { + t.Fatalf("the warming request came back changed: %s", out) + } if out := gatewayRequest(ctx, []byte(`{"note":"original"}`), GatewayContext{}); string(out) != `{"note":"original"}` { t.Fatalf("a hook past its default budget was kept: %s", out) }