tools.spec.ts 20 KB

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