From c4eb6d223e108b9c41c5f991efd9f9e285727387 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 10:44:22 +0000 Subject: [PATCH 1/4] test(formula): judge each distinct sweep refusal once, and give the validateExpression sweep a measured budget The validateExpression sweep in expression-refusal-codes.test.ts provokes 3,865 refusals, 199 of them distinct, and re-ran the same assertions on every duplicate. It now judges each distinct refusal once (keyed on the whole refusal), keeps counting every refusal, and still requires every code to be provoked. The breadth of the sweep is its claim and stays. The case is synchronous and took 5034 ms on a contended Test Core (4/8) shard, so it carries an explicit budget of 3x that reading, with the readings in its comment. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_017ihL2ebbZkr2QAEG1x7UC8 --- .../src/expression-refusal-codes.test.ts | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/formula/src/expression-refusal-codes.test.ts b/packages/formula/src/expression-refusal-codes.test.ts index f8aae2e37a4..51ee697b1e9 100644 --- a/packages/formula/src/expression-refusal-codes.test.ts +++ b/packages/formula/src/expression-refusal-codes.test.ts @@ -20,6 +20,7 @@ * red at the type check, and a code nobody pinned goes red here. */ +import { inspect } from 'node:util'; import { describe, expect, it } from 'vitest'; import { celEngine, collectCelRootIdentifiers, type CelRootIdentifiersResult } from './cel-engine'; import { templateEngine } from './template-engine'; @@ -855,6 +856,39 @@ function expectLocatorsRead(said: { code: string; params: unknown; source: strin } } +/** + * A refusal's identity in the sweep: the whole refusal, which is its `code`, + * `params`, `message` and `source` (`refusal()` in `validate.ts` builds exactly + * those four). `inspect` and not `JSON.stringify`, because JSON writes an + * `undefined` param as absent and `NaN` as `null`, and two refusals that differ + * only there must still be judged apart. + */ +function refusalKey(said: ExprValidationError): string { + return inspect(said, { depth: Infinity, breakLength: Infinity, maxArrayLength: Infinity, maxStringLength: Infinity }); +} + +/** + * The validateExpression sweep's budget. The case is synchronous: 5,760 + * validateExpression calls (3 roles x 128 inputs x 15 schemas), most of the + * time in building a typed CEL environment for each call. Its work is the + * sweep's breadth, which is the claim, so the breadth stays; only re-judging + * duplicate refusals was cut (see the case). Readings of the case, in ms: + * + * - CI, `main` push run 42192379976, job `Test Core (4/8)` (127808107135), a + * contended shard: 5034, `Test timed out in 5000ms.` A synchronous body + * runs to its end before vitest judges it, so 5034 is the whole run. + * Other `Test Core` jobs of the same three days: 429 to 3065. + * - Local, 4 vCPU, this file alone: 757 to 830 before the cut, BEFORE_IDLE + * after it. Pinned to one CPU shared with two busy loops: 2542 to 3063 + * before, AFTER_CONTENDED after. + * + * The rule follows `packages/cli/test/hook-timeout-override-refusal.test.ts`: + * 3x the slowest reading, rounded up to the next second. 3 x 5034 = 15102, so + * the budget is 16000. If the sweep's inputs or schemas grow, re-measure and + * re-size. + */ +const VALIDATE_SWEEP_BUDGET_MS = 16_000; + describe('expression refusal codes — the closed set', () => { it('has a pin for every code, and no pin for a code outside the set', () => { expect(Object.keys(PINS).sort()).toEqual([...EXPRESSION_REFUSAL_CODES].sort()); @@ -869,6 +903,7 @@ describe('expression refusal codes — the closed set', () => { it('every refusal validateExpression reports on the sweep carries a code from its set, with params the message interpolates', () => { const provoked = new Set(); + const judged = new Set(); let refusals = 0; for (const role of ['predicate', 'value', 'template'] as const) { for (const input of SWEEP_INPUTS) { @@ -876,6 +911,13 @@ describe('expression refusal codes — the closed set', () => { const r = validateExpression(role, input, schema); for (const said of [...r.errors, ...r.warnings]) { refusals++; + // The sweep's 3,865 refusals are 199 distinct ones, and every + // assertion below reads only the refusal itself — so one that + // equals a refusal already judged gets that verdict again, and is + // judged once. + const key = refusalKey(said); + if (judged.has(key)) continue; + judged.add(key); expect(VALIDATE_CODES.has(said.code), `${said.code} from ${JSON.stringify(input)}`).toBe(true); expect(typeof said.params).toBe('object'); expect(said.params).not.toBeNull(); @@ -890,7 +932,7 @@ describe('expression refusal codes — the closed set', () => { // producer owns, so a code whose arm stopped being reachable shows up too. expect(refusals).toBeGreaterThan(100); expect([...provoked].sort()).toEqual([...VALIDATE_CODES].sort()); - }); + }, VALIDATE_SWEEP_BUDGET_MS); it('every refusal collectCelRootIdentifiers reports on the sweep carries a code from its set', () => { const provoked = new Set(); From 7a6ff9240dc2d929701343e900fd13d5531ab5b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 10:46:00 +0000 Subject: [PATCH 2/4] test(formula): record the after-cut readings in the sweep budget's comment Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_017ihL2ebbZkr2QAEG1x7UC8 --- packages/formula/src/expression-refusal-codes.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/formula/src/expression-refusal-codes.test.ts b/packages/formula/src/expression-refusal-codes.test.ts index 51ee697b1e9..36def2551f9 100644 --- a/packages/formula/src/expression-refusal-codes.test.ts +++ b/packages/formula/src/expression-refusal-codes.test.ts @@ -878,9 +878,9 @@ function refusalKey(said: ExprValidationError): string { * contended shard: 5034, `Test timed out in 5000ms.` A synchronous body * runs to its end before vitest judges it, so 5034 is the whole run. * Other `Test Core` jobs of the same three days: 429 to 3065. - * - Local, 4 vCPU, this file alone: 757 to 830 before the cut, BEFORE_IDLE + * - Local, 4 vCPU, this file alone: 757 to 830 before the cut, 534 to 645 * after it. Pinned to one CPU shared with two busy loops: 2542 to 3063 - * before, AFTER_CONTENDED after. + * before, 1961 to 2137 after. * * The rule follows `packages/cli/test/hook-timeout-override-refusal.test.ts`: * 3x the slowest reading, rounded up to the next second. 3 x 5034 = 15102, so From 649a0ab7df90d6e2edafbca3e32bbba30f7ed37f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 11:37:46 +0000 Subject: [PATCH 3/4] test(formula): name the sample behind the sweep budget's readings The two counts in the validateExpression sweep's comments now say where they were read: the 3,865 / 199 refusal count at 98f640d581, and the 429-3065 ms band as seven sampled Test Core jobs. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_017ihL2ebbZkr2QAEG1x7UC8 --- packages/formula/src/expression-refusal-codes.test.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/formula/src/expression-refusal-codes.test.ts b/packages/formula/src/expression-refusal-codes.test.ts index 36def2551f9..c4c8a92afd7 100644 --- a/packages/formula/src/expression-refusal-codes.test.ts +++ b/packages/formula/src/expression-refusal-codes.test.ts @@ -877,7 +877,8 @@ function refusalKey(said: ExprValidationError): string { * - CI, `main` push run 42192379976, job `Test Core (4/8)` (127808107135), a * contended shard: 5034, `Test timed out in 5000ms.` A synchronous body * runs to its end before vitest judges it, so 5034 is the whole run. - * Other `Test Core` jobs of the same three days: 429 to 3065. + * Seven other `Test Core` jobs sampled from the same three days: 429 to + * 3065. * - Local, 4 vCPU, this file alone: 757 to 830 before the cut, 534 to 645 * after it. Pinned to one CPU shared with two busy loops: 2542 to 3063 * before, 1961 to 2137 after. @@ -911,10 +912,10 @@ describe('expression refusal codes — the closed set', () => { const r = validateExpression(role, input, schema); for (const said of [...r.errors, ...r.warnings]) { refusals++; - // The sweep's 3,865 refusals are 199 distinct ones, and every - // assertion below reads only the refusal itself — so one that - // equals a refusal already judged gets that verdict again, and is - // judged once. + // At 98f640d581 the sweep's 3,865 refusals are 199 distinct + // ones, and every assertion below reads only the refusal itself + // — so one that equals a refusal already judged gets that verdict + // again, and is judged once. const key = refusalKey(said); if (judged.has(key)) continue; judged.add(key); From 3f0ddde822903f6400d32ff754357c7e6c7595ee Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 11:43:23 +0000 Subject: [PATCH 4/4] test(formula): the budget comment's sample is six other jobs, not seven Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_017ihL2ebbZkr2QAEG1x7UC8 --- packages/formula/src/expression-refusal-codes.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/formula/src/expression-refusal-codes.test.ts b/packages/formula/src/expression-refusal-codes.test.ts index c4c8a92afd7..4449ec731ab 100644 --- a/packages/formula/src/expression-refusal-codes.test.ts +++ b/packages/formula/src/expression-refusal-codes.test.ts @@ -877,8 +877,8 @@ function refusalKey(said: ExprValidationError): string { * - CI, `main` push run 42192379976, job `Test Core (4/8)` (127808107135), a * contended shard: 5034, `Test timed out in 5000ms.` A synchronous body * runs to its end before vitest judges it, so 5034 is the whole run. - * Seven other `Test Core` jobs sampled from the same three days: 429 to - * 3065. + * The six other `Test Core` jobs sampled from the same three days: 429 + * to 3065. * - Local, 4 vCPU, this file alone: 757 to 830 before the cut, 534 to 645 * after it. Pinned to one CPU shared with two busy loops: 2542 to 3063 * before, 1961 to 2137 after.