mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-29 00:30:04 +08:00
* feat(office): add frame-forwarded preview and bundle integration * feat(office): present document and slideshow frames with video * test(office): simulate video frame cloning across preview sessions * fix(frame-forwarding): preserve document proportions during resize * fix(office-preview): resume frames after tab switches and restore margin dragging * refactor(office-preview): share submitted geometry and simplify fixture cleanup * refactor(office): remove obsolete viewport discard comparison * refactor(office): take shared textures from the dsh-shared-texture services The Office preview spec helper imported the bridge and lease types from the removed @deepseek-ai/dsh-shared-texture-client-types package, passed frame forwarding the failureSource() adapter that its Client service no longer declares, and the specs stubbed globalThis.dshDesktop, which frame forwarding no longer reads. The helper imports the types from @deepseek-ai/dsh-shared-texture/client and drops the adapter, and the specs stop stubbing dshDesktop. The shared-texture Agent Note drops the PR citation from its NodeNext declaration check sentence, and the README model-experience registry rewords the dsh-shared-texture entry. * fix(office-preview): take the React 19 ref types The client moved to React 19, whose types require an initial value for `useRef` and type a DOM ref created with `null` as `RefObject<T | null>`. Refs that start empty now pass `undefined`, the surface takes its element refs as `RefObject<HTMLDivElement | null>`, and `RefObject` replaces the deprecated `MutableRefObject`, as the rest of the client does. * fix(office-preview): align the producer and receiver tests on Kit 0.2.4 * chore(office-preview): refresh the client slot catalog * fix(office-preview): drain document releases and handle slideshow frame failures * refactor(office): expose Kit discovery and editor opening on officeKit * fix(office-preview): preserve slideshows across same-client event reconnects * refactor(frame-forwarding): use single-producer channels and retain Office slide previews * fix(plugins): show native Office preview only in Desktop * fix(office-preview): reconcile slideshow and document lifetimes on reconnect and refresh * fix(office-preview): simplify slideshow recovery and retain hidden fallback views * refactor(office-preview): type document operations and detach playback before refresh * feat(office-preview): lease documents by tab and reopen expired previews * fix(office-preview): retire slideshow mounts without blocking channel recovery * fix(office-preview): restore the last shown slide on channel reconnect * fix(office-preview): preserve channel loss while waiting for the first viewport * fix(office-preview): cancel slideshow readiness when playback stops * test(web): exclude desktop-only bundles in plugin-config e2e * fix(office): cancel retired viewport waits and count successful redraws * fix(office-preview): await timed-out open cleanup on plugin disposal
249 lines
12 KiB
TypeScript
249 lines
12 KiB
TypeScript
/**
|
|
* The Node-compatibility layer's refusals and its small answering faces.
|
|
*
|
|
* Two contracts live here. Every replaced symbol must be PRESENT — a missing
|
|
* CommonJS export degrades to `undefined` and fails at call time somewhere
|
|
* unrelated — and every symbol the worker cannot honour must refuse while naming
|
|
* itself, because these errors are routinely swallowed far from their cause and
|
|
* the name is what places them in a worker session's console.
|
|
*
|
|
* The member lists are the tables the modules are checked against: adding a
|
|
* refusing symbol without listing it here leaves it unproven, and listing one
|
|
* that starts answering fails.
|
|
*/
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { notAvailableError, notImplementedFail } from '../../src/node/notImplementedFail.ts'
|
|
import * as childProcess from '../../src/node/builtin_modules/implemented/child_process.ts'
|
|
import * as dnsPromises from '../../src/node/builtin_modules/mock/dns/promises.ts'
|
|
import * as https from '../../src/node/builtin_modules/mock/https.ts'
|
|
import * as net from '../../src/node/builtin_modules/mock/net.ts'
|
|
import * as sqlite from '../../src/node/builtin_modules/mock/sqlite.ts'
|
|
import * as stream from '../../src/node/builtin_modules/implemented/stream.ts'
|
|
import * as vm from '../../src/node/builtin_modules/mock/vm.ts'
|
|
import * as repl from '../../src/node/builtin_modules/mock/repl.ts'
|
|
import * as workerThreads from '../../src/node/builtin_modules/mock/worker_threads.ts'
|
|
import * as nodePty from '../../src/node/external_packages/node-pty.ts'
|
|
import * as libreofficeKit from '../../src/node/external_packages/libreoffice-kit.ts'
|
|
import * as libreofficeEditor from '../../src/node/external_packages/libreoffice-kit-editor.ts'
|
|
import * as execa from '../../src/node/external_packages/execa.ts'
|
|
import * as got from '../../src/node/external_packages/got.ts'
|
|
import * as piAi from '../../src/node/external_packages/pi-ai.ts'
|
|
import * as piCodingAgent from '../../src/node/external_packages/pi-coding-agent.ts'
|
|
import * as ripgrep from '../../src/node/external_packages/ripgrep.ts'
|
|
import * as ws from '../../src/node/external_packages/ws.ts'
|
|
import { REPLACED_EXTERNAL_PACKAGES } from '../../src/node/external_packages/replaced-externals.ts'
|
|
import { MODULE_PROXIES } from '../../src/module-proxies.ts'
|
|
import { createNodeBuiltins } from '../../src/node/builtins.ts'
|
|
import * as os from '../../src/node/builtin_modules/implemented/os.ts'
|
|
import * as perfHooks from '../../src/node/builtin_modules/implemented/perf_hooks.ts'
|
|
import { DSH_HOME, DSH_TMP } from '../../src/storage/paths.ts'
|
|
|
|
/** Node's standard code for a feature the running platform cannot provide. */
|
|
const PLATFORM_UNAVAILABLE = 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM'
|
|
|
|
/** Every refusal writes its message to the console before throwing; keep the run quiet. */
|
|
const quiet = (): void => { vi.spyOn(console, 'error').mockImplementation(() => {}) }
|
|
|
|
/** Symbols that refuse when called. */
|
|
const CALLED: [string, Record<string, unknown>, readonly string[]][] = [
|
|
['node:dns/promises', dnsPromises, ['lookup']],
|
|
['node:https', https, ['createServer']],
|
|
['node:net', net, ['createServer', 'connect']],
|
|
['node:sqlite', sqlite, ['backup']],
|
|
['node:vm', vm, ['createContext', 'runInContext', 'runInNewContext', 'runInThisContext', 'isContext']],
|
|
['node:repl', repl, ['start']],
|
|
['node:worker_threads', workerThreads, ['MessageChannel', 'MessagePort', 'markAsUntransferable', 'receiveMessageOnPort']],
|
|
// The rest of `node:child_process` runs commands (see child-process.spec.ts);
|
|
// these three need a real process, so they stay refusals.
|
|
['node:child_process', childProcess, ['execFileSync', 'execSync', 'fork']],
|
|
['node-pty', nodePty, ['spawn', 'open']],
|
|
['execa', execa, ['execa']],
|
|
['got', got.default, ['post']],
|
|
['@earendil-works/pi-coding-agent', piCodingAgent, [
|
|
'getAgentDir', 'initTheme', 'createAgentSessionServices', 'createAgentSessionFromServices',
|
|
'createBashToolDefinition', 'createMcpExtension', 'defineTool', 'resolveCliModel',
|
|
]],
|
|
['@earendil-works/pi-coding-agent', { create: piCodingAgent.ModelRuntime.create }, ['create']],
|
|
['@earendil-works/pi-coding-agent', { create: piCodingAgent.SettingsManager.create }, ['create']],
|
|
['@earendil-works/pi-coding-agent', {
|
|
create: piCodingAgent.SessionManager.create, open: piCodingAgent.SessionManager.open,
|
|
inMemory: piCodingAgent.SessionManager.inMemory, list: piCodingAgent.SessionManager.list,
|
|
}, ['create', 'open', 'inMemory', 'list']],
|
|
['@deepseek-ai/pi-ai', piAi, [
|
|
'createProvider', 'createModels', 'openAICompletionsApi', 'openAIResponsesApi', 'anthropicMessagesApi',
|
|
'isContextOverflow', 'getSupportedThinkingLevels', 'builtinModels',
|
|
]],
|
|
]
|
|
|
|
/** Classes that refuse when constructed. */
|
|
const CONSTRUCTED: [string, Record<string, unknown>, readonly string[]][] = [
|
|
['node:sqlite', sqlite, ['DatabaseSync', 'StatementSync']],
|
|
['node:vm', vm, ['Script']],
|
|
['node:worker_threads', workerThreads, ['Worker']],
|
|
['node:perf_hooks', perfHooks, ['PerformanceObserver']],
|
|
['ws', ws, ['WebSocket']],
|
|
['@earendil-works/pi-coding-agent', piCodingAgent, [
|
|
'ModelRegistry', 'ProjectTrustStore', 'ModelRuntime', 'SettingsManager', 'SessionManager',
|
|
]],
|
|
]
|
|
|
|
describe('not-implemented stubs', () => {
|
|
it('names the module and the symbol, carries the Node platform code, and reports before throwing', () => {
|
|
const reported = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
const error = notAvailableError('node:zlib', 'gzipSync')
|
|
expect(error.message).toBe('web-preview: node:zlib.gzipSync is not available in the worker host')
|
|
expect(error.code).toBe(PLATFORM_UNAVAILABLE)
|
|
expect(reported).toHaveBeenCalledWith(error.message)
|
|
|
|
const stub = notImplementedFail('node:zlib', 'gzipSync')
|
|
expect(() => stub()).toThrow(expect.objectContaining({ message: error.message, code: PLATFORM_UNAVAILABLE }))
|
|
})
|
|
|
|
for (const [module, namespace, members] of CALLED) {
|
|
it(`${module} refuses ${String(members.length)} called symbol(s)`, () => {
|
|
quiet()
|
|
for (const member of members) {
|
|
const value = namespace[member]
|
|
expect(typeof value, member).toBe('function')
|
|
expect(() => (value as () => unknown)(), member).toThrow(new RegExp(`${member}\\b.*not available in the worker host`))
|
|
}
|
|
})
|
|
}
|
|
|
|
for (const [module, namespace, members] of CONSTRUCTED) {
|
|
it(`${module} refuses ${String(members.length)} constructed symbol(s)`, () => {
|
|
quiet()
|
|
for (const member of members) {
|
|
const value = namespace[member]
|
|
expect(typeof value, member).toBe('function')
|
|
expect(() => new (value as new () => unknown)(), member).toThrow(/not available in the worker host/)
|
|
}
|
|
})
|
|
}
|
|
|
|
it('refuses node:worker_threads construction with the Node platform code', () => {
|
|
quiet()
|
|
expect(() => new workerThreads.MessageChannel()).toThrow(expect.objectContaining({ code: PLATFORM_UNAVAILABLE }))
|
|
expect(() => new workerThreads.Worker('')).toThrow(expect.objectContaining({ code: PLATFORM_UNAVAILABLE }))
|
|
})
|
|
|
|
it('keeps the CommonJS interop marker and a default export on every replaced module', () => {
|
|
for (const namespace of [
|
|
dnsPromises, net, sqlite, vm, repl, workerThreads, childProcess, stream, ws, nodePty, piAi, piCodingAgent, os, perfHooks, got,
|
|
]) {
|
|
const holder = namespace as { __esModule?: unknown; default?: unknown }
|
|
expect(holder.__esModule).toBe(true)
|
|
expect(holder.default).toBeDefined()
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('constructible-but-inert fakes', () => {
|
|
it('a ws server constructs, accepts listeners, and refuses to carry an upgrade', () => {
|
|
quiet()
|
|
expect(ws.Server).toBe(ws.WebSocketServer)
|
|
const server = new ws.WebSocketServer()
|
|
expect(server.clients.size).toBe(0)
|
|
expect(server.on()).toBe(server)
|
|
expect(() => server.handleUpgrade()).toThrow(/WebSocketServer.handleUpgrade is not available/)
|
|
expect(() => server.emit()).toThrow(/WebSocketServer.emit is not available/)
|
|
let closed = false
|
|
server.close(() => { closed = true })
|
|
expect(closed).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('replaced external packages', () => {
|
|
it('refuses Pi agent creation with the Node platform code', () => {
|
|
quiet()
|
|
expect(() => piCodingAgent.createAgentSessionServices()).toThrow(expect.objectContaining({
|
|
code: PLATFORM_UNAVAILABLE,
|
|
message: 'web-preview: @earendil-works/pi-coding-agent.createAgentSessionServices is not available in the worker host',
|
|
}))
|
|
})
|
|
|
|
it('reports Office conversion as unavailable without creating a Node worker', async () => {
|
|
quiet()
|
|
await expect(libreofficeKit.createConverter()).rejects.toMatchObject({
|
|
code: 'unavailable',
|
|
message: 'web-preview: @deepseek-ai/libreoffice-kit.createConverter is not available in the worker host',
|
|
})
|
|
})
|
|
|
|
it('reports a missing Office runtime as the kit\'s unavailable ConversionError', async () => {
|
|
quiet()
|
|
const failure = libreofficeKit.discoverRuntime()
|
|
await expect(failure).rejects.toBeInstanceOf(libreofficeKit.ConversionError)
|
|
await expect(failure).rejects.toMatchObject({
|
|
code: 'unavailable',
|
|
message: 'web-preview: @deepseek-ai/libreoffice-kit.discoverRuntime is not available in the worker host',
|
|
})
|
|
})
|
|
|
|
it('resolves native Office session creation to the unavailable browser capability', async () => {
|
|
quiet()
|
|
expect(REPLACED_EXTERNAL_PACKAGES).toContain('@deepseek-ai/libreoffice-kit/editor')
|
|
expect(MODULE_PROXIES['@deepseek-ai/libreoffice-kit/editor']).toBe('./node/external_packages/libreoffice-kit-editor.ts')
|
|
expect(createNodeBuiltins()['@deepseek-ai/libreoffice-kit/editor']!()).toBe(libreofficeEditor)
|
|
await expect(libreofficeEditor.openDocument()).rejects.toMatchObject({
|
|
code: 'unavailable',
|
|
message: 'web-preview: @deepseek-ai/libreoffice-kit/editor.openDocument is not available in the worker host',
|
|
})
|
|
})
|
|
|
|
it('lists the packages the loader serves from the bundle', () => {
|
|
expect(REPLACED_EXTERNAL_PACKAGES).not.toContain('chokidar')
|
|
expect(REPLACED_EXTERNAL_PACKAGES).not.toContain('@deepseek-ai/node-addon-system')
|
|
expect(REPLACED_EXTERNAL_PACKAGES).not.toContain('@deepseek-ai/node-addon-system/landlock-run')
|
|
expect(REPLACED_EXTERNAL_PACKAGES).toContain('ws')
|
|
})
|
|
|
|
it('answers the values callers read without invoking anything', () => {
|
|
// The ripgrep binary path is read as data by its consumer.
|
|
expect(typeof ripgrep.rgPath).toBe('string')
|
|
})
|
|
})
|
|
|
|
describe('node:net address predicates', () => {
|
|
it('classifies IPv4, IPv6, and neither', () => {
|
|
expect([net.isIPv4('127.0.0.1'), net.isIPv4('255.255.255.255')]).toEqual([true, true])
|
|
expect([net.isIPv4('256.0.0.1'), net.isIPv4('::1'), net.isIPv4('nope')]).toEqual([false, false, false])
|
|
expect([net.isIPv6('::1'), net.isIPv6('fe80::1'), net.isIPv6('127.0.0.1')]).toEqual([true, true, false])
|
|
expect([net.isIP('127.0.0.1'), net.isIP('::1'), net.isIP('nope')]).toEqual([4, 6, 0])
|
|
})
|
|
|
|
it('constructs a Socket but refuses to move bytes through it', () => {
|
|
const socket = new net.Socket()
|
|
expect(() => socket.write()).toThrow(/Socket.write is not available/)
|
|
expect(() => socket.end()).toThrow(/Socket.end is not available/)
|
|
// Disposal paths run against sockets that were never connected.
|
|
expect(() => { socket.destroy() }).not.toThrow()
|
|
})
|
|
})
|
|
|
|
describe('node:os', () => {
|
|
it('reports the virtual platform identity and the VFS directories', () => {
|
|
expect([os.EOL, os.tmpdir(), os.homedir()]).toEqual(['\n', DSH_TMP, DSH_HOME])
|
|
expect([os.platform(), os.type(), os.arch()]).toEqual(['linux', 'Linux', 'x64'])
|
|
expect([os.release(), os.hostname()]).toEqual(['0.0.0-dsh-worker', 'dsh-worker'])
|
|
})
|
|
|
|
it('reports no per-core facts and no network interfaces', () => {
|
|
expect(os.cpus()).toEqual([])
|
|
expect(os.networkInterfaces()).toEqual({})
|
|
expect(os.availableParallelism()).toBeGreaterThanOrEqual(1)
|
|
})
|
|
|
|
it('maps the terminal signal names its consumer reads', () => {
|
|
expect(os.constants.signals.SIGTERM).toBe(15)
|
|
expect(os.constants.signals.SIGKILL).toBe(9)
|
|
})
|
|
})
|
|
|
|
describe('node:perf_hooks', () => {
|
|
it("hands over the worker's own clock", () => {
|
|
expect(perfHooks.performance).toBe(globalThis.performance)
|
|
expect(perfHooks.performance.now()).toBeGreaterThan(0)
|
|
})
|
|
})
|