tool-subagent.spec.ts 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { Context } from 'cordis'
  3. import Loader from '@cordisjs/plugin-loader'
  4. import { CallId } from '@deepseek-ai/dsh-llm'
  5. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  6. import ToolRegistry from '@deepseek-ai/dsh-tools'
  7. import { type Agent } from '@deepseek-ai/dsh-agent'
  8. import AgentRegistry from '@deepseek-ai/dsh-agent'
  9. import SubagentService from '@deepseek-ai/dsh-subagent'
  10. import type { SubagentStartRequest } from '@deepseek-ai/dsh-subagent'
  11. import TaskService from '@deepseek-ai/dsh-tasks'
  12. import * as ToolTasks from '@deepseek-ai/dsh-tool-tasks'
  13. import * as mock from './scripted-provider.ts'
  14. import * as tool from '../src/index.ts'
  15. import { runOutcome, settleRun } from '../src/index.ts'
  16. import { SessionId } from '@deepseek-ai/dsh-session'
  17. /**
  18. * Drives the REAL plugin body: mounts `dsh-tool-subagent` on a real
  19. * `ToolRegistry` + `SubagentService`, with a package-local scripted child
  20. * boundary, and invokes the registered `subagent` tool through
  21. * `ctx.tools.execute`. Everything downstream of the child boundary is the
  22. * shipping code path.
  23. */
  24. /** A minimal parent Agent passed through to the provider request. */
  25. function fakeAgent(id = 'parent-1'): Agent {
  26. return { id: SessionId(id) } as unknown as Agent
  27. }
  28. async function setup(toolConfig: tool.Config, mockConfig: Partial<mock.Config> = {}) {
  29. const ctx = new Context()
  30. await ctx.plugin(SystemPrompt)
  31. await ctx.plugin(ToolRegistry)
  32. await ctx.plugin(SubagentService)
  33. await mock.mountScriptedProvider(ctx, { name: 'mock', ...mockConfig })
  34. await ctx.plugin(tool, toolConfig)
  35. return ctx
  36. }
  37. let callCounter = 0
  38. function callSubagent(ctx: Context, args: unknown, over: { agent?: Agent | undefined; signal?: AbortSignal } = {}) {
  39. // Distinguish "no override" (use a default agent) from an explicit
  40. // `{ agent: undefined }` (test the no-agent path). Under
  41. // exactOptionalPropertyTypes the key is omitted rather than set to undefined.
  42. const agent = 'agent' in over ? over.agent : fakeAgent()
  43. return ctx.tools.execute({
  44. callId: CallId(`call-${++callCounter}`),
  45. name: 'subagent',
  46. arguments: args,
  47. ...agent ? { agent } : {},
  48. ...over.signal ? { signal: over.signal } : {},
  49. })
  50. }
  51. function text(result: { content: { type: string; text?: string }[] }): string {
  52. return result.content.filter(b => b.type === 'text').map(b => b.text).join('')
  53. }
  54. describe('dsh-tool-subagent', () => {
  55. it('registers a `subagent` tool that delegates to the configured provider and returns its output', async () => {
  56. const ctx = await setup({ provider: 'mock' }, { reply: 'child says hi' })
  57. const result = await callSubagent(ctx, { description: 'do a thing', prompt: 'go research X' })
  58. expect(result.isError).toBe(false)
  59. expect(text(result)).toBe('child says hi')
  60. })
  61. it('exposes description + prompt + run_in_background to the model (no provider/type parameter)', async () => {
  62. const ctx = await setup({ provider: 'mock' })
  63. const schema = ctx.tools.schemas().find(s => s.name === 'subagent')
  64. expect(schema).toBeDefined()
  65. const props = (schema!.parameters as { properties?: Record<string, unknown> }).properties ?? {}
  66. expect(Object.keys(props).sort()).toEqual(['description', 'prompt', 'run_in_background'])
  67. expect(schema!.description).toContain('task_output')
  68. })
  69. it('omits run_in_background entirely when the instance disables it (schema and capability never disagree)', async () => {
  70. const ctx = await setup({ provider: 'mock', enableRunInBackground: false })
  71. const schema = ctx.tools.schemas().find(s => s.name === 'subagent')
  72. const props = (schema!.parameters as { properties?: Record<string, unknown> }).properties ?? {}
  73. expect(Object.keys(props).sort()).toEqual(['description', 'prompt'])
  74. expect(schema!.description).not.toContain('task_output')
  75. })
  76. it('refuses a forced run_in_background at execution time when the instance disables it', async () => {
  77. // Schema omission is advertising, not enforcement: the arg validator
  78. // allows undeclared keys, so the opt-out must also hold in execute().
  79. const ctx = await setup({ provider: 'mock', enableRunInBackground: false })
  80. const parent = { id: SessionId('sess-off'), inject: () => {}, options: {}, session: { header: { version: 0, id: 'sess-off', createdAt: 0 } } } as unknown as Agent
  81. const forced = await callSubagent(ctx, { description: 'd', prompt: 'p', run_in_background: true }, { agent: parent })
  82. expect(forced.isError).toBe(true)
  83. expect(text(forced)).toContain('run_in_background is disabled for this tool instance')
  84. // The provider was never asked to start a child.
  85. expect(ctx.subagents.getProvider('mock')).toBeDefined()
  86. const foreground = await callSubagent(ctx, { description: 'd', prompt: 'p' }, { agent: parent })
  87. expect(foreground.isError).toBe(false)
  88. })
  89. it('keeps foreground and background calls exclusive', async () => {
  90. const ctx = await setup({ provider: 'mock' })
  91. expect(ctx.tools.executionMode({
  92. callId: CallId('subagent-foreground'),
  93. name: 'subagent',
  94. arguments: { description: 'do work', prompt: 'Reply OK' },
  95. })).toEqual({ kind: 'exclusive' })
  96. expect(ctx.tools.executionMode({
  97. callId: CallId('subagent-background'),
  98. name: 'subagent',
  99. arguments: { description: 'do work', prompt: 'Reply OK', run_in_background: true },
  100. })).toEqual({ kind: 'exclusive' })
  101. })
  102. it.each([
  103. { stopReason: 'aborted' as const, fragment: 'cancelled' },
  104. { stopReason: 'error' as const, fragment: 'failed' },
  105. { stopReason: 'max-tokens' as const, fragment: 'token limit' },
  106. { stopReason: 'refusal' as const, fragment: 'declined' },
  107. ])('maps stop reason $stopReason to an isError result (not partial success)', async ({ stopReason, fragment }) => {
  108. const ctx = await setup({ provider: 'mock' }, { stopReason })
  109. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' })
  110. expect(result.isError).toBe(true)
  111. expect(text(result)).toContain(fragment)
  112. })
  113. it('registers under a configurable toolName so multiple providers can coexist', async () => {
  114. // The defining multi-provider use case: two loads, two distinct tool names,
  115. // each bound to a different provider — the tool registry rejects duplicate
  116. // names, so a configurable name is what makes this work.
  117. const ctx = new Context()
  118. await ctx.plugin(SystemPrompt)
  119. await ctx.plugin(ToolRegistry)
  120. await ctx.plugin(SubagentService)
  121. await mock.mountScriptedProvider(ctx, { name: 'spawn', reply: 'from spawn' })
  122. await mock.mountScriptedProvider(ctx, { name: 'acp', reply: 'from acp' })
  123. await ctx.plugin(tool, { provider: 'spawn', toolName: 'subagent' })
  124. await ctx.plugin(tool, { provider: 'acp', toolName: 'subagent_acp' })
  125. const names = ctx.tools.schemas().map(s => s.name).filter(n => n.startsWith('subagent')).sort()
  126. expect(names).toEqual(['subagent', 'subagent_acp'])
  127. const viaSpawn = await ctx.tools.execute({ callId: CallId('c-spawn'), name: 'subagent', arguments: { description: 'd', prompt: 'p' }, agent: fakeAgent() })
  128. const viaAcp = await ctx.tools.execute({ callId: CallId('c-acp'), name: 'subagent_acp', arguments: { description: 'd', prompt: 'p' }, agent: fakeAgent() })
  129. expect(text(viaSpawn)).toBe('from spawn')
  130. expect(text(viaAcp)).toBe('from acp')
  131. })
  132. it('treats an unknown (plugin-added) stop reason as an isError result', async () => {
  133. // SubagentStopReason is merge-extensible; the tool's stopReasonError default
  134. // arm must treat an unrecognized terminal reason as a failure, not success.
  135. const ctx = new Context()
  136. await ctx.plugin(SystemPrompt)
  137. await ctx.plugin(ToolRegistry)
  138. await ctx.plugin(SubagentService)
  139. ctx.subagents.registerProvider({
  140. name: 'weird',
  141. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  142. inheritsParentContext: false,
  143. start: async () => ({
  144. id: SessionId('weird-child'),
  145. localAgent: undefined,
  146. result: Promise.resolve({ output: [{ type: 'text', text: 'partial' }], stopReason: 'frobnicated' as never }),
  147. dispose: async () => {},
  148. }),
  149. })
  150. await ctx.plugin(tool, { provider: 'weird', maxDepth: 'provider-managed' })
  151. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' })
  152. expect(result.isError).toBe(true)
  153. expect(text(result)).toContain('abnormally')
  154. })
  155. it('forwards configured agentOptions into the start request', async () => {
  156. // Cover the `config.agentOptions ? … : {}` spread: a provider that captures
  157. // the request lets us assert the agentOptions reached it.
  158. let seen: { agentOptions?: { model?: string } } | undefined
  159. const ctx = new Context()
  160. await ctx.plugin(SystemPrompt)
  161. await ctx.plugin(ToolRegistry)
  162. await ctx.plugin(SubagentService)
  163. ctx.subagents.registerProvider({
  164. name: 'capture',
  165. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  166. inheritsParentContext: false,
  167. start: async (request) => {
  168. seen = request
  169. return {
  170. id: SessionId('capture-child'),
  171. localAgent: undefined,
  172. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  173. dispose: async () => {},
  174. }
  175. },
  176. })
  177. await ctx.plugin(tool, { provider: 'capture', agentOptions: { model: 'child-model' }, maxDepth: 'provider-managed' })
  178. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  179. expect(seen?.agentOptions).toEqual({ model: 'child-model' })
  180. })
  181. it('defaults toolName and omits agentOptions when apply() is called directly (schema bypass)', async () => {
  182. // `ctx.plugin` validates+defaults config first (toolName→'subagent', the
  183. // agentOptions object→{}), so the runtime `?? 'subagent'` fallback and the
  184. // no-agentOptions branch are only reachable via a direct apply() that
  185. // bypasses schemastery — the same pattern acp-agent uses for its defaults.
  186. let seen: { agentOptions?: unknown } | undefined
  187. const ctx = new Context()
  188. await ctx.plugin(SystemPrompt)
  189. await ctx.plugin(ToolRegistry)
  190. await ctx.plugin(SubagentService)
  191. ctx.subagents.registerProvider({
  192. name: 'bare',
  193. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  194. inheritsParentContext: false,
  195. start: async (request) => {
  196. seen = request
  197. return {
  198. id: SessionId('bare-child'),
  199. localAgent: undefined,
  200. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  201. dispose: async () => {},
  202. }
  203. },
  204. })
  205. // Direct apply with only `provider` — no toolName, no agentOptions.
  206. tool.apply(ctx, { provider: 'bare' })
  207. await new Promise(r => setTimeout(r, 10))
  208. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(true)
  209. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  210. expect(seen?.agentOptions).toBeUndefined()
  211. })
  212. it('fails loud when invoked without a calling agent', async () => {
  213. const ctx = await setup({ provider: 'mock' })
  214. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' }, { agent: undefined })
  215. expect(result.isError).toBe(true)
  216. expect(text(result)).toContain('requires a calling agent')
  217. })
  218. it('registers when the provider appears LATER — no load-order requirement (Loader starts siblings concurrently)', async () => {
  219. const ctx = new Context()
  220. await ctx.plugin(SystemPrompt)
  221. await ctx.plugin(ToolRegistry)
  222. await ctx.plugin(SubagentService)
  223. // Tool first: no provider yet — the tool must be absent, not broken.
  224. // Direct apply (schema bypass): also covers the waiting-note's default
  225. // toolName fallback, which validated config pre-fills.
  226. tool.apply(ctx, { provider: 'mock' })
  227. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(false)
  228. // Backend arrives (as a delayed sibling fiber would): the tool appears.
  229. await mock.mountScriptedProvider(ctx, { name: 'mock', reply: 'late but fine' })
  230. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(true)
  231. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' })
  232. expect(text(result)).toBe('late but fine')
  233. })
  234. it('mirrors the provider lifecycle: gone on backend dispose, re-derived wording on re-registration', async () => {
  235. const ctx = new Context()
  236. await ctx.plugin(SystemPrompt)
  237. await ctx.plugin(ToolRegistry)
  238. await ctx.plugin(SubagentService)
  239. const backend = await mock.mountScriptedProvider(ctx, { name: 'mock' }) // fresh conversation (descriptor: false)
  240. await ctx.plugin(tool, { provider: 'mock' })
  241. expect(ctx.tools.schemas().find(s => s.name === 'subagent')!.description).toContain('does not see this conversation')
  242. // Backend unloads (HMR shape): the tool must not outlive its provider.
  243. await backend.dispose()
  244. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(false)
  245. // Backend reloads with a DIFFERENT conversation-history descriptor: the wording is re-derived
  246. // from the fresh provider, not served stale from the first mount.
  247. await mock.mountScriptedProvider(ctx, { name: 'mock', inheritsParentContext: true })
  248. expect(ctx.tools.schemas().find(s => s.name === 'subagent')!.description).toContain('inherits this conversation')
  249. })
  250. it('the tool PLUGIN fiber owns its lifecycle listeners: disposal unmounts, and a disposed fiber never zombie-mounts', async () => {
  251. const ctx = new Context()
  252. await ctx.plugin(SystemPrompt)
  253. await ctx.plugin(ToolRegistry)
  254. await ctx.plugin(SubagentService)
  255. // Arm 1: a mounted tool dies with its plugin fiber; the provider survives.
  256. await mock.mountScriptedProvider(ctx, { name: 'mock' })
  257. const mounted = await ctx.plugin(tool, { provider: 'mock' })
  258. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(true)
  259. await mounted.dispose()
  260. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(false)
  261. expect(ctx.subagents.getProvider('mock')).toBeDefined()
  262. // Arm 2: a fiber disposed while WAITING must not react to the provider
  263. // arriving later — a surviving listener would re-register a tool that no
  264. // live plugin owns (the zombie mount).
  265. const waiting = await ctx.plugin(tool, { provider: 'later', toolName: 'subagent_later' })
  266. await waiting.dispose()
  267. await mock.mountScriptedProvider(ctx, { name: 'later' })
  268. expect(ctx.tools.schemas().some(s => s.name === 'subagent_later')).toBe(false)
  269. })
  270. it('ignores lifecycle events for OTHER providers', async () => {
  271. const ctx = new Context()
  272. await ctx.plugin(SystemPrompt)
  273. await ctx.plugin(ToolRegistry)
  274. await ctx.plugin(SubagentService)
  275. await mock.mountScriptedProvider(ctx, { name: 'mock' })
  276. await ctx.plugin(tool, { provider: 'mock' })
  277. // An unrelated provider registering (added-event with another name) and
  278. // unregistering (removed-event with another name) must not touch the tool.
  279. const other = await mock.mountScriptedProvider(ctx, { name: 'other', inheritsParentContext: true })
  280. expect(ctx.tools.schemas().filter(s => s.name === 'subagent')).toHaveLength(1)
  281. expect(ctx.tools.schemas().find(s => s.name === 'subagent')!.description).toContain('does not see this conversation')
  282. await other.dispose()
  283. expect(ctx.tools.schemas().some(s => s.name === 'subagent')).toBe(true)
  284. })
  285. it('derives spawn-shaped wording from a fresh-conversation provider (default mock)', async () => {
  286. const ctx = await setup({ provider: 'mock' })
  287. const schema = ctx.tools.schemas().find(s => s.name === 'subagent')!
  288. expect(schema.description).toContain('does not see this conversation')
  289. const props = (schema.parameters as { properties: Record<string, { description: string }> }).properties
  290. expect(props['prompt']!.description).toContain('include everything it needs')
  291. })
  292. it('derives inherited-context wording from a seeded-conversation provider', async () => {
  293. const ctx = await setup({ provider: 'mock', toolName: 'subagent' }, { inheritsParentContext: true })
  294. const schema = ctx.tools.schemas().find(s => s.name === 'subagent')!
  295. expect(schema.description).toContain('inherits this conversation')
  296. expect(schema.description).not.toContain('does not see this conversation')
  297. const props = (schema.parameters as { properties: Record<string, { description: string }> }).properties
  298. expect(props['prompt']!.description).toContain('completed turns')
  299. })
  300. it('disposes the run on the success path (no leaked child)', async () => {
  301. // Spy on the provider's run.dispose via a wrapping provider registered
  302. // directly on the service, then point the tool at it.
  303. const disposed = vi.fn()
  304. const ctx = new Context()
  305. await ctx.plugin(SystemPrompt)
  306. await ctx.plugin(ToolRegistry)
  307. await ctx.plugin(SubagentService)
  308. ctx.subagents.registerProvider({
  309. name: 'spy',
  310. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  311. inheritsParentContext: false,
  312. start: async () => ({
  313. id: SessionId('spy-child'),
  314. localAgent: undefined,
  315. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  316. dispose: async () => void disposed(),
  317. }),
  318. })
  319. await ctx.plugin(tool, { provider: 'spy', maxDepth: 'provider-managed' })
  320. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  321. expect(disposed).toHaveBeenCalledTimes(1)
  322. })
  323. it('disposes the run on the error path too', async () => {
  324. const disposed = vi.fn()
  325. const ctx = new Context()
  326. await ctx.plugin(SystemPrompt)
  327. await ctx.plugin(ToolRegistry)
  328. await ctx.plugin(SubagentService)
  329. ctx.subagents.registerProvider({
  330. name: 'spy',
  331. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  332. inheritsParentContext: false,
  333. start: async () => ({
  334. id: SessionId('spy-child'),
  335. localAgent: undefined,
  336. result: Promise.resolve({ output: [], stopReason: 'error' as const }),
  337. dispose: async () => void disposed(),
  338. }),
  339. })
  340. await ctx.plugin(tool, { provider: 'spy', maxDepth: 'provider-managed' })
  341. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' })
  342. expect(result.isError).toBe(true)
  343. expect(disposed).toHaveBeenCalledTimes(1)
  344. })
  345. it('passes the tool abort signal as the provider cancellation channel', async () => {
  346. const cancelled = vi.fn()
  347. const ctx = new Context()
  348. await ctx.plugin(SystemPrompt)
  349. await ctx.plugin(ToolRegistry)
  350. await ctx.plugin(SubagentService)
  351. ctx.subagents.registerProvider({
  352. name: 'spy',
  353. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  354. inheritsParentContext: false,
  355. start: async (request) => {
  356. if (request.signal.aborted) throw new Error('start aborted')
  357. let resolveResult: (r: { output: never[]; stopReason: 'aborted' }) => void
  358. const result = new Promise<{ output: never[]; stopReason: 'aborted' }>((res) => { resolveResult = res })
  359. request.signal.addEventListener('abort', () => {
  360. cancelled()
  361. resolveResult({ output: [], stopReason: 'aborted' })
  362. }, { once: true })
  363. return {
  364. id: SessionId('spy-child'),
  365. localAgent: undefined,
  366. result,
  367. dispose: async () => {},
  368. }
  369. },
  370. })
  371. await ctx.plugin(tool, { provider: 'spy', maxDepth: 'provider-managed' })
  372. const controller = new AbortController()
  373. const pending = callSubagent(ctx, { description: 'd', prompt: 'p' }, { signal: controller.signal })
  374. // Let provider.start install its listener before aborting.
  375. await Promise.resolve()
  376. await Promise.resolve()
  377. controller.abort()
  378. const result = await pending
  379. expect(cancelled).toHaveBeenCalledTimes(1)
  380. expect(result.isError).toBe(true)
  381. })
  382. it('passes an already-aborted signal so provider startup rejects', async () => {
  383. const sawAborted = vi.fn()
  384. const ctx = new Context()
  385. await ctx.plugin(SystemPrompt)
  386. await ctx.plugin(ToolRegistry)
  387. await ctx.plugin(SubagentService)
  388. ctx.subagents.registerProvider({
  389. name: 'spy',
  390. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  391. inheritsParentContext: false,
  392. start: async (request) => {
  393. if (request.signal.aborted) sawAborted()
  394. throw new Error('start aborted')
  395. },
  396. })
  397. await ctx.plugin(tool, { provider: 'spy', maxDepth: 'provider-managed' })
  398. const controller = new AbortController()
  399. controller.abort() // already aborted BEFORE the tool runs
  400. const result = await callSubagent(ctx, { description: 'd', prompt: 'p' }, { signal: controller.signal })
  401. expect(sawAborted).toHaveBeenCalledTimes(1)
  402. expect(result.isError).toBe(true)
  403. })
  404. it('tools depend on the service: no `subagent` tool without ctx.subagents', async () => {
  405. const ctx = new Context()
  406. await ctx.plugin(SystemPrompt)
  407. await ctx.plugin(ToolRegistry)
  408. // No SubagentService mounted. The tool injects ['tools','subagents'] so its
  409. // apply never runs; the tool is absent rather than half-registered.
  410. let booted = true
  411. try {
  412. await ctx.plugin(tool, { provider: 'mock' })
  413. await new Promise(r => setTimeout(r, 20))
  414. } catch {
  415. booted = false
  416. }
  417. // Either it never booted, or it booted but registered no tool.
  418. const present = ctx.get('tools')?.schemas().some(s => s.name === 'subagent') ?? false
  419. expect(booted && present).toBe(false)
  420. })
  421. it('has the namespace-plugin export shape (no stray default) so the Loader keeps name/inject/Config/apply', () => {
  422. // Postmortem 0001 guard: this plugin HAS `inject = ['tools','subagents']`, so
  423. // a stray `export default apply` would collapse the module via
  424. // `unwrapExports` (`exports.default ?? exports`), DROP `inject`, and crash at
  425. // load with "cannot get property … without inject". Guard the shape directly.
  426. expect('default' in tool).toBe(false)
  427. expect(tool.name).toBe('tool-subagent')
  428. expect(tool.inject).toEqual(['tools', 'subagents'])
  429. const loader = Object.create(Loader.prototype) as Loader
  430. const unwrapped = loader.unwrapExports(tool) as Record<string, unknown>
  431. expect(unwrapped).toBe(tool)
  432. expect(unwrapped.name).toBe('tool-subagent')
  433. expect(unwrapped.inject).toEqual(['tools', 'subagents'])
  434. expect(typeof unwrapped.apply).toBe('function')
  435. expect(unwrapped.Config).toBeDefined()
  436. })
  437. it('passes persona/toolFilter/maxDepth config through to the start request', async () => {
  438. let seen: { persona?: string; toolFilter?: unknown; maxDepth?: number } | undefined
  439. const ctx = new Context()
  440. await ctx.plugin(SystemPrompt)
  441. await ctx.plugin(ToolRegistry)
  442. await ctx.plugin(SubagentService)
  443. ctx.subagents.registerProvider({
  444. name: 'capture2',
  445. capabilities: { outputSchema: false, depthLimit: true, toolFilter: true, persona: true },
  446. inheritsParentContext: false,
  447. start: async (request) => {
  448. seen = request
  449. return {
  450. id: SessionId('capture2-child'),
  451. localAgent: undefined,
  452. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  453. dispose: async () => {},
  454. }
  455. },
  456. })
  457. await ctx.plugin(tool, {
  458. provider: 'capture2',
  459. persona: 'You are the child.',
  460. toolFilter: { deny: ['subagent'] },
  461. maxDepth: 2,
  462. })
  463. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  464. expect(seen?.persona).toBe('You are the child.')
  465. expect(seen?.toolFilter).toMatchObject({ deny: ['subagent'] })
  466. expect(seen?.maxDepth).toBe(2)
  467. })
  468. it.each([
  469. { label: 'a string', value: '1' as unknown as number },
  470. { label: 'NaN', value: Number.NaN },
  471. { label: 'positive infinity', value: Number.POSITIVE_INFINITY },
  472. { label: 'negative infinity', value: Number.NEGATIVE_INFINITY },
  473. { label: 'a negative integer', value: -1 },
  474. { label: 'a fractional number', value: 1.5 },
  475. { label: 'negative zero', value: -0 },
  476. { label: 'an unsafe integer', value: Number.MAX_SAFE_INTEGER + 1 },
  477. ])('rejects maxDepth=$label when the plugin loads', async ({ value }) => {
  478. await expect(setup({ provider: 'mock', maxDepth: value }))
  479. .rejects.toThrow()
  480. })
  481. it('validates maxDepth when apply() is invoked directly without Schemastery', () => {
  482. const ctx = new Context()
  483. expect(() => {
  484. tool.apply(ctx, {
  485. provider: 'unused',
  486. maxDepth: Number.NaN,
  487. })
  488. }).toThrow('subagent maxDepth must be a non-negative safe integer')
  489. })
  490. it('a partial toolFilter (deny only) does not materialize an empty allow-list (deny-all trap)', async () => {
  491. let seen: { toolFilter?: { readonly allow?: readonly string[]; readonly deny?: readonly string[] } } | undefined
  492. const ctx = new Context()
  493. await ctx.plugin(SystemPrompt)
  494. await ctx.plugin(ToolRegistry)
  495. await ctx.plugin(SubagentService)
  496. ctx.subagents.registerProvider({
  497. name: 'capture3',
  498. capabilities: { outputSchema: false, depthLimit: false, toolFilter: true, persona: false },
  499. inheritsParentContext: false,
  500. start: async (request) => {
  501. seen = request
  502. return {
  503. id: SessionId('capture3-child'),
  504. localAgent: undefined,
  505. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  506. dispose: async () => {},
  507. }
  508. },
  509. })
  510. await ctx.plugin(tool, { provider: 'capture3', toolFilter: { deny: ['subagent'] }, maxDepth: 'provider-managed' })
  511. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  512. expect(seen?.toolFilter).toEqual({ deny: ['subagent'] })
  513. expect(seen?.toolFilter).not.toHaveProperty('allow')
  514. })
  515. it('an omitted agentOptions does not materialize an empty object onto the request', async () => {
  516. // Same schemastery trap as toolFilter, adjacent field: an omitted
  517. // `agentOptions` config key materializes `{}` without the forced default,
  518. // which reads as present and puts a dishonest `agentOptions: {}` on every
  519. // start request.
  520. let seen: { agentOptions?: unknown } | undefined
  521. const ctx = new Context()
  522. await ctx.plugin(SystemPrompt)
  523. await ctx.plugin(ToolRegistry)
  524. await ctx.plugin(SubagentService)
  525. ctx.subagents.registerProvider({
  526. name: 'capture4',
  527. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  528. inheritsParentContext: false,
  529. start: async (request) => {
  530. seen = request
  531. return {
  532. id: SessionId('capture4-child'),
  533. localAgent: undefined,
  534. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  535. dispose: async () => {},
  536. }
  537. },
  538. })
  539. await ctx.plugin(tool, { provider: 'capture4', maxDepth: 'provider-managed' })
  540. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  541. expect(seen).toBeDefined()
  542. expect(seen).not.toHaveProperty('agentOptions')
  543. })
  544. it('an explicit empty toolFilter fails at plugin load, not at first delegation', async () => {
  545. const ctx = new Context()
  546. await ctx.plugin(SystemPrompt)
  547. await ctx.plugin(ToolRegistry)
  548. await ctx.plugin(SubagentService)
  549. ctx.subagents.registerProvider({
  550. name: 'p',
  551. capabilities: { outputSchema: false, depthLimit: false, toolFilter: true, persona: false },
  552. inheritsParentContext: false,
  553. start: () => { throw new Error('unreachable') },
  554. })
  555. const fiber = ctx.plugin(tool, { provider: 'p', toolFilter: {} })
  556. await expect(fiber).rejects.toThrow(/names neither `allow` nor `deny`/)
  557. })
  558. })
  559. describe('dsh-tool-subagent background mode', () => {
  560. /** A live parent with a dedicated scope fiber for structural task cleanup. */
  561. function ownerAgent(ctx: Context, sessionId: string, inject: (...args: unknown[]) => void = () => {}): Agent {
  562. const scopeFiber = ctx.plugin(() => {})
  563. const id = SessionId(sessionId)
  564. const agent = {
  565. id,
  566. ctx: scopeFiber.ctx,
  567. inject,
  568. options: {},
  569. session: { id, header: { version: 0, id, createdAt: 0 } },
  570. } as unknown as Agent
  571. ctx.agents.register(agent)
  572. return agent
  573. }
  574. async function backgroundSetup(toolConfig: tool.Config, mockConfig: Partial<mock.Config> = {}) {
  575. const ctx = await setup(toolConfig, mockConfig)
  576. await ctx.plugin(AgentRegistry)
  577. await ctx.plugin(TaskService)
  578. await ctx.plugin(ToolTasks, {})
  579. return ctx
  580. }
  581. it('returns a task id immediately and the answer is collected through task_output', async () => {
  582. const ctx = await backgroundSetup({ provider: 'mock', agentOptions: { model: 'child-model' } }, { reply: 'background answer' })
  583. const parent = ownerAgent(ctx, 'sess-parent')
  584. const start = await callSubagent(ctx, { description: 'deep research', prompt: 'dig in', run_in_background: true }, { agent: parent })
  585. expect(start.isError).toBe(false)
  586. expect(text(start)).toBe('started background subagent task subagent-1')
  587. const collected = await ctx.tools.execute({
  588. callId: CallId('collect-1'),
  589. name: 'task_output',
  590. arguments: { task_id: 'subagent-1', wait: true },
  591. agent: parent,
  592. })
  593. expect(text(collected)).toBe('background answer\n[status: completed]')
  594. // Final-output reads are idempotent (not consumed).
  595. const again = await ctx.tools.execute({
  596. callId: CallId('collect-2'),
  597. name: 'task_output',
  598. arguments: { task_id: 'subagent-1' },
  599. agent: parent,
  600. })
  601. expect(text(again)).toBe('background answer\n[status: completed]')
  602. })
  603. it('fails loud when the tasks runtime is not loaded', async () => {
  604. const ctx = await setup({ provider: 'mock' })
  605. const result = await callSubagent(ctx, { description: 'd', prompt: 'p', run_in_background: true })
  606. expect(result.isError).toBe(true)
  607. expect(text(result)).toContain('background tasks unavailable: load @deepseek-ai/dsh-tasks')
  608. })
  609. it('refuses to start when the tool signal is already aborted', async () => {
  610. const ctx = await backgroundSetup({ provider: 'mock' })
  611. const parent = ownerAgent(ctx, 'sess-parent')
  612. const controller = new AbortController()
  613. controller.abort()
  614. const result = await callSubagent(ctx, { description: 'd', prompt: 'p', run_in_background: true }, { agent: parent, signal: controller.signal })
  615. expect(result.isError).toBe(true)
  616. expect(text(result)).toContain('subagent delegation aborted')
  617. })
  618. it('settles an asynchronous provider-start failure as a failed task', async () => {
  619. const ctx = await backgroundSetup({ provider: 'mock' })
  620. const parent = ownerAgent(ctx, 'sess-parent')
  621. ctx.subagents.registerProvider({
  622. name: 'broken-start',
  623. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  624. inheritsParentContext: false,
  625. start: async () => { throw new Error('setup failed') },
  626. })
  627. tool.apply(ctx, { provider: 'broken-start', toolName: 'subagent_broken' })
  628. const started = await ctx.tools.execute({
  629. callId: CallId('broken-start'),
  630. name: 'subagent_broken',
  631. arguments: { description: 'broken', prompt: 'p', run_in_background: true },
  632. agent: parent,
  633. })
  634. expect(text(started)).toBe('started background subagent task subagent-1')
  635. const output = await ctx.tools.execute({
  636. callId: CallId('broken-output'),
  637. name: 'task_output',
  638. arguments: { task_id: 'subagent-1', wait: true },
  639. agent: parent,
  640. })
  641. expect(text(output)).toContain('[status: failed, Error: setup failed]')
  642. })
  643. it('kills a subagent task while provider readiness is still pending', async () => {
  644. const ctx = await backgroundSetup({ provider: 'mock' })
  645. const parent = ownerAgent(ctx, 'sess-parent')
  646. ctx.subagents.registerProvider({
  647. name: 'pending-start',
  648. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  649. inheritsParentContext: false,
  650. start: request => new Promise((_resolve, reject) => {
  651. request.signal.addEventListener('abort', () => { reject(new Error('startup aborted')) }, { once: true })
  652. }),
  653. })
  654. tool.apply(ctx, { provider: 'pending-start', toolName: 'subagent_pending' })
  655. await ctx.tools.execute({
  656. callId: CallId('pending-start'),
  657. name: 'subagent_pending',
  658. arguments: { description: 'pending', prompt: 'p', run_in_background: true },
  659. agent: parent,
  660. })
  661. await ctx.tools.execute({
  662. callId: CallId('pending-kill'),
  663. name: 'task_kill',
  664. arguments: { task_id: 'subagent-1', reason: 'no longer needed' },
  665. agent: parent,
  666. })
  667. const output = await ctx.tools.execute({
  668. callId: CallId('pending-output'),
  669. name: 'task_output',
  670. arguments: { task_id: 'subagent-1', wait: true },
  671. agent: parent,
  672. })
  673. expect(text(output)).toBe('(no new output)\n[status: killed]')
  674. })
  675. it('forwards task_kill reasons through the run signal (and defaults one when absent)', async () => {
  676. // Use a provider that remains live until its signal is aborted.
  677. const ctx = await backgroundSetup({ provider: 'mock', agentOptions: { model: 'child-model' } })
  678. const parent = ownerAgent(ctx, 'sess-parent')
  679. const cancels: (string | undefined)[] = []
  680. let starts = 0
  681. ctx.subagents.registerProvider({
  682. name: 'hanging',
  683. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  684. inheritsParentContext: false,
  685. start: async (request) => {
  686. let settle!: (value: { output: { type: 'text'; text: string }[]; stopReason: 'aborted' }) => void
  687. const id = SessionId(`hang-${++starts}`)
  688. const result = new Promise<{ output: { type: 'text'; text: string }[]; stopReason: 'aborted' }>((res) => { settle = res })
  689. request.signal.addEventListener('abort', () => {
  690. cancels.push(typeof request.signal.reason === 'string' ? request.signal.reason : undefined)
  691. settle({ output: [], stopReason: 'aborted' })
  692. }, { once: true })
  693. return {
  694. id,
  695. localAgent: undefined,
  696. result,
  697. dispose: () => Promise.resolve(),
  698. }
  699. },
  700. })
  701. // Direct apply preserves omitted agentOptions instead of applying schema defaults.
  702. tool.apply(ctx, { provider: 'hanging', toolName: 'subagent_hang' })
  703. const startOne = await ctx.tools.execute({ callId: CallId('h1'), name: 'subagent_hang', arguments: { description: 'one', prompt: 'p', run_in_background: true }, agent: parent })
  704. const startTwo = await ctx.tools.execute({ callId: CallId('h2'), name: 'subagent_hang', arguments: { description: 'two', prompt: 'p', run_in_background: true }, agent: parent })
  705. expect(text(startOne)).toBe('started background subagent task subagent-1')
  706. expect(text(startTwo)).toBe('started background subagent task subagent-2')
  707. const withReason = await ctx.tools.execute({ callId: CallId('k1'), name: 'task_kill', arguments: { task_id: 'subagent-1', reason: 'superseded' }, agent: parent })
  708. const withoutReason = await ctx.tools.execute({ callId: CallId('k2'), name: 'task_kill', arguments: { task_id: 'subagent-2' }, agent: parent })
  709. expect(text(withReason)).toBe('requested cancellation of task subagent-1')
  710. expect(text(withoutReason)).toBe('requested cancellation of task subagent-2')
  711. expect(cancels).toEqual(['superseded', 'background subagent task killed'])
  712. // The aborted children settle as killed tasks.
  713. const killed = await ctx.tools.execute({ callId: CallId('w1'), name: 'task_output', arguments: { task_id: 'subagent-1', wait: true }, agent: parent })
  714. expect(text(killed)).toBe('(no new output)\n[status: killed]')
  715. })
  716. it('runOutcome maps the stop-reason vocabulary onto task outcomes', () => {
  717. const output = [{ type: 'text' as const, text: 'partial' }]
  718. expect(runOutcome({ output, stopReason: 'completed' })).toEqual({ status: 'completed', output: 'partial' })
  719. expect(runOutcome({ output, stopReason: 'aborted' })).toEqual({ status: 'killed' })
  720. expect(runOutcome({ output, stopReason: 'error' })).toEqual({ status: 'failed', detail: 'error' })
  721. expect(runOutcome({ output, stopReason: 'max-tokens' })).toEqual({ status: 'failed', detail: 'max-tokens' })
  722. expect(runOutcome({ output, stopReason: 'refusal' })).toEqual({ status: 'failed', detail: 'refusal' })
  723. // Merge-extensible: an unknown reason is failed-with-detail, never success.
  724. expect(runOutcome({ output, stopReason: 'paused' as never })).toEqual({ status: 'failed', detail: 'paused' })
  725. })
  726. it('settleRun disposes the run before reporting, on both result paths', async () => {
  727. const order: string[] = []
  728. const completed = await settleRun({
  729. id: SessionId('child-1'),
  730. localAgent: undefined,
  731. result: Promise.resolve({ output: [{ type: 'text' as const, text: 'ok' }], stopReason: 'completed' as const }),
  732. dispose() { order.push('dispose'); return Promise.resolve() },
  733. })
  734. order.push('reported')
  735. expect(completed).toEqual({ status: 'completed', output: 'ok' })
  736. expect(order).toEqual(['dispose', 'reported'])
  737. // An infrastructure rejection still disposes and reports failed.
  738. let disposed = false
  739. const failed = await settleRun({
  740. id: SessionId('child-2'),
  741. localAgent: undefined,
  742. result: Promise.reject(new Error('transport gone')),
  743. dispose() { disposed = true; return Promise.resolve() },
  744. })
  745. expect(failed).toEqual({ status: 'failed', detail: 'Error: transport gone' })
  746. expect(disposed).toBe(true)
  747. const disposeFailed = await settleRun({
  748. id: SessionId('child-3'),
  749. localAgent: undefined,
  750. result: Promise.resolve({ output: [], stopReason: 'completed' }),
  751. dispose: () => Promise.reject(new Error('reap failed')),
  752. })
  753. expect(disposeFailed).toEqual({ status: 'failed', detail: 'dispose failed: Error: reap failed' })
  754. const bothFailed = await settleRun({
  755. id: SessionId('child-4'),
  756. localAgent: undefined,
  757. result: Promise.reject(new Error('result failed')),
  758. dispose: () => Promise.reject(new Error('reap failed')),
  759. })
  760. expect(bothFailed).toEqual({
  761. status: 'failed',
  762. detail: 'Error: result failed; dispose failed: Error: reap failed',
  763. })
  764. })
  765. })
  766. describe('background preflight failure (no orphaned child, by construction)', () => {
  767. it('never starts the child when tasks.start preflight throws', async () => {
  768. // With no control surface, task preflight fails before the provider can spawn.
  769. const ctx = await setup({ provider: 'mock' })
  770. await ctx.plugin(AgentRegistry)
  771. await ctx.plugin(TaskService)
  772. const scopeFiber = ctx.plugin(() => {})
  773. const id = SessionId('sess-p')
  774. const parent = {
  775. id,
  776. ctx: scopeFiber.ctx,
  777. inject: () => {},
  778. options: {},
  779. session: { id, header: { version: 0, id, createdAt: 0 } },
  780. } as unknown as Agent
  781. ctx.agents.register(parent)
  782. let starts = 0
  783. ctx.subagents.registerProvider({
  784. name: 'probe',
  785. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  786. inheritsParentContext: false,
  787. start: async () => {
  788. starts += 1
  789. return {
  790. id: SessionId('probe-child'),
  791. localAgent: undefined,
  792. result: Promise.resolve({ output: [], stopReason: 'completed' as const }),
  793. dispose: () => Promise.resolve(),
  794. }
  795. },
  796. })
  797. tool.apply(ctx, { provider: 'probe', toolName: 'subagent_probe' })
  798. const result = await ctx.tools.execute({
  799. callId: CallId('probe-1'),
  800. name: 'subagent_probe',
  801. arguments: { description: 'd', prompt: 'p', run_in_background: true },
  802. agent: parent,
  803. })
  804. expect(result.isError).toBe(true)
  805. expect(text(result)).toContain('no control surface is attached')
  806. // Declare-then-execute: the failed preflight means no child ever existed.
  807. expect(starts).toBe(0)
  808. })
  809. })
  810. describe('depth budget configuration', () => {
  811. /** Mount the tool over a request-capturing provider with full capabilities. */
  812. async function captureSetup(config: Omit<tool.Config, 'provider'> = {}) {
  813. const requests: SubagentStartRequest[] = []
  814. const ctx = new Context()
  815. await ctx.plugin(SystemPrompt)
  816. await ctx.plugin(ToolRegistry)
  817. await ctx.plugin(SubagentService)
  818. ctx.subagents.registerProvider({
  819. name: 'capture',
  820. capabilities: { outputSchema: true, depthLimit: true, toolFilter: true, persona: true },
  821. inheritsParentContext: false,
  822. start: async (request) => {
  823. requests.push(request)
  824. return {
  825. id: SessionId(`capture-child-${requests.length}`),
  826. localAgent: undefined,
  827. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  828. dispose: async () => {},
  829. }
  830. },
  831. })
  832. await ctx.plugin(tool, { provider: 'capture', ...config })
  833. return { ctx, requests }
  834. }
  835. it('defaults maxDepth to 3 and forwards it in the start request', async () => {
  836. const { ctx, requests } = await captureSetup()
  837. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  838. expect(requests[0]?.maxDepth).toBe(3)
  839. expect(requests[0]?.toolFilter).toBeUndefined()
  840. })
  841. it('forwards an explicit tool filter unchanged instead of encoding the depth policy into it', async () => {
  842. const { ctx, requests } = await captureSetup({ toolFilter: { deny: ['dangerous'] }, maxDepth: 0 })
  843. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  844. expect(requests[0]?.maxDepth).toBe(0)
  845. expect(requests[0]?.toolFilter).toEqual({ deny: ['dangerous'] })
  846. })
  847. it('rejects a numeric maxDepth on a provider without the depthLimit capability at mount', async () => {
  848. const ctx = new Context()
  849. await ctx.plugin(SystemPrompt)
  850. await ctx.plugin(ToolRegistry)
  851. await ctx.plugin(SubagentService)
  852. ctx.subagents.registerProvider({
  853. name: 'no-depth',
  854. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  855. inheritsParentContext: false,
  856. start: async () => { throw new Error('unreachable') },
  857. })
  858. await expect(ctx.plugin(tool, { provider: 'no-depth' }))
  859. .rejects.toThrow(/provider-managed/)
  860. })
  861. it("'provider-managed' omits the cap so a capability-less provider mounts and starts", async () => {
  862. const requests: SubagentStartRequest[] = []
  863. const ctx = new Context()
  864. await ctx.plugin(SystemPrompt)
  865. await ctx.plugin(ToolRegistry)
  866. await ctx.plugin(SubagentService)
  867. ctx.subagents.registerProvider({
  868. name: 'external',
  869. capabilities: { outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  870. inheritsParentContext: false,
  871. start: async (request) => {
  872. requests.push(request)
  873. return {
  874. id: SessionId('external-child'),
  875. localAgent: undefined,
  876. result: Promise.resolve({ output: [{ type: 'text', text: 'ok' }], stopReason: 'completed' as const }),
  877. dispose: async () => {},
  878. }
  879. },
  880. })
  881. await ctx.plugin(tool, { provider: 'external', maxDepth: 'provider-managed' })
  882. await callSubagent(ctx, { description: 'd', prompt: 'p' })
  883. expect(requests[0]?.maxDepth).toBeUndefined()
  884. expect(requests[0]?.toolFilter).toBeUndefined()
  885. })
  886. })