Skip to content

fix(ship): verify pre-commit execution (sc-1537) - #380

Merged
norvalbv merged 1 commit into
mainfrom
codex/sc-1537-hook-execution-proof
Aug 10, 2026
Merged

fix(ship): verify pre-commit execution (sc-1537)#380
norvalbv merged 1 commit into
mainfrom
codex/sc-1537-hook-execution-proof

Conversation

@norvalbv

@norvalbv norvalbv commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Fixes Story #1537.

Root cause: ship projected the Husky hook when core.hooksPath was unset, but git commit still used Git's empty default hooks directory. The unconditional success banner therefore claimed gates ran without evidence.

This change shares hook resolution between preparation and commit, fails closed when no executable pre-commit hook exists, and requires an attempt-specific execution marker before publishing. Private direct-exec wrappers preserve Husky's real path semantics for sibling hooks such as commit-msg. Setup and proof failures now emit accurate terminal telemetry.

Validation:

  • 125 affected ship tests passed
  • full suite: 3,740 passed, 5 skipped
  • typecheck and lint passed
  • GitNexus scope low; duplication, correctness, and commit-guard reviews passed

Summary by CodeRabbit

  • Bug Fixes
    • Improved commit validation across configured, overlay, package-managed, and default Git hooks.
    • Commits now fail safely when hook execution cannot be confirmed.
    • Added automatic rollback and clearer reporting when required gate output or execution proof is missing.
    • Improved capture of setup failures and gate logs for troubleshooting.
  • Reliability
    • Hook handling now supports projects with different hook-directory configurations and consumer roots.
    • Successful commits provide stronger verification that required checks actually ran.

Fixes Story #1537.

Root cause: ship projected the Husky hook when core.hooksPath was unset, but git commit still used Git's empty default hooks directory. The unconditional success banner therefore claimed gates ran without evidence.

This change shares hook resolution between preparation and commit, fails closed when no executable pre-commit hook exists, and requires an attempt-specific execution marker before publishing. Private direct-exec wrappers preserve Husky's real path semantics for sibling hooks such as commit-msg. Setup and proof failures now emit accurate terminal telemetry.

Validation:
- 125 affected ship tests passed
- full suite: 3,740 passed, 5 skipped
- typecheck and lint passed
- GitNexus scope low; duplication, correctness, and commit-guard reviews passed
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

commit_with_gate_capture now resolves and privately wraps pre-commit hooks, requires execution proof, and records setup or proof failures. Tests cover successful commits, fail-closed setup, rollback, telemetry, and temporary fixture cleanup.

Changes

Hook capture and validation

Layer / File(s) Summary
Root-aware hook resolution
cli/lib/ship/prepare-gate-worktree.sh
The resolver now checks overlay, Husky, configured, and Git default pre-commit hooks. Validation receives the consumer root.
Private hook capture and proof validation
cli/lib/ship/commit-with-gate-capture.sh
The capture flow records attempts, creates private hook wrappers, fails closed on setup errors, and rewinds commits when execution proof or gate output is missing.
Capture integration coverage
cli/__tests__/commit-with-gate-capture.test.mts, cli/__tests__/review-private-dependencies.test.mts
Tests cover successful hook execution, missing hooks, missing proof, telemetry, cleanup, and executable fixture hooks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant commit_with_gate_capture
  participant gate_worktree_pre_commit
  participant PrivateHookWrapper
  participant Git
  participant GateTelemetry
  commit_with_gate_capture->>gate_worktree_pre_commit: Resolve executable pre-commit hook
  gate_worktree_pre_commit-->>commit_with_gate_capture: Return hook path
  commit_with_gate_capture->>PrivateHookWrapper: Create private wrapper
  Git->>PrivateHookWrapper: Execute pre-commit hook
  PrivateHookWrapper-->>GateTelemetry: Record execution marker and gate output
  commit_with_gate_capture->>GateTelemetry: Record commit outcome
  commit_with_gate_capture->>Git: Rewind commit if proof is missing
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: verifying pre-commit hook execution during ship.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/sc-1537-hook-execution-proof

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.

@norvalbv
norvalbv marked this pull request as draft August 10, 2026 01:02
@norvalbv
norvalbv marked this pull request as ready for review August 10, 2026 07:51

@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 (2)
cli/lib/ship/commit-with-gate-capture.sh (2)

118-125: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider creating the wrapper directory outside the ship worktree.

mktemp -d "$wt/.devkit-ship-hooks.XXXXXX" places an untracked directory inside the worktree that the gate chain inspects. Any gate that asserts a clean working tree, or that stages with git add -A, sees this directory. The wrappers do not need to live in the worktree: every wrapper execs $DEVKIT_SHIP_REAL_HOOKS_DIR/<hook> by absolute path, and core.hooksPath accepts an absolute value.

If you move the directory to ${TMPDIR:-/tmp}, set core.hooksPath to the absolute $ship_hook_dir and drop the ship_hook_rel derivation.

♻️ Proposed change to isolate the wrapper directory
   if [ "$hook_setup_failed" -eq 0 ]; then
-    ship_hook_dir=$(mktemp -d "$wt/.devkit-ship-hooks.XXXXXX") || {
+    ship_hook_dir=$(mktemp -d "${TMPDIR:-/tmp}/devkit-ship-hooks.XXXXXX") || {
       hook_setup_error="ship: could not create the private hook wrapper — gates must not fail open"
       hook_setup_failed=1
       rc=1
     }
   fi
   if [ "$hook_setup_failed" -eq 0 ]; then
-    ship_hook_rel=${ship_hook_dir#"$wt/"}
+    ship_hook_rel=$ship_hook_dir
🤖 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 `@cli/lib/ship/commit-with-gate-capture.sh` around lines 118 - 125, Update the
hook-wrapper setup in commit-with-gate-capture.sh to create ship_hook_dir under
${TMPDIR:-/tmp} rather than inside wt, then configure core.hooksPath with the
absolute ship_hook_dir. Remove the ship_hook_rel derivation and adjust dependent
setup or cleanup logic to use the absolute directory directly, preserving the
existing failure handling.

129-143: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

The subshell masks a cat write failure.

The subshell exit status is the status of its last command, chmod 700. If cat fails part-way, for example on a full disk, chmod still succeeds on the truncated or empty file. The setup then reports success and installs a wrapper that does not exec the real hook.

The proof check at Line 200 still rewinds the commit, so the ship does not fail open. The operator instead sees "NO pre-commit execution proof" rather than the real cause. Chain the two commands so the write failure surfaces as a hook-setup error.

♻️ Proposed fix to propagate the write failure
       if ! (umask 077; cat > "$ship_hook_dir/$source_name" <<'SHIP_HOOK_WRAPPER'
 #!/bin/sh
 hook_name=${0##*/}
 if [ "$hook_name" = pre-commit ]; then
   printf '%s\n' "$DEVKIT_SHIP_HOOK_MARKER" >&2
 fi
 exec "$DEVKIT_SHIP_REAL_HOOKS_DIR/$hook_name" "$@"
 SHIP_HOOK_WRAPPER
-        chmod 700 "$ship_hook_dir/$source_name"); then
+        && chmod 700 "$ship_hook_dir/$source_name"); then
🤖 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 `@cli/lib/ship/commit-with-gate-capture.sh` around lines 129 - 143, Update the
wrapper creation block around the SHIP_HOOK_WRAPPER heredoc so the cat write and
chmod commands are chained, causing a cat failure to propagate instead of being
masked by chmod. Preserve the existing hook_setup_error, hook_setup_failed, and
rollback behavior when either setup command fails.
🤖 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 `@cli/lib/ship/commit-with-gate-capture.sh`:
- Around line 118-125: Update the hook-wrapper setup in
commit-with-gate-capture.sh to create ship_hook_dir under ${TMPDIR:-/tmp} rather
than inside wt, then configure core.hooksPath with the absolute ship_hook_dir.
Remove the ship_hook_rel derivation and adjust dependent setup or cleanup logic
to use the absolute directory directly, preserving the existing failure
handling.
- Around line 129-143: Update the wrapper creation block around the
SHIP_HOOK_WRAPPER heredoc so the cat write and chmod commands are chained,
causing a cat failure to propagate instead of being masked by chmod. Preserve
the existing hook_setup_error, hook_setup_failed, and rollback behavior when
either setup command fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e5f52b9-4cb0-433a-82c4-a19617753410

📥 Commits

Reviewing files that changed from the base of the PR and between b8c64c1 and 3812b98.

⛔ Files ignored due to path filters (2)
  • dist/cli/lib/ship/commit-with-gate-capture.sh is excluded by !**/dist/**
  • dist/cli/lib/ship/prepare-gate-worktree.sh is excluded by !**/dist/**
📒 Files selected for processing (4)
  • cli/__tests__/commit-with-gate-capture.test.mts
  • cli/__tests__/review-private-dependencies.test.mts
  • cli/lib/ship/commit-with-gate-capture.sh
  • cli/lib/ship/prepare-gate-worktree.sh

@norvalbv
norvalbv merged commit 8ff4c1d into main Aug 10, 2026
1 of 2 checks passed
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.

1 participant