From 6c879ab34a04ca233f60c9e1d219c3cc1a411c02 Mon Sep 17 00:00:00 2001 From: lofyer Date: Fri, 14 Aug 2026 13:25:00 +0800 Subject: [PATCH] refactor: remove ineffective Harness window guard --- .../deepseek-harness-child-process.test.ts | 118 ------------------ .../agent/deepseek-harness-child-process.ts | 82 ------------ src/main/deepseek-harness-host-bootstrap.ts | 4 - 3 files changed, 204 deletions(-) delete mode 100644 src/main/agent/deepseek-harness-child-process.test.ts delete mode 100644 src/main/agent/deepseek-harness-child-process.ts diff --git a/src/main/agent/deepseek-harness-child-process.test.ts b/src/main/agent/deepseek-harness-child-process.test.ts deleted file mode 100644 index 464537e..0000000 --- a/src/main/agent/deepseek-harness-child-process.test.ts +++ /dev/null @@ -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 - spawn: ReturnType - spawnSync: ReturnType -} { - 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) - }) -}) diff --git a/src/main/agent/deepseek-harness-child-process.ts b/src/main/agent/deepseek-harness-child-process.ts deleted file mode 100644 index a505d4b..0000000 --- a/src/main/agent/deepseek-harness-child-process.ts +++ /dev/null @@ -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() - } -} diff --git a/src/main/deepseek-harness-host-bootstrap.ts b/src/main/deepseek-harness-host-bootstrap.ts index ed675cd..a5c2463 100644 --- a/src/main/deepseek-harness-host-bootstrap.ts +++ b/src/main/deepseek-harness-host-bootstrap.ts @@ -12,12 +12,9 @@ import { startControlledDeepSeekHarnessHost, type ControlledHarnessHost } from './deepseek-harness-host' -import { installHarnessChildProcessWindowGuard } from './agent/deepseek-harness-child-process' const parentPort = process.parentPort const restoreDiagnostics = installHarnessDiagnosticGuard() -const restoreChildProcessWindowGuard = - installHarnessChildProcessWindowGuard() // The Windows ACL sandbox launches its JavaScript runner through // `process.execPath`. Inside an Electron UtilityProcess that path is Electron, // so descendants must opt into Electron's supported Node execution mode. @@ -44,7 +41,6 @@ async function close(): Promise { closed = true await host?.dispose().catch(() => undefined) transport?.dispose() - restoreChildProcessWindowGuard() restoreDiagnostics() }