From 275037c73da1a06117063b1bfb2ad5ceb1cd1a84 Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Thu, 18 Dec 2025 19:46:10 -0500 Subject: [PATCH] test: update worktree integration tests for feature branch handling - Modified test descriptions to clarify when worktrees are created during feature addition and editing. - Updated assertions to verify that worktrees and branches are created as expected when features are added or edited. - Enhanced test logic to ensure accurate verification of worktree existence and branch creation, reflecting recent changes in worktree management. --- apps/app/tests/worktree-integration.spec.ts | 36 +++++++++---------- .../auto-mode-service.integration.test.ts | 34 +++++++++++++++--- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/apps/app/tests/worktree-integration.spec.ts b/apps/app/tests/worktree-integration.spec.ts index 7f143868..a8a77c40 100644 --- a/apps/app/tests/worktree-integration.spec.ts +++ b/apps/app/tests/worktree-integration.spec.ts @@ -779,7 +779,7 @@ test.describe("Worktree Integration Tests", () => { expect(featureData.worktreePath).toBeUndefined(); }); - test("should store branch name when adding feature with new branch (worktree created at execution)", async ({ + test("should store branch name when adding feature with new branch (worktree created when adding feature)", async ({ page, }) => { await setupProjectWithPath(page, testRepo.path); @@ -788,7 +788,7 @@ test.describe("Worktree Integration Tests", () => { await waitForBoardView(page); // Use a branch name that doesn't exist yet - // Note: Worktrees are now created at execution time, not when adding to backlog + // Note: Worktrees are now created when features are added/edited, not at execution time const branchName = "feature/auto-create-worktree"; // Verify branch does NOT exist before we create the feature @@ -807,12 +807,16 @@ test.describe("Worktree Integration Tests", () => { // Confirm await confirmAddFeature(page); - // Wait for feature to be saved - await page.waitForTimeout(1000); + // Wait for feature to be saved and worktree to be created + await page.waitForTimeout(2000); - // Verify branch was NOT created when adding feature (created at execution time) + // Verify branch WAS created when adding feature (worktrees are created when features are added/edited) const branchesAfter = await listBranches(testRepo.path); - expect(branchesAfter).not.toContain(branchName); + expect(branchesAfter).toContain(branchName); + + // Verify worktree was created + const worktreePath = getWorktreePath(testRepo.path, branchName); + expect(fs.existsSync(worktreePath)).toBe(true); // Verify feature was created with correct branch name stored const featuresDir = path.join(testRepo.path, ".automaker", "features"); @@ -835,9 +839,6 @@ test.describe("Worktree Integration Tests", () => { // Verify branch name is stored expect(featureData.branchName).toBe(branchName); - // Verify worktreePath is NOT set (worktrees are created at execution time) - expect(featureData.worktreePath).toBeUndefined(); - // Verify feature is in backlog status expect(featureData.status).toBe("backlog"); }); @@ -2399,7 +2400,7 @@ test.describe("Worktree Integration Tests", () => { const newBranchName = "feature/edited-branch"; const expectedWorktreePath = getWorktreePath(testRepo.path, newBranchName); - // Verify worktree does NOT exist before editing (worktrees are created at execution time) + // Verify worktree does NOT exist before editing expect(fs.existsSync(expectedWorktreePath)).toBe(false); // Find and click the edit button on the feature card @@ -2435,22 +2436,19 @@ test.describe("Worktree Integration Tests", () => { const saveButton = page.locator('[data-testid="confirm-edit-feature"]'); await saveButton.click(); - // Wait for the dialog to close + // Wait for the dialog to close and worktree to be created await page.waitForTimeout(2000); - // Verify worktree was NOT created during editing (worktrees are created at execution time) - expect(fs.existsSync(expectedWorktreePath)).toBe(false); + // Verify worktree WAS created during editing (worktrees are now created when features are added/edited) + expect(fs.existsSync(expectedWorktreePath)).toBe(true); - // Verify branch was NOT created (created at execution time) + // Verify branch WAS created (worktrees are created when features are added/edited) const branches = await listBranches(testRepo.path); - expect(branches).not.toContain(newBranchName); + expect(branches).toContain(newBranchName); - // Verify feature was updated with correct branchName only - // Note: worktreePath is no longer stored - worktrees are created server-side at execution time + // Verify feature was updated with correct branchName featureData = JSON.parse(fs.readFileSync(featureFilePath, "utf-8")); expect(featureData.branchName).toBe(newBranchName); - // worktreePath should not exist in the feature data - expect(featureData.worktreePath).toBeUndefined(); }); test("should not create worktree when editing a feature and selecting main branch", async ({ diff --git a/apps/server/tests/integration/services/auto-mode-service.integration.test.ts b/apps/server/tests/integration/services/auto-mode-service.integration.test.ts index 45b4d6e4..ebf0857f 100644 --- a/apps/server/tests/integration/services/auto-mode-service.integration.test.ts +++ b/apps/server/tests/integration/services/auto-mode-service.integration.test.ts @@ -13,6 +13,10 @@ import { } from "../helpers/git-test-repo.js"; import * as fs from "fs/promises"; import * as path from "path"; +import { exec } from "child_process"; +import { promisify } from "util"; + +const execAsync = promisify(exec); vi.mock("@/providers/provider-factory.js"); @@ -43,13 +47,24 @@ describe("auto-mode-service.ts (integration)", () => { }); describe("worktree operations", () => { - it("should create git worktree for feature", async () => { - // Create a test feature + it("should use existing git worktree for feature", async () => { + const branchName = "feature/test-feature-1"; + + // Create a test feature with branchName set await createTestFeature(testRepo.path, "test-feature-1", { id: "test-feature-1", category: "test", description: "Test feature", status: "pending", + branchName: branchName, + }); + + // Create worktree before executing (worktrees are now created when features are added/edited) + const worktreesDir = path.join(testRepo.path, ".worktrees"); + const worktreePath = path.join(worktreesDir, "test-feature-1"); + await fs.mkdir(worktreesDir, { recursive: true }); + await execAsync(`git worktree add -b ${branchName} "${worktreePath}" HEAD`, { + cwd: testRepo.path, }); // Mock provider to complete quickly @@ -82,9 +97,20 @@ describe("auto-mode-service.ts (integration)", () => { false // isAutoMode ); - // Verify branch was created + // Verify branch exists (was created when worktree was created) const branches = await listBranches(testRepo.path); - expect(branches).toContain("feature/test-feature-1"); + expect(branches).toContain(branchName); + + // Verify worktree exists and is being used + // The service should have found and used the worktree (check via logs) + // We can verify the worktree exists by checking git worktree list + const worktrees = await listWorktrees(testRepo.path); + expect(worktrees.length).toBeGreaterThan(0); + // Verify that at least one worktree path contains our feature ID + const worktreePathsMatch = worktrees.some(wt => + wt.includes("test-feature-1") || wt.includes(".worktrees") + ); + expect(worktreePathsMatch).toBe(true); // Note: Worktrees are not automatically cleaned up by the service // This is expected behavior - manual cleanup is required