Skip to content

Commit 8e3f08d

Browse files
committed
refactor(contracts): gate the coverage compile-skip on solidity-coverage's run flag
Trigger the test-phase noCompile on solidity-coverage's own __SOLIDITY_COVERAGE_RUNNING HRE flag instead of our COVERAGE env var. The flag is true only during an actual coverage run, so a stray COVERAGE=true in the environment can no longer make a plain hardhat test skip compilation and run stale artifacts; and if the internal flag ever changes the worst case is the redundant compile returning, a perf regression rather than a correctness bug. Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders>
1 parent 880d63f commit 8e3f08d

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/ats/contracts/tasks/compile.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ task(TASK_COMPILE, "🛠 Compile and regenerate the contract registry.", async
3030
* solidity-coverage compiles the instrumented sources itself (its own `env.run(TASK_COMPILE)`),
3131
* then runs `env.run(TASK_TEST)` — and Hardhat's TASK_TEST compiles AGAIN as a dependency. That
3232
* second pass is a full ~60s instrumented solc rebuild per coverage shard for no benefit: the
33-
* instrumented artifacts already exist from solidity-coverage's own compile. The coverage task
34-
* wrapper (hardhat.config.ts) sets `COVERAGE=true`, so when that is set we force `noCompile`,
35-
* leaving the instrumented build untouched and the measured coverage identical.
33+
* instrumented artifacts already exist from solidity-coverage's own compile. Force `noCompile` for
34+
* the test phase of a coverage run, leaving the instrumented build untouched and the measured
35+
* coverage identical.
36+
*
37+
* Gate on solidity-coverage's own `__SOLIDITY_COVERAGE_RUNNING` flag (set on the HRE for the
38+
* duration of `hardhat coverage`) rather than our `COVERAGE` env var: the flag is authoritative —
39+
* true only during a real coverage run, so a stray `COVERAGE=true` in the environment can't make a
40+
* plain `hardhat test` skip compilation and run stale artifacts — and if the internal flag ever
41+
* disappears the worst case is the redundant compile returning (a perf regression, not a
42+
* correctness bug).
3643
*/
37-
task(TASK_TEST).setAction(async (args, _hre, runSuper) => {
38-
if (process.env.COVERAGE === "true") {
44+
task(TASK_TEST).setAction(async (args, hre, runSuper) => {
45+
const coverageRunning = (hre as { __SOLIDITY_COVERAGE_RUNNING?: boolean }).__SOLIDITY_COVERAGE_RUNNING === true;
46+
if (coverageRunning) {
3947
return runSuper({ ...args, noCompile: true });
4048
}
4149
return runSuper(args);

0 commit comments

Comments
 (0)