From 7ad0b140316437317064e3ee1506eacf68f3b85e Mon Sep 17 00:00:00 2001 From: Bertug Date: Fri, 26 Jun 2026 01:58:23 +0300 Subject: [PATCH] =?UTF-8?q?test(paidtool):=20de-flake=20postpaid=20meterin?= =?UTF-8?q?g=20=E2=80=94=20drop=20timing-dependent=20upper=20bound?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI run 28174117576 failed on "postpaid metering › charges based on actual execution metrics" (expected true, actual false). The handler sleeps 50ms and the test asserted the metered charge was < $0.15 (i.e. duration < 150ms) — a tight upper bound that flakes on slow/loaded CI runners where the real duration can spike past 150ms (GC, scheduler, cold runner). The failure is non- deterministic and unrelated to the change under test; re-runs and the merge build passed. Keep the meaningful lower bound (≥ $0.05 ⇒ ≥50ms of metered work) and replace the flaky upper bound with an exact check that the charge equals durationMs * rate — which actually proves "charges based on actual metrics" without depending on wall-clock speed. Full suite: 247 passing. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/__tests__/paidTool.test.mjs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/__tests__/paidTool.test.mjs b/src/__tests__/paidTool.test.mjs index 86ed264..fb35346 100644 --- a/src/__tests__/paidTool.test.mjs +++ b/src/__tests__/paidTool.test.mjs @@ -668,8 +668,16 @@ describe("Tollgate SDK", () => { const result = await tool({}, "agent-1"); assert.equal(result.success, true); - assert.ok(result.receipt.amount >= 0.05); // ~50ms × $0.001 - assert.ok(result.receipt.amount < 0.15); // shouldn't take > 150ms + // The handler sleeps 50ms, so the metered charge must reflect ≥50ms of + // work. Only assert the lower bound: a tight upper bound (e.g. <150ms) is + // timing-dependent and flakes on slow/loaded CI runners where the real + // duration can spike past 150ms (GC, scheduler, cold runner). + assert.ok( + result.receipt.amount >= 0.05, + `expected >= $0.05 for ~50ms of metered work, got ${result.receipt.amount}`, + ); + // Sanity: the charge is derived from actual duration, not a flat fee. + assert.equal(result.receipt.amount, result.metrics.durationMs * 0.001); }); });