Skip to content

Commit 20fd139

Browse files
kckernclaude
andcommitted
test(web): count parser calls under the piece budget instead of timing them
The 10,000-piece split took 1.26 s on CI against a 1 s bound. The budget was working: each junk piece costs ~3.6 ms to parse and only the first 100 are parsed. Assert that, and keep a loose time bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3bbc354 commit 20fd139

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎apps/web/test/unit/scriptureLookup.test.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,19 @@ describe('lookup: the request budget', async () => {
147147

148148
describe('splitBlocks: cost of a long junk reference', async () => {
149149
const { ReferenceService } = await import('../../src/services/ReferenceService.js');
150-
test('10,000 pieces with the default budget of 100 split in well under a second', () => {
151-
const svc = new ScriptureLookupService(new ReferenceService(null), null, null);
150+
test('10,000 pieces with the default budget of 100 parse only the first 100', () => {
151+
const referenceService = new ReferenceService(null);
152+
const parse = referenceService.parse.bind(referenceService);
153+
let calls = 0;
154+
referenceService.parse = text => { calls++; return parse(text); };
155+
const svc = new ScriptureLookupService(referenceService, null, null);
152156
const ref = Array.from({ length: 10000 }, () => 'x1').join(';');
153157
const t = performance.now();
154158
const blocks = svc.splitBlocks(ref, 100);
155-
expect(performance.now() - t).toBeLessThan(1000);
159+
// A junk piece can be parsed twice (alone, then with the previous book).
160+
expect(calls).toBeLessThanOrEqual(200);
161+
// About 0.4 s locally; the bound only catches a return to parsing every piece.
162+
expect(performance.now() - t).toBeLessThan(5000);
156163
expect(blocks).toHaveLength(10000);
157164
});
158165
});

0 commit comments

Comments
 (0)