From 6e03a7d501b68b7fac605962bafb0a2b012585a0 Mon Sep 17 00:00:00 2001 From: acamq <179265037+acamq@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:18:04 -0600 Subject: [PATCH] test(hooks): fix regression test for default-enabled worktree behavior The test at the bottom of 'worktree disabled by config' was misplaced and broken in two ways: - It lived outside the 'worktree support' describe block, so detectSpy was not in scope (compile error). - It passed no --worktree flag, meaning explicitWorktreePath was null and resolveWorktreeContext returned undefined regardless of worktreeEnabled, so the test could never observe the enabled behavior it claimed to assert. Move the test into 'worktree support' where detectSpy is available, pass --worktree /valid/wt in the user request, mock detectWorktreePath to return the path, and assert that 'Worktree Active' is injected and worktree_path is stored in boulder.json. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/hooks/start-work/index.test.ts | 72 ++++++++++++++++-------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/hooks/start-work/index.test.ts b/src/hooks/start-work/index.test.ts index 2fdf77ff7..55b63ce78 100644 --- a/src/hooks/start-work/index.test.ts +++ b/src/hooks/start-work/index.test.ts @@ -555,6 +555,29 @@ describe("start-work hook", () => { expect(output.parts[0].text).toContain("subagent") expect(output.parts[0].text).not.toContain("Worktree Setup Required") }) + + test("should enable worktree by default when worktreeEnabled option is undefined (regression)", async () => { + // given - single plan, no worktreeEnabled option (undefined = default enabled), valid worktree flag + const plansDir = join(testDir, ".sisyphus", "plans") + mkdirSync(plansDir, { recursive: true }) + writeFileSync(join(plansDir, "my-plan.md"), "# Plan\n- [ ] Task 1") + detectSpy.mockReturnValue("/valid/wt") + + const hook = createStartWorkHook(createMockPluginInput()) + const output = { + parts: [{ type: "text", text: "\n--worktree /valid/wt\n" }], + } + + // when + await hook["chat.message"]({ sessionID: "session-123" }, output) + + // then - worktree is enabled by default, so Worktree Active block is injected + expect(output.parts[0].text).toContain("Auto-Selected Plan") + expect(output.parts[0].text).toContain("Worktree Active") + expect(output.parts[0].text).toContain("/valid/wt") + const state = readBoulderState(testDir) + expect(state?.worktree_path).toBe("/valid/wt") + }) }) describe("worktree disabled by config", () => { @@ -625,42 +648,23 @@ describe("start-work hook", () => { expect(output.parts[0].text).toContain("RESUMING") }) - test("should NOT store worktree_path in boulder.json when worktreeEnabled is false", async () => { - // given - single plan, worktreeEnabled: false - const plansDir = join(testDir, ".sisyphus", "plans") - mkdirSync(plansDir, { recursive: true }) - writeFileSync(join(plansDir, "my-plan.md"), "# Plan\n- [ ] Task 1") + test("should NOT store worktree_path in boulder.json when worktreeEnabled is false", async () => { + // given - single plan, worktreeEnabled: false + const plansDir = join(testDir, ".sisyphus", "plans") + mkdirSync(plansDir, { recursive: true }) + writeFileSync(join(plansDir, "my-plan.md"), "# Plan\n- [ ] Task 1") - const hook = createStartWorkHook(createMockPluginInput(), { worktreeEnabled: false }) - const output = { - parts: [{ type: "text", text: "" }], - } + const hook = createStartWorkHook(createMockPluginInput(), { worktreeEnabled: false }) + const output = { + parts: [{ type: "text", text: "" }], + } - // when - await hook["chat.message"]({ sessionID: "session-123" }, output) + // when + await hook["chat.message"]({ sessionID: "session-123" }, output) - // then - boulder.json should not have worktree_path - const state = readBoulderState(testDir) - expect(state?.worktree_path).toBeUndefined() - }) - - test("should enable worktree by default when worktreeEnabled option is undefined (regression)", async () => { - // given - single plan, no worktreeEnabled option (undefined = default enabled) - const plansDir = join(testDir, ".sisyphus", "plans") - mkdirSync(plansDir, { recursive: true }) - writeFileSync(join(plansDir, "my-plan.md"), "# Plan\n- [ ] Task 1") - - const hook = createStartWorkHook(createMockPluginInput()) - const output = { - parts: [{ type: "text", text: "" }], - } - - // when - await hook["chat.message"]({ sessionID: "session-123" }, output) - - // then - should behave like worktree is enabled (no worktree content because no flag, but system ready for it) - expect(output.parts[0].text).toContain("Auto-Selected Plan") - expect(output.parts[0].text).not.toContain("Worktree Active") - }) + // then - boulder.json should not have worktree_path + const state = readBoulderState(testDir) + expect(state?.worktree_path).toBeUndefined() + }) }) })