refactor: remove ineffective Harness window guard
This commit is contained in:
@@ -1,118 +0,0 @@
|
|||||||
import type childProcess from 'node:child_process'
|
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
|
||||||
import { installHarnessChildProcessWindowGuard } from './deepseek-harness-child-process'
|
|
||||||
|
|
||||||
type HarnessChildProcessModule = Pick<
|
|
||||||
typeof childProcess,
|
|
||||||
'execFileSync' | 'spawn' | 'spawnSync'
|
|
||||||
>
|
|
||||||
|
|
||||||
function fakeChildProcessModule(): {
|
|
||||||
target: HarnessChildProcessModule
|
|
||||||
execFileSync: ReturnType<typeof vi.fn>
|
|
||||||
spawn: ReturnType<typeof vi.fn>
|
|
||||||
spawnSync: ReturnType<typeof vi.fn>
|
|
||||||
} {
|
|
||||||
const execFileSync = vi.fn(() => 'output')
|
|
||||||
const spawn = vi.fn(() => ({ pid: 1 }))
|
|
||||||
const spawnSync = vi.fn(() => ({ status: 0 }))
|
|
||||||
return {
|
|
||||||
target: {
|
|
||||||
execFileSync:
|
|
||||||
execFileSync as unknown as HarnessChildProcessModule['execFileSync'],
|
|
||||||
spawn: spawn as unknown as HarnessChildProcessModule['spawn'],
|
|
||||||
spawnSync:
|
|
||||||
spawnSync as unknown as HarnessChildProcessModule['spawnSync']
|
|
||||||
},
|
|
||||||
execFileSync,
|
|
||||||
spawn,
|
|
||||||
spawnSync
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('DeepSeek Harness child process window guard', () => {
|
|
||||||
it('does not alter child process launches outside Windows', () => {
|
|
||||||
const { target, spawn } = fakeChildProcessModule()
|
|
||||||
const originalSpawn = target.spawn
|
|
||||||
const syncExports = vi.fn()
|
|
||||||
|
|
||||||
const restore = installHarnessChildProcessWindowGuard(
|
|
||||||
'linux',
|
|
||||||
target,
|
|
||||||
syncExports
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(target.spawn).toBe(originalSpawn)
|
|
||||||
expect(syncExports).not.toHaveBeenCalled()
|
|
||||||
restore()
|
|
||||||
expect(spawn).not.toHaveBeenCalled()
|
|
||||||
expect(syncExports).not.toHaveBeenCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('forces hidden Windows launches and restores the original functions', () => {
|
|
||||||
const { target, execFileSync, spawn, spawnSync } =
|
|
||||||
fakeChildProcessModule()
|
|
||||||
const originals = { ...target }
|
|
||||||
const syncExports = vi.fn()
|
|
||||||
|
|
||||||
const restore = installHarnessChildProcessWindowGuard(
|
|
||||||
'win32',
|
|
||||||
target,
|
|
||||||
syncExports
|
|
||||||
)
|
|
||||||
|
|
||||||
target.spawn('runner.exe', ['--probe'], {
|
|
||||||
cwd: 'C:\\workspace',
|
|
||||||
windowsHide: false
|
|
||||||
})
|
|
||||||
target.spawnSync('taskkill.exe', {
|
|
||||||
stdio: 'ignore'
|
|
||||||
})
|
|
||||||
target.spawnSync('where.exe', undefined, {
|
|
||||||
encoding: 'utf8'
|
|
||||||
})
|
|
||||||
target.execFileSync('where.exe', ['pwsh.exe'], {
|
|
||||||
encoding: 'utf8',
|
|
||||||
windowsHide: false
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(spawn).toHaveBeenCalledWith(
|
|
||||||
'runner.exe',
|
|
||||||
['--probe'],
|
|
||||||
expect.objectContaining({
|
|
||||||
cwd: 'C:\\workspace',
|
|
||||||
windowsHide: true
|
|
||||||
})
|
|
||||||
)
|
|
||||||
expect(spawnSync).toHaveBeenCalledWith(
|
|
||||||
'where.exe',
|
|
||||||
undefined,
|
|
||||||
expect.objectContaining({
|
|
||||||
encoding: 'utf8',
|
|
||||||
windowsHide: true
|
|
||||||
})
|
|
||||||
)
|
|
||||||
expect(spawnSync).toHaveBeenCalledWith(
|
|
||||||
'taskkill.exe',
|
|
||||||
expect.objectContaining({
|
|
||||||
stdio: 'ignore',
|
|
||||||
windowsHide: true
|
|
||||||
})
|
|
||||||
)
|
|
||||||
expect(execFileSync).toHaveBeenCalledWith(
|
|
||||||
'where.exe',
|
|
||||||
['pwsh.exe'],
|
|
||||||
expect.objectContaining({
|
|
||||||
encoding: 'utf8',
|
|
||||||
windowsHide: true
|
|
||||||
})
|
|
||||||
)
|
|
||||||
expect(syncExports).toHaveBeenCalledTimes(1)
|
|
||||||
|
|
||||||
restore()
|
|
||||||
restore()
|
|
||||||
|
|
||||||
expect(target).toMatchObject(originals)
|
|
||||||
expect(syncExports).toHaveBeenCalledTimes(2)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
import childProcess from 'node:child_process'
|
|
||||||
import { syncBuiltinESMExports } from 'node:module'
|
|
||||||
|
|
||||||
type HarnessChildProcessModule = Pick<
|
|
||||||
typeof childProcess,
|
|
||||||
'execFileSync' | 'spawn' | 'spawnSync'
|
|
||||||
>
|
|
||||||
|
|
||||||
type SyncBuiltinExports = () => void
|
|
||||||
|
|
||||||
function withHiddenWindow(args: unknown[]): unknown[] {
|
|
||||||
const next = [...args]
|
|
||||||
const optionsIndex =
|
|
||||||
Array.isArray(next[1]) ||
|
|
||||||
(next[1] === undefined && next.length >= 3)
|
|
||||||
? 2
|
|
||||||
: 1
|
|
||||||
const options = next[optionsIndex]
|
|
||||||
next[optionsIndex] = {
|
|
||||||
...(options && typeof options === 'object' ? options : {}),
|
|
||||||
windowsHide: true
|
|
||||||
}
|
|
||||||
return next
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DeepSeek Harness 0.1.0-rc.6 omits `windowsHide` when its local subprocess
|
|
||||||
* service starts the ACL runner and PowerShell. In an Electron GUI process
|
|
||||||
* that can briefly create a visible console window. Keep this override scoped
|
|
||||||
* to the isolated Harness UtilityProcess and synchronize the built-in ESM
|
|
||||||
* bindings already captured by the bundled Harness modules.
|
|
||||||
*/
|
|
||||||
export function installHarnessChildProcessWindowGuard(
|
|
||||||
platform: NodeJS.Platform = process.platform,
|
|
||||||
target: HarnessChildProcessModule = childProcess,
|
|
||||||
syncExports: SyncBuiltinExports = syncBuiltinESMExports
|
|
||||||
): () => void {
|
|
||||||
if (platform !== 'win32') {
|
|
||||||
return () => undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const originals = {
|
|
||||||
execFileSync: target.execFileSync,
|
|
||||||
spawn: target.spawn,
|
|
||||||
spawnSync: target.spawnSync
|
|
||||||
}
|
|
||||||
const guardedExecFileSync = ((...args: unknown[]) =>
|
|
||||||
Reflect.apply(
|
|
||||||
originals.execFileSync,
|
|
||||||
target,
|
|
||||||
withHiddenWindow(args)
|
|
||||||
)) as typeof target.execFileSync
|
|
||||||
const guardedSpawn = ((...args: unknown[]) =>
|
|
||||||
Reflect.apply(
|
|
||||||
originals.spawn,
|
|
||||||
target,
|
|
||||||
withHiddenWindow(args)
|
|
||||||
)) as typeof target.spawn
|
|
||||||
const guardedSpawnSync = ((...args: unknown[]) =>
|
|
||||||
Reflect.apply(
|
|
||||||
originals.spawnSync,
|
|
||||||
target,
|
|
||||||
withHiddenWindow(args)
|
|
||||||
)) as typeof target.spawnSync
|
|
||||||
|
|
||||||
target.execFileSync = guardedExecFileSync
|
|
||||||
target.spawn = guardedSpawn
|
|
||||||
target.spawnSync = guardedSpawnSync
|
|
||||||
syncExports()
|
|
||||||
|
|
||||||
let restored = false
|
|
||||||
return () => {
|
|
||||||
if (restored) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
restored = true
|
|
||||||
target.execFileSync = originals.execFileSync
|
|
||||||
target.spawn = originals.spawn
|
|
||||||
target.spawnSync = originals.spawnSync
|
|
||||||
syncExports()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,12 +12,9 @@ import {
|
|||||||
startControlledDeepSeekHarnessHost,
|
startControlledDeepSeekHarnessHost,
|
||||||
type ControlledHarnessHost
|
type ControlledHarnessHost
|
||||||
} from './deepseek-harness-host'
|
} from './deepseek-harness-host'
|
||||||
import { installHarnessChildProcessWindowGuard } from './agent/deepseek-harness-child-process'
|
|
||||||
|
|
||||||
const parentPort = process.parentPort
|
const parentPort = process.parentPort
|
||||||
const restoreDiagnostics = installHarnessDiagnosticGuard()
|
const restoreDiagnostics = installHarnessDiagnosticGuard()
|
||||||
const restoreChildProcessWindowGuard =
|
|
||||||
installHarnessChildProcessWindowGuard()
|
|
||||||
// The Windows ACL sandbox launches its JavaScript runner through
|
// The Windows ACL sandbox launches its JavaScript runner through
|
||||||
// `process.execPath`. Inside an Electron UtilityProcess that path is Electron,
|
// `process.execPath`. Inside an Electron UtilityProcess that path is Electron,
|
||||||
// so descendants must opt into Electron's supported Node execution mode.
|
// so descendants must opt into Electron's supported Node execution mode.
|
||||||
@@ -44,7 +41,6 @@ async function close(): Promise<void> {
|
|||||||
closed = true
|
closed = true
|
||||||
await host?.dispose().catch(() => undefined)
|
await host?.dispose().catch(() => undefined)
|
||||||
transport?.dispose()
|
transport?.dispose()
|
||||||
restoreChildProcessWindowGuard()
|
|
||||||
restoreDiagnostics()
|
restoreDiagnostics()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user