mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-17 10:03:08 +00:00
* fix(copilot): correct tool.execution_complete event handling The CopilotProvider was using incorrect event type and data structure for tool execution completion events from the @github/copilot-sdk, causing tool call outputs to be empty. Changes: - Update event type from 'tool.execution_end' to 'tool.execution_complete' - Fix data structure to use nested result.content instead of flat result - Fix error structure to use error.message instead of flat error - Add success field to match SDK event structure - Add tests for empty and missing result handling This aligns with the official @github/copilot-sdk v0.1.16 types defined in session-events.d.ts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(copilot): add edge case test for error with code field Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(copilot): improve error handling and code quality Code review improvements: - Extract magic string '[ERROR]' to TOOL_ERROR_PREFIX constant - Add null-safe error handling with direct error variable assignment - Include error codes in error messages for better debugging - Add JSDoc documentation for tool.execution_complete handler - Update tests to verify error codes are displayed - Add missing tool_use_id assertion in error test These changes improve: - Code maintainability (no magic strings) - Debugging experience (error codes now visible) - Type safety (explicit null checks) - Test coverage (verify error code formatting) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Changes from fix/bug-fixes-1-0 * test(copilot): add edge case test for error with code field Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Changes from fix/bug-fixes-1-0 * fix: Handle detached HEAD state in worktree discovery and recovery * fix: Remove unused isDevServerStarting prop and md: breakpoint classes * fix: Add missing dependency and sanitize persisted cache data * feat: Ensure NODE_ENV is set to test in vitest configs * feat: Configure Playwright to run only E2E tests * fix: Improve PR tracking and dev server lifecycle management * feat: Add settings-based defaults for planning mode, model config, and custom providers. Fixes #816 * feat: Add worktree and branch selector to graph view * fix: Add timeout and error handling for worktree HEAD ref resolution * fix: use absolute icon path and place icon outside asar on Linux The hicolor icon theme index only lists sizes up to 512x512, so an icon installed only at 1024x1024 is invisible to GNOME/KDE's theme resolver, causing both the app launcher and taskbar to show a generic icon. Additionally, BrowserWindow.icon cannot be read by the window manager when the file is inside app.asar. - extraResources: copy logo_larger.png to resources/ (outside asar) so it lands at /opt/Automaker/resources/logo_larger.png on install - linux.desktop.Icon: set to the absolute resources path, bypassing the hicolor theme lookup and its size constraints entirely - icon-manager.ts: on Linux production use process.resourcesPath so BrowserWindow receives a real filesystem path the WM can read directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: use linux.desktop.entry for custom desktop Icon field electron-builder v26 rejects arbitrary keys in linux.desktop — the correct schema wraps custom .desktop overrides inside desktop.entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: set desktop name on Linux so taskbar uses the correct app icon Without app.setDesktopName(), the window manager cannot associate the running Electron process with automaker.desktop. GNOME/KDE fall back to _NET_WM_ICON which defaults to Electron's own bundled icon. Calling app.setDesktopName('automaker.desktop') before any window is created sets the _GTK_APPLICATION_ID hint and XDG app_id so the WM picks up the desktop entry's Icon for the taskbar. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix: memory and context views mobile friendly (#818) * Changes from fix/memory-and-context-mobile-friendly * fix: Improve file extension detection and add path traversal protection * refactor: Extract file extension utilities and add path traversal guards Code review improvements: - Extract isMarkdownFilename and isImageFilename to shared image-utils.ts - Remove duplicated code from context-view.tsx and memory-view.tsx - Add path traversal guard for context fixture utilities (matching memory) - Add 7 new tests for context fixture path traversal protection - Total 61 tests pass Addresses code review feedback from PR #813 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: Add e2e tests for profiles crud and board background persistence * Update apps/ui/playwright.config.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Add robust test navigation handling and file filtering * fix: Format NODE_OPTIONS configuration on single line * test: Update profiles and board background persistence tests * test: Replace iPhone 13 Pro with Pixel 5 for mobile test consistency * Update apps/ui/src/components/views/context-view.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: Remove test project directory * feat: Filter context files by type and improve mobile menu visibility --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Improve test reliability and localhost handling * chore: Use explicit TEST_USE_EXTERNAL_BACKEND env var for server cleanup * feat: Add E2E/CI mock mode for provider factory and auth verification * feat: Add remoteBranch parameter to pull and rebase operations * chore: Enhance E2E testing setup with worker isolation and auth state management - Updated .gitignore to include worker-specific test fixtures. - Modified e2e-tests.yml to implement test sharding for improved CI performance. - Refactored global setup to authenticate once and save session state for reuse across tests. - Introduced worker-isolated fixture paths to prevent conflicts during parallel test execution. - Improved test navigation and loading handling for better reliability. - Updated various test files to utilize new auth state management and fixture paths. * fix: Update Playwright configuration and improve test reliability - Increased the number of workers in Playwright configuration for better parallelism in CI environments. - Enhanced the board background persistence test to ensure dropdown stability by waiting for the list to populate before interaction, improving test reliability. * chore: Simplify E2E test configuration and enhance mock implementations - Updated e2e-tests.yml to run tests in a single shard for streamlined CI execution. - Enhanced unit tests for worktree list handling by introducing a mock for execGitCommand, improving test reliability and coverage. - Refactored setup functions to better manage command mocks for git operations in tests. - Improved error handling in mkdirSafe function to account for undefined stats in certain environments. * refactor: Improve test configurations and enhance error handling - Updated Playwright configuration to clear VITE_SERVER_URL, ensuring the frontend uses the Vite proxy and preventing cookie domain mismatches. - Enhanced MergeRebaseDialog logic to normalize selectedBranch for better handling of various ref formats. - Improved global setup with a more robust backend health check, throwing an error if the backend is not healthy after retries. - Refactored project creation tests to handle file existence checks more reliably. - Added error handling for missing E2E source fixtures to guide setup process. - Enhanced memory navigation to handle sandbox dialog visibility more effectively. * refactor: Enhance Git command execution and improve test configurations - Updated Git command execution to merge environment paths correctly, ensuring proper command execution context. - Refactored the Git initialization process to handle errors more gracefully and ensure user configuration is set before creating the initial commit. - Improved test configurations by updating Playwright test identifiers for better clarity and consistency across different project states. - Enhanced cleanup functions in tests to handle directory removal more robustly, preventing errors during test execution. * fix: Resolve React hooks errors from duplicate instances in dependency tree * style: Format alias configuration for improved readability --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: DhanushSantosh <dhanushsantoshs05@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
564 lines
17 KiB
TypeScript
564 lines
17 KiB
TypeScript
/**
|
|
* Git worktree utilities for testing
|
|
* Provides helpers for creating test git repos and managing worktrees
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { exec } from 'child_process';
|
|
import { promisify } from 'util';
|
|
import { Page } from '@playwright/test';
|
|
import { sanitizeBranchName, TIMEOUTS } from '../core/constants';
|
|
import { getWorkspaceRoot } from '../core/safe-paths';
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
// ============================================================================
|
|
// Types
|
|
// ============================================================================
|
|
|
|
export interface TestRepo {
|
|
path: string;
|
|
cleanup: () => Promise<void>;
|
|
}
|
|
|
|
export interface FeatureData {
|
|
id: string;
|
|
category: string;
|
|
description: string;
|
|
status: string;
|
|
branchName?: string;
|
|
worktreePath?: string;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Path Utilities
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Create a unique temp directory path for tests (always under workspace test/ dir).
|
|
* Git operations in these dirs never affect the main project.
|
|
*/
|
|
export function createTempDirPath(prefix: string = 'temp-worktree-tests'): string {
|
|
const uniqueId = `${process.pid}-${Math.random().toString(36).substring(2, 9)}`;
|
|
return path.join(getWorkspaceRoot(), 'test', `${prefix}-${uniqueId}`);
|
|
}
|
|
|
|
/**
|
|
* Get the expected worktree path for a branch
|
|
*/
|
|
export function getWorktreePath(projectPath: string, branchName: string): string {
|
|
const sanitizedName = sanitizeBranchName(branchName);
|
|
return path.join(projectPath, '.worktrees', sanitizedName);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Git Repository Management
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Create a temporary git repository for testing
|
|
*/
|
|
export async function createTestGitRepo(tempDir: string): Promise<TestRepo> {
|
|
// Create temp directory if it doesn't exist
|
|
if (!fs.existsSync(tempDir)) {
|
|
fs.mkdirSync(tempDir, { recursive: true });
|
|
}
|
|
|
|
const tmpDir = path.join(tempDir, `test-repo-${Date.now()}`);
|
|
fs.mkdirSync(tmpDir, { recursive: true });
|
|
|
|
// Use environment variables instead of git config to avoid affecting user's git config
|
|
// These env vars override git config without modifying it
|
|
const gitEnv = {
|
|
...process.env,
|
|
GIT_AUTHOR_NAME: 'Test User',
|
|
GIT_AUTHOR_EMAIL: 'test@example.com',
|
|
GIT_COMMITTER_NAME: 'Test User',
|
|
GIT_COMMITTER_EMAIL: 'test@example.com',
|
|
};
|
|
|
|
// Initialize git repo with explicit branch name to avoid CI environment differences
|
|
// Use -b main to set initial branch (git 2.28+), falling back to branch -M for older versions
|
|
try {
|
|
await execAsync('git init -b main', { cwd: tmpDir, env: gitEnv });
|
|
} catch {
|
|
// Fallback for older git versions that don't support -b flag
|
|
await execAsync('git init', { cwd: tmpDir, env: gitEnv });
|
|
}
|
|
|
|
// Create initial commit
|
|
fs.writeFileSync(path.join(tmpDir, 'README.md'), '# Test Project\n');
|
|
await execAsync('git add .', { cwd: tmpDir, env: gitEnv });
|
|
await execAsync('git commit -m "Initial commit"', { cwd: tmpDir, env: gitEnv });
|
|
|
|
// Ensure branch is named 'main' (handles both new repos and older git versions)
|
|
await execAsync('git branch -M main', { cwd: tmpDir, env: gitEnv });
|
|
|
|
// Create .automaker directories
|
|
const automakerDir = path.join(tmpDir, '.automaker');
|
|
const featuresDir = path.join(automakerDir, 'features');
|
|
fs.mkdirSync(featuresDir, { recursive: true });
|
|
|
|
// Create empty categories.json to avoid ENOENT errors in tests
|
|
fs.writeFileSync(path.join(automakerDir, 'categories.json'), '[]');
|
|
|
|
return {
|
|
path: tmpDir,
|
|
cleanup: async () => {
|
|
await cleanupTestRepo(tmpDir);
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Cleanup a test git repository
|
|
*/
|
|
export async function cleanupTestRepo(repoPath: string): Promise<void> {
|
|
try {
|
|
// Remove all worktrees first
|
|
const { stdout } = await execAsync('git worktree list --porcelain', {
|
|
cwd: repoPath,
|
|
}).catch(() => ({ stdout: '' }));
|
|
|
|
const worktrees = stdout
|
|
.split('\n\n')
|
|
.slice(1) // Skip main worktree
|
|
.map((block) => {
|
|
const pathLine = block.split('\n').find((line) => line.startsWith('worktree '));
|
|
return pathLine ? pathLine.replace('worktree ', '') : null;
|
|
})
|
|
.filter(Boolean);
|
|
|
|
for (const worktreePath of worktrees) {
|
|
try {
|
|
await execAsync(`git worktree remove "${worktreePath}" --force`, {
|
|
cwd: repoPath,
|
|
});
|
|
} catch {
|
|
// Ignore errors
|
|
}
|
|
}
|
|
|
|
// Remove the repository
|
|
fs.rmSync(repoPath, { recursive: true, force: true });
|
|
} catch (error) {
|
|
console.error('Failed to cleanup test repo:', error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Recursively remove directory contents then the directory (avoids ENOTEMPTY on some systems)
|
|
*/
|
|
function rmDirRecursive(dir: string): void {
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
rmDirRecursive(fullPath);
|
|
fs.rmdirSync(fullPath);
|
|
} else {
|
|
fs.unlinkSync(fullPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cleanup a temp directory and all its contents.
|
|
* Tries rmSync first; on ENOTEMPTY (e.g. macOS with git worktrees) falls back to recursive delete.
|
|
*/
|
|
export function cleanupTempDir(tempDir: string): void {
|
|
if (!fs.existsSync(tempDir)) return;
|
|
try {
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
} catch (err) {
|
|
const code = (err as NodeJS.ErrnoException)?.code;
|
|
if (code === 'ENOENT') {
|
|
// Directory already removed, nothing to do
|
|
} else if (code === 'ENOTEMPTY' || code === 'EPERM' || code === 'EBUSY') {
|
|
rmDirRecursive(tempDir);
|
|
try {
|
|
fs.rmdirSync(tempDir);
|
|
} catch (e2) {
|
|
if ((e2 as NodeJS.ErrnoException)?.code !== 'ENOENT') {
|
|
throw e2;
|
|
}
|
|
}
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|
|
// Git Operations
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Execute a git command in a repository
|
|
*/
|
|
export async function gitExec(
|
|
repoPath: string,
|
|
command: string
|
|
): Promise<{ stdout: string; stderr: string }> {
|
|
return execAsync(`git ${command}`, { cwd: repoPath });
|
|
}
|
|
|
|
/**
|
|
* Get list of git worktrees
|
|
*/
|
|
export async function listWorktrees(repoPath: string): Promise<string[]> {
|
|
try {
|
|
const { stdout } = await execAsync('git worktree list --porcelain', {
|
|
cwd: repoPath,
|
|
});
|
|
|
|
return stdout
|
|
.split('\n\n')
|
|
.slice(1) // Skip main worktree
|
|
.map((block) => {
|
|
const pathLine = block.split('\n').find((line) => line.startsWith('worktree '));
|
|
if (!pathLine) return null;
|
|
// Normalize path separators to OS native (git on Windows returns forward slashes)
|
|
const worktreePath = pathLine.replace('worktree ', '');
|
|
return path.normalize(worktreePath);
|
|
})
|
|
.filter(Boolean) as string[];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get list of git branches
|
|
*/
|
|
export async function listBranches(repoPath: string): Promise<string[]> {
|
|
const { stdout } = await execAsync('git branch --list', { cwd: repoPath });
|
|
return stdout
|
|
.split('\n')
|
|
.map((line) => line.trim().replace(/^[*+]\s*/, ''))
|
|
.filter(Boolean);
|
|
}
|
|
|
|
/**
|
|
* Get the current branch name
|
|
*/
|
|
export async function getCurrentBranch(repoPath: string): Promise<string> {
|
|
const { stdout } = await execAsync('git rev-parse --abbrev-ref HEAD', { cwd: repoPath });
|
|
return stdout.trim();
|
|
}
|
|
|
|
/**
|
|
* Create a git branch
|
|
*/
|
|
export async function createBranch(repoPath: string, branchName: string): Promise<void> {
|
|
await execAsync(`git branch ${branchName}`, { cwd: repoPath });
|
|
}
|
|
|
|
/**
|
|
* Checkout a git branch
|
|
*/
|
|
export async function checkoutBranch(repoPath: string, branchName: string): Promise<void> {
|
|
await execAsync(`git checkout ${branchName}`, { cwd: repoPath });
|
|
}
|
|
|
|
/**
|
|
* Create a git worktree using git command directly
|
|
*/
|
|
export async function createWorktreeDirectly(
|
|
repoPath: string,
|
|
branchName: string,
|
|
worktreePath?: string
|
|
): Promise<string> {
|
|
const sanitizedName = sanitizeBranchName(branchName);
|
|
const targetPath = worktreePath || path.join(repoPath, '.worktrees', sanitizedName);
|
|
|
|
await execAsync(`git worktree add "${targetPath}" -b ${branchName}`, { cwd: repoPath });
|
|
return targetPath;
|
|
}
|
|
|
|
/**
|
|
* Add and commit a file
|
|
*/
|
|
export async function commitFile(
|
|
repoPath: string,
|
|
filePath: string,
|
|
content: string,
|
|
message: string
|
|
): Promise<void> {
|
|
// Use environment variables instead of git config to avoid affecting user's git config
|
|
const gitEnv = {
|
|
...process.env,
|
|
GIT_AUTHOR_NAME: 'Test User',
|
|
GIT_AUTHOR_EMAIL: 'test@example.com',
|
|
GIT_COMMITTER_NAME: 'Test User',
|
|
GIT_COMMITTER_EMAIL: 'test@example.com',
|
|
};
|
|
|
|
fs.writeFileSync(path.join(repoPath, filePath), content);
|
|
await execAsync(`git add "${filePath}"`, { cwd: repoPath, env: gitEnv });
|
|
await execAsync(`git commit -m "${message}"`, { cwd: repoPath, env: gitEnv });
|
|
}
|
|
|
|
/**
|
|
* Get the latest commit message
|
|
*/
|
|
export async function getLatestCommitMessage(repoPath: string): Promise<string> {
|
|
const { stdout } = await execAsync('git log --oneline -1', { cwd: repoPath });
|
|
return stdout.trim();
|
|
}
|
|
|
|
// ============================================================================
|
|
// Feature File Management
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Create a feature file in the test repo
|
|
*/
|
|
export function createTestFeature(
|
|
repoPath: string,
|
|
featureId: string,
|
|
featureData: FeatureData
|
|
): void {
|
|
const featuresDir = path.join(repoPath, '.automaker', 'features');
|
|
const featureDir = path.join(featuresDir, featureId);
|
|
|
|
fs.mkdirSync(featureDir, { recursive: true });
|
|
fs.writeFileSync(path.join(featureDir, 'feature.json'), JSON.stringify(featureData, null, 2));
|
|
}
|
|
|
|
/**
|
|
* Read a feature file from the test repo
|
|
*/
|
|
export function readTestFeature(repoPath: string, featureId: string): FeatureData | null {
|
|
const featureFilePath = path.join(repoPath, '.automaker', 'features', featureId, 'feature.json');
|
|
|
|
if (!fs.existsSync(featureFilePath)) {
|
|
return null;
|
|
}
|
|
|
|
return JSON.parse(fs.readFileSync(featureFilePath, 'utf-8'));
|
|
}
|
|
|
|
/**
|
|
* List all feature directories in the test repo
|
|
*/
|
|
export function listTestFeatures(repoPath: string): string[] {
|
|
const featuresDir = path.join(repoPath, '.automaker', 'features');
|
|
|
|
if (!fs.existsSync(featuresDir)) {
|
|
return [];
|
|
}
|
|
|
|
return fs.readdirSync(featuresDir);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Project Setup for Tests
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Set up localStorage with a project pointing to a test repo
|
|
*/
|
|
export async function setupProjectWithPath(page: Page, projectPath: string): Promise<void> {
|
|
await page.addInitScript((pathArg: string) => {
|
|
const mockProject = {
|
|
id: 'test-project-worktree',
|
|
name: 'Worktree Test Project',
|
|
path: pathArg,
|
|
lastOpened: new Date().toISOString(),
|
|
};
|
|
|
|
const mockState = {
|
|
state: {
|
|
projects: [mockProject],
|
|
currentProject: mockProject,
|
|
currentView: 'board',
|
|
theme: 'dark',
|
|
sidebarOpen: true,
|
|
skipSandboxWarning: true,
|
|
apiKeys: { anthropic: '', google: '' },
|
|
chatSessions: [],
|
|
chatHistoryOpen: false,
|
|
maxConcurrency: 3,
|
|
useWorktrees: true, // Enable worktree feature for tests
|
|
currentWorktreeByProject: {
|
|
[pathArg]: { path: null, branch: 'main' }, // Initialize to main branch
|
|
},
|
|
worktreesByProject: {},
|
|
},
|
|
version: 2, // Must match app-store.ts persist version
|
|
};
|
|
|
|
localStorage.setItem('automaker-storage', JSON.stringify(mockState));
|
|
|
|
// Mark setup as complete to skip the setup wizard
|
|
const setupState = {
|
|
state: {
|
|
isFirstRun: false,
|
|
setupComplete: true,
|
|
currentStep: 'complete',
|
|
skipClaudeSetup: false,
|
|
},
|
|
version: 0, // setup-store.ts doesn't specify a version, so zustand defaults to 0
|
|
};
|
|
localStorage.setItem('automaker-setup', JSON.stringify(setupState));
|
|
|
|
// Disable splash screen in tests
|
|
localStorage.setItem('automaker-disable-splash', 'true');
|
|
}, projectPath);
|
|
}
|
|
|
|
/**
|
|
* Set up localStorage with a project pointing to a test repo with worktrees DISABLED
|
|
* Use this to test scenarios where the worktree feature flag is off
|
|
*/
|
|
export async function setupProjectWithPathNoWorktrees(
|
|
page: Page,
|
|
projectPath: string
|
|
): Promise<void> {
|
|
await page.addInitScript((pathArg: string) => {
|
|
const mockProject = {
|
|
id: 'test-project-no-worktree',
|
|
name: 'Test Project (No Worktrees)',
|
|
path: pathArg,
|
|
lastOpened: new Date().toISOString(),
|
|
};
|
|
|
|
const mockState = {
|
|
state: {
|
|
projects: [mockProject],
|
|
currentProject: mockProject,
|
|
currentView: 'board',
|
|
theme: 'dark',
|
|
sidebarOpen: true,
|
|
skipSandboxWarning: true,
|
|
apiKeys: { anthropic: '', google: '' },
|
|
chatSessions: [],
|
|
chatHistoryOpen: false,
|
|
maxConcurrency: 3,
|
|
useWorktrees: false, // Worktree feature DISABLED
|
|
currentWorktreeByProject: {},
|
|
worktreesByProject: {},
|
|
},
|
|
version: 2, // Must match app-store.ts persist version
|
|
};
|
|
|
|
localStorage.setItem('automaker-storage', JSON.stringify(mockState));
|
|
|
|
// Mark setup as complete to skip the setup wizard
|
|
const setupState = {
|
|
state: {
|
|
isFirstRun: false,
|
|
setupComplete: true,
|
|
currentStep: 'complete',
|
|
skipClaudeSetup: false,
|
|
},
|
|
version: 0, // setup-store.ts doesn't specify a version, so zustand defaults to 0
|
|
};
|
|
localStorage.setItem('automaker-setup', JSON.stringify(setupState));
|
|
|
|
// Disable splash screen in tests
|
|
localStorage.setItem('automaker-disable-splash', 'true');
|
|
}, projectPath);
|
|
}
|
|
|
|
/**
|
|
* Set up localStorage with a project that has STALE worktree data
|
|
* The currentWorktreeByProject points to a worktree path that no longer exists
|
|
* This simulates the scenario where a user previously selected a worktree that was later deleted
|
|
*/
|
|
export async function setupProjectWithStaleWorktree(
|
|
page: Page,
|
|
projectPath: string
|
|
): Promise<void> {
|
|
await page.addInitScript((pathArg: string) => {
|
|
const mockProject = {
|
|
id: 'test-project-stale-worktree',
|
|
name: 'Stale Worktree Test Project',
|
|
path: pathArg,
|
|
lastOpened: new Date().toISOString(),
|
|
};
|
|
|
|
const mockState = {
|
|
state: {
|
|
projects: [mockProject],
|
|
currentProject: mockProject,
|
|
currentView: 'board',
|
|
theme: 'dark',
|
|
sidebarOpen: true,
|
|
skipSandboxWarning: true,
|
|
apiKeys: { anthropic: '', google: '' },
|
|
chatSessions: [],
|
|
chatHistoryOpen: false,
|
|
maxConcurrency: 3,
|
|
useWorktrees: true, // Enable worktree feature for tests
|
|
currentWorktreeByProject: {
|
|
// This is STALE data - pointing to a worktree path that doesn't exist
|
|
[pathArg]: { path: '/non/existent/worktree/path', branch: 'feature/deleted-branch' },
|
|
},
|
|
worktreesByProject: {},
|
|
},
|
|
version: 2, // Must match app-store.ts persist version
|
|
};
|
|
|
|
localStorage.setItem('automaker-storage', JSON.stringify(mockState));
|
|
|
|
// Mark setup as complete to skip the setup wizard
|
|
const setupState = {
|
|
state: {
|
|
isFirstRun: false,
|
|
setupComplete: true,
|
|
currentStep: 'complete',
|
|
skipClaudeSetup: false,
|
|
},
|
|
version: 0, // setup-store.ts doesn't specify a version, so zustand defaults to 0
|
|
};
|
|
localStorage.setItem('automaker-setup', JSON.stringify(setupState));
|
|
|
|
// Disable splash screen in tests
|
|
localStorage.setItem('automaker-disable-splash', 'true');
|
|
}, projectPath);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Wait Utilities
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Wait for the board view to load
|
|
* Navigates to /board first since the index route shows WelcomeView
|
|
* Handles zustand store hydration timing (may show "no-project" briefly)
|
|
*/
|
|
export async function waitForBoardView(page: Page): Promise<void> {
|
|
// Navigate directly to /board route (index route shows welcome view)
|
|
const currentUrl = page.url();
|
|
if (!currentUrl.includes('/board')) {
|
|
await page.goto('/board');
|
|
await page.waitForLoadState('load');
|
|
}
|
|
|
|
// Wait for either board-view (success) or board-view-no-project (store not hydrated yet)
|
|
// Then poll until board-view appears (zustand hydrates from localStorage)
|
|
await page.waitForFunction(
|
|
() => {
|
|
const boardView = document.querySelector('[data-testid="board-view"]');
|
|
// Return true only when board-view is visible (store hydrated with project)
|
|
return boardView !== null;
|
|
},
|
|
{ timeout: TIMEOUTS.long }
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Wait for the worktree selector to be visible
|
|
*/
|
|
export async function waitForWorktreeSelector(page: Page): Promise<void> {
|
|
await page
|
|
.waitForSelector('[data-testid="worktree-selector"]', { timeout: TIMEOUTS.medium })
|
|
.catch(() => {
|
|
// Fallback: wait for "Branch:" text
|
|
return page.getByText('Branch:').waitFor({ timeout: TIMEOUTS.medium });
|
|
});
|
|
}
|