mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
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.
This commit is contained in:
@@ -779,7 +779,7 @@ test.describe("Worktree Integration Tests", () => {
|
|||||||
expect(featureData.worktreePath).toBeUndefined();
|
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,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
await setupProjectWithPath(page, testRepo.path);
|
await setupProjectWithPath(page, testRepo.path);
|
||||||
@@ -788,7 +788,7 @@ test.describe("Worktree Integration Tests", () => {
|
|||||||
await waitForBoardView(page);
|
await waitForBoardView(page);
|
||||||
|
|
||||||
// Use a branch name that doesn't exist yet
|
// 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";
|
const branchName = "feature/auto-create-worktree";
|
||||||
|
|
||||||
// Verify branch does NOT exist before we create the feature
|
// Verify branch does NOT exist before we create the feature
|
||||||
@@ -807,12 +807,16 @@ test.describe("Worktree Integration Tests", () => {
|
|||||||
// Confirm
|
// Confirm
|
||||||
await confirmAddFeature(page);
|
await confirmAddFeature(page);
|
||||||
|
|
||||||
// Wait for feature to be saved
|
// Wait for feature to be saved and worktree to be created
|
||||||
await page.waitForTimeout(1000);
|
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);
|
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
|
// Verify feature was created with correct branch name stored
|
||||||
const featuresDir = path.join(testRepo.path, ".automaker", "features");
|
const featuresDir = path.join(testRepo.path, ".automaker", "features");
|
||||||
@@ -835,9 +839,6 @@ test.describe("Worktree Integration Tests", () => {
|
|||||||
// Verify branch name is stored
|
// Verify branch name is stored
|
||||||
expect(featureData.branchName).toBe(branchName);
|
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
|
// Verify feature is in backlog status
|
||||||
expect(featureData.status).toBe("backlog");
|
expect(featureData.status).toBe("backlog");
|
||||||
});
|
});
|
||||||
@@ -2399,7 +2400,7 @@ test.describe("Worktree Integration Tests", () => {
|
|||||||
const newBranchName = "feature/edited-branch";
|
const newBranchName = "feature/edited-branch";
|
||||||
const expectedWorktreePath = getWorktreePath(testRepo.path, newBranchName);
|
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);
|
expect(fs.existsSync(expectedWorktreePath)).toBe(false);
|
||||||
|
|
||||||
// Find and click the edit button on the feature card
|
// 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"]');
|
const saveButton = page.locator('[data-testid="confirm-edit-feature"]');
|
||||||
await saveButton.click();
|
await saveButton.click();
|
||||||
|
|
||||||
// Wait for the dialog to close
|
// Wait for the dialog to close and worktree to be created
|
||||||
await page.waitForTimeout(2000);
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
// Verify worktree was NOT created during editing (worktrees are created at execution time)
|
// Verify worktree WAS created during editing (worktrees are now created when features are added/edited)
|
||||||
expect(fs.existsSync(expectedWorktreePath)).toBe(false);
|
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);
|
const branches = await listBranches(testRepo.path);
|
||||||
expect(branches).not.toContain(newBranchName);
|
expect(branches).toContain(newBranchName);
|
||||||
|
|
||||||
// Verify feature was updated with correct branchName only
|
// Verify feature was updated with correct branchName
|
||||||
// Note: worktreePath is no longer stored - worktrees are created server-side at execution time
|
|
||||||
featureData = JSON.parse(fs.readFileSync(featureFilePath, "utf-8"));
|
featureData = JSON.parse(fs.readFileSync(featureFilePath, "utf-8"));
|
||||||
expect(featureData.branchName).toBe(newBranchName);
|
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 ({
|
test("should not create worktree when editing a feature and selecting main branch", async ({
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import {
|
|||||||
} from "../helpers/git-test-repo.js";
|
} from "../helpers/git-test-repo.js";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import { exec } from "child_process";
|
||||||
|
import { promisify } from "util";
|
||||||
|
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
vi.mock("@/providers/provider-factory.js");
|
vi.mock("@/providers/provider-factory.js");
|
||||||
|
|
||||||
@@ -43,13 +47,24 @@ describe("auto-mode-service.ts (integration)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("worktree operations", () => {
|
describe("worktree operations", () => {
|
||||||
it("should create git worktree for feature", async () => {
|
it("should use existing git worktree for feature", async () => {
|
||||||
// Create a test feature
|
const branchName = "feature/test-feature-1";
|
||||||
|
|
||||||
|
// Create a test feature with branchName set
|
||||||
await createTestFeature(testRepo.path, "test-feature-1", {
|
await createTestFeature(testRepo.path, "test-feature-1", {
|
||||||
id: "test-feature-1",
|
id: "test-feature-1",
|
||||||
category: "test",
|
category: "test",
|
||||||
description: "Test feature",
|
description: "Test feature",
|
||||||
status: "pending",
|
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
|
// Mock provider to complete quickly
|
||||||
@@ -82,9 +97,20 @@ describe("auto-mode-service.ts (integration)", () => {
|
|||||||
false // isAutoMode
|
false // isAutoMode
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify branch was created
|
// Verify branch exists (was created when worktree was created)
|
||||||
const branches = await listBranches(testRepo.path);
|
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
|
// Note: Worktrees are not automatically cleaned up by the service
|
||||||
// This is expected behavior - manual cleanup is required
|
// This is expected behavior - manual cleanup is required
|
||||||
|
|||||||
Reference in New Issue
Block a user