From e9302928d0b8cad5b8a3f49b710764475bb1700d Mon Sep 17 00:00:00 2001 From: wellkilo Date: Sun, 13 Sep 2026 05:08:23 +0800 Subject: [PATCH] test(metrics): isolate snapshot read byte accounting Count only positional reads from the cost-log descriptor and use actual bytes returned, so the bounded-read assertions remain deterministic under full-suite concurrency. --- tests/hooks/ecc-metrics-bridge.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/hooks/ecc-metrics-bridge.test.js b/tests/hooks/ecc-metrics-bridge.test.js index c8dafe6dc..baa2cd21a 100644 --- a/tests/hooks/ecc-metrics-bridge.test.js +++ b/tests/hooks/ecc-metrics-bridge.test.js @@ -271,8 +271,11 @@ function runTests() { appendSessionCostRow(metricsDir, 'S1', snapshotRow); fs.readSync = function measuredRead(descriptor, buffer, offset, length, position) { - bytesReadFromCostLog += length; - return originalReadSync.call(this, descriptor, buffer, offset, length, position); + const bytesRead = originalReadSync.call( + this, descriptor, buffer, offset, length, position + ); + if (Number.isSafeInteger(position)) bytesReadFromCostLog += bytesRead; + return bytesRead; }; const result = readSessionCost('S1'); @@ -329,8 +332,11 @@ function runTests() { const originalReadSync = fs.readSync; let bytesReadFromCostLog = 0; fs.readSync = function measuredRead(descriptor, buffer, offset, length, position) { - bytesReadFromCostLog += length; - return originalReadSync.call(this, descriptor, buffer, offset, length, position); + const bytesRead = originalReadSync.call( + this, descriptor, buffer, offset, length, position + ); + if (Number.isSafeInteger(position)) bytesReadFromCostLog += bytesRead; + return bytesRead; }; try { assert.deepStrictEqual(readSessionCost('S1'), { totalCost: 1, totalIn: 100, totalOut: 50 });