| 1 | import assert from 'node:assert/strict' |
| 2 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' |
| 3 | import { tmpdir } from 'node:os' |
| 4 | import { join } from 'node:path' |
| 5 | import { test } from 'node:test' |
| 6 | import { activate, startHost } from './harness.mjs' |
| 7 | |
| 8 | function tempPlugin(source) { |
| 9 | const dir = mkdtempSync(join(tmpdir(), 'cw-dsh-022-')) |
| 10 | const entry = join(dir, 'index.mjs') |
| 11 | const dataDir = join(dir, 'data') |
| 12 | mkdirSync(dataDir, { recursive: true }) |
| 13 | writeFileSync(entry, source) |
| 14 | return { dir, entry, dataDir, cleanup: () => rmSync(dir, { recursive: true, force: true }) } |
| 15 | } |
| 16 | |
| 17 | test('DSH 0.2.2 pure-API exports and scoped module shims work and enforce dataDir confinement', async (t) => { |
| 18 | const host = await startHost() |
| 19 | t.after(() => host.stop()) |
| 20 | |
| 21 | const plugin = tempPlugin(` |
| 22 | import assert from 'node:assert/strict' |
| 23 | import { join } from 'node:path' |
| 24 | import { ReasoningEffortId, BlockAssembler, createAssistantMessage, contentHasImage } from '@deepseek-ai/dsh-llm' |
| 25 | import { SessionId, KNOWN_SESSION_EVENT_TYPES, deriveEventMessage } from '@deepseek-ai/dsh-session' |
| 26 | import { credentialRef } from '@deepseek-ai/dsh-credentials' |
| 27 | import { SettingsConflictError, settingsNamespace } from '@deepseek-ai/dsh-settings' |
| 28 | import { resolveDshHome } from '@deepseek-ai/dsh-home-paths' |
| 29 | import { writeFileAtomic, withFileLock } from '@deepseek-ai/dsh-atomic-write' |
| 30 | import { BUNDLED_SKILL_RANK, isModelInvocable, isUserInvocable, renderSkillContent } from '@deepseek-ai/dsh-skill' |
| 31 | import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol' |
| 32 | |
| 33 | export const name = 'dsh-shims-probe' |
| 34 | export const inject = ['tools', 'commands', 'settings', 'credentials', 'agentPresets', 'agentDefaultModel', 'sessionProjections', 'workspaceRegistry', 'typertGateway', 'web'] |
| 35 | export async function apply(ctx) { |
| 36 | assert.equal(ReasoningEffortId('high'), 'high') |
| 37 | const asm = new BlockAssembler() |
| 38 | asm.push({ type: 'text_delta', text: 'hel' }) |
| 39 | asm.push({ type: 'text_delta', text: 'lo' }) |
| 40 | assert.deepEqual(asm.finish(), [{ type: 'text', text: 'hello' }]) |
| 41 | assert.equal(createAssistantMessage({ content: [{ type: 'text', text: 'hi' }] }).role, 'assistant') |
| 42 | assert.equal(contentHasImage([{ type: 'image', attachment: {} }]), true) |
| 43 | |
| 44 | assert.equal(SessionId('s1'), 's1') |
| 45 | assert.ok(KNOWN_SESSION_EVENT_TYPES instanceof Set) |
| 46 | assert.ok(KNOWN_SESSION_EVENT_TYPES.has('message/user')) |
| 47 | const derived = deriveEventMessage({ type: 'message/user', text: 'hello' }) |
| 48 | assert.equal(derived.role, 'user') |
| 49 | assert.equal(derived.content[0].text, 'hello') |
| 50 | |
| 51 | assert.equal(credentialRef(' openai_key '), 'openai_key') |
| 52 | assert.throws(() => credentialRef(''), TypeError) |
| 53 | |
| 54 | assert.equal(settingsNamespace('my-ns'), 'my-ns') |
| 55 | const conflict = new SettingsConflictError('my-ns', 'r1', 'r2') |
| 56 | assert.equal(conflict.code, 'SETTINGS_CONFLICT') |
| 57 | |
| 58 | assert.equal(typeof BUNDLED_SKILL_RANK, 'number') |
| 59 | assert.equal(isModelInvocable({ disableModelInvocation: true }), false) |
| 60 | assert.equal(isUserInvocable({}), true) |
| 61 | assert.equal(renderSkillContent('---\\nname: demo\\n---\\nRun $ARGUMENTS', 'fast'), 'Run fast') |
| 62 | |
| 63 | assert.equal(typeof Remote.strictCodec, 'function') |
| 64 | assert.equal(typeof TypertRemoteService, 'function') |
| 65 | |
| 66 | const home = resolveDshHome() |
| 67 | const nested = resolveDshHome('sub', 'state.json') |
| 68 | assert.equal(nested, join(home, 'sub', 'state.json')) |
| 69 | assert.throws(() => resolveDshHome('..', 'escape.txt'), /escaping plugin dataDir/) |
| 70 | assert.throws(() => resolveDshHome('/etc/passwd'), /absolute or invalid/) |
| 71 | |
| 72 | await withFileLock(nested, async () => { |
| 73 | await writeFileAtomic(nested, JSON.stringify({ ok: true })) |
| 74 | }) |
| 75 | await assert.rejects(writeFileAtomic(join(home, '..', 'escape.txt'), 'nope'), /outside plugin dataDir/) |
| 76 | await assert.rejects(writeFileAtomic('.', 'nope'), /outside plugin dataDir/) |
| 77 | await assert.rejects(writeFileAtomic(home, 'nope'), /outside plugin dataDir/) |
| 78 | assert.throws(() => ctx.root.provide('agentPresets', { fake: true }), /may not provide core service \`agentPresets\`/) |
| 79 | |
| 80 | ctx.tools.register({ |
| 81 | name: 'advisory_timeout_tool', |
| 82 | description: 'tool with advisory timeoutMs', |
| 83 | parameters: { type: 'object', properties: {} }, |
| 84 | timeoutMs: 15000, |
| 85 | async execute() { return 'ok' }, |
| 86 | }) |
| 87 | |
| 88 | const disposePreset = ctx.agentPresets.register({ id: 'p1', name: 'Preset 1' }) |
| 89 | assert.equal((await ctx.agentPresets.list()).length, 1) |
| 90 | disposePreset() |
| 91 | assert.equal((await ctx.agentPresets.list()).length, 0) |
| 92 | |
| 93 | const disposeGw = ctx.typertGateway.register('demo', { ping: () => 'pong' }, []) |
| 94 | assert.deepEqual(ctx.typertGateway.list(), ['demo']) |
| 95 | disposeGw() |
| 96 | |
| 97 | const disposeSearch = ctx.web.registerSearchProvider({ id: 'custom-search', name: 'Custom' }) |
| 98 | assert.equal(ctx.web.listSearchProviders().length, 1) |
| 99 | disposeSearch() |
| 100 | |
| 101 | assert.throws(() => ctx.workspaceRegistry.create(), /read-only/) |
| 102 | |
| 103 | ctx.commands.register({ |
| 104 | name: 'session-probe', |
| 105 | description: 'verify agent.session', |
| 106 | handler(inv) { |
| 107 | return { kind: 'success', text: inv.agent.session.id + ':' + (inv.agent.session.header.cwd ?? '') } |
| 108 | }, |
| 109 | }) |
| 110 | } |
| 111 | `) |
| 112 | t.after(() => plugin.cleanup()) |
| 113 | |
| 114 | const { ref, result } = await activate(host, 'dsh-shims-probe', plugin.entry, { data_dir: plugin.dataDir }) |
| 115 | assert.equal(result.status, 'ok', result.diagnostic) |
| 116 | const written = JSON.parse(readFileSync(join(plugin.dir, 'data', 'sub', 'state.json'), 'utf8')) |
| 117 | assert.deepEqual(written, { ok: true }) |
| 118 | |
| 119 | const cmdReg = host.registry.find((entry) => entry.op === 'register' && entry.kind === 'command' && entry.spec.name === 'session-probe') |
| 120 | assert.ok(cmdReg) |
| 121 | const cmdOut = await host.call('command/run', { |
| 122 | handle: cmdReg.handle, |
| 123 | raw_input: '', |
| 124 | command_id: 'cmd-1', |
| 125 | workspace: '/tmp/ws', |
| 126 | session_id: 'sess-42', |
| 127 | deadline_ms: 5000, |
| 128 | }) |
| 129 | assert.deepEqual(cmdOut, { kind: 'success', text: 'sess-42:/tmp/ws' }) |
| 130 | |
| 131 | assert.deepEqual(await host.call('ext/deactivate', { owner: ref }), { disposed: true, leaked: [] }) |
| 132 | }) |
| 133 | |
| 134 | test('tools.guard is deny-only, subagents.getProvider("fork") works, tools/result projects, and approval/request is refused', async (t) => { |
| 135 | const host = await startHost() |
| 136 | t.after(() => host.stop()) |
| 137 | |
| 138 | const plugin = tempPlugin(` |
| 139 | import assert from 'node:assert/strict' |
| 140 | export const name = 'guard-and-fork' |
| 141 | export const inject = ['tools', 'subagents'] |
| 142 | export function apply(ctx) { |
| 143 | const fork = ctx.subagents.getProvider('fork') |
| 144 | assert.ok(fork) |
| 145 | assert.equal(fork.inheritsParentContext, true) |
| 146 | assert.equal(fork.capabilities.depthLimit, true) |
| 147 | |
| 148 | ctx.tools.guard((exec) => { |
| 149 | if (exec.name === 'blocked_tool') return 'blocked by policy' |
| 150 | if (exec.name === 'blocked_object') return { reason: 'blocked by denial object', info: { rule: 'r1' } } |
| 151 | if (exec.name === 'blocked_explicit') return { kind: 'deny', reason: 'explicit deny' } |
| 152 | if (exec.name === 'try_allow') return { kind: 'allow', reason: 'must not auto-approve' } |
| 153 | return undefined |
| 154 | }) |
| 155 | |
| 156 | ctx.on('tools/result', () => {}) |
| 157 | } |
| 158 | `) |
| 159 | t.after(() => plugin.cleanup()) |
| 160 | |
| 161 | const { ref, result } = await activate(host, 'guard-and-fork', plugin.entry) |
| 162 | assert.equal(result.status, 'ok', result.diagnostic) |
| 163 | |
| 164 | const preHook = host.registry.find((entry) => entry.op === 'register' && entry.kind === 'hook' && entry.spec.name === 'tools/pre-execute') |
| 165 | const postHook = host.registry.find((entry) => entry.op === 'register' && entry.kind === 'hook' && entry.spec.name === 'tools/post-execute') |
| 166 | assert.ok(preHook) |
| 167 | assert.ok(postHook) |
| 168 | |
| 169 | const denyVerdict = await host.call('hook/evaluate', { |
| 170 | handle: preHook.handle, |
| 171 | event: 'tools/pre-execute', |
| 172 | payload: { name: 'blocked_tool', call_id: 'c1', input: {}, workspace: '/tmp', mode: 'act', model: 'm' }, |
| 173 | deadline_ms: 5000, |
| 174 | }) |
| 175 | assert.deepEqual(denyVerdict, { kind: 'deny', reason: 'blocked by policy' }) |
| 176 | |
| 177 | const objectDenyVerdict = await host.call('hook/evaluate', { |
| 178 | handle: preHook.handle, |
| 179 | event: 'tools/pre-execute', |
| 180 | payload: { name: 'blocked_object', call_id: 'c1b', input: {}, workspace: '/tmp', mode: 'act', model: 'm' }, |
| 181 | deadline_ms: 5000, |
| 182 | }) |
| 183 | assert.deepEqual(objectDenyVerdict, { kind: 'deny', reason: 'blocked by denial object' }) |
| 184 | |
| 185 | const explicitDenyVerdict = await host.call('hook/evaluate', { |
| 186 | handle: preHook.handle, |
| 187 | event: 'tools/pre-execute', |
| 188 | payload: { name: 'blocked_explicit', call_id: 'c1c', input: {}, workspace: '/tmp', mode: 'act', model: 'm' }, |
| 189 | deadline_ms: 5000, |
| 190 | }) |
| 191 | assert.deepEqual(explicitDenyVerdict, { kind: 'deny', reason: 'explicit deny' }) |
| 192 | |
| 193 | const abstainVerdict = await host.call('hook/evaluate', { |
| 194 | handle: preHook.handle, |
| 195 | event: 'tools/pre-execute', |
| 196 | payload: { name: 'try_allow', call_id: 'c2', input: {}, workspace: '/tmp', mode: 'act', model: 'm' }, |
| 197 | deadline_ms: 5000, |
| 198 | }) |
| 199 | assert.deepEqual(abstainVerdict, { kind: 'abstain' }) |
| 200 | |
| 201 | assert.deepEqual(await host.call('ext/deactivate', { owner: ref }), { disposed: true, leaked: [] }) |
| 202 | |
| 203 | const badEvent = tempPlugin(` |
| 204 | export const name = 'bad-approval-listener' |
| 205 | export function apply(ctx) { |
| 206 | ctx.on('approval/request', () => {}) |
| 207 | } |
| 208 | `) |
| 209 | t.after(() => badEvent.cleanup()) |
| 210 | const refused = (await activate(host, 'bad-approval-listener', badEvent.entry)).result |
| 211 | assert.equal(refused.status, 'failed') |
| 212 | assert.match(refused.diagnostic, /DSH lifecycle approval\/request is not projected/) |
| 213 | |
| 214 | const childGuardPlugin = tempPlugin(` |
| 215 | export const name = 'child-guard-refusal' |
| 216 | export const inject = ['tools', 'subagents'] |
| 217 | export function apply(ctx) { |
| 218 | ctx.on('agent/created', ({ agent }) => { |
| 219 | agent.ctx.tools.guard(() => 'deny') |
| 220 | }) |
| 221 | ctx.tools.register({ |
| 222 | name: 'trigger_child_guard', |
| 223 | description: 'trigger child guard refusal', |
| 224 | parameters: { type: 'object', properties: {} }, |
| 225 | async execute(_input, exec) { |
| 226 | await ctx.subagents.startActivation({ |
| 227 | provider: 'fork', |
| 228 | childId: 'child-1', |
| 229 | request: { parent: exec.agent, prompt: [{ type: 'text', text: 'hi' }] }, |
| 230 | }) |
| 231 | return 'unexpected' |
| 232 | }, |
| 233 | }) |
| 234 | } |
| 235 | `) |
| 236 | t.after(() => childGuardPlugin.cleanup()) |
| 237 | const childAct = await activate(host, 'child-guard-refusal', childGuardPlugin.entry) |
| 238 | assert.equal(childAct.result.status, 'ok', childAct.result.diagnostic) |
| 239 | const triggerReg = host.registry.find((entry) => entry.op === 'register' && entry.kind === 'tool' && entry.spec.name === 'trigger_child_guard') |
| 240 | assert.ok(triggerReg) |
| 241 | await assert.rejects( |
| 242 | host.call('tool/call', { |
| 243 | handle: triggerReg.handle, |
| 244 | call_id: 'cg-1', |
| 245 | input: {}, |
| 246 | workspace: '/tmp/ws', |
| 247 | session_id: 'sess-cg', |
| 248 | subagent_ticket: 'sub-tkt', |
| 249 | deadline_ms: 5000, |
| 250 | }), |
| 251 | /child tools\.guard is not supported/, |
| 252 | ) |
| 253 | assert.deepEqual(await host.call('ext/deactivate', { owner: childAct.ref }), { disposed: true, leaked: [] }) |
| 254 | }) |
| 255 | |
| 256 | test('DSH P1/P2 module singletons (@deepseek-ai/dsh-agent, dsh-app-boot) and read-only/scoped host services enforce fail-closed boundaries', async (t) => { |
| 257 | const host = await startHost() |
| 258 | t.after(() => host.stop()) |
| 259 | |
| 260 | const pluginA = tempPlugin(` |
| 261 | import assert from 'node:assert/strict' |
| 262 | import { assembleContextFor, installModelSelection } from '@deepseek-ai/dsh-agent' |
| 263 | import { getDshRuntimeVersion, loadProfileDirectory, resolveBundleDir, createRuntimeResolution } from '@deepseek-ai/dsh-app-boot' |
| 264 | |
| 265 | export const name = 'dsh-p1-probe-a' |
| 266 | export const inject = ['sessionPersistence', 'storageDomain', 'invariants', 'permissionPresets'] |
| 267 | export async function apply(ctx) { |
| 268 | assert.deepEqual(assembleContextFor([{ role: 'user', text: 'hi' }]), [{ role: 'user', text: 'hi' }]) |
| 269 | const disposeModel = installModelSelection(ctx, {}) |
| 270 | assert.equal(typeof disposeModel, 'function') |
| 271 | disposeModel() |
| 272 | |
| 273 | assert.equal(typeof getDshRuntimeVersion(), 'string') |
| 274 | assert.ok(getDshRuntimeVersion().length > 0) |
| 275 | assert.throws(() => loadProfileDirectory(), /not available in Codewhale/) |
| 276 | assert.throws(() => resolveBundleDir(), /not available in Codewhale/) |
| 277 | await assert.rejects(createRuntimeResolution(), /not available in Codewhale/) |
| 278 | |
| 279 | assert.equal(await ctx.sessionPersistence.findLog('sess-1'), undefined) |
| 280 | assert.deepEqual(await ctx.sessionPersistence.listLogs(), []) |
| 281 | assert.equal(await ctx.sessionPersistence.readLog('sess-1'), undefined) |
| 282 | assert.equal(ctx.sessionPersistence.artifactDirectory({ id: 'sess-1' }), undefined) |
| 283 | await assert.rejects(ctx.sessionPersistence.deleteLog('sess-1'), /refused in Codewhale/) |
| 284 | await assert.rejects(ctx.sessionPersistence.removeLog('sess-1'), /refused in Codewhale/) |
| 285 | await assert.rejects(ctx.sessionPersistence.writeLog('sess-1', {}), /refused in Codewhale/) |
| 286 | |
| 287 | assert.equal(ctx.storageDomain.get('workspace'), undefined) |
| 288 | const domain = await ctx.storageDomain.open({ name: 'cache' }) |
| 289 | assert.deepEqual(ctx.storageDomain.list(), ['cache']) |
| 290 | const table = domain.table('items') |
| 291 | await table.set('k1', { v: 42 }) |
| 292 | assert.deepEqual(await table.get('k1'), { v: 42 }) |
| 293 | assert.equal(await table.has('k1'), true) |
| 294 | assert.deepEqual(await table.keys(), ['k1']) |
| 295 | assert.deepEqual(await table.list(), [{ v: 42 }]) |
| 296 | assert.deepEqual(await table.entries(), [['k1', { v: 42 }]]) |
| 297 | assert.equal(await table.delete('k1'), true) |
| 298 | assert.equal(await table.get('k1'), undefined) |
| 299 | await assert.rejects(table.set('big', 'x'.repeat(70 * 1024)), /exceeds size limit/) |
| 300 | await assert.rejects(table.set('big-buf', new ArrayBuffer(128 * 1024)), /exceeds size limit/) |
| 301 | await assert.rejects(table.set('big-map', new Map([['payload', 'x'.repeat(128 * 1024)]])), /exceeds size limit/) |
| 302 | const circular = {} |
| 303 | circular.self = circular |
| 304 | await assert.rejects(table.set('circular', circular), /JSON-serializable/) |
| 305 | await assert.rejects(table.set('bigint', 1n), /JSON-serializable/) |
| 306 | await assert.rejects(table.set('undef', undefined), /JSON-serializable/) |
| 307 | |
| 308 | const sibling = ctx.storageDomain.get('cache') |
| 309 | assert.ok(sibling) |
| 310 | const siblingTable = sibling.table('items') |
| 311 | await domain.close() |
| 312 | assert.equal(ctx.storageDomain.get('cache'), undefined) |
| 313 | await assert.rejects(table.get('k1'), /is closed/) |
| 314 | await assert.rejects(siblingTable.set('k2', { v: 1 }), /is closed/) |
| 315 | await assert.rejects(siblingTable.get('k1'), /is closed/) |
| 316 | |
| 317 | const disposeInv = ctx.invariants.register('demo-inv', () => {}) |
| 318 | assert.deepEqual(ctx.invariants.list(), ['demo-inv']) |
| 319 | disposeInv() |
| 320 | assert.deepEqual(ctx.invariants.list(), []) |
| 321 | |
| 322 | const disposers = [] |
| 323 | for (let i = 0; i < 64; i += 1) { |
| 324 | disposers.push(ctx.invariants.register('inv-' + i, () => {})) |
| 325 | } |
| 326 | assert.equal(ctx.invariants.list().length, 64) |
| 327 | assert.throws(() => ctx.invariants.register('inv-overflow', () => {}), /limit reached/) |
| 328 | for (const d of disposers) d() |
| 329 | assert.deepEqual(ctx.invariants.list(), []) |
| 330 | |
| 331 | assert.equal(ctx.permissionPresets.availability, 'readonly') |
| 332 | assert.equal(ctx.permissionPresets.defaultPreset, 'ask') |
| 333 | assert.deepEqual(ctx.permissionPresets.names, ['ask', 'accept-edits', 'auto-review', 'full-access']) |
| 334 | assert.equal(ctx.permissionPresets.get('ask')?.readonly, true) |
| 335 | assert.equal(ctx.permissionPresets.get('unknown'), undefined) |
| 336 | assert.throws(() => ctx.permissionPresets.apply('full-access'), /read-only in Codewhale/) |
| 337 | assert.throws(() => ctx.permissionPresets.set('full-access'), /read-only in Codewhale/) |
| 338 | assert.throws(() => ctx.permissionPresets.register({ name: 'evil' }), /read-only in Codewhale/) |
| 339 | |
| 340 | for (const svc of ['sessionPersistence', 'storageDomain', 'invariants', 'permissionPresets']) { |
| 341 | assert.throws(() => ctx.root.provide(svc, { fake: true }), /may not provide core service/) |
| 342 | } |
| 343 | |
| 344 | const retainedDomain = await ctx.storageDomain.open({ name: 'retained-across-deactivate' }) |
| 345 | const retainedTable = retainedDomain.table('items') |
| 346 | await retainedTable.set('k1', { ok: true }) |
| 347 | globalThis.__cwRetainedStorageTable = retainedTable |
| 348 | } |
| 349 | `) |
| 350 | t.after(() => pluginA.cleanup()) |
| 351 | |
| 352 | const act = await activate(host, 'dsh-p1-probe-a', pluginA.entry, { dataDir: pluginA.dataDir }) |
| 353 | assert.equal(act.result.status, 'ok', act.result.diagnostic) |
| 354 | assert.deepEqual(await host.call('ext/deactivate', { owner: act.ref }), { disposed: true, leaked: [] }) |
| 355 | |
| 356 | const pluginB = tempPlugin(` |
| 357 | import assert from 'node:assert/strict' |
| 358 | export const name = 'dsh-p1-probe-b' |
| 359 | export async function apply() { |
| 360 | const retained = globalThis.__cwRetainedStorageTable |
| 361 | assert.ok(retained) |
| 362 | try { |
| 363 | await assert.rejects(retained.get('k1'), /is closed/) |
| 364 | await assert.rejects(retained.set('after', { ok: false }), /is closed/) |
| 365 | } finally { |
| 366 | delete globalThis.__cwRetainedStorageTable |
| 367 | } |
| 368 | } |
| 369 | `) |
| 370 | t.after(() => pluginB.cleanup()) |
| 371 | const actB = await activate(host, 'dsh-p1-probe-b', pluginB.entry, { dataDir: pluginB.dataDir }) |
| 372 | assert.equal(actB.result.status, 'ok', actB.result.diagnostic) |
| 373 | assert.deepEqual(await host.call('ext/deactivate', { owner: actB.ref }), { disposed: true, leaked: [] }) |
| 374 | }) |
| 375 | |
| 376 | test('@deepseek-ai/dsh-error shares the single HarnessError constructor with dsh-llm, dsh-tools, and AttachmentError', async (t) => { |
| 377 | const host = await startHost() |
| 378 | t.after(() => host.stop()) |
| 379 | |
| 380 | const plugin = tempPlugin(` |
| 381 | import assert from 'node:assert/strict' |
| 382 | import { HarnessError as DshErrorHarness } from '@deepseek-ai/dsh-error' |
| 383 | import { HarnessError as LlmHarness } from '@deepseek-ai/dsh-llm' |
| 384 | import { HarnessError as ToolsHarness, ToolOutputError } from '@deepseek-ai/dsh-tools' |
| 385 | |
| 386 | export const name = 'dsh-error-singleton-probe' |
| 387 | export const inject = ['attachments'] |
| 388 | export async function apply(ctx) { |
| 389 | assert.equal(DshErrorHarness, LlmHarness) |
| 390 | assert.equal(DshErrorHarness, ToolsHarness) |
| 391 | const toolErr = new ToolOutputError('demo_tool', ['bad output']) |
| 392 | assert.ok(toolErr instanceof DshErrorHarness) |
| 393 | assert.ok(toolErr instanceof LlmHarness) |
| 394 | try { |
| 395 | await ctx.attachments.validateImage({ data: new Uint8Array(), mediaType: 'image/png' }) |
| 396 | assert.fail('expected empty image to reject') |
| 397 | } catch (error) { |
| 398 | assert.equal(error?.name, 'AttachmentError') |
| 399 | assert.equal(error?.code, 'INVALID_IMAGE') |
| 400 | assert.ok(error instanceof DshErrorHarness) |
| 401 | } |
| 402 | } |
| 403 | `) |
| 404 | t.after(() => plugin.cleanup()) |
| 405 | |
| 406 | const act = await activate(host, 'dsh-error-singleton-probe', plugin.entry) |
| 407 | assert.equal(act.result.status, 'ok', act.result.diagnostic) |
| 408 | assert.deepEqual(await host.call('ext/deactivate', { owner: act.ref }), { disposed: true, leaked: [] }) |
| 409 | }) |
| 410 |