Skip to content

fix(sandbox): reinstall pre-push branch-protection hook after install - #4440

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-reinstall-branch-protection-hook
Jul 10, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-reinstall-branch-protection-hook

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

Source

A bug found while reading recently-changed sandbox daemon code (packages/sandbox/daemon/git/protect-branch.ts, packages/sandbox/daemon/setup/orchestrator.ts).

Why a maintainer wants this

installProtectedBranchHook() writes a pre-push hook that blocks pushing to main/master from a sandbox — the guard that stops an agent (or a buggy publish flow) from pushing straight to the protected branch. It only runs once, during gitSetup(), before stepInstall() runs the target repo's own install command (npm install / bun install / etc.).

Failure scenario

Any target repo whose package.json has a postinstall/prepare script that (re)installs its own git hooks — lefthook install, husky install, husky, pre-commit install, etc., all common in the JS ecosystem — will overwrite .git/hooks/pre-push during that install step, silently removing Studio's branch-protection hook with no re-check afterward. From that point on, a push to main/master from the sandbox succeeds instead of being rejected.

Verified locally: a package.json with a postinstall script that rewrites .git/hooks/pre-push overwrites it during a real (offline, dependency-free) bun install in well under a second.

Fix

Reinstall the hook right after a real install completes successfully in stepInstall(), so branch protection survives whatever the repo's own install scripts did to .git/hooks.

Regression test

packages/sandbox/daemon/setup/orchestrator.test.ts — "reinstalls the pre-push hook after an install script clobbers it". Installs the hook, drives a real pm-change → install step against a fixture repo whose postinstall overwrites the hook, and asserts the hook is restored afterward. Confirmed this test fails on the pre-fix code (hook stays clobbered) and passes after the fix.

Verify

bun test packages/sandbox/daemon/setup/orchestrator.test.ts

Checks run locally

  • bun run fmt
  • bunx tsc --noEmit in packages/sandbox
  • bun test packages/sandbox/daemon/setup/orchestrator.test.ts (12/12 pass)

Full CI will run the broader suite.


Summary by cubic

Reinstalls the pre-push branch-protection hook right after a successful install so postinstall tools don’t clobber it. Keeps sandbox pushes to main/master blocked as intended.

  • Bug Fixes
    • Reinstalls the hook in SetupOrchestrator.stepInstall() after real installs complete.
    • Emits a warning if reinstall fails without breaking the boot.
    • Adds a regression test that simulates a postinstall overwrite and verifies the hook is restored.

Written for commit 73befdd. Summary will update on new commits.

Review in cubic

installProtectedBranchHook() runs once during gitSetup(), before
stepInstall() runs the repo's own install command (npm/bun/yarn/pnpm
install). A postinstall/prepare script in the target repo (lefthook,
husky, etc.) can rewrite .git/hooks/pre-push during that install,
silently dropping the hook that blocks pushing to main/master from a
sandbox — with no re-check afterward.

Reinstall the hook right after a real install succeeds, so branch
protection survives whatever the repo's own install scripts did to
.git/hooks.
@pedrofrxncx
pedrofrxncx merged commit e1ad032 into main Jul 10, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-reinstall-branch-protection-hook branch July 10, 2026 22:58
decocms Bot pushed a commit that referenced this pull request Jul 10, 2026
PR: #4440 fix(sandbox): reinstall pre-push branch-protection hook after install
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.13.0 -> 1.13.1

Deploy-Scope: both
pedrofrxncx added a commit that referenced this pull request Jul 11, 2026
mkdirSync/writeFileSync/chmodSync block the daemon's single event loop
(CONTRIBUTING.md rule #4) — a single missed health probe flips a healthy
sandbox to crashed and tears the pod down mid-session. #4440 just added a
second call site for this function (after every real install), doubling
the exposure. Switch to node:fs/promises and await both call sites.
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