From 08dc1dfae9b21c5f770ef4e414f907906ee2eab8 Mon Sep 17 00:00:00 2001 From: Lakshya77089 Date: Sat, 27 Jun 2026 12:42:09 +0530 Subject: [PATCH] fix(benchmarks): match CRLF code fences in loc.js The fenced-block regex had no \r? before \n, so CRLF output ( ```js\r\n ) matched no block and the metric fell back to counting the whole response, prose and fences included. correctness.js already handles \r?\n; align loc.js with it and add a CRLF regression case. Fixes #339 --- benchmarks/loc.js | 4 +++- benchmarks/loc.test.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/benchmarks/loc.js b/benchmarks/loc.js index 93e13dd9..e08d0262 100644 --- a/benchmarks/loc.js +++ b/benchmarks/loc.js @@ -3,7 +3,9 @@ // Recorded as the `code_loc` metric per arm (always passes; it is a measurement, not a gate). module.exports = (output) => { const text = String(output || ''); - const blocks = [...text.matchAll(/```[a-zA-Z0-9_+-]*\n([\s\S]*?)```/g)].map((m) => m[1]); + // \r? so CRLF fences match too; without it, CRLF output finds no block and + // the whole response (prose included) gets counted. Mirrors correctness.js. + const blocks = [...text.matchAll(/```[a-zA-Z0-9_+-]*\r?\n([\s\S]*?)```/g)].map((m) => m[1]); // Drop /* ... */ block comments before counting; the line filter below only // caught `*`-aligned JSDoc, so plain block comments were miscounted as code. const code = (blocks.length ? blocks.join('\n') : text).replace(/\/\*[\s\S]*?\*\//g, ''); diff --git a/benchmarks/loc.test.js b/benchmarks/loc.test.js index de302814..c19725e0 100644 --- a/benchmarks/loc.test.js +++ b/benchmarks/loc.test.js @@ -13,6 +13,8 @@ const cases = [ ['inline block comment keeps its code line', score('```js\nconst x = 1; /* note */\nconst y = 2;\n```'), 2], ['line comments still stripped', score('```js\n// header\nconst x = 1;\n```'), 1], ['plain code unchanged', score('```js\nconst a = 1;\nconst b = 2;\n```'), 2], + // CRLF-fenced output must still find the block, not fall back to the whole text. + ['crlf fences count only the code', score('Here:\r\n```js\r\nconst a = 1;\r\nconst b = 2;\r\n```\r\nDone.'), 2], ]; for (const [name, got, want] of cases) { assert.strictEqual(got, want, `FAILED: ${name} (got ${got}, want ${want})`);