tools.spec.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import { Context } from 'cordis'
  3. import { CallId } from '@deepseek-ai/dsh-llm'
  4. import { Session, SessionId } from '@deepseek-ai/dsh-session'
  5. import AgentRegistry from '@deepseek-ai/dsh-agent'
  6. import type { Agent } from '@deepseek-ai/dsh-agent'
  7. import PtyService from '@deepseek-ai/dsh-pty'
  8. import type {
  9. PtyBackend,
  10. PtyBackendSession,
  11. PtyReadRequest,
  12. PtySendOperation,
  13. PtySendRequest,
  14. PtySessionStatus,
  15. PtySignal,
  16. PtyWaitReason,
  17. } from '@deepseek-ai/dsh-pty'
  18. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  19. import ToolRegistry from '@deepseek-ai/dsh-tools'
  20. import * as ToolBashPersistent from '@deepseek-ai/dsh-tool-bash-persistent'
  21. const contexts: Context[] = []
  22. let callNumber = 0
  23. afterEach(async () => {
  24. for (const ctx of contexts.splice(0)) await ctx.fiber.dispose()
  25. })
  26. function agent(ctx: Context, cwd: string | undefined): Agent {
  27. const id = SessionId(`persistent-bash-owner-${callNumber}`)
  28. const scope = ctx.plugin(() => {})
  29. const value: Agent = {
  30. id,
  31. options: {},
  32. session: new Session(id, [], {
  33. version: 0,
  34. id,
  35. createdAt: 0,
  36. ...cwd === undefined ? {} : { cwd },
  37. }),
  38. status: 'idle',
  39. acceptsNextStep: false,
  40. ctx: scope.ctx,
  41. followup: () => {},
  42. steer: () => {},
  43. inject: () => {},
  44. send: () => {},
  45. updateInbox: () => 'not-found',
  46. cancel() {},
  47. whenIdle: () => Promise.resolve(),
  48. }
  49. ctx.agents.register(value)
  50. return value
  51. }
  52. function text(result: { content: { type: string; text?: string }[] }): string {
  53. return result.content.filter(block => block.type === 'text').map(block => block.text).join('')
  54. }
  55. function call(
  56. ctx: Context,
  57. owner: Agent | undefined,
  58. command: string,
  59. signal = new AbortController().signal,
  60. ) {
  61. return ctx.tools.execute({
  62. signal,
  63. callId: CallId(`persistent-bash-${++callNumber}`),
  64. name: 'bash',
  65. arguments: { command },
  66. ...owner === undefined ? {} : { agent: owner },
  67. })
  68. }
  69. type StubMode =
  70. | 'normal'
  71. | 'prompt-only'
  72. | 'prompt-crlf'
  73. | 'empty-read'
  74. | 'stalled-read'
  75. | 'exit'
  76. | 'signal-exit'
  77. | 'unknown-exit'
  78. | 'wait-for-abort'
  79. | 'end-on-abort'
  80. | 'idle-then-normal'
  81. | 'large'
  82. | 'nonzero'
  83. | 'torn-status'
  84. | 'finish-torn-status'
  85. | 'end-only'
  86. | 'init-exit'
  87. | 'init-timeout'
  88. | 'spawn-error'
  89. | 'send-error'
  90. | 'prompt-after-idle'
  91. | 'empty-page-after-latest'
  92. class StubPtySession implements PtyBackendSession {
  93. readonly motd = '__DSH_PERSISTENT_BASH_PROMPT__ '
  94. readonly pid = 123
  95. statusValue: PtySessionStatus = { kind: 'running' }
  96. scrollback = this.motd
  97. closed: string[] = []
  98. mode: StubMode
  99. sends = 0
  100. pendingText = ''
  101. historyTruncated = false
  102. constructor(mode: StubMode) {
  103. this.mode = mode
  104. }
  105. startSend(request: PtySendRequest): PtySendOperation {
  106. this.sends += 1
  107. if (request.text.startsWith('stty -echo')) {
  108. if (this.mode === 'init-exit') {
  109. this.statusValue = { kind: 'exited', exitCode: 1, signal: null }
  110. return this.operation(Promise.resolve(this.result('', 'session_exit')))
  111. }
  112. if (this.mode === 'init-timeout') {
  113. return this.operation(Promise.resolve(this.result('', 'timeout')))
  114. }
  115. return this.operation(Promise.resolve(this.result(this.motd, 'stdin_read')))
  116. }
  117. if (this.mode === 'send-error') throw new Error('stub send failed')
  118. if (this.mode === 'wait-for-abort' || this.mode === 'end-on-abort') {
  119. const done = new Promise<ReturnType<StubPtySession['result']>>((resolve) => {
  120. request.signal?.addEventListener('abort', () => {
  121. const start = /__DSH_PERSISTENT_BASH_START_[^_]+(?:-[^_]+)*__/.exec(request.text)?.[0]
  122. const end = /__DSH_PERSISTENT_BASH_END_[^:]+:/.exec(request.text)?.[0]
  123. const output = this.mode === 'end-on-abort'
  124. ? `${start ?? ''}\ninterrupted\n${end ?? ''}130\n${this.motd}`
  125. : 'partial output'
  126. this.scrollback += output
  127. resolve(this.result(output, 'stdin_read'))
  128. }, { once: true })
  129. })
  130. return this.operation(done)
  131. }
  132. if (this.mode === 'idle-then-normal') {
  133. this.mode = 'normal'
  134. this.pendingText = request.text
  135. return this.operation(Promise.resolve(this.result('', 'inferred_idle')))
  136. }
  137. if (this.mode === 'prompt-after-idle') {
  138. if (request.text.length > 0) {
  139. const start = /__DSH_PERSISTENT_BASH_START_[^_]+(?:-[^_]+)*__/.exec(request.text)?.[0]
  140. const output = `${start ?? ''}\npartial syntax output\n`
  141. this.scrollback += output
  142. return this.operation(Promise.resolve(this.result(output, 'inferred_idle')))
  143. }
  144. const output = `bash: syntax error\n${this.motd}`
  145. this.scrollback += output
  146. return this.operation(Promise.resolve(this.result(output, 'stdin_read')))
  147. }
  148. if (this.mode === 'prompt-only' || this.mode === 'prompt-crlf') {
  149. const newline = this.mode === 'prompt-crlf' ? '\r\n' : '\n'
  150. const output = `bash: syntax error${newline}${this.motd}${newline}`
  151. this.scrollback += output
  152. return this.operation(Promise.resolve(this.result(output, 'stdin_read')))
  153. }
  154. const sent = request.text.length > 0 ? request.text : this.pendingText
  155. this.pendingText = ''
  156. const start = /__DSH_PERSISTENT_BASH_START_[^_]+(?:-[^_]+)*__/.exec(sent)?.[0]
  157. const end = /__DSH_PERSISTENT_BASH_END_[^:]+:/.exec(sent)?.[0]
  158. if (this.mode === 'torn-status') {
  159. const output = `${start ?? ''}\nhello from stub\n${end ?? ''}`
  160. this.scrollback += output
  161. this.mode = 'finish-torn-status'
  162. return this.operation(Promise.resolve(this.result(output, 'inferred_idle')))
  163. }
  164. if (this.mode === 'finish-torn-status') {
  165. const output = `7\n${this.motd}`
  166. this.scrollback += output
  167. return this.operation(Promise.resolve(this.result(output, 'stdin_read')))
  168. }
  169. if (this.mode === 'end-only') {
  170. const output = `recovered output\n${end ?? ''}0\n${this.motd}`
  171. this.scrollback += output
  172. return this.operation(Promise.resolve(this.result(output, 'stdin_read')))
  173. }
  174. const commandOutput = this.mode === 'large'
  175. ? 'x'.repeat(100)
  176. : this.mode === 'nonzero' ? '' : 'hello from stub'
  177. const exitCode = this.mode === 'nonzero' ? 7 : 0
  178. const output = `${start ?? ''}\n${commandOutput}\n${end ?? ''}${exitCode}\n${this.motd}`
  179. this.scrollback += output
  180. if (this.mode === 'exit' || this.mode === 'signal-exit' || this.mode === 'unknown-exit') {
  181. const exitedOutput = `${start ?? ''}\nhello from stub\n`
  182. this.scrollback = this.scrollback.slice(0, -output.length) + exitedOutput
  183. this.statusValue = this.mode === 'signal-exit'
  184. ? { kind: 'exited', exitCode: null, signal: 'SIGTERM' }
  185. : this.mode === 'exit'
  186. ? { kind: 'exited', exitCode: 9, signal: null }
  187. : { kind: 'exited', exitCode: null, signal: null }
  188. return this.operation(Promise.resolve(this.result(exitedOutput, 'session_exit')))
  189. }
  190. return this.operation(Promise.resolve(this.result(output, 'stdin_read')))
  191. }
  192. read(request: PtyReadRequest) {
  193. if (this.mode === 'empty-read') {
  194. return { text: '', totalLines: 0, lineBegin: 0, lineEnd: 0, truncated: false }
  195. }
  196. if (this.mode === 'stalled-read') {
  197. return { text: 'stalled', totalLines: 1, lineBegin: 0, lineEnd: 0, truncated: false }
  198. }
  199. if (this.mode === 'empty-page-after-latest' && (request.offset ?? 0) > 0) {
  200. return { text: '', totalLines: 2, lineBegin: 1, lineEnd: 1, truncated: false }
  201. }
  202. const lines = this.scrollback.split('\n')
  203. return {
  204. text: this.scrollback,
  205. totalLines: this.mode === 'empty-page-after-latest' ? lines.length + 1 : lines.length,
  206. lineBegin: 0,
  207. lineEnd: this.mode === 'empty-page-after-latest' ? 1 : lines.length,
  208. truncated: this.historyTruncated,
  209. }
  210. }
  211. signal(_signal: PtySignal) {
  212. return Promise.resolve({ delivered: true as const, targetPgid: 123 })
  213. }
  214. status() {
  215. return this.statusValue
  216. }
  217. async close(reason: string) {
  218. this.closed.push(reason)
  219. this.statusValue = { kind: 'exited', exitCode: 0, signal: null }
  220. }
  221. private result(viewport: string, waitReason: PtyWaitReason) {
  222. return { viewport, waitReason, sessionStatus: this.statusValue, truncated: false }
  223. }
  224. private operation(done: Promise<ReturnType<StubPtySession['result']>>): PtySendOperation {
  225. return {
  226. done,
  227. readOutput: () => ({ delta: '', truncated: false }),
  228. cancel: () => false,
  229. }
  230. }
  231. }
  232. function stubBackend(initialMode: StubMode = 'normal') {
  233. const sessions: StubPtySession[] = []
  234. const backend: PtyBackend = {
  235. type: 'stub',
  236. async spawn() {
  237. if (initialMode === 'spawn-error') throw new Error('stub spawn failed')
  238. const session = new StubPtySession(initialMode)
  239. sessions.push(session)
  240. return session
  241. },
  242. }
  243. return { backend, sessions }
  244. }
  245. async function setup(
  246. config: ToolBashPersistent.Config = { backendType: 'stub' },
  247. initialMode: StubMode = 'normal',
  248. ) {
  249. const ctx = new Context()
  250. contexts.push(ctx)
  251. await ctx.plugin(SystemPrompt)
  252. await ctx.plugin(ToolRegistry)
  253. await ctx.plugin(AgentRegistry)
  254. await ctx.plugin(PtyService)
  255. const stub = stubBackend(initialMode)
  256. ctx.pty.registerBackend(stub.backend)
  257. const fiber = await ctx.plugin(ToolBashPersistent, config)
  258. return { ctx, stub, fiber, owner: agent(ctx, '/workspace') }
  259. }
  260. describe('tool-bash-persistent', () => {
  261. it('registers a configurable schema and reuses one owner shell', async () => {
  262. const { ctx, owner, stub, fiber } = await setup({
  263. backendType: 'stub',
  264. description: 'deployment-specific persistent shell',
  265. })
  266. const schema = ctx.tools.schemas()[0]
  267. expect(ctx.tools.schemas().map(item => item.name)).toEqual(['bash'])
  268. expect(schema?.description).toBe('deployment-specific persistent shell')
  269. expect(schema?.parameters).toMatchObject({
  270. required: ['command'],
  271. properties: { command: { type: 'string' } },
  272. })
  273. expect(ctx.tools.get('bash')?.presentCall?.({ command: 'pwd' }))
  274. .toEqual({ card: 'terminal', title: 'pwd' })
  275. expect(text(await call(ctx, owner, 'echo one'))).toBe('hello from stub')
  276. expect(text(await call(ctx, owner, 'echo two'))).toBe('hello from stub')
  277. expect(stub.sessions).toHaveLength(1)
  278. expect(stub.sessions[0]?.sends).toBe(3)
  279. const ownerWithoutCwd = agent(ctx, undefined)
  280. expect(text(await call(ctx, ownerWithoutCwd, 'pwd'))).toBe('hello from stub')
  281. expect(stub.sessions).toHaveLength(2)
  282. await fiber.dispose()
  283. expect(ctx.tools.schemas()).toEqual([])
  284. expect(ctx.tools.get('bash')).toBeUndefined()
  285. })
  286. it('handles inferred idle, prompt fallback, shell exit, clipping, and cleanup', async () => {
  287. const { ctx, owner, stub, fiber } = await setup({
  288. backendType: 'stub',
  289. maxOutputChars: 10,
  290. })
  291. await call(ctx, owner, 'warm up')
  292. const session = stub.sessions[0]!
  293. session.mode = 'idle-then-normal'
  294. expect(text(await call(ctx, owner, 'silent then complete'))).toContain('hello from')
  295. session.mode = 'prompt-only'
  296. const promptFallback = text(await call(ctx, owner, 'bad {'))
  297. expect(promptFallback).toContain('bash: synt')
  298. expect(promptFallback).not.toContain('DSH_PERSISTENT_BASH_PROMPT')
  299. session.mode = 'prompt-crlf'
  300. session.scrollback = ''
  301. const crlfPromptFallback = text(await call(ctx, owner, 'bad {'))
  302. expect(crlfPromptFallback).toContain('bash: synt')
  303. expect(crlfPromptFallback).not.toContain('DSH_PERSISTENT_BASH_PROMPT')
  304. session.mode = 'end-only'
  305. session.scrollback = ''
  306. const missingStart = text(await call(ctx, owner, 'recover marker'))
  307. expect(missingStart).toContain('recovered')
  308. expect(missingStart).toContain('beginning of this command output was dropped')
  309. expect(missingStart).toContain('<response clipped>')
  310. session.mode = 'large'
  311. expect(text(await call(ctx, owner, 'large'))).toContain('<response clipped>')
  312. session.mode = 'nonzero'
  313. expect(text(await call(ctx, owner, 'false'))).toBe('[exit code: 7]')
  314. session.mode = 'exit'
  315. const exited = text(await call(ctx, owner, 'exit'))
  316. expect(exited).toContain('hello from')
  317. expect(exited).toContain('[shell exited: code 9]')
  318. expect(exited).not.toContain('[exit code: 9]')
  319. expect(exited).toContain('next bash call starts from the workspace')
  320. expect(session.closed).toContain('persistent bash shell exited')
  321. await call(ctx, owner, 'new shell')
  322. expect(stub.sessions).toHaveLength(2)
  323. const replacement = stub.sessions[1]!
  324. replacement.mode = 'signal-exit'
  325. expect(text(await call(ctx, owner, 'kill shell')))
  326. .toContain('[shell killed by signal: SIGTERM]')
  327. await call(ctx, owner, 'another shell')
  328. expect(stub.sessions).toHaveLength(3)
  329. const externallyClosed = ctx.pty.list(owner)[0]?.sessionId
  330. expect(externallyClosed).toBeDefined()
  331. await ctx.pty.kill(owner, externallyClosed!, 'external cleanup')
  332. await fiber.dispose()
  333. expect(stub.sessions[2]?.closed).toEqual(['external cleanup'])
  334. })
  335. it('waits for status digits after a torn completion marker', async () => {
  336. const { ctx, owner, stub } = await setup({ backendType: 'stub', maxOutputChars: 1_000 })
  337. await call(ctx, owner, 'warm up')
  338. stub.sessions[0]!.mode = 'torn-status'
  339. stub.sessions[0]!.scrollback = ''
  340. expect(text(await call(ctx, owner, 'torn status'))).toBe('hello from stub\n[exit code: 7]')
  341. })
  342. it('reports a shell exit when the backend has no code or signal', async () => {
  343. const { ctx, owner, stub } = await setup({ backendType: 'stub' })
  344. await call(ctx, owner, 'warm up')
  345. stub.sessions[0]!.mode = 'unknown-exit'
  346. expect(text(await call(ctx, owner, 'exit without status'))).toContain('[shell exited]')
  347. })
  348. it('marks a short missing-prefix result and tolerates exhausted scrollback pages', async () => {
  349. const { ctx, owner, stub } = await setup({ backendType: 'stub', maxOutputChars: 1_000 })
  350. await call(ctx, owner, 'warm up')
  351. const session = stub.sessions[0]!
  352. session.mode = 'end-only'
  353. session.scrollback = ''
  354. expect(text(await call(ctx, owner, 'missing start')))
  355. .toContain('beginning of this command output was dropped')
  356. session.mode = 'empty-read'
  357. expect(text(await call(ctx, owner, 'empty page'))).toContain('hello from stub')
  358. session.mode = 'stalled-read'
  359. expect(text(await call(ctx, owner, 'stalled page'))).toContain('hello from stub')
  360. session.mode = 'empty-page-after-latest'
  361. expect(text(await call(ctx, owner, 'empty continuation page'))).toContain('hello from stub')
  362. })
  363. it('sanitizes a prompt fallback reached after multiple polling rounds', async () => {
  364. const { ctx, owner, stub } = await setup({ backendType: 'stub', maxOutputChars: 1_000 })
  365. await call(ctx, owner, 'warm up')
  366. const session = stub.sessions[0]!
  367. session.mode = 'prompt-after-idle'
  368. session.scrollback = ''
  369. const result = text(await call(ctx, owner, 'bad {'))
  370. expect(result).toContain('partial syntax output')
  371. expect(result).toContain('bash: syntax error')
  372. expect(result).not.toContain('DSH_PERSISTENT_BASH_PROMPT')
  373. expect(result).not.toContain('DSH_PERSISTENT_BASH_START')
  374. })
  375. it('does not attribute old scrollback truncation to a complete current command', async () => {
  376. const { ctx, owner, stub } = await setup({ backendType: 'stub', maxOutputChars: 1_000 })
  377. await call(ctx, owner, 'warm up')
  378. stub.sessions[0]!.historyTruncated = true
  379. const result = text(await call(ctx, owner, 'short command'))
  380. expect(result).toBe('hello from stub')
  381. expect(result).not.toContain('<response clipped>')
  382. expect(result).not.toContain('beginning of this command output was dropped')
  383. })
  384. it('closes a timed-out shell and reports bounded partial output', async () => {
  385. const { ctx, owner, stub } = await setup({ backendType: 'stub', timeoutMs: 10 })
  386. await call(ctx, owner, 'warm up')
  387. stub.sessions[0]!.mode = 'wait-for-abort'
  388. const result = await call(ctx, owner, 'hang')
  389. expect(text(result)).toContain('timed out after 0 seconds or experienced an OOM error')
  390. expect(text(result)).toContain('partial output')
  391. expect(text(result)).toContain('next bash call starts from the workspace')
  392. expect(stub.sessions[0]?.closed).toContain('persistent bash command timed out')
  393. })
  394. it.each(['wait-for-abort', 'end-on-abort'] as const)(
  395. 'cancels %s work, resets the shell, and releases a queued call',
  396. async (mode) => {
  397. const { ctx, owner, stub } = await setup({ backendType: 'stub', timeoutMs: 5_000 })
  398. await call(ctx, owner, 'warm up')
  399. stub.sessions[0]!.mode = mode
  400. const controller = new AbortController()
  401. const cancelled = call(ctx, owner, 'hang', controller.signal)
  402. const queued = call(ctx, owner, 'after cancellation')
  403. setTimeout(() => {
  404. controller.abort(new Error('caller stopped'))
  405. }, 5)
  406. expect((await cancelled).isError).toBe(true)
  407. expect(text(await queued)).toBe('hello from stub')
  408. expect(stub.sessions[0]?.closed).toContain('persistent bash command aborted')
  409. expect(stub.sessions).toHaveLength(2)
  410. },
  411. )
  412. it.each(['init-exit', 'init-timeout'] as const)(
  413. 'fails initialization and closes the unusable shell for %s',
  414. async (mode) => {
  415. const { ctx, owner, stub } = await setup({ backendType: 'stub' }, mode)
  416. expect((await call(ctx, owner, 'pwd')).isError).toBe(true)
  417. expect(stub.sessions[0]?.closed).toContain('persistent bash initialization failed')
  418. },
  419. )
  420. it('clears a failed spawn without trying to close an unpublished shell', async () => {
  421. const { ctx, owner, stub } = await setup({ backendType: 'stub' }, 'spawn-error')
  422. expect((await call(ctx, owner, 'pwd')).isError).toBe(true)
  423. expect(stub.sessions).toHaveLength(0)
  424. })
  425. it('resets a cached shell after startSend fails', async () => {
  426. const { ctx, owner, stub } = await setup()
  427. await call(ctx, owner, 'warm up')
  428. stub.sessions[0]!.mode = 'send-error'
  429. expect((await call(ctx, owner, 'fails')).isError).toBe(true)
  430. expect(stub.sessions[0]?.closed).toContain('persistent bash send failed')
  431. expect(text(await call(ctx, owner, 'recovers'))).toBe('hello from stub')
  432. expect(stub.sessions).toHaveLength(2)
  433. })
  434. it('cancels and awaits a pending shell spawn when the plugin is disposed', async () => {
  435. const ctx = new Context()
  436. contexts.push(ctx)
  437. await ctx.plugin(SystemPrompt)
  438. await ctx.plugin(ToolRegistry)
  439. await ctx.plugin(AgentRegistry)
  440. await ctx.plugin(PtyService)
  441. const spawnStarted = Promise.withResolvers<undefined>()
  442. const spawnAborted = Promise.withResolvers<undefined>()
  443. ctx.pty.registerBackend({
  444. type: 'slow',
  445. spawn: spec => new Promise((_resolve, reject) => {
  446. spawnStarted.resolve(undefined)
  447. spec.signal?.addEventListener('abort', () => {
  448. spawnAborted.resolve(undefined)
  449. const reason: unknown = spec.signal?.reason
  450. reject(reason instanceof Error
  451. ? reason
  452. : new Error('slow PTY spawn aborted', { cause: reason }))
  453. }, { once: true })
  454. }),
  455. })
  456. const fiber = await ctx.plugin(ToolBashPersistent, { backendType: 'slow' })
  457. const owner = agent(ctx, '/workspace')
  458. const running = call(ctx, owner, 'pwd')
  459. await spawnStarted.promise
  460. await fiber.dispose()
  461. await spawnAborted.promise
  462. expect((await running).isError).toBe(true)
  463. expect(ctx.pty.list(owner)).toEqual([])
  464. })
  465. it('rejects invalid config and invalid calls', async () => {
  466. const { ctx, owner, stub } = await setup()
  467. expect((await call(ctx, undefined, 'pwd')).isError).toBe(true)
  468. expect(text(await call(ctx, owner, ' '))).toContain('command must be a non-empty string')
  469. const controller = new AbortController()
  470. controller.abort(new Error('caller stopped'))
  471. expect((await call(ctx, owner, 'pwd', controller.signal)).isError).toBe(true)
  472. expect(stub.sessions).toHaveLength(0)
  473. expect(() => {
  474. ToolBashPersistent.apply(new Context(), { backendType: '' })
  475. }).toThrow('backendType must be non-empty')
  476. expect(() => {
  477. ToolBashPersistent.apply(new Context(), { timeoutMs: 0 })
  478. }).toThrow('timeoutMs must be a positive safe integer')
  479. expect(() => {
  480. ToolBashPersistent.apply(new Context(), { maxOutputChars: 0 })
  481. }).toThrow('maxOutputChars must be a positive safe integer')
  482. expect(() => {
  483. ToolBashPersistent.apply(new Context(), { description: ' ' })
  484. }).toThrow('description must be non-empty')
  485. })
  486. })