@@ -3,7 +3,7 @@ import * as os from "os"
33import * as fs from "fs/promises"
44import { readFileSync } from "fs"
55
6- import { runTests } from "@vscode/test-electron"
6+ import { downloadAndUnzipVSCode , runTests } from "@vscode/test-electron"
77import { LLMock } from "@copilotkit/aimock"
88
99import { addApplyDiffResultFixtures } from "./fixtures/apply-diff"
@@ -21,6 +21,8 @@ import { addSearchFilesResultFixtures } from "./fixtures/search-files"
2121import { addSubtaskFixtures } from "./fixtures/subtasks"
2222import { addUseMcpToolResultFixtures } from "./fixtures/use-mcp-tool"
2323import { addWriteToFileResultFixtures } from "./fixtures/write-to-file"
24+ import { createScenarioWorkspace , removeScenarioWorkspace } from "./restart/scenarioWorkspace"
25+ import { runRestartScenario } from "./restart/vscodeCoordinator"
2426
2527function getCliFlagValue ( flag : string ) {
2628 return process . argv . find ( ( arg , index ) => process . argv [ index - 1 ] === flag )
@@ -43,13 +45,18 @@ function isBedrockTargetedRun(testFile?: string, testGrep?: string) {
4345 return testGrep ?. toLowerCase ( ) . includes ( "bedrock" ) ?? false
4446}
4547
48+ function isRestartPersistenceTargetedRun ( testFile ?: string ) : boolean {
49+ return testFile ?. toLowerCase ( ) . includes ( "restart-persistence" ) ?? false
50+ }
51+
4652async function main ( ) {
4753 const isRecord = process . env . AIMOCK_RECORD === "true"
4854 const testGrep = getCliFlagValue ( "--grep" ) || process . env . TEST_GREP
4955 const testFile = getCliFlagValue ( "--file" ) || process . env . TEST_FILE
5056 const isDeepSeekTest = isDeepSeekTargetedRun ( testFile , testGrep )
5157 const isGeminiTest = testFile ?. toLowerCase ( ) . includes ( "gemini.test" ) ?? false
5258 const isBedrockTest = isBedrockTargetedRun ( testFile , testGrep )
59+ const isRestartPersistenceTest = isRestartPersistenceTargetedRun ( testFile )
5360
5461 if ( isRecord && isDeepSeekTest && ! process . env . DEEPSEEK_API_KEY ) {
5562 throw new Error ( "AIMOCK_RECORD=true requires DEEPSEEK_API_KEY to record DeepSeek fixtures" )
@@ -83,11 +90,14 @@ async function main() {
8390 const extensionTestsPath = path . resolve ( __dirname , "./suite/index" )
8491
8592 let testWorkspace : string | undefined
93+ let scenarioWorkspace : Awaited < ReturnType < typeof createScenarioWorkspace > > | undefined
8694
8795 try {
88- // Create a temporary workspace folder for tests before installing fixtures that
89- // need workspace-specific paths.
90- testWorkspace = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "roo-test-workspace-" ) )
96+ // Create a temporary workspace folder for regular tests. Restart scenarios own
97+ // all of their paths under the dedicated scenario root below.
98+ if ( ! isRestartPersistenceTest ) {
99+ testWorkspace = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "roo-test-workspace-" ) )
100+ }
91101
92102 if ( useMock ) {
93103 const fixturesDir = path . resolve ( __dirname , "../fixtures" )
@@ -173,20 +183,46 @@ async function main() {
173183 const pkg = JSON . parse ( readFileSync ( path . resolve ( __dirname , "../package.json" ) , "utf-8" ) )
174184 const vscodeVersion = process . env . VSCODE_VERSION || pkg . devDependencies [ "@types/vscode" ]
175185
176- await runTests ( {
177- extensionDevelopmentPath,
178- extensionTestsPath,
179- launchArgs : [ testWorkspace ] ,
180- extensionTestsEnv,
181- version : vscodeVersion ,
182- } )
186+ if ( isRestartPersistenceTest ) {
187+ scenarioWorkspace = await createScenarioWorkspace ( )
188+ const vscodeExecutablePath = await downloadAndUnzipVSCode ( {
189+ version : vscodeVersion ,
190+ extensionDevelopmentPath,
191+ } )
192+ await runRestartScenario ( {
193+ vscodeExecutablePath,
194+ extensionDevelopmentPath,
195+ extensionTestsPath,
196+ scenario : "restart-persistence" ,
197+ workspace : scenarioWorkspace ,
198+ environment : extensionTestsEnv ,
199+ expectedExitPolicies : [
200+ { phase : "create" , termination : "graceful-quit" , code : 1 , signal : null } ,
201+ { phase : "verify" , termination : "graceful-quit" , code : 1 , signal : null } ,
202+ ] ,
203+ } )
204+ } else {
205+ if ( ! testWorkspace ) {
206+ throw new Error ( "Regular E2E runs require a temporary test workspace" )
207+ }
208+ await runTests ( {
209+ extensionDevelopmentPath,
210+ extensionTestsPath,
211+ launchArgs : [ testWorkspace ] ,
212+ extensionTestsEnv,
213+ version : vscodeVersion ,
214+ } )
215+ }
183216 } catch ( error ) {
184217 console . error ( "Failed to run tests" , error )
185218 process . exitCode = 1
186219 } finally {
187220 if ( testWorkspace ) {
188221 await fs . rm ( testWorkspace , { recursive : true , force : true } )
189222 }
223+ if ( scenarioWorkspace ) {
224+ await removeScenarioWorkspace ( scenarioWorkspace )
225+ }
190226 await mock ?. stop ( )
191227 }
192228}
0 commit comments