File size: 5,598 Bytes
1dbc34b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #!/usr/bin/env node
/**
* Setup script for E2E test fixtures
* Creates the necessary test fixture directories and files before running Playwright tests
* Also resets the server's settings.json to a known state for test isolation
*/
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Resolve workspace root (apps/ui/scripts -> workspace root)
const WORKSPACE_ROOT = path.resolve(__dirname, '../../..');
const FIXTURE_PATH = path.join(WORKSPACE_ROOT, 'test/fixtures/projectA');
const SPEC_FILE_PATH = path.join(FIXTURE_PATH, '.automaker/app_spec.txt');
const CONTEXT_DIR = path.join(FIXTURE_PATH, '.automaker/context');
const CONTEXT_METADATA_PATH = path.join(CONTEXT_DIR, 'context-metadata.json');
const SERVER_SETTINGS_PATH = path.join(WORKSPACE_ROOT, 'apps/server/data/settings.json');
// Create a shared test workspace directory that will be used as default for project creation
const TEST_WORKSPACE_DIR = path.join(os.tmpdir(), 'automaker-e2e-workspace');
const SPEC_CONTENT = `<app_spec>
<name>Test Project A</name>
<description>A test fixture project for Playwright testing</description>
<tech_stack>
<item>TypeScript</item>
<item>React</item>
</tech_stack>
</app_spec>
`;
// Clean settings.json for E2E tests - no current project so localStorage can control state
const E2E_SETTINGS = {
version: 4,
setupComplete: true,
isFirstRun: false,
skipClaudeSetup: false,
theme: 'dark',
sidebarOpen: true,
chatHistoryOpen: false,
maxConcurrency: 3,
defaultSkipTests: true,
enableDependencyBlocking: true,
skipVerificationInAutoMode: false,
useWorktrees: true,
defaultPlanningMode: 'skip',
defaultRequirePlanApproval: false,
muteDoneSound: false,
phaseModels: {
enhancementModel: { model: 'sonnet' },
fileDescriptionModel: { model: 'haiku' },
imageDescriptionModel: { model: 'haiku' },
validationModel: { model: 'sonnet' },
specGenerationModel: { model: 'opus' },
featureGenerationModel: { model: 'sonnet' },
backlogPlanningModel: { model: 'sonnet' },
projectAnalysisModel: { model: 'sonnet' },
ideationModel: { model: 'sonnet' },
},
enhancementModel: 'sonnet',
validationModel: 'opus',
enabledCursorModels: ['auto', 'composer-1'],
cursorDefaultModel: 'auto',
keyboardShortcuts: {
board: 'K',
agent: 'A',
spec: 'D',
context: 'C',
settings: 'S',
terminal: 'T',
toggleSidebar: '`',
addFeature: 'N',
addContextFile: 'N',
startNext: 'G',
newSession: 'N',
openProject: 'O',
projectPicker: 'P',
cyclePrevProject: 'Q',
cycleNextProject: 'E',
splitTerminalRight: 'Alt+D',
splitTerminalDown: 'Alt+S',
closeTerminal: 'Alt+W',
tools: 'T',
ideation: 'I',
githubIssues: 'G',
githubPrs: 'R',
newTerminalTab: 'Alt+T',
},
// Default test project using the fixture path - tests can override via route mocking if needed
projects: [
{
id: 'e2e-default-project',
name: 'E2E Test Project',
path: FIXTURE_PATH,
lastOpened: new Date().toISOString(),
},
],
trashedProjects: [],
currentProjectId: 'e2e-default-project',
projectHistory: [],
projectHistoryIndex: 0,
lastProjectDir: TEST_WORKSPACE_DIR,
recentFolders: [],
worktreePanelCollapsed: false,
lastSelectedSessionByProject: {},
autoLoadClaudeMd: false,
skipSandboxWarning: true,
codexAutoLoadAgents: false,
codexSandboxMode: 'workspace-write',
codexApprovalPolicy: 'on-request',
codexEnableWebSearch: false,
codexEnableImages: true,
codexAdditionalDirs: [],
mcpServers: [],
enableSandboxMode: false,
mcpAutoApproveTools: true,
mcpUnrestrictedTools: true,
promptCustomization: {},
localStorageMigrated: true,
};
function setupFixtures() {
console.log('Setting up E2E test fixtures...');
console.log(`Workspace root: ${WORKSPACE_ROOT}`);
console.log(`Fixture path: ${FIXTURE_PATH}`);
console.log(`Test workspace dir: ${TEST_WORKSPACE_DIR}`);
// Create test workspace directory for project creation tests
if (!fs.existsSync(TEST_WORKSPACE_DIR)) {
fs.mkdirSync(TEST_WORKSPACE_DIR, { recursive: true });
console.log(`Created test workspace directory: ${TEST_WORKSPACE_DIR}`);
}
// Create fixture directory
const specDir = path.dirname(SPEC_FILE_PATH);
if (!fs.existsSync(specDir)) {
fs.mkdirSync(specDir, { recursive: true });
console.log(`Created directory: ${specDir}`);
}
// Create app_spec.txt
fs.writeFileSync(SPEC_FILE_PATH, SPEC_CONTENT);
console.log(`Created fixture file: ${SPEC_FILE_PATH}`);
// Create .automaker/context and context-metadata.json (expected by context view / FS read)
if (!fs.existsSync(CONTEXT_DIR)) {
fs.mkdirSync(CONTEXT_DIR, { recursive: true });
console.log(`Created directory: ${CONTEXT_DIR}`);
}
fs.writeFileSync(CONTEXT_METADATA_PATH, JSON.stringify({ files: {} }, null, 2));
console.log(`Created fixture file: ${CONTEXT_METADATA_PATH}`);
// Reset server settings.json to a clean state for E2E tests
const settingsDir = path.dirname(SERVER_SETTINGS_PATH);
if (!fs.existsSync(settingsDir)) {
fs.mkdirSync(settingsDir, { recursive: true });
console.log(`Created directory: ${settingsDir}`);
}
fs.writeFileSync(SERVER_SETTINGS_PATH, JSON.stringify(E2E_SETTINGS, null, 2));
console.log(`Reset server settings: ${SERVER_SETTINGS_PATH}`);
console.log('E2E test fixtures setup complete!');
}
setupFixtures();
|