test: give the 10k-iteration sort-key property test its own timeout
All checks were successful
CI / Lint, typecheck, test (pull_request) Successful in 6m45s
CI / Build container images (pull_request) Successful in 2m51s
CI / Auth e2e pack (pull_request) Successful in 8m54s
CI / Import/export fidelity gate (pull_request) Successful in 58s
CD / Build and push images (push) Successful in 15s
CD / Deploy to Test (push) Successful in 16s
CD / Smoke tests against Test (push) Successful in 1m17s
CD / Promote to Int (push) Successful in 13s
CI / Lint, typecheck, test (push) Successful in 6m52s
CI / Build container images (push) Has been skipped
CI / Auth e2e pack (push) Successful in 8m43s
Release / Build release images and notes (push) Successful in 2m48s
CI / Import/export fidelity gate (push) Successful in 56s
Release / Release-candidate operations QA (push) Successful in 56s
Prod deploy / Deploy the released images to Prod (push) Successful in 17s

Under parallel CI load the test repeatedly exceeded the default 5000 ms
per-test timeout (run 685 on main, run 699 on an unrelated PR); the
identical test passed on rerun. Locally it finishes in about 1.3 s, so
30 s is generous headroom, not a mask for a regression.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017aviRTgWCcAHUh1SBoxf6P
This commit is contained in:
Claude Fable 5 2026-08-02 14:01:14 +02:00
parent a327126fac
commit 78258c4f9b

View File

@ -26,48 +26,56 @@ describe('sort-key helpers (issue #45)', () => {
* pattern repeatedly drop the last page between the first two must never
* collide and never overflow the key length, because the caller rebalances
* when {@link nextKeyOrRebalance} returns null.
*
* Under parallel CI load the 10.000 iterations have repeatedly exceeded the
* default 5 s per-test timeout (runs 685, 699 same code passed on rerun),
* so this test carries its own budget.
*/
it('10.000 adversarial reorders never collide or overflow (rebalance verified)', () => {
// Start with five pages in a fixed order.
let order = evenlySpacedKeys(5).map((key, i) => ({ id: `p${i}`, key }));
let rebalances = 0;
it(
'10.000 adversarial reorders never collide or overflow (rebalance verified)',
{ timeout: 30_000 },
() => {
// Start with five pages in a fixed order.
let order = evenlySpacedKeys(5).map((key, i) => ({ id: `p${i}`, key }));
let rebalances = 0;
const rebalance = (): void => {
const keys = evenlySpacedKeys(order.length);
order = order.map((page, i) => ({ ...page, key: keys[i]! }));
rebalances += 1;
};
const rebalance = (): void => {
const keys = evenlySpacedKeys(order.length);
order = order.map((page, i) => ({ ...page, key: keys[i]! }));
rebalances += 1;
};
for (let i = 0; i < 10_000; i += 1) {
// Move the last page to sit between the first and second — the tightest
// possible gap, which is what grows key length fastest.
const moved = order[order.length - 1]!;
const rest = order.slice(0, -1);
const afterKey = rest[0]!.key;
const beforeKey = rest[1]!.key;
for (let i = 0; i < 10_000; i += 1) {
// Move the last page to sit between the first and second — the tightest
// possible gap, which is what grows key length fastest.
const moved = order[order.length - 1]!;
const rest = order.slice(0, -1);
const afterKey = rest[0]!.key;
const beforeKey = rest[1]!.key;
const key = nextKeyOrRebalance(afterKey, beforeKey);
if (key === null) {
// Rebalance keeps the CURRENT order, then retry the move once.
rebalance();
const k2 = nextKeyOrRebalance(order[0]!.key, order[1]!.key);
expect(k2).not.toBeNull();
order = [order[0]!, { ...moved, key: k2! }, ...order.slice(1)];
} else {
order = [rest[0]!, { ...moved, key }, ...rest.slice(1)];
const key = nextKeyOrRebalance(afterKey, beforeKey);
if (key === null) {
// Rebalance keeps the CURRENT order, then retry the move once.
rebalance();
const k2 = nextKeyOrRebalance(order[0]!.key, order[1]!.key);
expect(k2).not.toBeNull();
order = [order[0]!, { ...moved, key: k2! }, ...order.slice(1)];
} else {
order = [rest[0]!, { ...moved, key }, ...rest.slice(1)];
}
// Invariants after every move: keys unique, bounded, and consistent with
// the intended array order.
const keys = order.map((p) => p.key);
expect(new Set(keys).size).toBe(keys.length);
expect(Math.max(...keys.map((k) => k.length))).toBeLessThanOrEqual(MAX_SORT_KEY_LENGTH);
for (let j = 1; j < keys.length; j += 1) {
expect(keys[j - 1]! < keys[j]!).toBe(true);
}
}
// Invariants after every move: keys unique, bounded, and consistent with
// the intended array order.
const keys = order.map((p) => p.key);
expect(new Set(keys).size).toBe(keys.length);
expect(Math.max(...keys.map((k) => k.length))).toBeLessThanOrEqual(MAX_SORT_KEY_LENGTH);
for (let j = 1; j < keys.length; j += 1) {
expect(keys[j - 1]! < keys[j]!).toBe(true);
}
}
// The adversarial pattern must have forced at least one rebalance.
expect(rebalances).toBeGreaterThan(0);
});
// The adversarial pattern must have forced at least one rebalance.
expect(rebalances).toBeGreaterThan(0);
},
);
});