---
name: "Mergemaster quality gates fail because merge worktree has no frontend dependencies"
---

# Bug 154: Mergemaster quality gates always fail — merge worktree missing frontend deps

## Description

`run_squash_merge()` in `server/src/agents.rs` creates an ephemeral git worktree at `.story_kit/merge_workspace`, does the squash merge + commit, then runs quality gates. But it **never installs frontend dependencies**, so every gate fails and master never moves forward.

## Root Cause

The merge worktree is created via `git worktree add` (line 2383-2396) which is just a git checkout — no `node_modules/`, no `frontend/dist/`. The quality gates (`run_merge_quality_gates` at line 2773) then run:

1. **`cargo clippy`** (line 2781) — FAILS because RustEmbed requires `frontend/dist/` to exist at compile time
2. **`pnpm build`** (line 2818) — FAILS because no `node_modules/` (never ran `pnpm install`)
3. **`pnpm test`** (line 2841) — FAILS for the same reason

Result: `gates_passed: false`, worktree cleaned up, master unchanged. Every single merge attempt fails.

## The Fix

Add frontend dependency setup between worktree creation (line 2396) and quality gates (line 2513). After the squash merge commit succeeds, but before gates run:

1. `mkdir -p frontend/dist` — minimum for cargo clippy to not fail on RustEmbed
2. Run `pnpm install` in the worktree's `frontend/` directory
3. The existing `pnpm build` gate (line 2818) will then populate `frontend/dist/` properly

The dependency install step should happen right after the commit (line 2511) and before the quality gates comment at line 2513. Add it as a clearly labeled section:

```
// ── Install frontend dependencies for quality gates ──────────
```

If `pnpm install` fails, treat it the same as a gate failure: log output, cleanup, return `success: false`.

## Key File

- `server/src/agents.rs` line 2383-2396: worktree creation (no deps installed)
- `server/src/agents.rs` line 2513-2549: quality gates (need deps to pass)
- `server/src/agents.rs` line 2773: `run_merge_quality_gates()` — runs cargo clippy, pnpm build, pnpm test

## Acceptance Criteria

- [ ] After merge worktree is created and commit is made, `pnpm install` runs in the worktree's `frontend/` directory
- [ ] `mkdir -p frontend/dist` is created before cargo clippy runs (as a fallback in case pnpm install succeeds but build hasn't run yet)
- [ ] If `pnpm install` fails, merge is aborted cleanly with diagnostic output
- [ ] Quality gates (cargo clippy, pnpm build, pnpm test) pass in the merge worktree for a normal merge with no conflicts
