Skip to content

feat(cli): auto-recompiling when aztec test is run#20729

Merged
nventuro merged 15 commits into
merge-train/fairiesfrom
02-20-feat_cli_auto-recompiling_when_aztec_test_is_run
Mar 6, 2026
Merged

feat(cli): auto-recompiling when aztec test is run#20729
nventuro merged 15 commits into
merge-train/fairiesfrom
02-20-feat_cli_auto-recompiling_when_aztec_test_is_run

Conversation

@benesjan

@benesjan benesjan commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

In this PR I ensure that contracts get automatically recompiled when aztec test is run. To avoid unnecessary compilations I use make command inspired approach of checking timestamp of source files (*.toml and *.nr files) against the timestamp of the oldest artifact in the /target dir (as artifact I consider any *.json file).

Note: By using the oldest timestamp we would get constant recompilation on each run in case the dev placed there some random *.json file.

Question: Does the reviewer think this ^ is fine? Alternatively I could nuke the target dir whenever a recompilation is being run. This feels a bit dangerous though. Another approach would be to predict the artifact name of individual crates and just check against those. This would be the most efficient but it introduces complexity and brittleness in case nargo artifact names change. I think I would keep it as it is for now and come up with solution if someone complains about constant recompilations.

I initially thought I will implement this in the aztec test command but that command is fully implemented in bash. When I had AI implement this the resulting bash was impossible to comprehend so I told it to rewrite in typescript. Given that the aztec test command is calling aztec compile that is implemented in typescript it made sense for this PR to modify only that command. This has the added advantage that it will make bugs in this code way more visible because when a dev runs aztec compile they will either see that the code is getting re-compiled or they will get "No source changes detected, skipping compilation." log. If they modify a contract, run aztec compile and see that nothing got compiled it will be obvious that the thing is broken.

Closes https://linear.app/aztec-labs/issue/F-197/auto-recompile-contracts-on-tests

benesjan commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch from 4fe024b to 0ce0067 Compare February 21, 2026 10:26
@benesjan benesjan force-pushed the 02-20-feat_cli_asserting_that_contract_crates_have_no_tests branch from c23a37d to 05bbbf0 Compare February 21, 2026 10:40
@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch 2 times, most recently from 7a2fec1 to 96b2f70 Compare February 23, 2026 06:58
@benesjan benesjan force-pushed the 02-20-feat_cli_asserting_that_contract_crates_have_no_tests branch 2 times, most recently from f9b122d to fc7e946 Compare February 23, 2026 15:11
@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch 3 times, most recently from 277bf39 to 54a6fc1 Compare February 23, 2026 16:25
@benesjan benesjan force-pushed the 02-20-feat_cli_asserting_that_contract_crates_have_no_tests branch from d3a3170 to 11d8d00 Compare February 23, 2026 16:25
@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch from 54a6fc1 to b16a65d Compare February 24, 2026 04:19
Base automatically changed from 02-20-feat_cli_asserting_that_contract_crates_have_no_tests to merge-train/fairies February 24, 2026 04:32
@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch 4 times, most recently from 59a1df5 to a12d173 Compare February 26, 2026 10:28
@benesjan benesjan force-pushed the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch from ee08542 to c70a2ba Compare February 26, 2026 15:57
@benesjan benesjan marked this pull request as ready for review February 26, 2026 16:08
@benesjan benesjan requested a review from nventuro February 26, 2026 16:56
@nventuro

nventuro commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Note: By using the oldest timestamp we would get constant recompilation on each run in case the dev placed there some random *.json file.

Question: Does the reviewer think this ^ is fine? Alternatively I could nuke the target dir whenever a recompilation is being run. This feels a bit dangerous though. Another approach would be to predict the artifact name of individual crates and just check against those. This would be the most efficient but it introduces complexity and brittleness in case nargo artifact names change. I think I would keep it as it is for now and come up with solution if someone complains about constant recompilations.

I agree with your reasoning 100%. The target dir should not be used by users.

I initially thought I will implement this in the aztec test command but that command is fully implemented in bash. When I had AI implement this the resulting bash was impossible to comprehend so I told it to rewrite in typescript.

I believe part of the reason to implement it in bash was to skip loading all of the TS. Did you not notice a huge slowdown due to the importing of ts modules etc?

I do agree with bash being a terrible way to do things, but because the CLI is currently huge this is a problem today. The real solution would be to split the CLI (or to split commands) so that compile test etc are all lightweight.

@benesjan

benesjan commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

Did you not notice a huge slowdown due to the importing of ts modules etc?

@nventuro I just did measurements on the default workspace tests and the version with the check is like 0.3s slower than version without it. Given that to run it all takes like 5s this doesn't seem to be a problem.

Comment thread yarn-project/aztec/scripts/aztec.sh
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.test.ts
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.ts Outdated
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.test.ts Outdated
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.ts Outdated
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.ts Outdated
Comment thread yarn-project/aztec/src/cli/cmds/utils/needs_recompile.ts Outdated
@benesjan benesjan marked this pull request as draft March 5, 2026 06:18
@benesjan benesjan marked this pull request as ready for review March 5, 2026 08:23
@benesjan benesjan requested a review from nventuro March 5, 2026 09:01

@nventuro nventuro 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.

Lovely.

WE HAVE AUTORECOMPILE ON TEST YAY

@nventuro nventuro merged commit 409d7f7 into merge-train/fairies Mar 6, 2026
16 checks passed
@nventuro nventuro deleted the 02-20-feat_cli_auto-recompiling_when_aztec_test_is_run branch March 6, 2026 23:38
github-merge-queue Bot pushed a commit that referenced this pull request Mar 9, 2026
BEGIN_COMMIT_OVERRIDE
feat: add note hash and nullifier helper functions with domain
separation (#21189)
feat(cli): auto-recompiling when aztec test is run (#20729)
docs: small delayedpubmut update (#21229)
test: restore pubmut tests (#21228)
END_COMMIT_OVERRIDE
benesjan added a commit that referenced this pull request Apr 16, 2026
In this PR I ensure that contracts get automatically recompiled when
`aztec test` is run. To avoid unnecessary compilations I use `make`
command inspired approach of checking timestamp of source files (*.toml
and *.nr files) against the timestamp of the oldest artifact in the
`/target` dir (as artifact I consider any `*.json` file).

**Note:** By using the oldest timestamp we would get constant
recompilation on each run in case the dev placed there some random
`*.json` file.

**Question**: Does the reviewer think this ^ is fine? Alternatively I
could nuke the `target` dir whenever a recompilation is being run. This
feels a bit dangerous though. Another approach would be to predict the
artifact name of individual crates and just check against those. This
would be the most efficient but it introduces complexity and brittleness
in case `nargo` artifact names change. I think I would keep it as it is
for now and come up with solution if someone complains about constant
recompilations.

I initially thought I will implement this in the `aztec test` command
but that command is fully implemented in bash. When I had AI implement
this the resulting bash was impossible to comprehend so I told it to
rewrite in typescript. Given that the `aztec test` command is calling
`aztec compile` that is implemented in typescript it made sense for this
PR to modify only that command. This has the added advantage that it
will make bugs in this code way more visible because when a dev runs
`aztec compile` they will either see that the code is getting
re-compiled or they will get "No source changes detected, skipping
compilation." log. If they modify a contract, run `aztec compile` and
see that nothing got compiled it will be obvious that the thing is
broken.

Closes
https://linear.app/aztec-labs/issue/F-197/auto-recompile-contracts-on-tests

---------

Co-authored-by: benesjan <benesjan@users.noreply.github.com>
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
benesjan added a commit that referenced this pull request Apr 16, 2026
## Summary

Backports 6 PRs with aztec CLI improvements from `next` to `v4-next`:

- #20681 - refactor: aztec new and init creating 2 crates
- #20711 - test: aztec new scaffold works
- #20723 - feat(cli): warning if contract crate has tests
- #20729 - feat(cli): auto-recompiling when aztec test is run
- #21007 - feat: aztec new supporting multiple contract crates
- #21245 - feat: asserts that aztec dep version matches cli
@benesjan

Copy link
Copy Markdown
Contributor Author

Backported to v4-next in #22587

Thunkar added a commit that referenced this pull request Apr 17, 2026
BEGIN_COMMIT_OVERRIDE
fix(pxe): cap event filter toBlock to last synced block (#22573)
fix(pxe): round tx expiration timestamp to reduce precision (#22577)
fix: eliminate anvil watcher warp race and false success logs (#22584)
refactor: aztec new and init creating 2 crates (#20681)
test: aztec new scaffold works (#20711)
feat(cli): warning if contract crate has tests (#20723)
feat(cli): auto-recompiling when aztec test is run (#20729)
feat: aztec new supporting multiple contract crates (#21007)
feat: asserts that aztec dep version matches cli (#21245)
chore: backport aztec CLI improvements to v4-next (#22587)
feat: check noir release has nargo binaries before releasing (#22551)
chore: cache chainInfo in embeddedwallet (#22592)
fix: wrap external getCapsule in transactionAsync (#22595)
fix(pxe): throw clear error for invalid comparator in pick_notes
(#22585)
refactor(aztec-nr): rename conversion fns to encode_/decode_ naming
(#22576)
feat: infrastructure for testing `[new_contract_artfiacts,
old_aztec_stack]` (#22593)
chore: fix unnecessary and inconsistent side-effect counter increments
(#22245)
fix: update FaceID wallet redirects and strip anchors in redirect
validation (#22505)
docs: add getting started on testnet guide (#22366)
docs: add getting started on testnet guide (backport #22366) (#22619)
feat(aztec-nr): new BoundedVec emit private log APIs (#22064)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants