From 64e731b5e883e4d44c19844df8f618ea034317ba Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 8 May 2026 23:20:57 +0100 Subject: [PATCH] test: avoid cooldown expiry sort allocation --- src/agents/model-fallback.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/agents/model-fallback.test.ts b/src/agents/model-fallback.test.ts index b1737efb172..51e54ea4edc 100644 --- a/src/agents/model-fallback.test.ts +++ b/src/agents/model-fallback.test.ts @@ -131,9 +131,15 @@ const authRuntimeMock = vi.hoisted(() => { continue; } const stats = store.usageStats?.[profileId]; - const expiry = [stats?.cooldownUntil, stats?.disabledUntil] - .filter((value): value is number => isActive(value, ts)) - .toSorted((a, b) => a - b)[0]; + const cooldownUntil = stats?.cooldownUntil; + const disabledUntil = stats?.disabledUntil; + let expiry: number | undefined; + if (isActive(cooldownUntil, ts)) { + expiry = cooldownUntil; + } + if (isActive(disabledUntil, ts) && (expiry === undefined || disabledUntil < expiry)) { + expiry = disabledUntil; + } if (expiry !== undefined && (soonest === null || expiry < soonest)) { soonest = expiry; }