|
| 1 | +/** |
| 2 | + * Integration tests for the TUI create-project wizard. |
| 3 | + * |
| 4 | + * These tests launch the agentcore CLI in a headless PTY session and drive |
| 5 | + * through the interactive project creation flow: entering a project name, |
| 6 | + * optionally adding an agent (stepping through the full agent wizard), and |
| 7 | + * verifying that the project is created successfully on disk. |
| 8 | + * |
| 9 | + * All tests are wrapped in describe.skipIf(!isAvailable) so they are |
| 10 | + * gracefully skipped when node-pty is not available. |
| 11 | + */ |
| 12 | +import { TuiSession, isAvailable } from '../../src/tui-harness/index.js'; |
| 13 | +import { realpathSync } from 'fs'; |
| 14 | +import { mkdtemp, rm } from 'fs/promises'; |
| 15 | +import { tmpdir } from 'os'; |
| 16 | +import { join } from 'path'; |
| 17 | +import { afterEach, describe, expect, it } from 'vitest'; |
| 18 | + |
| 19 | +describe.skipIf(!isAvailable)('create wizard TUI flow', () => { |
| 20 | + const CLI_ENTRY = join(process.cwd(), 'dist/cli/index.mjs'); |
| 21 | + |
| 22 | + let session: TuiSession | undefined; |
| 23 | + let tempDir: string | undefined; |
| 24 | + |
| 25 | + afterEach(async () => { |
| 26 | + if (session?.alive) await session.close(); |
| 27 | + session = undefined; |
| 28 | + if (tempDir) { |
| 29 | + // eslint-disable-next-line @typescript-eslint/no-empty-function |
| 30 | + await rm(tempDir, { recursive: true, force: true }).catch(() => {}); |
| 31 | + tempDir = undefined; |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + // --------------------------------------------------------------------------- |
| 36 | + // (a) Full create wizard — create project with agent |
| 37 | + // --------------------------------------------------------------------------- |
| 38 | + it('creates a project with an agent through the full wizard', async () => { |
| 39 | + tempDir = realpathSync(await mkdtemp(join(tmpdir(), 'tui-create-'))); |
| 40 | + |
| 41 | + session = await TuiSession.launch({ |
| 42 | + command: 'node', |
| 43 | + args: [CLI_ENTRY], |
| 44 | + cwd: tempDir, |
| 45 | + cols: 120, |
| 46 | + rows: 40, |
| 47 | + }); |
| 48 | + |
| 49 | + // Step 1: HomeScreen — no project found |
| 50 | + await session.waitFor('No AgentCore project found', 15000); |
| 51 | + |
| 52 | + // Step 2: Press enter to navigate to CreateScreen |
| 53 | + await session.sendSpecialKey('enter'); |
| 54 | + |
| 55 | + // Step 3: Wait for the project name prompt |
| 56 | + await session.waitFor('Project name', 10000); |
| 57 | + |
| 58 | + // Step 4: Type the project name and submit |
| 59 | + await session.sendKeys('testproject'); |
| 60 | + await session.sendSpecialKey('enter'); |
| 61 | + |
| 62 | + // Step 5: Wait for the "add agent" prompt |
| 63 | + await session.waitFor('Would you like to add an agent now?', 10000); |
| 64 | + |
| 65 | + // Step 6: Select "Yes, add an agent" (first option — just press enter) |
| 66 | + await session.sendSpecialKey('enter'); |
| 67 | + |
| 68 | + // Step 7: Agent name prompt |
| 69 | + await session.waitFor('Agent name', 10000); |
| 70 | + |
| 71 | + // Step 8: Accept default agent name |
| 72 | + await session.sendSpecialKey('enter'); |
| 73 | + |
| 74 | + // Step 9: Agent type selection |
| 75 | + await session.waitFor('Select agent type', 10000); |
| 76 | + |
| 77 | + // Step 10: Select first option (Create new agent) |
| 78 | + await session.sendSpecialKey('enter'); |
| 79 | + |
| 80 | + // Step 11: Language selection |
| 81 | + await session.waitFor(/Python|Select language/, 10000); |
| 82 | + |
| 83 | + // Step 12: Select Python (first option) |
| 84 | + await session.sendSpecialKey('enter'); |
| 85 | + |
| 86 | + // Step 13: Build type selection |
| 87 | + await session.waitFor(/build|CodeZip|Container|Direct Code Deploy/i, 10000); |
| 88 | + |
| 89 | + // Step 14: Select first build type |
| 90 | + await session.sendSpecialKey('enter'); |
| 91 | + |
| 92 | + // Step 15: Framework selection |
| 93 | + await session.waitFor(/Strands|Select.*framework|Select/i, 10000); |
| 94 | + |
| 95 | + // Step 16: Select first framework |
| 96 | + await session.sendSpecialKey('enter'); |
| 97 | + |
| 98 | + // Step 17: Model provider selection |
| 99 | + await session.waitFor(/Bedrock|Select.*model|model.*provider/i, 10000); |
| 100 | + |
| 101 | + // Step 18: Select first model provider |
| 102 | + await session.sendSpecialKey('enter'); |
| 103 | + |
| 104 | + // Step 19: Memory selection — some model providers may insert an API key |
| 105 | + // step before this. Wait for either memory or API key text. |
| 106 | + const memoryOrApiKeyScreen = await session.waitFor(/memory|api.?key|Review Configuration/i, 10000); |
| 107 | + |
| 108 | + const memoryOrApiKeyText = memoryOrApiKeyScreen.lines.join('\n'); |
| 109 | + |
| 110 | + if (/api.?key/i.test(memoryOrApiKeyText)) { |
| 111 | + // API key step — accept default / skip |
| 112 | + await session.sendSpecialKey('enter'); |
| 113 | + // Now wait for memory |
| 114 | + await session.waitFor(/memory|Review Configuration/i, 10000); |
| 115 | + } |
| 116 | + |
| 117 | + // If we landed on memory selection (not yet at Review), select first option |
| 118 | + const currentScreen = session.readScreen(); |
| 119 | + const currentText = currentScreen.lines.join('\n'); |
| 120 | + |
| 121 | + if (!/Review Configuration/i.test(currentText)) { |
| 122 | + await session.sendSpecialKey('enter'); |
| 123 | + } |
| 124 | + |
| 125 | + // Step 20: Review and confirm |
| 126 | + await session.waitFor('Review Configuration', 10000); |
| 127 | + await session.sendSpecialKey('enter'); |
| 128 | + |
| 129 | + // Step 21: Wait for project creation to complete (generous timeout) |
| 130 | + const successScreen = await session.waitFor('Project created successfully', 30000); |
| 131 | + |
| 132 | + const successText = successScreen.lines.join('\n'); |
| 133 | + expect(successText).toContain('Project created successfully'); |
| 134 | + }, 120_000); |
| 135 | + |
| 136 | + // --------------------------------------------------------------------------- |
| 137 | + // (b) Create wizard — skip agent creation |
| 138 | + // --------------------------------------------------------------------------- |
| 139 | + it('creates a project without adding an agent', async () => { |
| 140 | + tempDir = realpathSync(await mkdtemp(join(tmpdir(), 'tui-create-skip-'))); |
| 141 | + |
| 142 | + session = await TuiSession.launch({ |
| 143 | + command: 'node', |
| 144 | + args: [CLI_ENTRY], |
| 145 | + cwd: tempDir, |
| 146 | + cols: 120, |
| 147 | + rows: 40, |
| 148 | + }); |
| 149 | + |
| 150 | + // HomeScreen |
| 151 | + await session.waitFor('No AgentCore project found', 15000); |
| 152 | + |
| 153 | + // Navigate to CreateScreen |
| 154 | + await session.sendSpecialKey('enter'); |
| 155 | + |
| 156 | + // Project name prompt |
| 157 | + await session.waitFor('Project name', 10000); |
| 158 | + |
| 159 | + // Type project name and submit |
| 160 | + await session.sendKeys('skiptest'); |
| 161 | + await session.sendSpecialKey('enter'); |
| 162 | + |
| 163 | + // Wait for the "add agent" prompt |
| 164 | + await session.waitFor('Would you like to add an agent now?', 10000); |
| 165 | + |
| 166 | + // Move to "No, I'll do it later" and select it |
| 167 | + await session.sendSpecialKey('down'); |
| 168 | + await session.sendSpecialKey('enter'); |
| 169 | + |
| 170 | + // Wait for project creation to complete |
| 171 | + const successScreen = await session.waitFor('Project created successfully', 30000); |
| 172 | + |
| 173 | + const successText = successScreen.lines.join('\n'); |
| 174 | + expect(successText).toContain('Project created successfully'); |
| 175 | + }); |
| 176 | + |
| 177 | + // --------------------------------------------------------------------------- |
| 178 | + // (c) Back navigation during wizard |
| 179 | + // --------------------------------------------------------------------------- |
| 180 | + it('navigates back from CreateScreen to HelpScreen with escape', async () => { |
| 181 | + tempDir = realpathSync(await mkdtemp(join(tmpdir(), 'tui-create-back-'))); |
| 182 | + |
| 183 | + session = await TuiSession.launch({ |
| 184 | + command: 'node', |
| 185 | + args: [CLI_ENTRY], |
| 186 | + cwd: tempDir, |
| 187 | + cols: 120, |
| 188 | + rows: 40, |
| 189 | + }); |
| 190 | + |
| 191 | + // HomeScreen |
| 192 | + await session.waitFor('No AgentCore project found', 15000); |
| 193 | + |
| 194 | + // Navigate to CreateScreen |
| 195 | + await session.sendSpecialKey('enter'); |
| 196 | + |
| 197 | + // Confirm we are on the CreateScreen |
| 198 | + await session.waitFor('Project name', 10000); |
| 199 | + |
| 200 | + // Press escape to go back |
| 201 | + await session.sendSpecialKey('escape'); |
| 202 | + |
| 203 | + // Verify we are back on HelpScreen |
| 204 | + const homeScreen = await session.waitFor('Commands', 10000); |
| 205 | + |
| 206 | + const homeText = homeScreen.lines.join('\n'); |
| 207 | + expect(homeText).toContain('Commands'); |
| 208 | + }); |
| 209 | +}); |
0 commit comments