fix(hooks): generate worktree setup-runner from target worktree's orca.yaml (#1280)

* fix(hooks): generate worktree setup-runner from target worktree's orca.yaml

Extend getEffectiveHooks, getSetupCommandSource, and runHook with an
optional worktreePath parameter. When provided, loadHooks reads the
yaml from that path; otherwise it falls back to repo.path. Update
the worktree-creation paths in worktree-remote.ts and orca-runtime.ts
to thread the new worktreePath through after the worktree exists, so
the generated setup-runner reflects the yaml at the tip of the target
worktree's branch instead of the primary checkout's stale yaml.

Add a regression test in hooks.test.ts that mocks two distinct
orca.yaml files (primary and worktree) and asserts the worktree's
content wins when worktreePath is passed.

The legacy hooks:check IPC handler keeps reading from repo.path
unchanged.

Closes #1256

* fix(hooks): skip auto-setup when worktree script differs from preview

Add setupScriptsMatch helper that compares the primary checkout's
setup script (what the renderer shows the user before worktree
creation) to the target worktree's script (what would actually run
after creation). When they differ, createLocalWorktree skips the
auto-launch and logs a warning, so a base-branch yaml that introduces
or modifies setup commands cannot execute under the trust granted to
the primary's preview. CLI-created worktrees use the worktree-bound
load directly because trust is granted by the CLI invocation context,
which is annotated in orca-runtime.ts.

Adds regression coverage for both matching and differing script cases.

* test(hooks): add setupScriptsMatch to worktree IPC test mocks

The new setupScriptsMatch import in worktree-remote.ts means the
existing vi.mock('../hooks') blocks in worktrees.test.ts and
worktrees-windows.test.ts now need to expose it. Default the mock to
returning true so existing tests continue to exercise the run-setup
path; the new behavior gating is covered by the dedicated
setupScriptsMatch unit tests.
This commit is contained in:
Trevin Chow
2026-05-02 18:27:09 -07:00
committed by GitHub
parent 1f99e81be3
commit fd3e62603d
7 changed files with 157 additions and 15 deletions
+5 -2
View File
@@ -1036,7 +1036,10 @@ export class OrcaRuntimeService {
let setup: CreateWorktreeResult['setup']
let warning: string | undefined
const hooks = getEffectiveHooks(repo)
// Why: CLI-created worktrees do not have a renderer preview to mismatch
// against. Trust is granted by the direct CLI invocation (`--run-hooks`),
// so loading the setup hook from the created worktree is intentional here.
const hooks = getEffectiveHooks(repo, worktreePath)
if (hooks?.scripts.setup && args.runHooks === true) {
if (this.authoritativeWindowId !== null) {
try {
@@ -1052,7 +1055,7 @@ export class OrcaRuntimeService {
console.error(`[hooks] Failed to prepare setup runner for ${worktreePath}:`, error)
}
} else {
void runHook('setup', worktreePath, repo).then((result) => {
void runHook('setup', worktreePath, repo, worktreePath).then((result) => {
if (!result.success) {
console.error(`[hooks] setup hook failed for ${worktreePath}:`, result.output)
}