From 0e213d25efe75ff079202cf87305a624654a807d Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 19:05:07 +0800 Subject: [PATCH] test: make the #3380 P2 ladder assertion state-based, immune to runner stalls The P2 integration test asserted the armed back-off by sampling snap.retryAt - Date.now() into a [30, 95]ms window. That window measures observation delay, not the back-off: any runner stall between the 3rd failure arming retryAt = now + 80ms and the snapshot read makes the delta negative (got -49ms on ubuntu-24/24 in PR #6807 run 43698036798; got 25ms on #5597 windows and #5487 ubuntu). The mock's tools.register throw and the production arm (dsh-native.ts registerTools .catch) run in the same event-loop turn, so the applied ladder step is exactly retryAt minus the throw time. Record the throw time in the mock callback and assert against _regBackoffForTest(failStreak) with a tight in-turn window instead. Refs #3571 (checklist item 1), #4599 --- tests/issue3380-dsh-rereg-selflock.test.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/issue3380-dsh-rereg-selflock.test.ts b/tests/issue3380-dsh-rereg-selflock.test.ts index 55a200afda..1c1e596f10 100644 --- a/tests/issue3380-dsh-rereg-selflock.test.ts +++ b/tests/issue3380-dsh-rereg-selflock.test.ts @@ -274,15 +274,29 @@ test("#3380 P2 integration: failures escalate on the ladder, then heal clean", a _resetRegisterForTest(undefined); resetRootLayer(); let failing = true; - const raw = mockCtx({ registerError: () => (failing ? new Error("manifest down (transient)") : undefined) }); + const armTimes: number[] = []; + const raw = mockCtx({ + registerError: () => { + const err = failing ? new Error("manifest down (transient)") : undefined; + if (err !== undefined) armTimes.push(Date.now()); + return err; + }, + }); const ctx = mockCtxTyped(raw); apply(ctx); // Third consecutive failure arms the third ladder step (4×base). await waitFor(() => _registerStateForTest().failStreak >= 3, "three consecutive failures"); const snap = _registerStateForTest(); assert.equal(snap.lastRegistrationError, "manifest down (transient)", "last error recorded for status surfaces"); - const delta = snap.retryAt - Date.now(); - assert.ok(delta >= 30 && delta <= 95, `retryAt sits on the 80ms ladder step (got ${delta}ms)`); + // #3571: the throw lands in the same event-loop turn as the + // back-off arm (registerTools .catch), so retryAt minus the arm + // time IS the applied ladder step — immune to runner stalls + // between the arm and this observation. + const armTime = armTimes[snap.failStreak - 1]; + assert.ok(armTime !== undefined, "failing registration threw before the arm"); + const step = snap.retryAt - armTime; + const expected = _regBackoffForTest(snap.failStreak); + assert.ok(step >= expected - 20 && step <= expected + 25, `retryAt sits on the ${expected}ms ladder step (got ${step}ms)`); // Heal: the transient fault clears, the next attempt succeeds, and // the bookkeeping resets. failing = false;