Skip to content

Commit

Permalink
WIP platform trickyness
Browse files Browse the repository at this point in the history
  • Loading branch information
RXminuS committed Jul 2, 2024
1 parent 0e92314 commit ea7ca7a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 43 additions & 12 deletions vscode/e2e/utils/vscody/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const workerOptionsSchema = zod.object({
recordingDir: zod.string(),
vscodeServerPortRange: zod.tuple([zod.number(), zod.number()]).default([33100, 33200]),
keepRuntimeDirs: zod.enum(['all', 'failed', 'none']).default('none'),
allowGlobalVSCodeModification: zod.boolean().default(false),
})

const testOptionsSchema = zod.object({
Expand Down Expand Up @@ -124,6 +125,7 @@ const optionsFixture: ReturnType<
vscodeExtensionCacheDir,
keepRuntimeDirs,
vscodeServerPortRange,
allowGlobalVSCodeModification,
},
use
) => {
Expand All @@ -138,6 +140,7 @@ const optionsFixture: ReturnType<
vscodeExtensionCacheDir,
keepRuntimeDirs,
vscodeServerPortRange,
allowGlobalVSCodeModification,
} satisfies { [key in keyof WorkerOptions]-?: WorkerOptions[key] },
{}
)
Expand Down Expand Up @@ -374,18 +377,14 @@ const implFixture = _test.extend<TestContext, WorkerContext>({
const serverExecutableDir = path.resolve(process.cwd(), validOptions.vscodeServerTmpDir)
await fs.mkdir(serverExecutableDir, { recursive: true })
// We nullify the time it takes to download VSCode as it can vary wildly!
const electronExecutable = await stretchTimeout(
const [codeCliPath, codeTunnelCliPath] = await stretchTimeout(
() => downloadOrWaitForVSCode({ validOptions, executableDir }),
{
max: DOWNLOAD_GRACE_TIME,
testInfo,
}
)
let [cliPath] = resolveCliArgsFromVSCodeExecutablePath(electronExecutable)
//replce code with code-tunnel(.exe) either if the last binary or if code.exe
cliPath = cliPath
.replace(/code$/, 'code-tunnel')
.replace(/code\.(?:exe|cmd)$/, 'code-tunnel.exe')

// Machine settings should simply serve as a baseline to ensure
// tests by default work smoothly. Any test specific preferences
// should be set in workspace settings instead.
Expand Down Expand Up @@ -439,14 +438,20 @@ const implFixture = _test.extend<TestContext, WorkerContext>({
const args = [
...validOptions.vscodeExtensions.flatMap(v => ['--install-extension', v]),
]
await pspawn(cliPath, args, {
const res = await pspawn(codeTunnelCliPath, args, {
env: {
...process.env,
// VSCODE_EXTENSIONS: sharedExtensionsDir, This doesn't work either
},
stdio: ['inherit', 'ignore', 'inherit'],
stdio: ['inherit', 'inherit', 'inherit'],
})
} catch (e) {
console.log('I AM HERE')
if (
typeof e === 'string' &&
e.includes('code version use stable --install-dir /path/to/installation')
) {
}
console.error(e)
throw e
} finally {
Expand Down Expand Up @@ -494,7 +499,7 @@ const implFixture = _test.extend<TestContext, WorkerContext>({
CODY_TESTING_BFG_DIR: path.resolve(process.cwd(), validOptions.binaryTmpDir),
CODY_TESTING_SYMF_DIR: path.resolve(process.cwd(), validOptions.binaryTmpDir),
}
const codeProcess = spawn(cliPath, args, {
const codeProcess = spawn(codeTunnelCliPath, args, {
env,
stdio: ['inherit', 'ignore', 'inherit'],
detached: false,
Expand Down Expand Up @@ -624,20 +629,46 @@ async function downloadOrWaitForVSCode({
executableDir,
validOptions,
}: Pick<TestContext, 'validOptions'> & { executableDir: string }) {
let electronExecutable = ''
const lockfilePath = path.join(executableDir, '.lock')
const releaseLock = await waitForLock(executableDir, { lockfilePath, delay: 500 })

try {
electronExecutable = await downloadAndUnzipVSCode({
const electronPath = await downloadAndUnzipVSCode({
cachePath: executableDir,
version: 'stable',
reporter: new CustomConsoleReporter(process.stdout.isTTY),
})
const installPath = path.join(
executableDir,
path.relative(executableDir, electronPath).split(path.sep)[0]
)
const [cliPath] = resolveCliArgsFromVSCodeExecutablePath(electronPath)
//replce code with code-tunnel(.exe) either if the last binary or if code.exe
const tunnelPath = cliPath
.replace(/code$/, 'code-tunnel')
.replace(/code\.(?:exe|cmd)$/, 'code-tunnel.exe')

// we need to make sure vscode has global configuration set
const res = await pspawn(tunnelPath, ['version', 'show'], {
stdio: ['inherit', 'pipe', 'inherit'],
})
if (res.code !== 0 || res.stdout.includes('No existing installation found')) {
if (!validOptions.allowGlobalVSCodeModification) {
throw new Error('Global VSCode path modification is not allowed')
}
await pspawn(tunnelPath, ['version', 'use', 'stable', '--install-dir', installPath], {
stdio: ['inherit', 'inherit', 'inherit'],
})
} else if (res.code !== 0) {
throw new Error(JSON.stringify(res))
}
return [cliPath, tunnelPath]
//If this fails I assume we haven't configured VSCode globally. Since
//getting portable mode to work is annoying we just set this
//installation as the global one.
} finally {
releaseLock()
}
return electronExecutable
}

async function getFilesRecursive(dir: string): Promise<Array<Dirent>> {
Expand Down
1 change: 1 addition & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@
"progress": "^2.0.3",
"react-head": "^3.4.2",
"typescript-language-server": "^4.3.3",
"ulidx": "^2.3.0",
"vite-plugin-svgr": "^4.2.0",
"vscode-jsonrpc": "^8.2.0",
"vscode-languageserver-protocol": "^3.17.5",
Expand Down
5 changes: 4 additions & 1 deletion vscode/playwright.v2.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { mkdirSync, readdirSync, rmSync } from 'node:fs'
import * as os from 'node:os'
import * as path from 'node:path'
import { type ReporterDescription, defineConfig } from '@playwright/test'
import { ulid } from 'ulidx'
import type { SymlinkExtensions } from './e2e/utils/symlink-extensions.setup'
import type { TestOptions, WorkerOptions } from './e2e/utils/vscody'

const isWin = process.platform.startsWith('win')
const isCI = !!process.env.CI

// This makes sure that each run gets a unique run id. This shouldn't really be
// used other than to invalidate lockfiles etc.
process.env.RUN_ID = process.env.RUN_ID || new Date().toISOString()
process.env.RUN_ID = process.env.RUN_ID || ulid()

const globalTmpDir = path.resolve(__dirname, `../.test/runs/${process.env.RUN_ID}/`)
mkdirSync(globalTmpDir, { recursive: true })
Expand Down Expand Up @@ -58,6 +60,7 @@ export default defineConfig<WorkerOptions & TestOptions & SymlinkExtensions>({
geolocation: { longitude: -122.40825783227943, latitude: 37.78124453182266 },
acceptDownloads: false,
keepRuntimeDirs: 'all',
allowGlobalVSCodeModification: isCI,
trace: {
mode: isCI ? 'retain-on-failure' : 'on',
attachments: true,
Expand Down

0 comments on commit ea7ca7a

Please sign in to comment.