The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): stage node-pty without fs.cpSync/fs.rmSync (non-ASCII Windows paths)
Kósa2d88b9b4dfec
diff --git a/apps/desktop/scripts/stage-native-deps.mjs b/apps/desktop/scripts/stage-native-deps.mjsindex 385d031725b..a0ad4074781 100644--- a/apps/desktop/scripts/stage-native-deps.mjs+++ b/apps/desktop/scripts/stage-native-deps.mjs@@ -14,12 +14,13 @@ import { fileURLToPath } from 'node:url'import { dirname, resolve, join } from 'node:path'import {chmodSync,- cpSync,+ copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,- rmSync,+ rmdirSync,+ unlinkSync,writeFileSync} from 'node:fs'import { spawnSync } from 'node:child_process'@@ -33,6 +34,52 @@ function makeExecutable(filePath) {chmodSync(filePath, 0o755)}+// ─── libuv-safe fs primitives ────────────────────────────────────────+//+// Node 24's native rewrite of fs.cpSync/fs.rmSync mishandles non-ASCII+// Windows paths (observed on v24.11.1 with an accented Windows user name,+// i.e. a default %LOCALAPPDATA%\hermes home): a recursive cpSync fails+// with EIO "Access is denied" or hard-crashes the process, an overwriting+// cpSync fails with a bogus errno-0 unlink error, and rmSync silently+// deletes nothing — leaving a half-staged tree that breaks every retry.+// copyFileSync/unlinkSync/rmdirSync/readdirSync go through libuv and+// handle those paths correctly, so staging uses them exclusively.++/** Recursively copy a directory without fs.cpSync. */+function copyDirSync(srcDir, destDir) {+ mkdirSync(destDir, { recursive: true })+ for (const entry of readdirSync(srcDir, { withFileTypes: true })) {+ const src = join(srcDir, entry.name)+ const dest = join(destDir, entry.name)+ if (entry.isDirectory()) {+ copyDirSync(src, dest)+ } else {+ copyFileSync(src, dest)+ }+ }+}++/**+ * Recursively delete a directory without fs.rmSync (missing dir is fine),+ * then verify the tree is actually gone — a silent no-op here surfaces+ * later as an inexplicable staging failure, so fail loudly instead.+ */+function removeDirSync(dir) {+ if (!existsSync(dir)) return+ for (const entry of readdirSync(dir, { withFileTypes: true })) {+ const full = join(dir, entry.name)+ if (entry.isDirectory()) {+ removeDirSync(full)+ } else {+ unlinkSync(full)+ }+ }+ rmdirSync(dir)+ if (existsSync(dir)) {+ throw new Error(`[stage-native-deps] failed to remove ${dir}`)+ }+}+function patchUnixTerminalAsarPaths(destRoot) {const filePath = join(destRoot, 'lib', 'unixTerminal.js')if (!existsSync(filePath)) return@@ -74,7 +121,7 @@ function copyGlobByExt(srcDir, destDir, extensions) {}if (extensions.some((ext) => entry.name.endsWith(ext))) {mkdirSync(destDir, { recursive: true })- cpSync(join(srcDir, entry.name), join(destDir, entry.name))+ copyFileSync(join(srcDir, entry.name), join(destDir, entry.name))}}}@@ -96,12 +143,12 @@ function copyBuildRelease(srcDir, destDir) {mkdirSync(destDir, { recursive: true })for (const entry of readdirSync(srcDir, { withFileTypes: true })) {if (entry.isDirectory()) {- cpSync(join(srcDir, entry.name), join(destDir, entry.name), { recursive: true })+ copyDirSync(join(srcDir, entry.name), join(destDir, entry.name))continue}if (entry.name === 'spawn-helper' || /\.(node|dll|exe)$/.test(entry.name)) {const destFile = join(destDir, entry.name)- cpSync(join(srcDir, entry.name), destFile)+ copyFileSync(join(srcDir, entry.name), destFile)if (entry.name === 'spawn-helper') {makeExecutable(destFile)}@@ -240,12 +287,12 @@ function validateStagedBinaries(destRoot, targetPlatform) {export function stageNodePtyInto(srcRoot, destRoot, { platform = process.platform, arch = process.arch } = {}) {const hostMatch = platform === process.platform && arch === process.arch- rmSync(destRoot, { recursive: true, force: true })+ removeDirSync(destRoot)mkdirSync(destRoot, { recursive: true })// package.json — needed so `require('node-pty')` resolves the package// (reads "main") rather than treating it as a directory with no entry.- cpSync(join(srcRoot, 'package.json'), join(destRoot, 'package.json'))+ copyFileSync(join(srcRoot, 'package.json'), join(destRoot, 'package.json'))// lib/**/*.js — the JS surface node-pty's `main` points into.copyGlobByExt(join(srcRoot, 'lib'), join(destRoot, 'lib'), ['.js'])@@ -261,16 +308,16 @@ export function stageNodePtyInto(srcRoot, destRoot, { platform = process.platformkdirSync(destPrebuild, { recursive: true })for (const entry of readdirSync(prebuildDir, { withFileTypes: true })) {if (entry.name === 'conpty' && entry.isDirectory()) {- cpSync(join(prebuildDir, 'conpty'), join(destPrebuild, 'conpty'), { recursive: true })+ copyDirSync(join(prebuildDir, 'conpty'), join(destPrebuild, 'conpty'))continue}if (entry.isFile() && /\.(node|dll|exe)$/.test(entry.name)) {- cpSync(join(prebuildDir, entry.name), join(destPrebuild, entry.name))+ copyFileSync(join(prebuildDir, entry.name), join(destPrebuild, entry.name))continue}if (entry.name === 'spawn-helper') {const destFile = join(destPrebuild, entry.name)- cpSync(join(prebuildDir, entry.name), destFile)+ copyFileSync(join(prebuildDir, entry.name), destFile)makeExecutable(destFile)}}diff --git a/apps/desktop/scripts/stage-native-deps.test.mjs b/apps/desktop/scripts/stage-native-deps.test.mjsindex 9d20a039fbb..4e74bccc5ed 100644--- a/apps/desktop/scripts/stage-native-deps.test.mjs+++ b/apps/desktop/scripts/stage-native-deps.test.mjs@@ -339,6 +339,48 @@ test.skipIf(process.platform === 'win32')(})+// ─── non-ASCII path regression tests ───────────────────────────────+//+// Node 24's native fs.cpSync/fs.rmSync mishandle non-ASCII Windows paths+// (accented user-profile dirs): recursive copies fail or crash, overwrite+// copies fail with a bogus errno-0 unlink error, and rmSync silently+// deletes nothing. Staging therefore uses libuv-backed primitives only.+// This test stages into an accented src/dest tree — twice, so the+// restage exercises the delete-then-recopy path — to keep it that way.++test('non-ASCII paths: staging into an accented tree works and restages cleanly', () => {+ const tmp = fs.mkdtempSync(join(os.tmpdir(), 'hermes-stage-'))+ try {+ const accented = join(tmp, 'áccentéd ünïcødé-pŕöfílé')+ const srcRoot = join(accented, 'node-pty')+ const destRoot = join(accented, 'dest')++ makeFakeNodePty(srcRoot, {+ prebuildPlatform: process.platform,+ prebuildArch: process.arch+ })+ // Windows prebuilds ship a nested conpty/ payload — cover the+ // recursive-directory branch on every platform.+ const conptyDir = join(srcRoot, 'prebuilds', `${process.platform}-${process.arch}`, 'conpty')+ fs.mkdirSync(conptyDir, { recursive: true })+ fs.writeFileSync(join(conptyDir, 'conpty.dll'), 'fake dll')+ fs.writeFileSync(join(conptyDir, 'OpenConsole.exe'), 'fake exe')++ for (let pass = 1; pass <= 2; pass++) {+ stageNodePtyInto(srcRoot, destRoot, { platform: process.platform, arch: process.arch })++ const stagedPrebuild = join(destRoot, 'prebuilds', `${process.platform}-${process.arch}`)+ assert.equal(existsSync(join(destRoot, 'package.json')), true, `pass ${pass}: package.json staged`)+ assert.equal(existsSync(join(destRoot, 'lib', 'index.js')), true, `pass ${pass}: lib staged`)+ assert.equal(existsSync(join(stagedPrebuild, 'pty.node')), true, `pass ${pass}: prebuild staged`)+ assert.equal(existsSync(join(stagedPrebuild, 'conpty', 'conpty.dll')), true, `pass ${pass}: conpty dir staged`)+ assert.equal(existsSync(join(stagedPrebuild, 'conpty', 'OpenConsole.exe')), true, `pass ${pass}: conpty exe staged`)+ }+ } finally {+ fs.rmSync(tmp, { recursive: true, force: true })+ }+})+test('validation rejects a staged binary with the wrong platform magic', () => {const tmp = fs.mkdtempSync(join(os.tmpdir(), 'hermes-stage-'))try {