Skip to content

The agent that grows with you

fix(desktop): remove a half-installed get-windows dir before the workspace npm install (#90829)

teknium1f97f8d5fd5fa
diff --git a/apps/desktop/scripts/stage-native-deps.mjs b/apps/desktop/scripts/stage-native-deps.mjs
index 96b0aeb915e..e6c1282f510 100644
--- a/apps/desktop/scripts/stage-native-deps.mjs
+++ b/apps/desktop/scripts/stage-native-deps.mjs
@@ -662,15 +662,15 @@ export function installGetWindowsNativeBinding(
* `node_modules` ancestors `require.resolve` does (the workspace root hoist or
* the app-local copy).
*/
-export function findHalfInstalledGetWindowsDir(startDir = projectRoot, exists = existsSync) {
+export function findHalfInstalledGetWindowsDir(startDir = projectRoot) {
for (let dir = startDir; ; dir = dirname(dir)) {
const candidate = join(dir, 'node_modules', 'get-windows')
- if (exists(candidate)) return candidate
+ if (existsSync(candidate)) return candidate
if (dirname(dir) === dir) return null
}
}
-/** The warning printed when get-windows cannot be staged; exported for tests. */
+/** The warning printed when get-windows cannot be staged. */
export function missingGetWindowsWarning({ platform, arch, halfInstalledDir }) {
const lines = [
`[stage-native-deps] get-windows not installed (optional dep skipped for ${platform}-${arch}); ` +
@@ -680,8 +680,8 @@ export function missingGetWindowsWarning({ platform, arch, halfInstalledDir }) {
lines.push(
`[stage-native-deps] ${halfInstalledDir} exists but is not a loadable package — an ` +
'interrupted npm install left it half-extracted (look for TAR_ENTRY_ERROR in the install log). ' +
- 'To restore read_window_below: close every Hermes window and gateway, then run ' +
- '`npm install get-windows --save-exact` in apps/desktop and rebuild with `hermes desktop --force-build`.'
+ 'To restore read_window_below: close every Hermes window and gateway so the extract is not ' +
+ 'interrupted again, then run `hermes desktop --force-build` — it removes the stale dir before npm.'
)
}
return lines.join('\n')
diff --git a/apps/desktop/scripts/stage-native-deps.test.mjs b/apps/desktop/scripts/stage-native-deps.test.mjs
index 2cd0b237c61..f5f01472888 100644
--- a/apps/desktop/scripts/stage-native-deps.test.mjs
+++ b/apps/desktop/scripts/stage-native-deps.test.mjs
@@ -677,7 +677,7 @@ test('staging degrades (never throws) when get-windows is absent on every platfo
}
assert.equal(warnings.length, 4)
assert.ok(warnings.every((w) => w.includes('read_window_below will be unavailable')))
- assert.ok(warnings.every((w) => !w.includes('npm install get-windows')), 'no repair hint without a stale dir')
+ assert.ok(warnings.every((w) => !w.includes('half-extracted')), 'no repair hint without a stale dir')
})
test('a half-installed get-windows dir is found and named in a repair hint', () => {
@@ -705,7 +705,7 @@ test('a half-installed get-windows dir is found and named in a repair hint', ()
console.warn = origWarn
}
assert.equal(warnings.length, 1)
- assert.match(warnings[0], /npm install get-windows --save-exact/)
+ assert.match(warnings[0], /hermes desktop --force-build/)
assert.ok(warnings[0].includes(join(tmp, 'node_modules', 'get-windows')))
fs.rmSync(join(tmp, 'node_modules'), { recursive: true, force: true })
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.py
index 4fe1189c825..77ab523861a 100644
--- a/hermes_cli/main_desktop.py
+++ b/hermes_cli/main_desktop.py
@@ -1401,12 +1401,31 @@ def _register_linux_desktop_entry(defer: bool = False):
return None
+def _remove_half_installed_get_windows(project_root: Path) -> list[Path]:
+ """Delete a ``node_modules/get-windows`` an interrupted extract left without ``package.json``.
+
+ A Windows in-place update with the Desktop/gateway holding files open fails tar
+ extraction mid-package (#90829); npm never revisits a directory that already exists,
+ so the optional dep stayed unresolvable on every later update until a manual repair.
+ Both the workspace hoist and the app-local copy are checked.
+ """
+ removed = []
+ for candidate in (project_root / "node_modules" / "get-windows",
+ project_root / "apps" / "desktop" / "node_modules" / "get-windows"):
+ if candidate.is_dir() and not (candidate / "package.json").exists():
+ shutil.rmtree(candidate, ignore_errors=True)
+ print(f" ⚠ Removed half-installed {candidate} so npm re-extracts it")
+ removed.append(candidate)
+ return removed
+
+
def _install_desktop_workspace_deps(npm: str, env: dict) -> None:
"""npm-install the desktop workspace; exits on a failure that isn't a repairable missing Electron dist."""
from hermes_cli.main import PROJECT_ROOT
from hermes_cli.main_web_build import _run_npm_install_deterministic
from hermes_constants import with_hermes_node_path
print("→ Installing desktop workspace dependencies...")
+ _remove_half_installed_get_windows(PROJECT_ROOT)
# Managed Node on PATH so npm's child scripts that shell out to bare `node`
# (e.g. electron-winstaller's select-7z-arch.js) resolve it even when the
# desktop updater chain lost shell PATH customizations. Wrapping the NixOS
diff --git a/tests/hermes_cli/test_desktop_half_installed_get_windows.py b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
index f0a42196060..7554534946c 100644
--- a/tests/hermes_cli/test_desktop_half_installed_get_windows.py
+++ b/tests/hermes_cli/test_desktop_half_installed_get_windows.py
@@ -13,7 +13,7 @@ def test_half_installed_dir_is_removed_and_a_complete_one_is_kept(tmp_path):
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"}')
+ (complete / "package.json").write_text('{"name": "get-windows"}', encoding="utf-8")
removed = main_desktop._remove_half_installed_get_windows(tmp_path)