Skip to content

fix(install): preview hooks during dry runs - #11010

Merged
jdx merged 9 commits into
jdx:mainfrom
risu729:codex-20260716-015720-b44bfa
Jul 15, 2026
Merged

jdx merged 9 commits into
jdx:mainfrom
risu729:codex-20260716-015720-b44bfa

Conversation

@risu729

@risu729 risu729 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • prevent mise install --dry-run and mise bootstrap --dry-run from executing preinstall or postinstall hooks
  • route execution and preview through one hook pipeline using the existing dry_run flag so hook enablement, shell matching, root matching, and platform selection cannot drift
  • print selected shell and task invocations while preserving argv boundaries in paths and commands containing spaces
  • preserve normal postinstall behavior when every requested tool is already installed
  • cover missing-tool and already-installed paths for --dry-run and --dry-run-code, verifying hooks and tool installs have no side effects

Root cause

The no-missing-tools path in Install::install_missing_runtimes called the postinstall hook directly, bypassing the dry-run guard used by tool installation.

Validation

  • mise run lint-fix
  • mise run test:e2e e2e/cli/test_bootstrap e2e/cli/test_install_dry_run
  • cargo test --all-features hooks::tests::inline_command_display_preserves_argv_boundaries
  • cargo fmt --all -- --check
  • shellcheck -x e2e/cli/test_bootstrap e2e/cli/test_install_dry_run
  • shfmt -d e2e/cli/test_bootstrap e2e/cli/test_install_dry_run
  • git diff --check

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

Dry-run hook previews

Layer / File(s) Summary
Preview configured hook actions
src/hooks.rs
Adds preview_one_hook to filter configured hooks and print their actions without executing them.
Wire previews into installation flows
src/toolset/toolset_install.rs, src/cli/install.rs, e2e/cli/test_bootstrap
Dry-run installation and bootstrap paths preview preinstall and postinstall hooks; an end-to-end test verifies no marker file is created.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • jdx/mise#10615: Updates the no-op postinstall path to represent empty installed-tool context, alongside related dry-run preview behavior.

Suggested reviewers: jdx

Poem

I’m a rabbit with hooks to preview,
No pawprint left when dry runs ensue.
“Would run,” the brave shell sings,
While untouched stay marker things—
A carrot-bright install comes true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: previewing install hooks during dry runs.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes mise install --dry-run and mise bootstrap --dry-run incorrectly executing preinstall/postinstall hooks by routing both execution and preview through a single dry_run flag added to the hook pipeline, and patches the root-cause bug where the all-tools-already-installed fast path in install_missing_runtimes bypassed the dry-run guard entirely.

  • Adds dry_run: bool to run_one_hook, run_one_hook_with_context, and run_matched_hook; when true, calls the new preview_matched_hook which prints what would run (shell command, task invocation, or inline script) without any side effects.
  • Extracts HookAction::run_for_current_platform() to remove duplicated OS-detection logic shared between execute and the new preview path.
  • New e2e tests cover the bootstrap and all-tools-installed cases, verifying that hook-output files are never created during dry runs.

Confidence Score: 5/5

Safe to merge — the change only reroutes dry-run hook calls through a new read-only preview path and is well-covered by new e2e tests.

The bug fix is surgical: a single dry_run: bool parameter propagated consistently through the hook pipeline, with actual hook execution guarded correctly in all three call sites. The new preview_matched_hook is side-effect-free, and e2e tests directly verify hook scripts are never created during dry runs.

No files require special attention.

Important Files Changed

Filename Overview
src/hooks.rs Adds dry_run param to run_one_hook, run_one_hook_with_context, and run_matched_hook; routes dry-run through new preview_matched_hook which prints what would execute without side effects. Also extracts run_for_current_platform() to avoid duplicated OS-detection logic.
src/toolset/toolset_install.rs Plumbs opts.dry_run into both the preinstall and postinstall hook calls; dry-run branch now previews postinstall without building the full installed-tools list, and correctly skips the footer finish.
src/cli/install.rs Fixes root cause: adds a dry-run guard in the all-tools-already-installed fast path so postinstall hook preview (not execution) is used, and avoids full toolset resolution just for hook-selection context.
e2e/cli/test_bootstrap Extends bootstrap e2e tests with two new scenarios: postinstall preview when all tools already installed, and preinstall+postinstall preview when tools are missing; verifies hook files are never created.
e2e/cli/test_install_dry_run Adds hook-aware assertions to the install dry-run tests: verifies both hooks are previewed when tools are missing, and only postinstall is previewed when all tools are installed, without ever executing the hook scripts.

Reviews (9): Last reviewed commit: "fix(install): preserve hook preview argu..." | Re-trigger Greptile

@risu729 risu729 changed the title fix(install): skip postinstall hook during dry runs fix(bootstrap): prevent command execution during dry runs Jul 15, 2026

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
e2e/cli/test_bootstrap (1)

321-324: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert that the hook is discovered to ensure the template rendered successfully.

If template rendering silently fails (e.g., due to an unregistered exec function throwing a Tera error), the final hook won't be defined in the internal configuration. The test will pass trivially because the hook command is never processed.

Replace assert_succeed with assert_contains to verify that the dry-run output contains the preview of the hook's command. This strictly guarantees that the template successfully parsed and rendered without executing the exec function.

💡 Proposed fix
-assert_succeed "mise bootstrap --dry-run"
+assert_contains "mise bootstrap --dry-run" "touch template_exec_hook_ran"
 assert_fail "test -f template_exec_ran"
 assert_fail "test -f template_exec_hook_ran"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/cli/test_bootstrap` around lines 321 - 324, Update the dry-run assertion
in the bootstrap test to use assert_contains and verify the output includes the
rendered final hook command preview. Keep the existing file-absence assertions,
and match the expected hook command text so the test confirms the hook was
discovered and the template rendered successfully.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@e2e/cli/test_bootstrap`:
- Around line 321-324: Update the dry-run assertion in the bootstrap test to use
assert_contains and verify the output includes the rendered final hook command
preview. Keep the existing file-absence assertions, and match the expected hook
command text so the test confirms the hook was discovered and the template
rendered successfully.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c892593-4f0b-4542-a42b-8eec97a4020b

📥 Commits

Reviewing files that changed from the base of the PR and between a6da274 and 81b77af.

📒 Files selected for processing (4)
  • e2e/cli/test_bootstrap
  • src/cli/bootstrap.rs
  • src/system/files.rs
  • src/tera.rs

@risu729 risu729 changed the title fix(bootstrap): prevent command execution during dry runs fix: prevent side effects in dry-run commands Jul 15, 2026
@risu729 risu729 changed the title fix: prevent side effects in dry-run commands fix(install): preview hooks during dry runs Jul 15, 2026
@risu729
risu729 marked this pull request as ready for review July 15, 2026 19:12
@jdx
jdx merged commit 8006c36 into jdx:main Jul 15, 2026
33 checks passed
@risu729
risu729 deleted the codex-20260716-015720-b44bfa branch July 16, 2026 03:56
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