Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(windows): harden vswhere probe fallbacks

HopeCollectorfdc76b6b60b7
diff --git a/CLAUDE.md b/CLAUDE.md
index 02c7df57c..826780d7c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -2102,9 +2102,13 @@ extra dependency, and is what electron-updater's generic provider expects on Win
Squirrel was not adopted. Builds are **unsigned** (no Windows cert; electron-builder skips
signing when no cert env is present). `bootstrap-windows.bat` (repo root) takes a fresh Windows
machine to a built checkout: it verifies Node ≥ 20 / VS Build Tools C++ / Python 3 with exact
-winget hints (it never installs machine-wide tools itself, and refuses to run elevated) and runs
-`npm ci`. `.github/workflows/win-package-smoke.yml` is a **workflow_dispatch-only** packaging
-smoke on windows-latest — build only, never publishes. **Follow-ups, in order:** Windows
+winget hints (it never installs machine-wide tools itself, and the full bootstrap refuses to run
+elevated) and runs `npm ci`. Its `--check-vs-build-tools` mode is the narrow exception used by
+`quality-windows`: it branches before the elevation refusal, runs only the VS C++ probe, and exits
+before the Node / Python / `npm ci` steps. Fixture injection additionally requires the explicit
+`NODETERM_BOOTSTRAP_TESTING=1` sentinel. `.github/workflows/win-package-smoke.yml` is a
+**workflow_dispatch-only** packaging smoke on windows-latest — build only, never publishes.
+**Follow-ups, in order:** Windows
auto-update wiring (electron-updater NSIS leg + `latest.yml` on the nodeterm.dev feed — blocked
on signing: an unsigned auto-update is a downgrade in trust), a release.yml Windows job, and the
fork's PE-identity polish (electron-builder leaves `OriginalFilename` empty; the fork's
diff --git a/bootstrap-windows.bat b/bootstrap-windows.bat
index ed0b6de9d..6dc5b8f49 100644
--- a/bootstrap-windows.bat
+++ b/bootstrap-windows.bat
@@ -109,17 +109,20 @@ if not exist "%VSWHERE%" (
)
set "VSWHERE_ARGS=-products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -latest -property installationPath"
-call "%VSWHERE%" %VSWHERE_ARGS% >nul 2>nul
-if errorlevel 1 (
- echo [FAILED] vswhere could not query Visual Studio installations.
- exit /b 1
-)
-
rem vswhere returns exit code 0 even when the query matches nothing. Capture the first path and
rem test the value itself; checking only ERRORLEVEL silently accepts a machine without C++ tools.
set "VS_INSTALLATION="
+rem CALL is intentional: production uses vswhere.exe, but the cmd.exe tests inject a .cmd fixture
+rem that must return control to this script.
for /f "usebackq delims=" %%I in (`call "%VSWHERE%" %VSWHERE_ARGS% 2^>nul`) do if not defined VS_INSTALLATION set "VS_INSTALLATION=%%I"
if not defined VS_INSTALLATION (
+ rem FOR /F does not preserve the nested command's exit status. Query again only after an empty
+ rem capture so the retry status classifies query failure versus no matching installation.
+ call "%VSWHERE%" %VSWHERE_ARGS% >nul 2>nul
+ if errorlevel 1 (
+ echo [FAILED] vswhere could not query Visual Studio installations.
+ exit /b 1
+ )
echo [MISSING] No Visual Studio installation with the C++ build tools component was found.
echo Install: winget install Microsoft.VisualStudio.2022.BuildTools --override "--quiet --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
exit /b 1
diff --git a/src/main/bootstrap-windows.test.ts b/src/main/bootstrap-windows.test.ts
index 48063aaef..0ef43caaa 100644
--- a/src/main/bootstrap-windows.test.ts
+++ b/src/main/bootstrap-windows.test.ts
@@ -23,7 +23,22 @@ interface ProbeResult {
invocations: string[]
}
-function runVisualStudioProbe(vswhereBody: string): ProbeResult {
+interface ProbeOptions {
+ createVswhere?: boolean
+ testingSentinel?: string | null
+ inheritInternalOverride?: boolean
+}
+
+function readInvocationLog(invocationLog: string): string {
+ try {
+ return readFileSync(invocationLog, 'utf8')
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return ''
+ throw error
+ }
+}
+
+function runVisualStudioProbe(vswhereBody: string, options: ProbeOptions = {}): ProbeResult {
const scratch = mkdtempSync(path.join(tmpdir(), 'nodeterm-bootstrap-'))
scratchDirectories.push(scratch)
const installation = path.join(scratch, 'VS Build Tools')
@@ -37,18 +52,37 @@ function runVisualStudioProbe(vswhereBody: string): ProbeResult {
// The space in the filename makes this fixture exercise the quoting around VSWHERE too.
const fakeVswhere = path.join(scratch, 'fake vswhere.cmd')
const invocationLog = path.join(scratch, 'vswhere-arguments.txt')
- writeFileSync(
- fakeVswhere,
- `@echo off\r\necho %*>>"%NODETERM_TEST_VSWHERE_ARGS_LOG%"\r\n${vswhereBody}\r\n`,
- 'utf8'
- )
+ const invocationState = path.join(scratch, 'vswhere-invocation-state')
+ if (options.createVswhere !== false) {
+ writeFileSync(
+ fakeVswhere,
+ `@echo off\r\necho %*>>"%NODETERM_TEST_VSWHERE_ARGS_LOG%"\r\n${vswhereBody}\r\n`,
+ 'utf8'
+ )
+ }
- const env = {
- ...process.env,
- NODETERM_BOOTSTRAP_TESTING: '1',
- NODETERM_TEST_VSWHERE: fakeVswhere,
- NODETERM_TEST_VSWHERE_ARGS_LOG: invocationLog,
- NODETERM_TEST_VS_INSTALLATION: installation
+ const controlledKeys = new Set([
+ '_NODETERM_VSWHERE_OVERRIDE',
+ 'NODETERM_BOOTSTRAP_TESTING',
+ 'NODETERM_TEST_VSWHERE',
+ 'NODETERM_TEST_VSWHERE_ARGS_LOG',
+ 'NODETERM_TEST_VS_INSTALLATION',
+ 'NODETERM_TEST_VSWHERE_STATE',
+ 'VS_INSTALLATION'
+ ])
+ const env: NodeJS.ProcessEnv = Object.fromEntries(
+ Object.entries(process.env).filter(([key]) => !controlledKeys.has(key.toUpperCase()))
+ )
+ env.NODETERM_TEST_VSWHERE_ARGS_LOG = invocationLog
+ env.NODETERM_TEST_VS_INSTALLATION = installation
+ env.NODETERM_TEST_VSWHERE_STATE = invocationState
+ env.NODETERM_TEST_VSWHERE = fakeVswhere
+ env.VS_INSTALLATION = installation
+ if (options.testingSentinel !== null) {
+ env.NODETERM_BOOTSTRAP_TESTING = options.testingSentinel ?? '1'
+ }
+ if (options.inheritInternalOverride) {
+ env._NODETERM_VSWHERE_OVERRIDE = fakeVswhere
}
// Keep the batch path and its argument as separate argv entries. Node quotes the path for
// CreateProcess, so a checkout directory containing spaces reaches cmd.exe intact.
@@ -64,12 +98,13 @@ function runVisualStudioProbe(vswhereBody: string): ProbeResult {
)
expect(result.error).toBeUndefined()
+ const invocationText = readInvocationLog(invocationLog).trim()
return {
status: result.status,
stdout: result.stdout,
stderr: result.stderr,
installation,
- invocations: readFileSync(invocationLog, 'utf8').trim().split(/\r?\n/)
+ invocations: invocationText ? invocationText.split(/\r?\n/) : []
}
}
@@ -87,6 +122,47 @@ describeWindows('bootstrap-windows Visual Studio probe', () => {
}
})
+ it('reports a missing vswhere executable without invoking a fixture', () => {
+ const result = runVisualStudioProbe('', { createVswhere: false })
+
+ expect(result.status).toBe(1)
+ expect(result.stdout, result.stderr).toContain(
+ '[MISSING] Visual Studio Build Tools were not found (vswhere.exe absent).'
+ )
+ expect(result.invocations).toEqual([])
+ })
+
+ it('rejects fixture overrides unless the test sentinel is exactly 1', () => {
+ for (const testingSentinel of [null, '0']) {
+ const result = runVisualStudioProbe('echo FIXTURE-MUST-NOT-RUN', {
+ testingSentinel,
+ inheritInternalOverride: true
+ })
+
+ expect(result.invocations).toEqual([])
+ expect(result.stdout).not.toContain('FIXTURE-MUST-NOT-RUN')
+ }
+ })
+
+ it('keeps fixture state inside the check-only dispatch boundary', () => {
+ const source = readFileSync(sourceBootstrap, 'utf8')
+ const overrideClear = source.indexOf('set "_NODETERM_VSWHERE_OVERRIDE="')
+ const checkOnlyDispatch = source.indexOf(
+ 'if /i "%~1"=="--check-vs-build-tools" goto :check_vs_build_tools_only'
+ )
+ const checkOnlyLabel = source.search(/^:check_vs_build_tools_only\r?$/m)
+ const fixtureAssignment = source.indexOf(
+ 'if "%NODETERM_BOOTSTRAP_TESTING%"=="1" set "_NODETERM_VSWHERE_OVERRIDE=%NODETERM_TEST_VSWHERE%"'
+ )
+ const sharedProbeLabel = source.search(/^:check_vs_build_tools\r?$/m)
+
+ expect(overrideClear).toBeGreaterThan(-1)
+ expect(checkOnlyDispatch).toBeGreaterThan(overrideClear)
+ expect(checkOnlyLabel).toBeGreaterThan(checkOnlyDispatch)
+ expect(fixtureAssignment).toBeGreaterThan(checkOnlyLabel)
+ expect(sharedProbeLabel).toBeGreaterThan(fixtureAssignment)
+ })
+
it('rejects a successful vswhere query with empty output', () => {
const result = runVisualStudioProbe('exit /b 0')
@@ -106,7 +182,20 @@ describeWindows('bootstrap-windows Visual Studio probe', () => {
'[FAILED] vswhere could not query Visual Studio installations.'
)
expect(result.stdout).not.toContain('[MISSING] No Visual Studio installation')
- expectVswhereInvocations(result, 1)
+ expectVswhereInvocations(result, 2)
+ })
+
+ it('does not launder a later query failure into a missing installation', () => {
+ const result = runVisualStudioProbe(
+ 'if exist "%NODETERM_TEST_VSWHERE_STATE%" exit /b 7\r\ntype nul >"%NODETERM_TEST_VSWHERE_STATE%"\r\nexit /b 0'
+ )
+
+ expect(result.status).toBe(1)
+ expect(result.stdout, result.stderr).toContain(
+ '[FAILED] vswhere could not query Visual Studio installations.'
+ )
+ expect(result.stdout).not.toContain('[MISSING] No Visual Studio installation')
+ expectVswhereInvocations(result, 2)
})
it('rejects a reported C++ toolchain path that does not exist', () => {
@@ -120,7 +209,20 @@ describeWindows('bootstrap-windows Visual Studio probe', () => {
`[FAILED] vswhere reported a Visual Studio path that does not exist: "${missingInstallation}"`
)
expect(result.stdout).not.toContain('[OK] Visual Studio C++ build tools')
- expectVswhereInvocations(result, 2)
+ expectVswhereInvocations(result, 1)
+ })
+
+ it('uses the first path when vswhere reports multiple installations', () => {
+ const result = runVisualStudioProbe(
+ 'echo %NODETERM_TEST_VS_INSTALLATION%\r\necho %NODETERM_TEST_VS_INSTALLATION%\\missing-installation'
+ )
+
+ expect(result.status).toBe(0)
+ expect(result.stdout, result.stderr).toContain(
+ `[OK] Visual Studio C++ build tools: "${result.installation}"`
+ )
+ expect(result.stdout).not.toContain('Running npm ci')
+ expectVswhereInvocations(result, 1)
})
it('accepts a reported C++ toolchain path, including spaces', () => {
@@ -130,6 +232,6 @@ describeWindows('bootstrap-windows Visual Studio probe', () => {
expect(result.stdout, result.stderr).toContain(
`[OK] Visual Studio C++ build tools: "${result.installation}"`
)
- expectVswhereInvocations(result, 2)
+ expectVswhereInvocations(result, 1)
})
})