mirror of
https://github.com/stablyai/orca.git
synced 2026-09-25 08:02:31 +00:00
* refactor(windows): vendor the registry addon as @orca/windows-registry windows-native-registry@3.2.2 was last published in 2023 by a single maintainer. Orca called two of its exports, both read-only, so the whole dependency is replaced by a local N-API addon under native/. The vendored addon is read-only by construction: setValue, createKey and deleteKey are gone, so RegDeleteTreeW no longer ships in the app. Two upstream defects are also fixed rather than carried over — the name/data scratch buffers were file-scope statics that concurrent reads would scribble over, and createKey/deleteKey called .c_str() on a temporary. Build wiring keeps the existing shape: still an optionalDependency gated to win32, still excluded from pnpm's allowBuilds so only Orca's own Windows rebuild runs node-gyp for it, still copied into the packaged resources. The CI native caches now key on the vendored sources so an addon.cc edit cannot restore a stale .node. * test(windows): check the vendored registry addon against reg.exe The addon is vendored source, so no upstream release proves it still decodes values the way Orca's PATH readers expect. reg.exe is the only independent oracle on the box. * ci(windows): register the registry addon test on the Windows runner A Windows-gated file self-skips on ubuntu, so without both registrations it reports success while running on no machine at all. * fix(build): link the registry addon as a workspace package, not file: As a `file:` dependency pnpm re-resolved and re-linked the package on every install, including `--frozen-lockfile` (measured: "added 1" on a repeat no-op install). That virtual-store churn ran concurrently with node-gyp reading the same tree and cost @vscode/windows-process-tree its binding.gyp mid-rebuild, failing package (windows) whenever the native cache hit and only that module needed building. The linux packaging job hit the same race from the other side, as a pnpm staging move failure. A workspace link resolves once and leaves the store alone; repeat installs are now 55ms no-ops. native/windows-registry is listed explicitly so `packages:` still does not auto-discover mobile/. * fix(build): stop tracking node-gyp output for the vendored addon The build/ tree is generated per host and ABI; the committed copy was macOS-specific gyp scaffolding from a local build and would have shipped stale Makefiles to every checkout. * chore: ignore the vendored addon's node-gyp bin output too node-gyp also emits bin/<platform>-<abi>/ beside build/; both are per-host generated output that must never be committed.
403 lines
15 KiB
JavaScript
403 lines
15 KiB
JavaScript
import { existsSync, readFileSync } from 'node:fs'
|
|
import { removeTreeSync } from '../../src/shared/windows-transient-lock-removal.ts'
|
|
import { join } from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
gitLineEndingEnv,
|
|
initGitWorkTree,
|
|
mkTempProject,
|
|
runRebuildScript,
|
|
writeFakeElectronRebuild,
|
|
writeFakeLoadableNodePty,
|
|
writeFakeNodePtyConptyPayload,
|
|
writeFakeUsableElectronPackage,
|
|
writeFakeWindowsProcessTree,
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi,
|
|
writeFakeWindowsRegistry,
|
|
writeNodePtyPatchFile,
|
|
writePatchedNodePtyBuildArtifacts,
|
|
writeWindowsProcessTreePatchFile
|
|
} from './rebuild-native-deps-test-fixtures.mjs'
|
|
|
|
describe('rebuild-native-deps patched node-pty rebuild', () => {
|
|
it.skipIf(process.platform !== 'win32')(
|
|
'repairs a missing ConPTY runtime before probing without recompiling node-pty',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir, { nativeDir: '../build/Release/' })
|
|
writeFakeWindowsRegistry(projectDir)
|
|
writeFakeWindowsProcessTree(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, process.arch)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath,
|
|
npm_config_platform: 'win32',
|
|
npm_config_arch: process.arch
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('Restored node-pty ConPTY runtime files')
|
|
expect(result.stdout).toContain(
|
|
'Native modules already load in Electron; skipping rebuild.'
|
|
)
|
|
expect(existsSync(rebuildLogPath)).toBe(false)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
it('stages windows-process-tree node-addon-api headers before a Windows rebuild', () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi(projectDir)
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{ npm_config_platform: 'win32', npm_config_arch: 'x64' },
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(
|
|
readFileSync(
|
|
join(
|
|
projectDir,
|
|
'node_modules',
|
|
'@vscode',
|
|
'windows-process-tree',
|
|
'deps',
|
|
'node-addon-api',
|
|
'napi.h'
|
|
),
|
|
'utf8'
|
|
)
|
|
).toBe('// napi.h\n')
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
|
|
const commandLineSourcePath = (projectDir) =>
|
|
join(
|
|
projectDir,
|
|
'node_modules',
|
|
'@vscode',
|
|
'windows-process-tree',
|
|
'src',
|
|
'process_commandline.cc'
|
|
)
|
|
|
|
// Why inside a git work tree: `git apply` run under one prefixes patch paths
|
|
// with the cwd-relative prefix, silently skips what does not match, and still
|
|
// exits 0. The package dir is always under the project root in production, so
|
|
// a fixture in %TEMP% alone would pass while the real repair did nothing.
|
|
//
|
|
// Why both line-ending modes: the patch is stored LF while upstream ships this
|
|
// source CRLF, so whether the pre-image matches depends on `core.autocrlf` --
|
|
// and under `false`, Git's own built-in default, it did not. The repair blinds
|
|
// git to the repo, so that value comes from global config, i.e. from whichever
|
|
// option the developer's installer wrote. Pinning both makes the case cover the
|
|
// host that breaks rather than the host that happens to run it.
|
|
for (const autocrlf of ['false', 'true']) {
|
|
it(`repairs an un-applied command-line patch in a work tree (autocrlf=${autocrlf})`, () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
initGitWorkTree(projectDir)
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi(projectDir, {
|
|
commandLinePatchApplied: false
|
|
})
|
|
writeWindowsProcessTreePatchFile(projectDir)
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{
|
|
npm_config_platform: 'win32',
|
|
npm_config_arch: 'x64',
|
|
...gitLineEndingEnv(autocrlf)
|
|
},
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(readFileSync(commandLineSourcePath(projectDir), 'utf8')).toContain(
|
|
'kProcessCommandLineInformation'
|
|
)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Why fail rather than build: an unpatched command-line reader compiles fine
|
|
// and then opens every process with PROCESS_VM_READ to walk its PEB, which is
|
|
// the primitive the patch exists to remove.
|
|
it('refuses a Windows rebuild when the command-line patch cannot be applied', () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
initGitWorkTree(projectDir)
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi(projectDir, { commandLinePatchApplied: false })
|
|
// No patch file, so the repair has nothing to apply.
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{ npm_config_platform: 'win32', npm_config_arch: 'x64' },
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status).not.toBe(0)
|
|
expect(result.stderr).toContain('process_commandline.cc')
|
|
expect(readFileSync(commandLineSourcePath(projectDir), 'utf8')).not.toContain(
|
|
'kProcessCommandLineInformation'
|
|
)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
|
|
it('refuses a Windows rebuild when the process creation-time patch is missing', () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi(projectDir, { creationTimePatchApplied: false })
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{ npm_config_platform: 'win32', npm_config_arch: 'x64' },
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status).not.toBe(0)
|
|
expect(result.stderr).toContain('process creation-time patch')
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
|
|
it('restores the ConPTY runtime payload after a Windows Electron rebuild', () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{ npm_config_platform: 'win32', npm_config_arch: 'x64' },
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('Restored node-pty ConPTY runtime files for win10-x64')
|
|
const runtimeDir = join(projectDir, 'node_modules', 'node-pty', 'build', 'Release', 'conpty')
|
|
expect(readFileSync(join(runtimeDir, 'conpty.dll'), 'utf8')).toBe('conpty.dll x64')
|
|
expect(readFileSync(join(runtimeDir, 'OpenConsole.exe'), 'utf8')).toBe('OpenConsole.exe x64')
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
|
|
it.skipIf(process.platform !== 'win32')(
|
|
'does not rebuild a healthy node-pty when another Windows addon fails its probe',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir)
|
|
writeFakeWindowsProcessTree(projectDir)
|
|
writeFakeNodePtyConptyPayload(projectDir, process.arch)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath,
|
|
npm_config_platform: 'win32',
|
|
npm_config_arch: process.arch
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('Rebuilding failed native modules: @orca/windows-registry')
|
|
const rebuildCall = JSON.parse(readFileSync(rebuildLogPath, 'utf8').trim())
|
|
expect(rebuildCall.onlyModules).toEqual(['@orca/windows-registry'])
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform !== 'win32')(
|
|
'rebuilds a loadable ConPTY native that lacks Orca job ownership',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir, { ownsPtyJob: false })
|
|
writeFakeWindowsRegistry(projectDir)
|
|
writeFakeWindowsProcessTree(projectDir)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath,
|
|
npm_config_platform: 'win32',
|
|
npm_config_arch: process.arch
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('Rebuilding failed native modules: node-pty')
|
|
expect(result.stdout).toContain('missing listJobProcessIds')
|
|
const rebuildCall = JSON.parse(readFileSync(rebuildLogPath, 'utf8').trim())
|
|
expect(rebuildCall.onlyModules).toEqual(['node-pty'])
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'rebuilds when Electron can load node-pty but patched build artifacts are missing',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir)
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir)
|
|
writeNodePtyPatchFile(projectDir)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain(
|
|
'Patched node-pty build artifacts are missing; rebuilding from source.'
|
|
)
|
|
|
|
const rebuildCall = JSON.parse(readFileSync(rebuildLogPath, 'utf8').trim())
|
|
expect(rebuildCall.onlyModules).toEqual(['node-pty'])
|
|
expect(rebuildCall.ignoreModules).toEqual(['cpu-features'])
|
|
expect(rebuildCall.force).toBe(true)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'keeps the Electron load-probe fast path once patched node-pty artifacts exist',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir)
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir, { nativeDir: '../build/Release/' })
|
|
writeNodePtyPatchFile(projectDir)
|
|
writePatchedNodePtyBuildArtifacts(projectDir)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain(
|
|
'Native modules already load in Electron; skipping rebuild.'
|
|
)
|
|
expect(existsSync(rebuildLogPath)).toBe(false)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'rebuilds when patched artifacts exist but Electron falls back to node-pty prebuilds',
|
|
() => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
const rebuildLogPath = join(projectDir, 'electron-rebuild.log')
|
|
writeFakeUsableElectronPackage(projectDir)
|
|
writeFakeElectronRebuild(projectDir, { logPathEnv: 'ORCA_REBUILD_TEST_LOG' })
|
|
writeFakeLoadableNodePty(projectDir, { nativeDir: '../prebuilds/darwin-arm64/' })
|
|
writeNodePtyPatchFile(projectDir)
|
|
writePatchedNodePtyBuildArtifacts(projectDir)
|
|
|
|
const result = runRebuildScript(projectDir, {
|
|
ORCA_REBUILD_TEST_LOG: rebuildLogPath
|
|
})
|
|
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('Rebuilding failed native modules: node-pty')
|
|
expect(result.stdout).toContain("expected build/Release so Orca's node-pty patch is active")
|
|
|
|
const rebuildCall = JSON.parse(readFileSync(rebuildLogPath, 'utf8').trim())
|
|
expect(rebuildCall.onlyModules).toEqual(['node-pty'])
|
|
expect(rebuildCall.force).toBe(true)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
}
|
|
)
|
|
|
|
// The binary this step produces is the one copied into the packaged app. The
|
|
// relay build checks its own artifact and ensure-native-runtime checks what it
|
|
// loads; nothing checked this one, so a rebuild that quietly emitted the
|
|
// upstream reader shipped. Both non-clean states have to fail, which is the
|
|
// caller the tri-state was missing: after a rebuild that reported success, an
|
|
// absent binary is a broken build, not an absence to shrug at.
|
|
for (const [addon, expected] of [
|
|
['unpatched', 'still imports ReadProcessMemory'],
|
|
['none', 'is not there']
|
|
]) {
|
|
it(`fails a Windows rebuild that leaves ${addon} windows-process-tree bytes`, () => {
|
|
const projectDir = mkTempProject()
|
|
|
|
try {
|
|
writeFakeUsableElectronPackage(projectDir, { platform: 'win32' })
|
|
writeFakeElectronRebuild(projectDir, { addon })
|
|
writeFakeNodePtyConptyPayload(projectDir, 'x64')
|
|
writeFakeWindowsProcessTreeWithNodeAddonApi(projectDir)
|
|
|
|
const result = runRebuildScript(
|
|
projectDir,
|
|
{ npm_config_platform: 'win32', npm_config_arch: 'x64' },
|
|
['--platform=win32', '--arch=x64', '--force']
|
|
)
|
|
|
|
expect(result.status).not.toBe(0)
|
|
expect(result.stderr).toContain(expected)
|
|
} finally {
|
|
removeTreeSync(projectDir)
|
|
}
|
|
})
|
|
}
|
|
})
|