Skip to content

fix: make solidity --snapshot-check read-only - #8391

Merged
schaable merged 7 commits into
mainfrom
fix/read-only-snapshot-check
Jun 23, 2026
Merged

schaable merged 7 commits into
mainfrom
fix/read-only-snapshot-check

Conversation

@schaable

@schaable schaable commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

--snapshot-check no longer writes or deletes snapshot files. It exits with an error only when a tracked gas value differs; snapshots added or missing relative to the baseline are reported for information only; a missing baseline is reported with a hint to run --snapshot. Output reworded to read-only language. Tests updated, with a regression test covering the scoped-run-deletes-group-files scenario from the issue.

Closes #8358.

Docs updated NomicFoundation/hardhat-website#278.

Screenshots

Added/removed snapshots

image

No baseline (fn snapshots)

image

No baseline (both)

image

Combined (failed + added + no baseline)

image

@schaable
schaable requested a review from Copilot June 13, 2026 20:31
@schaable schaable self-assigned this Jun 13, 2026
@changeset-bot

changeset-bot Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a52bd4c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Hardhat’s Solidity gas snapshot checking so hardhat test solidity --snapshot-check becomes strictly read-only: it no longer bootstraps, rewrites, or deletes snapshot baseline files on disk, and instead only reports differences (failing only on changed tracked values) with improved “read-only” wording.

Changes:

  • Make --snapshot-check stop writing/updating .gas-snapshot and snapshots/*.json (including avoiding deletions on scoped runs).
  • Replace “written” semantics with an explicit noBaseline signal and update log output to match the new behavior.
  • Update and extend tests, including a regression test for the “scoped run deletes group files” scenario from #8358.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/hardhat/src/internal/builtin-plugins/gas-analytics/function-gas-snapshots.ts Removes baseline writes during snapshot-check; introduces noBaseline and updates logging for added/removed output wording.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts Removes baseline writes/deletions during snapshot-check; introduces noBaseline and adjusts log messaging for read-only behavior.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts Updates snapshot-check result logging conditions to use noBaseline instead of “written”.
packages/hardhat/test/internal/builtin-plugins/gas-analytics/tasks/solidity-test/task-action.ts Updates assertions to validate read-only behavior and adds regression coverage for scoped runs not deleting snapshot group files.
.changeset/quiet-melons-wave.md Adds a patch changeset documenting the read-only --snapshot-check behavior change.

@schaable
schaable requested a review from kanej June 13, 2026 20:57

@kanej kanej left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have gone through the changes and I have no feedback at the code level.

I left a few comments, but one change I think we should make:

  • if filtering or a named file has been passed, we shouldn't show the added/removed sections

Copilot AI review requested due to automatic review settings June 22, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread .changeset/quiet-melons-wave.md Resolved
@schaable

Copy link
Copy Markdown
Member Author

@kanej I've addressed all of the requested changes. Can you take another look?

@schaable
schaable added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit d24c71e Jun 23, 2026
178 checks passed
@schaable
schaable deleted the fix/read-only-snapshot-check branch June 23, 2026 13:33
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hardhat test solidity --snapshot-check mutates the snapshot baseline on disk

3 participants