Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Response from https://update.code.visualstudio.com/api/versions/commit:<commit>/<target>/<quality>
*/
interface
ITargetMetadata
{
:
string
;
:
string
;
:
string
;
:
string
;
:
string
;
:
number
;
:
string
;
:
boolean
;
}
/**
* Maps a sanity test target to the build pipeline artifact that carries it, for `--artifacts-dir`
* runs against builds that were never published. An unmapped target fails loudly rather than
* silently falling back to the update service.
*/
const
:
<
<
string
,
string
>>
=
{
'cli-alpine-arm64'
:
'vscode_cli_alpine_arm64_cli'
,
'cli-alpine-x64'
:
'vscode_cli_alpine_x64_cli'
,
'cli-darwin-arm64'
:
'vscode_cli_darwin_arm64_cli'
,
'cli-darwin-x64'
:
'vscode_cli_darwin_x64_cli'
,
'cli-linux-arm64'
:
'vscode_cli_linux_arm64_cli'
,
'cli-linux-armhf'
:
'vscode_cli_linux_armhf_cli'
,
'cli-linux-x64'
:
'vscode_cli_linux_x64_cli'
,
'cli-win32-arm64'
:
'vscode_cli_win32_arm64_cli'
,
'cli-win32-x64'
:
'vscode_cli_win32_x64_cli'
,
'darwin'
:
'vscode_client_darwin_x64_archive'
,
'darwin-arm64'
:
'vscode_client_darwin_arm64_archive'
,
'darwin-arm64-dmg'
:
'vscode_client_darwin_arm64_dmg'
,
'darwin-universal'
:
'vscode_client_darwin_universal_archive'
,
'darwin-universal-dmg'
:
'vscode_client_darwin_universal_dmg'
,
'darwin-x64-dmg'
:
'vscode_client_darwin_x64_dmg'
,
'linux-arm64'
:
'vscode_client_linux_arm64_archive-unsigned'
,
'linux-armhf'
:
'vscode_client_linux_armhf_archive-unsigned'
,
'linux-deb-arm64'
:
'vscode_client_linux_arm64_deb-package'
,
'linux-deb-armhf'
:
'vscode_client_linux_armhf_deb-package'
,
'linux-deb-x64'
:
'vscode_client_linux_x64_deb-package'
,
'linux-rpm-arm64'
:
'vscode_client_linux_arm64_rpm-package'
,
'linux-rpm-armhf'
:
'vscode_client_linux_armhf_rpm-package'
,
'linux-rpm-x64'
:
'vscode_client_linux_x64_rpm-package'
,
'linux-snap-x64'
:
'vscode_client_linux_x64_snap'
,
'linux-x64'
:
'vscode_client_linux_x64_archive-unsigned'
,
'server-alpine-arm64'
:
'vscode_server_alpine_arm64_archive-unsigned'
,
'server-alpine-arm64-web'
:
'vscode_web_alpine_arm64_archive-unsigned'
,
'server-darwin'
:
'vscode_server_darwin_x64_archive'
,
'server-darwin-arm64'
:
'vscode_server_darwin_arm64_archive'
,
'server-darwin-arm64-web'
:
'vscode_web_darwin_arm64_archive'
,
'server-darwin-web'
:
'vscode_web_darwin_x64_archive'
,
'server-linux-alpine'
:
'vscode_server_linux_alpine_archive-unsigned'
,
'server-linux-alpine-web'
:
'vscode_web_linux_alpine_archive-unsigned'
,
'server-linux-arm64'
:
'vscode_server_linux_arm64_archive-unsigned'
,
'server-linux-arm64-web'
:
'vscode_web_linux_arm64_archive-unsigned'
,
'server-linux-x64'
:
'vscode_server_linux_x64_archive-unsigned'
,
'server-linux-x64-web'
:
'vscode_web_linux_x64_archive-unsigned'
,
'server-win32-arm64'
:
'vscode_server_win32_arm64_archive'
,
'server-win32-arm64-web'
:
'vscode_web_win32_arm64_archive'
,
'server-win32-x64'
:
'vscode_server_win32_x64_archive'
,
'server-win32-x64-web'
:
'vscode_web_win32_x64_archive'
,
'win32-arm64'
:
'vscode_client_win32_arm64_setup'
,
'win32-arm64-archive'
:
'vscode_client_win32_arm64_archive'
,
'win32-arm64-user'
:
'vscode_client_win32_arm64_user-setup'
,
'win32-x64'
:
'vscode_client_win32_x64_setup'
,
'win32-x64-archive'
:
'vscode_client_win32_x64_archive'
,
'win32-x64-user'
:
'vscode_client_win32_x64_user-setup'
,
}
;
/**
* Provides context and utilities for VS Code sanity tests.
*/
/dpkg frontend lock was locked by another process|unable to acquire the dpkg frontend lock|could not get lock \/var\/lib\/dpkg\/lock-frontend/i
;
private
readonly
=
new
Set<string>
(
)
;
private
readonly
=
new
Set<string>
(
)
;
private
=
3010
;
private
:
string
|
undefined
;
private
=
0
;
private
:
number
|
undefined
;
private
:
string
|
undefined
;
public
constructor
(
public
readonly
:
<
{
:
'stable'
|
'insider'
|
'exploration'
;
:
string
;
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
string
|
undefined
;
:
string
|
undefined
;
:
string
|
undefined
;
}
>
)
{
}
/**
* Returns true if the current process is running as root.
*/
public
readonly
=
.
?.
(
)
===
0
;
/**
* Returns the detected capabilities of the current system.
*/
public
readonly
=
detectCapabilities
(
)
;
/**
* Returns the OS temp directory with expanded long names on Windows.
*/
public
readonly
=
(
(
)
=>
{
let
=
.
realpathSync
(
.
tmpdir
(
)
)
;
// On Windows, expand short 8.3 file names to long names
if
(
.
platform
(
)
===
'win32'
)
{
=
.
.
native
(
)
;
}
return
;
}
)
(
)
;
/**
* Runs a test only if the required capabilities are present.
* @paramname The name of the test.
* @paramrequire The required capabilities for the test.
* @paramfn The test function.
* @returns The Mocha test object or void if the test is skipped.
*/
public
test
(
:
string
,
require
:
[
]
,
fn
:
(
)
=>
Promise
<
void
>
)
:
.
|
void
{
if
(
!
this
.
.
&&
require
.
some
(
=>
!
this
.
.
has
(
)
)
)
{
return
;
}
const
=
this
;
return
test
(
,
async
function
(
)
{
.
=
;
.
=
0
;
.
log
(
`Starting test: ${name}`
)
;
const
=
.
homedir
(
)
;
.
chdir
(
)
;
.
log
(
`Changed working directory to: ${homeDir}`
)
;
try
{
await
fn
(
)
;
}
catch
(
)
{
.
log
(
`Test failed with error: ${error instanceofError? error.message :String(error)}`
)
;
throw
;
}
finally
{
.
=
undefined
;
.
chdir
(
)
;
.
log
(
`Changed working directory to: ${homeDir}`
)
;
if
(
.
.
)
{
.
cleanup
(
)
;
}
.
log
(
`Finished test: ${name}`
)
;
}
}
)
;
}
/**
* The console outputs collected during the current test.
*/
public
:
string
[
]
=
[
]
;
/**
* Logs a message with a timestamp.
*/
public
log
(
:
string
)
{
const
=
`[${newDate().toISOString()}] ${message}`
;
this
.
.
push
(
)
;
if
(
this
.
.
)
{
console
.
log
(
)
;
}
}
/**
* Logs an error message and throws an Error.
*/
/**
* Returns a promise that resolves after the specified delay in milliseconds.
* @paramdelay The delay in milliseconds to wait before resolving the promise.
*/
private
timeout
(
:
number
)
{
return
new
Promise
(
=>
setTimeout
(
,
)
)
;
}
/**
* Creates a new temporary directory and returns its path.
*/
public
createTempDir
(
)
:
string
{
const
=
.
mkdtempSync
(
.
join
(
this
.
,
'vscode-sanity'
)
)
;
this
.
log
(
`Created temp directory: ${tempDir}`
)
;
this
.
.
add
(
)
;
return
;
}
/**
* Creates a new temporary directory in WSL and returns its path.
*/
/**
* Deletes a directory in WSL.
* @paramdir The WSL directory path to delete.
*/
public
deleteWslDir
(
:
string
)
:
void
{
this
.
log
(
`Deleting WSL directory: ${dir}`
)
;
this
.
runNoErrors
(
'wsl'
,
'rm'
,
'-rf'
,
)
;
}
/**
* Converts a Windows path to a WSL path.
* @paramwindowsPath The Windows path to convert (e.g., 'C:\Users\test').
* @returns The WSL path (e.g., '/mnt/c/Users/test').
*/
public
toWslPath
(
:
string
)
:
string
{
return
.
replace
(
/^([A-Za-z]):/
,
(
,
)
=>
`/mnt/${drive.toLowerCase()}`
)
.
replaceAll
(
'\\'
,
'/'
)
;
}
/**
* Returns the name of the default WSL distribution.
* @returns The default WSL distribution name (e.g., 'Ubuntu').
*/
public
getDefaultWslDistro
(
)
:
string
{
const
=
this
.
runNoErrors
(
'wsl'
,
'--list'
,
'--quiet'
)
;
const
=
.
.
trim
(
)
.
split
(
'\n'
)
[
0
]
.
replace
(
/\0/g
,
''
)
.
trim
(
)
;
if
(
!
)
{
this
.
error
(
'No WSL distribution found'
)
;
}
this
.
log
(
`Default WSL distribution: ${distro}`
)
;
return
;
}
/**
* Returns the WSL version of the Ubuntu distribution, or undefined if not found.
*/
public
getUbuntuWslVersion
(
)
:
number
|
undefined
{
if
(
this
.
!==
undefined
)
{
return
this
.
;
}
const
=
this
.
runNoErrors
(
'wsl'
,
'--list'
,
'--verbose'
)
;
for
(
const
of
.
.
split
(
/\r?\n/
)
)
{
const
=
.
trim
(
)
;
if
(
!
||
/^NAME\s+STATE\s+VERSION$/i
.
test
(
)
)
{
continue
;
}
const
=
.
replace
(
/^\*\s*/
,
''
)
;
const
=
.
split
(
/\s+/
)
;
if
(
.
<
3
||
[
0
]
!==
'Ubuntu'
)
{
continue
;
}
const
=
Number
(
[
.
-
1
]
)
;
if
(
!
.
isNaN
(
)
)
{
this
.
=
;
return
this
.
;
}
}
return
undefined
;
}
/**
* Ensures that the directory for the specified file path exists.
*/
public
ensureDirExists
(
:
string
)
{
const
=
.
dirname
(
)
;
if
(
!
.
existsSync
(
)
)
{
.
mkdirSync
(
,
{
:
true
}
)
;
}
}
/**
* Cleans up all temporary directories created during the test run.
*/
public
cleanup
(
)
{
for
(
const
of
this
.
)
{
this
.
log
(
`Deleting temp directory: ${dir}`
)
;
try
{
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
this
.
log
(
`Deleted temp directory: ${dir}`
)
;
}
catch
(
)
{
this
.
warn
(
`Failed to delete temp directory: ${dir}: ${error}`
)
;
}
}
this
.
.
clear
(
)
;
for
(
const
of
this
.
)
{
try
{
this
.
deleteWslDir
(
)
;
}
catch
(
)
{
this
.
warn
(
`Failed to delete WSL temp directory: ${dir}: ${error}`
)
;
}
}
this
.
.
clear
(
)
;
}
/**
* Fetches a URL and ensures there are no errors.
* @paramurl The URL to fetch.
* @returns The fetch Response object.
*/
public
async
fetchNoErrors
(
:
string
)
:
Promise
<
&
{
:
.
}
>
{
const
=
5
;
let
:
|
undefined
;
for
(
let
=
0
;
<
;
++
)
{
if
(
>
0
)
{
const
=
.
pow
(
2
,
-
1
)
*
1000
;
this
.
warn
(
`Retrying fetch (attempt ${attempt +1}/${maxRetries}) after ${delay}ms`
)
;
await
this
.
timeout
(
)
;
}
try
{
const
=
await
fetch
(
)
;
if
(
!
.
)
{
=
new
Error
(
`Failed to fetch ${url}: ${response.status}${response.statusText}`
`Failed to fetch ${url} after ${maxRetries} attempts: ${lastError?.message}`
)
;
}
/**
* Fetches metadata for a specific VS Code release target.
* @paramtarget The target platform (e.g., 'cli-linux-x64').
* @returns The target metadata.
*/
`Invalid metadata response for ${target}: ${JSON.stringify(result)}`
)
;
}
this
.
log
(
`Fetched metadata for ${target}: ${JSON.stringify(result)}`
)
;
return
;
}
/**
* Downloads installer for specified VS Code release target.
* @paramtarget The target platform (e.g., 'cli-linux-x64').
* @returns The path to the downloaded file.
*/
public
async
downloadTarget
(
:
string
)
:
Promise
<
string
>
{
if
(
this
.
.
)
{
return
this
.
resolveArtifact
(
)
;
}
const
{
,
}
=
await
this
.
fetchMetadata
(
)
;
const
=
.
join
(
this
.
createTempDir
(
)
,
.
basename
(
)
)
;
this
.
log
(
`Downloading ${url} to ${filePath}`
)
;
this
.
runNoErrors
(
'curl'
,
'-fSL'
,
'--retry'
,
'5'
,
'--retry-delay'
,
'2'
,
'--retry-all-errors'
,
'-o'
,
,
)
;
this
.
log
(
`Downloaded ${url} to ${filePath}`
)
;
this
.
validateSha256Hash
(
,
)
;
return
;
}
/**
* Resolves a target from a directory of downloaded build pipeline artifacts, laid out as
* `<artifacts-dir>/<artifact-name>/<file>`. There is no update service metadata for these
* builds, so the SHA-256 check is skipped.
* @paramtarget The target platform (e.g., 'cli-linux-x64').
* @returns The path to the artifact file.
*/
private
resolveArtifact
(
:
string
)
:
string
{
const
=
[
]
;
if
(
!
)
{
this
.
error
(
`No pipeline artifact is mapped for target ${target}. Add it to 'targetArtifacts', or exclude the test from this run.`
)
;
}
const
=
.
join
(
this
.
.
!
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
error
(
`Artifact ${artifact} for target ${target} was not downloaded to ${artifactDir}`
)
;
}
const
:
string
[
]
=
[
]
;
this
.
collectFiles
(
,
,
true
)
;
if
(
.
!==
1
)
{
this
.
error
(
`Expected exactly one file in artifact ${artifact}, found ${files.length}: ${files.join(', ')}`
)
;
}
this
.
log
(
`Resolved target ${target} to ${files[0]} from artifact ${artifact}`
)
;
return
[
0
]
;
}
/**
* Collects all files from the specified directory recursively.
*/
private
collectFiles
(
:
string
,
:
string
[
]
,
=
false
)
:
void
{
for
(
const
of
.
readdirSync
(
,
{
:
true
}
)
)
{
const
=
.
join
(
,
.
)
;
if
(
.
isDirectory
(
)
)
{
if
(
!
||
.
!==
'_manifest'
)
{
this
.
collectFiles
(
,
,
)
;
}
}
else
{
.
push
(
)
;
}
}
}
/**
* Validates the SHA-256 hash of a file.
* @paramfilePath The path to the file to validate.
* @paramexpectedHash The expected SHA-256 hash in hexadecimal format.
*/
public
validateSha256Hash
(
:
string
,
:
string
)
{
this
.
log
(
`Validating SHA256 hash for ${filePath}`
)
;
const
=
.
readFileSync
(
)
;
const
=
createHash
(
'sha256'
)
.
update
(
)
.
digest
(
'hex'
)
;
if
(
!==
)
{
this
.
error
(
`Hash mismatch for ${filePath}: expected ${expectedHash}, got ${hash}`
)
;
}
}
/**
* Validates every Authenticode signature of a Windows executable.
* @paramfilePath The path to the file to validate.
*/
public
validateAuthenticodeSignature
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'windows'
)
)
{
this
.
log
(
`Skipping Authenticode signature validation for ${filePath} (signing checks disabled)`
)
;
return
;
}
this
.
log
(
`Validating Authenticode signature for ${filePath}`
`Failed to validate Authenticode signatures for ${filePath}: ${result.error.message}`
)
;
}
const
=
`${result.stdout}\n${result.stderr}`
.
trim
(
)
;
if
(
.
.
test
(
)
)
{
this
.
error
(
`Authenticode signature uses a test certificate for ${filePath}`
)
;
}
if
(
.
!==
0
)
{
this
.
error
(
`Not all Authenticode signatures are valid for ${filePath}${details ?`:\n${details}`:''}`
)
;
}
this
.
log
(
`All Authenticode signatures are valid for ${filePath}`
)
;
}
/**
* Collects all files matching the Authenticode include pattern from the specified directory recursively.
*/
private
collectAuthenticodeFiles
(
:
string
,
:
string
[
]
)
:
void
{
const
=
.
readdirSync
(
,
{
:
true
}
)
;
for
(
const
of
)
{
const
=
.
join
(
,
.
)
;
if
(
.
isDirectory
(
)
)
{
this
.
collectAuthenticodeFiles
(
,
)
;
}
else
if
(
.
.
test
(
.
)
)
{
if
(
.
.
test
(
)
)
{
this
.
log
(
`Skipping excluded file from Authenticode validation: ${filePath}`
)
;
}
else
{
.
push
(
)
;
}
}
}
}
/**
* Validates Authenticode signatures for all executable files in the specified directory.
* @paramdir The directory to scan for executable files.
*/
public
validateAllAuthenticodeSignatures
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'windows'
)
)
{
this
.
log
(
`Skipping Authenticode signature validation for ${dir} (signing checks disabled)`
)
;
return
;
}
const
:
string
[
]
=
[
]
;
this
.
collectAuthenticodeFiles
(
,
)
;
this
.
log
(
`Found ${files.length} file(s) to validate Authenticode signatures`
)
;
for
(
const
of
)
{
this
.
validateAuthenticodeSignature
(
)
;
}
}
/**
* Collects all files matching the VersionInfo include pattern from the specified directory recursively.
*/
private
collectVersionInfoFiles
(
:
string
,
:
string
[
]
)
:
void
{
const
=
.
readdirSync
(
,
{
:
true
}
)
;
for
(
const
of
)
{
const
=
.
join
(
,
.
)
;
if
(
.
isDirectory
(
)
)
{
this
.
collectVersionInfoFiles
(
,
)
;
}
else
if
(
.
.
test
(
.
)
)
{
if
(
.
.
test
(
.
)
||
.
.
test
(
)
)
{
this
.
log
(
`Skipping excluded file from VersionInfo validation: ${filePath}`
)
;
}
else
{
.
push
(
)
;
}
}
}
}
/**
* Validates that a Windows binary has a non-empty ProductName in VersionInfo.
* @paramfilePath The path to the file to validate.
*/
public
validateVersionInfo
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'windows'
)
)
{
this
.
log
(
`Skipping VersionInfo validation for ${filePath} (signing checks disabled)`
)
;
return
;
}
this
.
log
(
`Validating VersionInfo for ${filePath}`
)
;
this
.
validateVersionInfoForFiles
(
[
]
)
;
}
/**
* Validates VersionInfo ProductName for the specified list of files in a single PowerShell call.
*/
`VersionInfo ProductName is set for ${filePath}: ${productName.trim()}`
)
;
}
else
{
.
push
(
)
;
}
}
}
if
(
.
>
0
)
{
this
.
error
(
`VersionInfo ProductName is missing or empty for:\n${invalid.join('\n')}`
)
;
}
}
/**
* Validates that all .exe, .dll, .node and .msi binaries in the specified directory have a non-empty ProductName in VersionInfo.
* @paramdir The directory to scan for binary files.
*/
public
validateAllVersionInfo
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'windows'
)
)
{
this
.
log
(
`Skipping VersionInfo validation for ${dir} (signing checks disabled)`
)
;
return
;
}
const
:
string
[
]
=
[
]
;
this
.
collectVersionInfoFiles
(
,
)
;
this
.
log
(
`Found ${files.length} file(s) to validate VersionInfo`
)
;
this
.
validateVersionInfoForFiles
(
)
;
}
/**
* Validates the codesign signature of a macOS binary or app bundle.
* @paramfilePath The path to the file or app bundle to validate.
*/
public
validateCodesignSignature
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'darwin'
)
)
{
this
.
log
(
`Skipping codesign signature validation for ${filePath} (signing checks disabled)`
)
;
return
;
}
this
.
log
(
`Validating codesign signature for ${filePath}`
)
;
const
=
this
.
run
(
'codesign'
,
'--verify'
,
'--deep'
,
'--strict'
,
'--verbose=2'
,
)
;
if
(
.
!==
undefined
)
{
this
.
error
(
`Failed to run codesign: ${result.error.message}`
)
;
}
if
(
.
!==
0
)
{
this
.
error
(
`Codesign signature is not valid for ${filePath}: ${result.stderr}`
)
;
}
this
.
log
(
`Validating notarization for ${filePath}`
)
;
const
=
this
.
run
(
'spctl'
,
'--assess'
,
'--type'
,
'open'
,
'--context'
,
'context:primary-signature'
,
'--verbose=2'
,
)
;
if
(
.
!==
undefined
)
{
this
.
error
(
`Failed to run spctl: ${notaryResult.error.message}`
)
;
}
if
(
.
!==
0
)
{
this
.
error
(
`Notarization is not valid for ${filePath}: ${notaryResult.stderr}`
)
;
}
}
/**
* Validates codesign signatures for all Mach-O binaries in the specified directory.
* @paramdir The directory to scan for Mach-O binaries.
*/
public
validateAllCodesignSignatures
(
:
string
)
{
if
(
!
this
.
.
||
!
this
.
.
has
(
'darwin'
)
)
{
this
.
log
(
`Skipping codesign signature validation for ${dir} (signing checks disabled)`
)
;
return
;
}
const
=
.
readdirSync
(
,
{
:
true
}
)
;
for
(
const
of
)
{
const
=
.
join
(
,
.
)
;
if
(
.
isDirectory
(
)
)
{
// For .app bundles, validate the bundle itself, not its contents
if
(
.
.
endsWith
(
'.app'
)
||
.
.
endsWith
(
'.framework'
)
)
{
this
.
validateCodesignSignature
(
)
;
}
else
{
this
.
validateAllCodesignSignatures
(
)
;
}
}
else
if
(
this
.
isMachOBinary
(
)
)
{
this
.
validateCodesignSignature
(
)
;
}
}
}
/**
* Checks if a file is a Mach-O binary by examining its magic number.
* @paramfilePath The path to the file to check.
* @returns True if the file is a Mach-O binary.
*/
private
isMachOBinary
(
:
string
)
:
boolean
{
try
{
const
=
.
openSync
(
,
'r'
)
;
const
=
.
alloc
(
4
)
;
.
readSync
(
,
,
0
,
4
,
0
)
;
.
closeSync
(
)
;
const
=
.
readUInt32BE
(
0
)
;
return
===
0xFEEDFACE
||
===
0xCEFAEDFE
||
===
0xFEEDFACF
||
===
0xCFFAEDFE
||
===
0xCAFEBABE
||
===
0xBEBAFECA
;
}
catch
{
return
false
;
}
}
/**
* Downloads and unpacks the specified VS Code release target.
* @paramtarget The target platform (e.g., 'cli-linux-x64').
* @returns The path to the unpacked directory.
*/
public
async
downloadAndUnpack
(
:
string
)
:
Promise
<
string
>
{
const
=
await
this
.
downloadTarget
(
)
;
return
this
.
unpackArchive
(
)
;
}
/**
* Unpacks a .zip or .tar.gz archive to a temporary directory.
* @paramarchivePath The path to the archive file.
* @returns The path to the temporary directory where the archive was unpacked.
*/
public
unpackArchive
(
:
string
)
:
string
{
const
=
this
.
createTempDir
(
)
;
this
.
log
(
`Unpacking ${archivePath} to ${dir}`
)
;
this
.
runNoErrors
(
'tar'
,
'-xzf'
,
,
'-C'
,
,
'--no-same-permissions'
)
;
this
.
log
(
`Unpacked ${archivePath} to ${dir}`
)
;
return
;
}
/**
* Mounts a macOS DMG file and returns the mount point.
* @paramdmgPath The path to the DMG file.
* @returns The path to the mounted volume.
*/
public
mountDmg
(
:
string
)
:
string
{
this
.
log
(
`Mounting DMG ${dmgPath}`
)
;
const
=
this
.
runNoErrors
(
'hdiutil'
,
'attach'
,
,
'-nobrowse'
,
'-readonly'
)
;
// Parse the output to find the mount point (last column of the last line)
const
=
.
.
trim
(
)
.
split
(
'\n'
)
;
const
=
[
.
-
1
]
;
const
=
.
split
(
'\t'
)
.
pop
(
)
?.
trim
(
)
;
if
(
!
||
!
.
existsSync
(
)
)
{
this
.
error
(
`Failed to find mount point for DMG ${dmgPath}`
)
;
}
this
.
log
(
`Mounted DMG at ${mountPoint}`
)
;
return
;
}
/**
* Unmounts a macOS DMG volume.
* @parammountPoint The path to the mounted volume.
*/
public
unmountDmg
(
:
string
)
:
void
{
this
.
log
(
`Unmounting DMG ${mountPoint}`
)
;
this
.
runNoErrors
(
'hdiutil'
,
'detach'
,
)
;
this
.
log
(
`Unmounted DMG ${mountPoint}`
)
;
}
/**
* Runs a command synchronously.
* @paramcommand The command to run.
* @paramargs Optional arguments for the command.
* @returns The result of the spawnSync call.
*/
public
run
(
:
string
,
...
:
string
[
]
)
:
<
string
>
{
this
.
log
(
`Running command: ${command}${args.join(' ')}`
)
;
return
spawnSync
(
,
,
{
:
'utf-8'
}
)
as
<
string
>
;
}
/**
* Runs a command synchronously and ensures it succeeds.
* @paramcommand The command to run.
* @paramargs Optional arguments for the command.
* @returns The result of the spawnSync call.
*/
public
runNoErrors
(
:
string
,
...
:
string
[
]
)
:
<
string
>
{
const
=
this
.
run
(
,
...
)
;
if
(
.
!==
undefined
)
{
this
.
error
(
`Failed to run command: ${result.error.message}`
)
;
}
if
(
.
!==
0
)
{
this
.
error
(
`Command exited with code ${result.status}: ${result.stderr}`
)
;
}
return
;
}
/**
* Runs a command with sudo if not running as root, and ensures it succeeds.
* @paramcommand The command to run.
* @paramargs Optional arguments for the command.
* @returns The result of the spawnSync call.
*/
private
runSudoNoErrors
(
:
string
,
...
:
string
[
]
)
:
<
string
>
{
if
(
this
.
)
{
return
this
.
runNoErrors
(
,
...
)
;
}
else
{
return
this
.
runNoErrors
(
'sudo'
,
,
...
)
;
}
}
/**
* Runs a dpkg command with retries if the frontend lock is busy, and ensures it succeeds.
*/
private
async
runDpkgNoErrors
(
...
:
string
[
]
)
{
const
=
this
.
?
'dpkg'
:
'sudo'
;
const
=
this
.
?
:
[
'dpkg'
,
...
]
;
const
=
5
;
let
:
string
|
undefined
;
for
(
let
=
0
;
<
;
++
)
{
if
(
>
0
)
{
const
=
.
pow
(
2
,
-
1
)
*
1000
;
this
.
log
(
`Retrying dpkg command (attempt ${attempt +1}/${maxRetries}) after ${delay}ms`
)
;
await
this
.
timeout
(
)
;
}
const
=
this
.
run
(
,
...
)
;
if
(
.
!==
undefined
)
{
=
`Failed to run command: ${result.error.message}`
;
break
;
}
if
(
.
===
0
)
{
return
;
}
=
`Command exited with code ${result.status}: ${result.stderr}`
;
const
=
`${result.stdout}${result.stderr}`
;
if
(
!
.
.
test
(
)
)
{
break
;
}
this
.
log
(
`dpkg lock is busy, waiting for the other package manager process to finish`
)
;
}
this
.
error
(
??
`Command failed after ${maxRetries} attempts because the dpkg frontend lock remained busy`
)
;
}
/**
* Kills a process and all its child processes.
* @parampid The process ID to kill.
*/
public
killProcessTree
(
:
number
)
:
void
{
this
.
log
(
`Killing process tree for PID: ${pid}`
)
;
if
(
.
platform
(
)
===
'win32'
)
{
spawnSync
(
'taskkill'
,
[
'/T'
,
'/F'
,
'/PID'
,
.
toString
(
)
]
)
;
}
else
{
.
kill
(
-
,
'SIGKILL'
)
;
}
this
.
log
(
`Killed process tree for PID: ${pid}`
)
;
}
/**
* Returns the Windows installation directory for VS Code based on the installation type and quality.
* @paramtype The type of installation ('user' or 'system').
* @returns The path to the VS Code installation directory.
*/
private
getWindowsInstallDir
(
:
'user'
|
'system'
)
:
string
{
let
:
string
;
if
(
===
'system'
)
{
=
.
[
'ProgramW6432'
]
||
.
[
'PROGRAMFILES'
]
||
''
;
}
else
{
=
.
join
(
.
[
'LOCALAPPDATA'
]
||
''
,
'Programs'
)
;
}
switch
(
this
.
.
)
{
case
'stable'
:
return
.
join
(
,
'Microsoft VS Code'
)
;
case
'insider'
:
return
.
join
(
,
'Microsoft VS Code Insiders'
)
;
case
'exploration'
:
return
.
join
(
,
'Microsoft VS Code Exploration'
)
;
}
}
/**
* Installs a Microsoft Installer package silently.
* @paraminstallerPath The path to the installer executable.
* @returns The path to the installed VS Code executable.
*/
public
installWindowsApp
(
:
'user'
|
'system'
,
:
string
)
:
string
{
this
.
log
(
`Installing ${installerPath} in silent mode`
)
;
this
.
runNoErrors
(
,
'/silent'
,
'/mergetasks=!runcode'
)
;
this
.
log
(
`Installed ${installerPath} successfully`
)
;
const
=
this
.
getWindowsInstallDir
(
)
;
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
.
join
(
,
'Code.exe'
)
;
break
;
case
'insider'
:
=
.
join
(
,
'Code - Insiders.exe'
)
;
break
;
case
'exploration'
:
=
.
join
(
,
'Code - Exploration.exe'
)
;
break
;
}
if
(
!
.
existsSync
(
)
)
{
this
.
error
(
`Desktop entry point does not exist: ${entryPoint}`
)
;
}
this
.
log
(
`Installed VS Code executable at: ${entryPoint}`
)
;
return
;
}
/**
* Uninstalls a Windows application silently.
* @paramtype The type of installation ('user' or 'system').
*/
public
async
uninstallWindowsApp
(
:
'user'
|
'system'
)
{
const
=
this
.
getWindowsInstallDir
(
)
;
const
=
.
join
(
,
'unins000.exe'
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
error
(
`Uninstaller does not exist: ${uninstallerPath}`
)
;
}
this
.
log
(
`Uninstalling VS Code from ${appDir} in silent mode`
)
;
this
.
runNoErrors
(
,
'/silent'
)
;
this
.
log
(
`Uninstalled VS Code from ${appDir} successfully`
)
;
await
this
.
timeout
(
2000
)
;
if
(
.
existsSync
(
)
)
{
const
:
string
[
]
=
[
]
;
this
.
collectFiles
(
,
)
;
const
=
.
map
(
=>
.
relative
(
,
)
)
.
sort
(
)
.
join
(
'\n'
)
||
'(no files)'
;
this
.
error
(
`Installation directory still exists after uninstall: ${appDir}\nRemaining files:\n${remainingFileList}`
)
;
}
}
/**
* Installs VS Code Linux DEB package.
* @parampackagePath The path to the DEB file.
* @returns The path to the installed VS Code executable.
*/
public
async
installDeb
(
:
string
)
:
Promise
<
string
>
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/usr/share'
,
,
)
;
if
(
.
existsSync
(
)
)
{
this
.
error
(
`Cannot install ${packagePath}: ${name} is already installed at ${entryPoint}. This usually means a previous test run was terminated before cleanup completed; investigate the prior failure rather than silencing this error.`
)
;
}
this
.
log
(
`Installing ${packagePath} using DEB package manager`
)
;
await
this
.
runDpkgNoErrors
(
'-i'
,
)
;
this
.
log
(
`Installed ${packagePath} successfully`
)
;
this
.
log
(
`Installed VS Code executable at: ${entryPoint}`
)
;
return
;
}
/**
* Uninstalls VS Code Linux DEB package. Safe to call when the package is not
* installed (no-op) so that test cleanup in a `finally` block is always safe.
*/
public
async
uninstallDeb
(
)
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/usr/share'
,
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
log
(
`DEB package ${name} not installed, skipping uninstall`
)
;
return
;
}
this
.
log
(
`Uninstalling DEB package ${packagePath}`
)
;
await
this
.
runDpkgNoErrors
(
'-r'
,
)
;
this
.
log
(
`Uninstalled DEB package ${packagePath} successfully`
)
;
await
this
.
timeout
(
1000
)
;
if
(
.
existsSync
(
)
)
{
this
.
error
(
`Package still exists after uninstall: ${packagePath}`
)
;
}
}
/**
* Installs VS Code Linux RPM package.
* @parampackagePath The path to the RPM file.
* @returns The path to the installed VS Code executable.
*/
public
installRpm
(
:
string
)
:
string
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/usr/bin'
,
)
;
if
(
.
existsSync
(
)
)
{
this
.
error
(
`Cannot install ${packagePath}: ${name} is already installed at ${installedBinary}. This usually means a previous test run was terminated before cleanup completed; investigate the prior failure rather than silencing this error.`
)
;
}
this
.
log
(
`Installing ${packagePath} using RPM package manager`
)
;
this
.
runSudoNoErrors
(
'rpm'
,
'-i'
,
)
;
this
.
log
(
`Installed ${packagePath} successfully`
)
;
const
=
.
join
(
'/usr/share'
,
,
)
;
this
.
log
(
`Installed VS Code executable at: ${entryPoint}`
)
;
return
;
}
/**
* Uninstalls VS Code Linux RPM package. Safe to call when the package is not
* installed (no-op) so that test cleanup in a `finally` block is always safe.
*/
public
async
uninstallRpm
(
)
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/usr/bin'
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
log
(
`RPM package ${name} not installed, skipping uninstall`
`Package still exists after uninstall: ${packagePath}`
)
;
}
}
/**
* Installs VS Code Linux Snap package.
* @parampackagePath The path to the Snap file.
* @returns The path to the installed VS Code executable.
*/
public
installSnap
(
:
string
)
:
string
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/snap/bin'
,
)
;
if
(
.
existsSync
(
)
)
{
this
.
error
(
`Cannot install ${packagePath}: ${name} is already installed at ${snapWrapper}. This usually means a previous test run was terminated before cleanup completed; investigate the prior failure rather than silencing this error.`
)
;
}
this
.
log
(
`Installing ${packagePath} using Snap package manager`
)
;
this
.
runSudoNoErrors
(
'snap'
,
'install'
,
,
'--classic'
,
'--dangerous'
)
;
this
.
log
(
`Installed ${packagePath} successfully`
)
;
// Snap wrapper scripts are in /snap/bin, but actual Electron binary is in /snap/<package>/current/usr/share/
const
=
`/snap/${name}/current/usr/share/${name}/${name}`
;
this
.
log
(
`Installed VS Code executable at: ${entryPoint}`
)
;
return
;
}
/**
* Uninstalls VS Code Linux Snap package. Safe to call when the package is not
* installed (no-op) so that test cleanup in a `finally` block is always safe.
*/
public
async
uninstallSnap
(
)
{
const
=
this
.
getLinuxBinaryName
(
)
;
const
=
.
join
(
'/snap/bin'
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
log
(
`Snap package ${name} not installed, skipping uninstall`
`Package still exists after uninstall: ${packagePath}`
)
;
}
}
/**
* Returns the Linux binary name based on quality.
*/
private
getLinuxBinaryName
(
)
:
string
{
switch
(
this
.
.
)
{
case
'stable'
:
return
'code'
;
case
'insider'
:
return
'code-insiders'
;
case
'exploration'
:
return
'code-exploration'
;
}
}
/**
* Returns the entry point executable for the VS Code Desktop installation in the specified directory.
* @paramdir The directory of the VS Code installation.
* @returns The path to the entry point executable.
*/
public
getDesktopEntryPoint
(
:
string
)
:
string
{
let
:
string
=
''
;
switch
(
.
platform
(
)
)
{
case
'darwin'
:
{
let
:
string
;
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
'Visual Studio Code.app'
;
=
'Code'
;
break
;
case
'insider'
:
=
'Visual Studio Code - Insiders.app'
;
=
'Code - Insiders'
;
break
;
case
'exploration'
:
=
'Visual Studio Code - Exploration.app'
;
=
'Code - Exploration'
;
break
;
}
=
.
join
(
,
,
'Contents/MacOS'
,
)
;
break
;
}
case
'linux'
:
{
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
`code`
;
break
;
case
'insider'
:
=
`code-insiders`
;
break
;
case
'exploration'
:
=
`code-exploration`
;
break
;
}
=
.
join
(
,
)
;
break
;
}
case
'win32'
:
{
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
'Code.exe'
;
break
;
case
'insider'
:
=
'Code - Insiders.exe'
;
break
;
case
'exploration'
:
=
'Code - Exploration.exe'
;
break
;
}
=
.
join
(
,
)
;
break
;
}
}
if
(
!
||
!
.
existsSync
(
)
)
{
this
.
error
(
`Desktop entry point does not exist: ${filePath}`
)
;
}
return
;
}
/**
* Returns the entry point executable for the VS Code CLI in the specified directory.
* @paramdir The directory containing unpacked CLI files.
* @returns The path to the CLI entry point executable.
*/
public
getCliEntryPoint
(
:
string
)
:
string
{
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
'code'
;
break
;
case
'insider'
:
=
'code-insiders'
;
break
;
case
'exploration'
:
=
'code-exploration'
;
break
;
}
if
(
.
platform
(
)
===
'win32'
)
{
+=
'.exe'
;
}
const
=
.
join
(
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
error
(
`CLI entry point does not exist: ${entryPoint}`
)
;
}
return
;
}
/**
* Returns the entry point executable for the VS Code server in the specified directory.
* @paramdir The directory containing unpacked server files.
* @paramforWsl If true, returns the Linux entry point (for running in WSL on Windows).
* @returns The path to the server entry point executable.
*/
public
getServerEntryPoint
(
:
string
,
=
false
)
:
string
{
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
'code-server'
;
break
;
case
'insider'
:
=
'code-server-insiders'
;
break
;
case
'exploration'
:
=
'code-server-exploration'
;
break
;
}
if
(
.
platform
(
)
===
'win32'
&&
!
)
{
+=
'.cmd'
;
}
const
=
.
join
(
this
.
getFirstSubdirectory
(
)
,
'bin'
,
)
;
if
(
!
.
existsSync
(
)
)
{
this
.
error
(
`Server entry point does not exist: ${entryPoint}`
)
;
}
return
;
}
/**
* Returns the first subdirectory within the specified directory.
*/
public
getFirstSubdirectory
(
:
string
)
:
string
{
const
=
.
readdirSync
(
,
{
:
true
}
)
.
filter
(
=>
.
isDirectory
(
)
)
.
at
(
0
)
?.
;
if
(
!
)
{
this
.
error
(
`No subdirectories found in directory: ${dir}`
)
;
}
return
.
join
(
,
)
;
}
/**
* Creates a portable data directory in the specified unpacked VS Code directory.
* @paramdir The directory where VS Code was unpacked.
* @returns The path to the created portable data directory.
*/
public
createPortableDataDir
(
:
string
)
:
string
{
const
=
.
join
(
,
.
platform
(
)
===
'darwin'
?
'code-portable-data'
:
'data'
)
;
this
.
log
(
`Creating portable data directory: ${dataDir}`
)
;
.
mkdirSync
(
,
{
:
true
}
)
;
this
.
log
(
`Created portable data directory: ${dataDir}`
)
;
return
;
}
/**
* Launches a web browser for UI testing.
* @returns The launched Browser instance.
*/
/**
* Awaits a page promise and sets the default timeout.
* @parampagePromise The promise that resolves to a Page.
* @returns The page with the timeout configured.
*/
public
async
getPage
(
:
Promise
<
>
)
:
Promise
<
>
{
const
=
await
;
.
setDefaultTimeout
(
3
*
60
*
1000
)
;
return
;
}
/**
* Closes a Playwright Electron application gracefully, falling back to a forced
* kill of the process tree if the close hangs (for example after a renderer crash).
*/
public
async
closeElectronApp
(
:
,
=
60_000
)
:
Promise
<
void
>
{
this
.
log
(
'Closing the application'
)
;
const
=
.
process
(
)
.
;
let
:
.
|
undefined
;
try
{
await
Promise
.
race
(
[
.
close
(
)
,
new
Promise<never>
(
(
,
)
=>
{
=
setTimeout
(
(
)
=>
reject
(
new
Error
(
`app.close() did not complete within ${timeoutMs}ms`
)
)
,
,
)
;
}
)
,
]
)
;
}
catch
(
)
{
this
.
warn
(
`Failed to close application gracefully: ${error instanceofError? error.message :String(error)}`
)
;
if
(
)
{
try
{
this
.
killProcessTree
(
)
;
}
catch
(
)
{
this
.
warn
(
`Failed to force-kill application process tree: ${killError instanceofError? killError.message :String(killError)}`
)
;
}
}
}
finally
{
if
(
)
{
clearTimeout
(
)
;
}
}
}
/**
* Returns a per-test crash dump directory for the desktop app to use with
* `--crash-reporter-directory`. Returns undefined if `--crash-dumps-dir` was
* not provided.
*/
public
getCrashDumpsDir
(
)
:
string
|
undefined
{
if
(
!
this
.
.
||
!
this
.
)
{
return
undefined
;
}
const
=
this
.
.
replace
(
/[^a-zA-Z0-9_-]/g
,
'_'
)
;
return
.
join
(
this
.
.
,
)
;
}
/**
* Captures a screenshot of the current page if one is active.
*/
`Failed to capture screenshot: ${e instanceofError? e.message :String(e)}`
)
;
}
}
/**
* Constructs a web server URL with optional token and folder parameters.
* @paramport The port number of the web server.
* @paramtoken The optional authentication token.
* @paramfolder The optional workspace folder path to open.
* @returns The constructed web server URL.
*/
public
getWebServerUrl
(
:
string
,
?
:
string
,
?
:
string
)
:
URL
{
const
=
new
URL
(
`http://localhost:${port}`
)
;
if
(
)
{
.
.
set
(
'tkn'
,
)
;
}
if
(
)
{
=
.
replaceAll
(
'\\'
,
'/'
)
;
if
(
!
.
startsWith
(
'/'
)
)
{
=
`/${folder}`
;
}
.
.
set
(
'folder'
,
)
;
}
return
;
}
/**
* Returns the tunnel URL for the VS Code server.
* @parambaseUrl The base URL for *vscode.dev/tunnel connection.
* @paramworkspaceDir Optional folder path to open
* @returns The tunnel URL with folder in pathname.
*/
public
getTunnelUrl
(
:
string
,
?
:
string
)
:
string
{
const
=
new
URL
(
)
;
.
.
set
(
'vscode-version'
,
this
.
.
)
;
if
(
)
{
let
=
.
replaceAll
(
'\\'
,
'/'
)
;
if
(
!
.
startsWith
(
'/'
)
)
{
=
`/${folder}`
;
}
.
=
.
.
replace
(
/\/+$/
,
''
)
+
;
}
return
.
toString
(
)
;
}
/**
* Returns a random alphanumeric token of length 10.
*/
public
getRandomToken
(
)
:
string
{
return
Array
.
from
(
{
:
10
}
,
(
)
=>
.
floor
(
.
random
(
)
*
36
)
.
toString
(
36
)
)
.
join
(
''
)
;
}
/**
* Returns a unique port number, starting from 3010 and incrementing.
*/
public
getUniquePort
(
)
:
string
{
return
String
(
this
.
++
)
;
}
/**
* Returns the default WSL server extensions directory path.
* @returns The path to the extensions directory (e.g., '~/.vscode-server-insiders/extensions').
*/
public
getWslServerExtensionsDir
(
)
:
string
{
let
:
string
;
switch
(
this
.
.
)
{
case
'stable'
:
=
'.vscode-server'
;
break
;
case
'insider'
:
=
'.vscode-server-insiders'
;
break
;
case
'exploration'
:
=
'.vscode-server-exploration'
;
break
;
}
return
`~/${serverDir}/extensions`
;
}
/**
* Runs a VS Code command-line application (such as server or CLI).
* @paramname The name of the app as it will appear in logs.
* @paramcommand Command to run.
* @paramargs Arguments for the command.
* @paramonLine Callback to handle output lines.
*/
public
async
runCliApp
(
:
string
,
:
string
,
:
string
[
]
,
onLine
:
(
:
string
)
=>
Promise
<
boolean
|
void
|
undefined
>
)
{
this
.
log
(
`Starting ${name} with command line: ${command}${args.join(' ')}`