Files
deepseek-harness/packages/ptc-runtime/ptc-runtime-node/tests/bindings.spec.ts
T
sjw1231 6b3023d888 feat(ptc): give run_code and PTC runtime failures error codes
run_code argument checks now throw ToolArgsError (INVALID_ARGS),
including timeoutMs or sandbox_permissions passed to a runtime whose
schema does not expose them; a missing runtime, workingDirectory, or
sandboxPolicy throws ToolContextUnavailableError. CodeRunFailedError
gains CODE_RUN_UNAVAILABLE after executor disposal, keeping
CODE_RUN_FAILED as the default. A runtime
rejection without its own code becomes CODE_RUN_FAILED with the
rejection as cause; caller cancellation keeps the signal's reason.

The PTC runtime Service Definition adds PtcRuntimeError for contract
misuse: PTC_RUNTIME_INVALID_ARGUMENT, PTC_RUNTIME_UNAVAILABLE, and
PTC_RUNTIME_CONFLICT. The Node runtime throws it for invalid specs and
bindings, use after disposal, incomplete retained cleanup, concurrent
runs for one owner, and a retained environment under another sandbox
policy. dsh-ptc-runtime now declares @deepseek-ai/dsh-error.

Refs #7869
2026-11-09 15:14:31 +08:00

26 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { validateBindings } from '../src/bindings.ts'
const INVALID_ARGUMENT = { name: 'PtcRuntimeError', code: 'PTC_RUNTIME_INVALID_ARGUMENT' }
describe('program binding validation', () => {
it.each(['$name', '', 'while', 'lambda', 'console'])('rejects unusable global %s', (global) => {
expect(() => validateBindings({ program: '', bindings: [{ global, functions: {} }] })).toThrow(expect.objectContaining(INVALID_ARGUMENT))
})
it('rejects duplicated globals and accepts arbitrary own member names', () => {
const functions = Object.create(null) as Record<string, () => Promise<string>>
functions.__proto__ = async () => 'own'
expect(validateBindings({ program: '', bindings: [{ global: 'tools', functions }] }).get('tools')?.functions).toBe(functions)
expect(() => validateBindings({ program: '', bindings: [{ global: 'tools', functions }, { global: 'tools', functions }] })).toThrow('duplicate')
})
it.each(['$name', 'while', 'console', 'tools'])('rejects invalid error class name %s', (name) => {
expect(() => validateBindings({ program: '', bindings: [{ global: 'tools', functions: {}, errorClass: { name, memberNameProperty: 'member' } }] })).toThrow(expect.objectContaining(INVALID_ARGUMENT))
})
it.each(['', 'name', '__member__'])('rejects invalid error member %s', (memberNameProperty) => {
expect(() => validateBindings({ program: '', bindings: [{ global: 'tools', functions: {}, errorClass: { name: 'ToolError', memberNameProperty } }] })).toThrow(expect.objectContaining(INVALID_ARGUMENT))
})
it('rejects two injected constructors with the same name', () => {
expect(() => validateBindings({ program: '', bindings: ['first', 'second'].map(global => ({ global, functions: {}, errorClass: { name: 'ToolError', memberNameProperty: 'member' } })) })).toThrow('duplicate')
})
})