-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: forge test
deletes any existing snapshots
directory by design
#9477
Comments
@smartcontracts that dir is cleaned up to make sure gas snapshots are properly recorded for tests, @zerosnacks maybe we could pattern match and remove only the foundry gas snapshot files? Or should be reserved dir and should be reconfigured as above? |
Thanks for flagging this, for context this is the relevant code section: foundry/crates/forge/bin/cmd/test/mod.rs Lines 309 to 318 in 3a1e76b
This is an edge case that wasn't considered, I'll have a look at how best to handle this: Some possible approaches:
In the base case the snapshots directory should not be cleaned out if the developer does not use Foundry's gas snapshot cheatcodes. The configured For context: https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts-bedrock/snapshots For now the workaround you are using should work and continue to work but it is clearly less than ideal. |
forge test
deletes any existing snapshots
directoryforge test
deletes any existing snapshots
directory by design
Additional issue highlighted in #9511 is that when the user runs a partial test |
@zerosnacks as i understand, currently:
If that's the case I think:
is the only option, given it's impossible to understand which snapshot is written by which test. That said, i'm wondering if it would have made more sense to uniquify snapshots per test contract. |
Hi @sakulstra
You raise an interesting point, if we were to enforce a function name pattern we could selectively remove files using the same match case. I'm a bit hesitant to introduce breaking changes here given its steady adoption. Realistically the least breaking change would be to: remove the functionality of clearing out the directory upon I'll draft a PR and make sure this removal doesn't cause any regressions. |
I see the motivation, but idk if it's the best tradeoff. Thematic composition, one can still do in some post-processing, but fixing the dx is impossible in userland atm.
Imho breaking changes - especially when with a clear reason, and migration path - are perfectly fine even now. Perhaps makes sense to reconsider changing after v1 though, when ppl can fix a proper version and delay the upgrade to when they have time to care about the migration 😅 |
I know is kinda ot in this issue, but fits on the overall topic 😅 |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (e5dbb7a 2024-12-03T00:25:01.006590000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
Running
forge test
in our repository seems to delete any existing "snapshots" folder if it already exists. We use a folder called "snapshots" to contain all of our snapshots, so this folder isn't exclusive to forge things. I've gotten around this for now by changing ourfoundry.toml
to set the configuredsnapshots
folder to a fake directory.From a quick glance it looks like this is the source of the issue:
foundry/crates/config/src/lib.rs
Lines 1042 to 1046 in 805d7ce
I haven't checked what this is actually being used for but if I have some time later I might take a stab at a fix.
The text was updated successfully, but these errors were encountered: