Skip to content

The agent that grows with you

fix(desktop): degrade instead of failing the build when get-windows lacks its binding or helper

teknium1048e7b974f71
diff --git a/apps/desktop/scripts/stage-native-deps.mjs b/apps/desktop/scripts/stage-native-deps.mjs
index d200facbbbc..96b0aeb915e 100644
--- a/apps/desktop/scripts/stage-native-deps.mjs
+++ b/apps/desktop/scripts/stage-native-deps.mjs
@@ -536,7 +536,15 @@ export function stageGetWindowsInto(
if (platform === 'darwin') {
const helper = join(srcRoot, 'main')
if (!existsSync(helper)) {
- throw new Error('[stage-native-deps] get-windows is missing its macOS helper binary (main)')
+ // A half-extracted install (#90829) can keep the package but lose the
+ // helper; the runtime already fails soft on an unstaged module, so lose
+ // only window enumeration rather than the whole Desktop build.
+ removeDirSync(destRoot)
+ console.warn(
+ '[stage-native-deps] get-windows is missing its macOS helper binary (main); ' +
+ 'not staged — read_window_below will be unavailable in this build'
+ )
+ return undefined
}
copyFileSync(helper, join(destRoot, 'main'))
makeExecutable(join(destRoot, 'main'))
@@ -560,15 +568,7 @@ export function stageGetWindowsInto(
: []
let bindingDirs = scanBindingDirs()
let installAttempted = false
- if (bindingDirs.length === 0 && arch === 'arm64') {
- // get-windows 9.3.0 publishes win32 prebuilds for ia32/x64 only.
- // The staged windows.js deliberately fails soft when binding/ is absent,
- // so preserve the desktop build and disable only window enumeration.
- console.warn(
- '[stage-native-deps] get-windows has no win32-arm64 prebuilt binding; ' +
- 'staging the fail-soft JS surface without native window enumeration.'
- )
- } else if (bindingDirs.length === 0 && typeof install === 'function') {
+ if (bindingDirs.length === 0 && arch !== 'arm64' && typeof install === 'function') {
// A plain `npm install` won't re-run an install script for a package
// that is already on disk, so every checkout that installed while
// get-windows was missing from allowScripts stays bricked even after
@@ -579,14 +579,27 @@ export function stageGetWindowsInto(
'[stage-native-deps] get-windows has no win32 binding; running its native installer...'
)
installAttempted = true
- install()
+ try {
+ install()
+ } catch (error) {
+ console.warn(
+ `[stage-native-deps] get-windows native installer failed: ${error instanceof Error ? error.message : String(error)}`
+ )
+ }
bindingDirs = scanBindingDirs()
}
- if (bindingDirs.length === 0 && arch !== 'arm64') {
+ if (bindingDirs.length === 0) {
+ // get-windows 9.3.0 publishes win32 prebuilds for ia32/x64 only, and a
+ // half-extracted install (#90829) can leave even those without one. The
+ // staged windows.js deliberately fails soft when binding/ is absent, so
+ // preserve the desktop build and disable only window enumeration.
const reason = installAttempted
- ? `native installer completed without producing a win32-${arch} binding under lib/binding`
- : `has no win32-${arch} prebuilt binding under lib/binding`
- throw new Error(`[stage-native-deps] get-windows ${reason}`)
+ ? `native installer produced no win32-${arch} binding`
+ : `has no win32-${arch} prebuilt binding`
+ console.warn(
+ `[stage-native-deps] get-windows ${reason}; ` +
+ 'staging the fail-soft JS surface without native window enumeration.'
+ )
}
for (const dir of bindingDirs) {
const dest = join(destRoot, 'lib', 'binding', dir)
diff --git a/apps/desktop/scripts/stage-native-deps.test.mjs b/apps/desktop/scripts/stage-native-deps.test.mjs
index 533b53b3edc..2cd0b237c61 100644
--- a/apps/desktop/scripts/stage-native-deps.test.mjs
+++ b/apps/desktop/scripts/stage-native-deps.test.mjs
@@ -463,21 +463,31 @@ test('win32 staging rejects a binding dir that claims win32 but holds a foreign
}
})
-test('win32-x64 staging fails when only foreign bindings exist', () => {
+test('win32-x64 staging degrades to the fail-soft JS surface when only foreign bindings exist', () => {
const tmp = fs.mkdtempSync(join(os.tmpdir(), 'hermes-stage-'))
+ const warnings = []
+ const origWarn = console.warn
+ console.warn = (msg) => warnings.push(String(msg))
try {
const srcRoot = join(tmp, 'get-windows')
const destRoot = join(tmp, 'dest')
+ // Half-extracted install (#90829): the package resolves, but lib/binding
+ // holds only the darwin dir the tarball bundles and the installer is a no-op.
makeFakeGetWindows(srcRoot, {
bindings: [{ dir: 'napi-9-darwin-unknown-arm64', platform: 'darwin' }]
})
- assert.throws(
- () => stageGetWindowsInto(srcRoot, destRoot, { platform: 'win32', arch: 'x64' }),
- /no win32-x64 prebuilt binding/
+ assert.equal(
+ stageGetWindowsInto(srcRoot, destRoot, { platform: 'win32', arch: 'x64', install: () => {} }),
+ destRoot
)
+ assert.ok(existsSync(join(destRoot, 'lib', 'windows.js')))
+ assert.ok(!existsSync(join(destRoot, 'lib', 'binding')))
+ assert.equal(warnings.length, 1)
+ assert.match(warnings[0], /native installer produced no win32-x64 binding/)
} finally {
+ console.warn = origWarn
fs.rmSync(tmp, { recursive: true, force: true })
}
})
@@ -534,28 +544,24 @@ test('win32 staging self-heals through the native installer when the binding is
}
})
-test('win32 staging rejects a successful installer that produces no binding', () => {
+test('darwin staging degrades (not staged) when the helper binary is missing', () => {
const tmp = fs.mkdtempSync(join(os.tmpdir(), 'hermes-stage-'))
+ const warnings = []
+ const origWarn = console.warn
+ console.warn = (msg) => warnings.push(String(msg))
try {
const srcRoot = join(tmp, 'get-windows')
const destRoot = join(tmp, 'dest')
- makeFakeGetWindows(srcRoot, { bindings: [] })
+ makeFakeGetWindows(srcRoot)
+ fs.rmSync(join(srcRoot, 'main'))
- assert.throws(
- () =>
- stageGetWindowsInto(srcRoot, destRoot, {
- platform: 'win32',
- arch: 'x64',
- install: () => {}
- }),
- (error) => {
- assert.match(error.message, /installer completed without producing a win32-x64 binding/)
- assert.doesNotMatch(error.message, /npm rebuild/)
- return true
- }
- )
+ assert.equal(stageGetWindowsInto(srcRoot, destRoot, { platform: 'darwin' }), undefined)
+ assert.ok(!existsSync(destRoot), 'a helper-less module must not ship half-staged')
+ assert.equal(warnings.length, 1)
+ assert.match(warnings[0], /missing its macOS helper binary/)
} finally {
+ console.warn = origWarn
fs.rmSync(tmp, { recursive: true, force: true })
}
})
diff --git a/tests/hermes_cli/test_desktop_half_installed_get_windows.py b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
new file mode 100644
index 00000000000..f0a42196060
--- /dev/null
+++ b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
@@ -0,0 +1,42 @@
+"""A half-extracted ``node_modules/get-windows`` self-heals before the desktop npm install (#90829).
+
+An in-place Windows update with the Desktop/gateway holding files open fails tar extraction
+mid-package, leaving the dir without ``package.json``; npm never revisits an existing dir, so
+the optional dep stayed broken on every later update until a manual repair.
+"""
+
+from hermes_cli import main_desktop
+
+
+def test_half_installed_dir_is_removed_and_a_complete_one_is_kept(tmp_path):
+ half = tmp_path / "node_modules" / "get-windows" / "lib" / "binding"
+ half.mkdir(parents=True)
+ complete = tmp_path / "apps" / "desktop" / "node_modules" / "get-windows"
+ complete.mkdir(parents=True)
+ (complete / "package.json").write_text('{"name": "get-windows"}')
+
+ removed = main_desktop._remove_half_installed_get_windows(tmp_path)
+
+ assert removed == [tmp_path / "node_modules" / "get-windows"]
+ assert not (tmp_path / "node_modules" / "get-windows").exists()
+ assert (complete / "package.json").exists()
+
+
+def test_install_removes_the_half_installed_dir_before_npm_runs(tmp_path, monkeypatch):
+ half = tmp_path / "node_modules" / "get-windows"
+ half.mkdir(parents=True)
+ seen: list[bool] = []
+
+ def _fake_npm(npm, cwd, **kwargs):
+ seen.append(half.exists())
+ return type("R", (), {"returncode": 0})()
+
+ import hermes_cli.main as main_mod
+ import hermes_cli.main_web_build as web_build
+ monkeypatch.setattr(main_mod, "PROJECT_ROOT", tmp_path)
+ monkeypatch.setattr(web_build, "_run_npm_install_deterministic", _fake_npm)
+ monkeypatch.setattr(main_desktop, "_nixos_build_env", lambda: {})
+
+ main_desktop._install_desktop_workspace_deps("npm", {})
+
+ assert seen == [False], "npm must run only after the stale dir is gone"