fix(coverage): stream coverage data json to disk#8292
Conversation
For large --coverage runs, the serialized coverage data exceeds Node's JSON.stringify string-length ceiling and saveData throws RangeError: Invalid string length. Switching to writeJsonFileAsStream avoids the intermediate string. Fixes NomicFoundation#8071.
🦋 Changeset detectedLatest commit: b9cbaab The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Can you provide a reproduction of the bug with the latest version first? We already did some things related to this recently, so the bug may not be present. |
This would be equivalent to having 5M solidity statements in a single project |
|
@alcuadrado I've spun up a small script to replicate the issue across 3.1.6, 3.1.12, and latest versions: hh-8071-poc. POC concludes that #8213 already addressed both issues that resurface. |
|
Thanks a lot for the follow up investigation, @gultekinmakif! Appreciate it :) |
Summary
This PR addresses a bug:
Fix
Both
saveDataandloadDatanow usewriteJsonFileAsStream/readJsonFileAsStreaminstead of their non-streaming counterparts. The rationale comment mirrorsbuild-system.ts:1035.Tests
Introducing any regression tests would not make any sense, so I tested the behaviour change locally.
I ran a small Node script that builds a
Record<string, number>of 5,000,000 coverage-tag-shaped entries (~520 MB serialized, same order of magnitude as the failure on the linked issue).The script confirms that this PR is able to stream large files, while the main branch fails.
Changeset
patchonhardhat.Notes
writeJsonFilecall sites that might exhibit similar behavior on sufficiently large inputs:build-system.ts:1027gas-analytics-manager.ts:109gas-analytics-manager.ts:151snapshot-cheatcodes.ts:224