tools.spec.ts 20 KB

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