Skip to content

Commit 616794c

Browse files
committed
test(plugin-sharing): size the three scrypt cases near vitest's 5000 ms default to their measured work
The share-link password cases derive scrypt keys at the production parameters on purpose, so their wall time scales with the shard that runs them. Three of them read over half of the 5000 ms default on Test Core: the NFKC case (timed out at 5030 and 5039 ms), the cross-verify case (4136 ms) and the no-log case (3805 ms). Each now carries an explicit budget of 3x its slowest reading, rounded up to the next second. The other 49 scrypt-reaching cases in the package keep the default. No parameter, production file or vitest config changes. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYYhVJ78u7PhwFViWo1EmQ
1 parent ca135dc commit 616794c

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎packages/plugins/plugin-sharing/src/share-link-password-webcontainer.test.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ vi.mock('node:crypto', async (importOriginal) => {
2727
const PASSWORD = 'Ünïcödé pass 21839';
2828
const nodeScrypt = vi.mocked(nodeCrypto.scrypt);
2929

30+
/**
31+
* [#22418] Explicit budgets, sized to the measured work. Every case here
32+
* derives scrypt keys at the production parameters (N=16384, r=16) on purpose,
33+
* the pure-JS path at several times the native cost, so a case's wall time is
34+
* its derivation count times what one derivation costs on the shard that runs
35+
* it. vitest's 5000 ms default is a number nobody chose for that work.
36+
*
37+
* The rule: a case whose slowest `Test Core` reading is over half the default
38+
* gets 3x that reading, rounded up to the next second. 3x clears the largest
39+
* spread one case showed between two CI runs (1.88x) with room for a heavier
40+
* shard. The two cases with one derivation per path (slowest reading 1435 ms)
41+
* keep the default, which already leaves them 3.4x. When a case's derivation
42+
* count changes, re-size it from a fresh reading, never by lowering the
43+
* parameters.
44+
*/
45+
/** 3 pure-JS + 3 native derivations; CI readings 4136 and 3688 ms. */
46+
const CROSS_VERIFY_BUDGET_MS = 13_000;
47+
/**
48+
* 4 pure-JS + 4 native; CI timed out at 5030 and 5039 ms, so the reading is
49+
* projected: 4/3 of the 3 + 3 case's 4136 ms in the same run, 5515 ms.
50+
*/
51+
const NFKC_BUDGET_MS = 17_000;
52+
3053
function onWebContainer(on: boolean) {
3154
vi.stubEnv('STACKBLITZ', on ? '1' : '');
3255
vi.stubEnv('SHELL', on ? '/bin/jsh' : '/bin/bash');
@@ -67,7 +90,7 @@ describe('[#21839] share-link password: node:crypto and pure-JS scrypt are inter
6790
expect(await verifyShareLinkPassword(PASSWORD, nativeHash)).toBe(true);
6891
expect(await verifyShareLinkPassword('wrong 21839', nativeHash)).toBe(false);
6992
expect(nodeScrypt).not.toHaveBeenCalled();
70-
});
93+
}, CROSS_VERIFY_BUDGET_MS);
7194

7295
it('a password whose NFKC form differs from its input is one password on both paths', async () => {
7396
// A decomposed e + combining acute, and a fullwidth A: NFKC rewrites both.
@@ -93,7 +116,7 @@ describe('[#21839] share-link password: node:crypto and pure-JS scrypt are inter
93116
expect(await verifyShareLinkPassword(normalised, nativeHash)).toBe(true);
94117
expect(await verifyShareLinkPassword('cafe A 21839', nativeHash)).toBe(false);
95118
expect(nodeScrypt).not.toHaveBeenCalled();
96-
});
119+
}, NFKC_BUDGET_MS);
97120

98121
it('the pure-JS key is byte-identical to node:crypto for the same password and salt', async () => {
99122
onWebContainer(true);

‎packages/plugins/plugin-sharing/src/share-link-password.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ describe('[#21839] how the password travels in', () => {
471471
expect(loggedText(logger)).not.toContain(wrong);
472472
});
473473

474+
// [#22418] An explicit budget, sized to the measured work: one mint and eight
475+
// redemptions are nine native scrypt derivations at the production
476+
// parameters, the most of any case in this file. Its slowest `Test Core`
477+
// reading was 3805 ms, over half of vitest's 5000 ms default, so it gets 3x
478+
// that, rounded up to the next second; the rule and why 3x is in
479+
// share-link-password-webcontainer.test.ts. Every other case here read at
480+
// most 2163 ms and keeps the default.
474481
it('no log line carries the presented password, on any outcome', async () => {
475482
const { http, link, logger } = await protectedConversation();
476483
for (const pw of [PASSWORD, 'wrong one 21839']) {
@@ -481,7 +488,7 @@ describe('[#21839] how the password travels in', () => {
481488
}
482489
expect(loggedText(logger)).not.toContain(PASSWORD);
483490
expect(loggedText(logger)).not.toContain('wrong one 21839');
484-
});
491+
}, 12_000);
485492
});
486493

487494
describe('[#22049] the password header declares its encoding', () => {

0 commit comments

Comments
 (0)