From 3f1793e0c080bcee547afce53c4286429baf7eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sol=C3=A1r?= Date: Sat, 29 Aug 2026 19:16:42 +0200 Subject: [PATCH] test: prove pLimit limits page concurrency Mutation testing showed `active < concurrency` could be replaced by `true` with every test still passing. Nothing anywhere proved that page processing is actually limited; the existing concurrency tests only check that a run finishes and that invalid values throw. The new test counts callbacks in flight and asserts the peak equals the configured concurrency. With the mutant applied all nine pages start at once and the peak is 9, so the test fails. Every mutant in the pLimit block is now killed, timed out or errors out. None survive. The score goes from 61.13 to 63.77, and core.ts from 60.85 to 64.55. `thresholds.break` moves from null to 60 so the score cannot regress below the baseline that main now has. Co-Authored-By: Claude Opus 5 --- stryker.config.mjs | 3 ++- test/parsePdf.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/stryker.config.mjs b/stryker.config.mjs index fe14adc..4077997 100644 --- a/stryker.config.mjs +++ b/stryker.config.mjs @@ -52,5 +52,6 @@ export default { reporters: ['html', 'clear-text', 'progress', 'json'], htmlReporter: { fileName: 'reports/mutation/index.html' }, jsonReporter: { fileName: 'reports/mutation/mutation.json' }, - thresholds: { break: null, high: 80, low: 60 }, + // `break` fails the run below this score. Raise it as mutants get killed. + thresholds: { break: 60, high: 80, low: 60 }, }; diff --git a/test/parsePdf.test.ts b/test/parsePdf.test.ts index 702ff6d..b942e0e 100644 --- a/test/parsePdf.test.ts +++ b/test/parsePdf.test.ts @@ -2,6 +2,7 @@ import assert from 'node:assert'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { describe, it } from 'node:test'; +import { setTimeout as delay } from 'node:timers/promises'; import { parsePdf } from '#afpp/src/index.js'; @@ -126,4 +127,30 @@ describe('parsePdf', () => { assert.equal(data.length, 9); }); }); + + describe('concurrency limit', () => { + it('should run at most `concurrency` pages at the same time', async () => { + const input = path.join('test', 'example.pdf'); + const concurrency = 2; + let active = 0; + let peak = 0; + + const data = await parsePdf(input, { concurrency }, async (content) => { + active++; + peak = Math.max(peak, active); + // Hold the slot so that pages processed at the same time overlap here. + await delay(50); + active--; + return content; + }); + + assert.equal(data.length, 9); + // Without the limit all nine pages start at once and the peak is 9. + assert.equal( + peak, + concurrency, + `expected at most ${concurrency} pages at a time, saw ${peak}`, + ); + }); + }); });