Prechádzať zdrojové kódy

Merge codex/subprocess-win32-process-primitives into codex/subprocess-native-containment

# Conflicts:
#	packages/subprocess/win32-process/package.json
pku-xht 1 mesiac pred
rodič
commit
884cd6be70

+ 0 - 2
packages/sandbox/sandbox-windows-acl/src/index.ts

@@ -55,8 +55,6 @@ import * as abi from './win32-abi.ts'
 export { AclWriteGrant } from './grant.ts'
 export { assertTempRootOutsideWorkspace } from './path-boundary.ts'
 export { tempWriteSid, workspaceWriteSid } from './workspace-sid.ts'
-export { Win32Error } from '@deepseek-ai/dsh-win32-process'
-
 /** Construction options: the workspace/temp allowlists and their distinct SID identities. */
 export interface AclSandboxOptions {
   /** Directories the confined child may write into (must exist and be caller-owned). */

+ 1 - 1
packages/sandbox/sandbox-windows-acl/tests/ffi.spec.ts

@@ -9,7 +9,7 @@
 import { describe, expect, it, vi } from 'vitest'
 import koffi from 'koffi'
 
-import { Win32Error } from '../src/index.ts'
+import { Win32Error } from '@deepseek-ai/dsh-win32-process'
 import {
   allocBytes, decodePtrAt, getTempPath,
   isInvalidHandle, sameSidAt,

+ 1 - 1
packages/subprocess/win32-process/package.json

@@ -1,7 +1,7 @@
 {
   "name": "@deepseek-ai/dsh-win32-process",
   "description": "Shared low-level Win32 process, stdio, and Job Object primitives",
-  "version": "0.1.0-rc.7",
+  "version": "0.1.0-rc.8",
   "publishConfig": {
     "access": "public"
   },

+ 9 - 5
packages/subprocess/win32-process/tests/process-failure-paths.spec.ts

@@ -254,7 +254,7 @@ describe('spawnInheritedJobProcess failure paths', () => {
 
   it('terminates the suspended child before closing handles when Job assignment fails', () => {
     const terminateProcess = vi.fn(() => 1)
-    const { api, closeHandle } = inheritedApi({
+    const { api, closeHandle, closed } = inheritedApi({
       assignProcessToJobObject: vi.fn(() => 0),
       terminateProcess,
     })
@@ -269,10 +269,11 @@ describe('spawnInheritedJobProcess failure paths', () => {
     expect(closeHandle).toHaveBeenCalledWith(201n)
     expect(closeHandle).toHaveBeenCalledWith(200n)
     expect(closeHandle).toHaveBeenCalledWith(100n)
+    expect(closed).toEqual([201n, 200n, 100n])
   })
 
   it('closes the assigned child and Job when ResumeThread fails', () => {
-    const { api, closeHandle } = inheritedApi({ resumeThread: vi.fn(() => 0xFFFFFFFF) })
+    const { api, closeHandle, closed } = inheritedApi({ resumeThread: vi.fn(() => 0xFFFFFFFF) })
     let caught: unknown
     try {
       spawnInheritedJobProcess(api, { command: 'probe.exe', args: [], cwd: 'C:\\', token })
@@ -283,6 +284,7 @@ describe('spawnInheritedJobProcess failure paths', () => {
     expect(closeHandle).toHaveBeenCalledWith(201n)
     expect(closeHandle).toHaveBeenCalledWith(200n)
     expect(closeHandle).toHaveBeenCalledWith(100n)
+    expect(closed).toEqual([201n, 200n, 100n])
   })
 
   it('closes the job and reports when SetInformationJobObject fails', () => {
@@ -311,7 +313,9 @@ describe('spawnInheritedJobProcess failure paths', () => {
   })
 
   it('returns the pid, process handle, and kill-on-close job when every call succeeds', () => {
-    const { api, closeHandle } = inheritedApi()
+    const assignProcessToJobObject = vi.fn(() => 1)
+    const resumeThread = vi.fn(() => 0)
+    const { api, closeHandle } = inheritedApi({ assignProcessToJobObject, resumeThread })
     const spawned = spawnInheritedJobProcess(api, { command: 'probe.exe', args: [], cwd: 'C:\\', token })
     expect(spawned.pid).toBe(1234)
     expect(spawned.process).toBe(200n)
@@ -320,8 +324,8 @@ describe('spawnInheritedJobProcess failure paths', () => {
     expect(closeHandle).toHaveBeenCalledWith(201n)
     expect(closeHandle).not.toHaveBeenCalledWith(200n)
     expect(closeHandle).not.toHaveBeenCalledWith(100n)
-    expect(api.assignProcessToJobObject).toHaveBeenCalledWith(100n, 200n)
-    expect(api.resumeThread).toHaveBeenCalledWith(201n)
+    expect(assignProcessToJobObject).toHaveBeenCalledWith(100n, 200n)
+    expect(resumeThread).toHaveBeenCalledWith(201n)
   })
 })
 

+ 0 - 32
packages/subprocess/win32-process/tests/process.spec.ts

@@ -186,38 +186,6 @@ describe('spawnInheritedJobProcess', () => {
     expect(closeHandle).toHaveBeenCalledWith(60n)
   })
 
-  it('terminates the suspended child before closing handles when Job assignment fails', () => {
-    const closeHandle = vi.fn((_handle: NativePtr) => 1)
-    const terminateProcess = vi.fn(() => 1)
-    const { api } = inheritedApi({
-      assignProcessToJobObject: vi.fn(() => 0),
-      terminateProcess,
-      closeHandle,
-    })
-    expect(() => spawnInheritedJobProcess(api, {
-      command: 'cmd.exe',
-      args: [],
-      cwd: 'C:\\work',
-      token,
-    })).toThrow(Win32Error)
-    expect(terminateProcess).toHaveBeenCalledWith(60n, 1)
-    expect(closeHandle.mock.calls.map(([handle]) => handle)).toEqual([61n, 60n, 50n])
-  })
-
-  it('closes the assigned Job and process when ResumeThread fails', () => {
-    const closeHandle = vi.fn((_handle: NativePtr) => 1)
-    const { api } = inheritedApi({
-      resumeThread: vi.fn(() => 0xFFFFFFFF),
-      closeHandle,
-    })
-    expect(() => spawnInheritedJobProcess(api, {
-      command: 'cmd.exe',
-      args: [],
-      cwd: 'C:\\work',
-      token,
-    })).toThrow(Win32Error)
-    expect(closeHandle.mock.calls.map(([handle]) => handle)).toEqual([61n, 60n, 50n])
-  })
 })
 
 describe('wait and pipe cleanup', () => {