mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-02 04:00:31 +00:00
Two private experimental packages run the whole harness tree inside one dedicated Web Worker. dsh-experimental-webworker-runtime owns the in-memory VFS (BigInt stats with per-path identity and strictly increasing mtimes), the CommonJS wrapper loader over a lazily-evaluated builtin table whose shims typecheck against Node's own module types, the postMessage tunnel speaking plain HTTP, the AsyncLocalStorage runtime, and the worker assembly. dsh-experimental-webworker-packer lowers every module body at pack time against the shared wrapper contract, sweeps the profile closure by static reachability, and writes a deterministically gzip-compressed tar the worker inflates through the browser's native DecompressionStream while it downloads.
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
/**
|
|
* The worker's process shim: the layout-derived environment and the Node 22
|
|
* `getBuiltinModule` face, which must answer the loader's module proxies for
|
|
* builtin ids and undefined for everything else — never an image resolution.
|
|
*/
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { installProcessGlobal } from '../../src/node/globals/process.ts'
|
|
import { setActiveModuleLoader, WorkerModuleLoader } from '../../src/module-system/module-loader.ts'
|
|
import { MemoryVfs } from '../../src/storage/memory.ts'
|
|
|
|
const realProcess = globalThis.process
|
|
|
|
afterEach(() => {
|
|
;(globalThis as { process: unknown }).process = realProcess
|
|
})
|
|
|
|
describe('process shim', () => {
|
|
it('publishes cwd, env, and version zero for the loader probe', () => {
|
|
const shim = installProcessGlobal({ cwd: '/dsh', env: { DSH_HOME: '/dsh/home' } })
|
|
expect(shim.cwd()).toBe('/dsh')
|
|
expect(shim.env.DSH_HOME).toBe('/dsh/home')
|
|
// "0.0.0" keeps the vendored Loader off Node internals so the worker owns
|
|
// the module seam.
|
|
expect(shim.versions.node).toBe('0.0.0')
|
|
})
|
|
|
|
it('answers getBuiltinModule from the module proxies and undefined otherwise', () => {
|
|
const fs = { marker: 'fs-proxy' }
|
|
// The table holds factories, and a builtin must keep one identity across
|
|
// requires (`instanceof`, `Buffer.isBuffer`), so this one answers with the
|
|
// same object every time.
|
|
const factory = (): unknown => fs
|
|
const vfs = new MemoryVfs()
|
|
vfs.seedDirectory('/dsh')
|
|
const loader = new WorkerModuleLoader({
|
|
vfs,
|
|
root: '/dsh',
|
|
staticModules: { 'node:fs': factory, 'fs': factory },
|
|
})
|
|
setActiveModuleLoader(loader)
|
|
const shim = installProcessGlobal({ cwd: '/dsh', env: {} })
|
|
// The shim calls the factory: a caller receives the module, never the thunk.
|
|
expect(shim.getBuiltinModule('fs')).toBe(fs)
|
|
expect(shim.getBuiltinModule('node:fs')).toBe(fs)
|
|
expect(shim.getBuiltinModule('no-such-builtin')).toBeUndefined()
|
|
})
|
|
})
|