sdk.snapshot.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /**
  2. * Keyless snapshot coverage for the TypeScript SDK path: each scenario spawns
  3. * the real `dsh --profile sdk` runtime through
  4. * `@deepseek-ai/dsh-sdk-client`, drives one turn over stdio JSON-RPC,
  5. * and pins the SDK `RunResult`, the complete notification stream, and the
  6. * persisted session logs. Replay serves recorded model
  7. * responses via `llm-replay` (`cordis.snapshot.yml`); `DSH_SNAPSHOT=record`
  8. * re-records against the live API; `DSH_SNAPSHOT=refresh` replays committed
  9. * fixtures and rewrites expected outputs.
  10. */
  11. import { existsSync } from 'node:fs'
  12. import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
  13. import { tmpdir } from 'node:os'
  14. import { basename, delimiter, join } from 'node:path'
  15. import { fileURLToPath, pathToFileURL } from 'node:url'
  16. import { describe, expect, it } from 'vitest'
  17. import {
  18. normalizeSessionLog,
  19. normalizeSessionSnapshot,
  20. normalizeStdout,
  21. refreshFixtureReplacements,
  22. scrubRequestHeaders,
  23. scrubSessionSnapshot,
  24. stabilizeFixtureMessageIds,
  25. stabilizeRefreshLog,
  26. tokenizeSessionFixtureCwd,
  27. type HarvestedLog,
  28. type NormalizeContext,
  29. } from '@deepseek-ai/dsh-acp-snapshot'
  30. import { DeepSeekHarness, type HarnessNotification, type RunResult } from '@deepseek-ai/dsh-sdk-client'
  31. const testsDir = dirOf(import.meta.url)
  32. const snapshotsDir = join(testsDir, 'snapshots')
  33. const liveConfig = join(testsDir, '..', 'typescript-sdk.cordis.yml')
  34. const replayConfig = join(testsDir, '..', 'typescript-sdk.cordis.snapshot.yml')
  35. const minimalLiveConfig = join(testsDir, '..', 'typescript-sdk-minimal.cordis.yml')
  36. const minimalReplayConfig = join(testsDir, '..', 'typescript-sdk-minimal.cordis.snapshot.yml')
  37. const sessionUploadLivePatch = join(testsDir, '..', 'session-upload.cordis.yml')
  38. const sessionUploadReplayPatch = join(testsDir, '..', 'session-upload.snapshot.cordis.yml')
  39. const exampleMode = process.env.DSH_EXAMPLE_MODE ?? 'src'
  40. const replayPlugin = fileURLToPath(new URL(
  41. exampleMode === 'lib'
  42. ? '../../../packages/test-support/llm-replay/lib/index.js'
  43. : '../../../packages/test-support/llm-replay/src/index.ts',
  44. import.meta.url,
  45. ))
  46. const MINIMAL_SYSTEM_PROMPT = 'You are the environment-selected minimal software engineer.'
  47. const MINIMAL_BASH_DESCRIPTION = `Run commands in a bash shell
  48. * When invoking this tool, the contents of the "command" parameter does NOT need to be XML-escaped.
  49. * You don't have access to the internet via this tool.
  50. * You do have access to a mirror of common linux and python packages via apt and pip.
  51. * State is persistent across command calls and discussions with the user.
  52. * To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.
  53. * Please avoid commands that may produce a very large amount of output.
  54. * Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.`
  55. const mode = process.env.DSH_SNAPSHOT ?? 'replay'
  56. const recording = mode === 'record'
  57. const refreshing = mode === 'refresh'
  58. function dirOf(url: string): string {
  59. return fileURLToPath(new URL('.', url))
  60. }
  61. interface SdkScenario {
  62. /** Scenario name; the snapshots/<name> fixture directory. */
  63. name: string
  64. /** The user prompt for the single SDK turn. */
  65. prompt: string
  66. /** Fixed SDK session id, so fixtures and replay binding stay stable. */
  67. sessionId: string
  68. /** How many child sessions the turn persists (subagent scenarios). */
  69. children: number
  70. /** Optional scenario-specific live and replay compositions. */
  71. configs?: { live: string; replay: string }
  72. /** Additional ordered patches applied after the selected live or replay patch. */
  73. additionalPatches?: { live: readonly string[]; replay: readonly string[] }
  74. /** Environment overrides passed to the runtime subprocess. */
  75. environment?: Readonly<Record<string, string>>
  76. /** Cwd-relative files whose final contents are part of the scenario contract. */
  77. expectedFiles?: Readonly<Record<string, string>>
  78. /** Assembled model-facing tool names and required argument keys. */
  79. expectedTools?: Readonly<Record<string, readonly string[]>>
  80. /** Exact assembled system prompt for the root request. */
  81. expectedSystem?: string
  82. /** Exact model-facing descriptions for selected tools. */
  83. expectedToolDescriptions?: Readonly<Record<string, string>>
  84. /** Expected runtime-context state in the real assembled request. */
  85. runtimeContext?: false | { includes: readonly string[]; excludes: readonly string[] }
  86. }
  87. const SCENARIOS: SdkScenario[] = [
  88. {
  89. name: 'text-turn',
  90. prompt: 'Reply with exactly: SDK snapshot OK',
  91. sessionId: 'sdk-snapshot-text',
  92. children: 0,
  93. additionalPatches: { live: [sessionUploadLivePatch], replay: [sessionUploadReplayPatch] },
  94. },
  95. {
  96. name: 'bash-tool',
  97. prompt: 'Run this exact command with your bash tool, then reply with its stdout only: echo dsh-sdk-proof-7391',
  98. sessionId: 'sdk-snapshot-bash',
  99. children: 0,
  100. },
  101. {
  102. name: 'subagent-spawn-in-process',
  103. prompt: "Use the subagent tool exactly once with description 'echo probe' and prompt: Reply with exactly: child answer 42. Then reply with the subagent's final answer verbatim.",
  104. sessionId: 'sdk-snapshot-subagent',
  105. children: 1,
  106. },
  107. {
  108. name: 'persistent-tools',
  109. prompt: 'Prove that bash state persists. Then create {{cwd}}/note.txt with a tab-indented line, view it, replace that literal tab-indented line, and make the persistent shell exit with code 9.',
  110. sessionId: 'persistent-tools-snapshot',
  111. children: 0,
  112. configs: { live: minimalLiveConfig, replay: minimalReplayConfig },
  113. environment: { DSH_SYSTEM_PROMPT: MINIMAL_SYSTEM_PROMPT },
  114. expectedFiles: { 'note.txt': 'target:\n\tnew\n' },
  115. expectedTools: { bash: ['command'], str_replace_editor: ['command', 'path'] },
  116. expectedSystem: MINIMAL_SYSTEM_PROMPT,
  117. expectedToolDescriptions: { bash: MINIMAL_BASH_DESCRIPTION },
  118. runtimeContext: {
  119. includes: ['Current DSH file policy: danger-full-access', 'Approval prompts are disabled in this session'],
  120. excludes: ['workspace-write'],
  121. },
  122. },
  123. ]
  124. interface PersistedLog {
  125. readonly path: string
  126. readonly content: string
  127. readonly header: Record<string, unknown>
  128. }
  129. interface MissingFile {
  130. readonly missing: true
  131. }
  132. async function jsonlFiles(dir: string): Promise<string[]> {
  133. const entries = await readdir(dir, { recursive: true })
  134. return entries.filter(entry => entry.endsWith('.jsonl')).map(entry => join(dir, entry)).sort()
  135. }
  136. async function persistedLogs(sessionsRoot: string): Promise<PersistedLog[]> {
  137. const files = await jsonlFiles(sessionsRoot)
  138. return Promise.all(files.map(async (path) => {
  139. const content = await readFile(path, 'utf8')
  140. const header = JSON.parse(content.slice(0, content.indexOf('\n'))) as Record<string, unknown>
  141. return { path, content, header }
  142. }))
  143. }
  144. interface LoggedRequestHeader {
  145. type?: string
  146. data?: { header?: { system?: unknown; tools?: LoggedTool[] } }
  147. }
  148. interface LoggedTool {
  149. readonly name: string
  150. readonly description?: unknown
  151. readonly parameters: { readonly required?: string[] }
  152. }
  153. function assembledTools(log: PersistedLog): LoggedTool[] {
  154. const event = log.content.trimEnd().split('\n')
  155. .map(line => JSON.parse(line) as LoggedRequestHeader)
  156. .find(candidate => candidate.type === 'request/header')
  157. const tools = event?.data?.header?.tools
  158. if (tools === undefined) throw new Error('session log has no request/header tools')
  159. return tools
  160. }
  161. function assembledToolRequirements(log: PersistedLog): Record<string, string[]> {
  162. return Object.fromEntries(assembledTools(log).map(tool => [tool.name, tool.parameters.required ?? []]))
  163. }
  164. function assembledToolDescriptions(log: PersistedLog): Record<string, string> {
  165. return Object.fromEntries(assembledTools(log).map((tool) => {
  166. if (typeof tool.description !== 'string') throw new Error(`tool ${tool.name} has no description`)
  167. return [tool.name, tool.description]
  168. }))
  169. }
  170. function assembledSystem(log: PersistedLog): string {
  171. const event = log.content.trimEnd().split('\n')
  172. .map(line => JSON.parse(line) as LoggedRequestHeader)
  173. .find(candidate => candidate.type === 'request/header')
  174. const system = event?.data?.header?.system
  175. if (typeof system !== 'string') throw new Error('session log has no request/header system')
  176. return system
  177. }
  178. function assembledRuntimeContexts(log: PersistedLog): string[] {
  179. return log.content.trimEnd().split('\n').flatMap((line) => {
  180. const event = JSON.parse(line) as {
  181. type?: string
  182. data?: { source?: { kind?: string; plugin?: string }; content?: Array<{ type?: string; text?: unknown }> }
  183. }
  184. if (event.type !== 'user/message'
  185. || event.data?.source?.kind !== 'plugin'
  186. || event.data.source.plugin !== '@deepseek-ai/dsh-system-prompt') return []
  187. return event.data.content?.flatMap(block => block.type === 'text' && typeof block.text === 'string' ? [block.text] : []) ?? []
  188. })
  189. }
  190. function contextOf(logs: readonly { content: string; header: Record<string, unknown> }[], cwd: string): NormalizeContext {
  191. return {
  192. sessionIds: logs.flatMap(log => typeof log.header.id === 'string' ? [log.header.id] : []),
  193. cwd,
  194. }
  195. }
  196. function contextOfContents(contents: readonly string[]): NormalizeContext {
  197. const headers = contents.map(content => JSON.parse(content.slice(0, content.indexOf('\n'))) as Record<string, unknown>)
  198. return {
  199. sessionIds: headers.flatMap(header => typeof header.id === 'string' ? [header.id] : []),
  200. cwd: typeof headers[0]?.cwd === 'string' ? headers[0].cwd : '\0no-cwd\0',
  201. }
  202. }
  203. async function hydrateReplayFixtures(scenario: SdkScenario, cwd: string): Promise<string[]> {
  204. const root = join(cwd, '.replay-fixtures')
  205. await mkdir(root, { recursive: true })
  206. return Promise.all(fixtureFiles(scenario).map(async (source) => {
  207. const destination = join(root, basename(source))
  208. await writeFile(destination, (await readFile(source, 'utf8')).replaceAll('{{cwd}}', cwd))
  209. return destination
  210. }))
  211. }
  212. async function readExpectedFile(path: string): Promise<string | MissingFile> {
  213. try {
  214. return await readFile(path, 'utf8')
  215. } catch (error: unknown) {
  216. if (error instanceof Error && (error as NodeJS.ErrnoException).code === 'ENOENT') return { missing: true }
  217. throw error
  218. }
  219. }
  220. /** Materialize a built-mode replay patch with an absolute test-plugin module URL. */
  221. async function materializeReplayPatch(source: string, cwd: string): Promise<string> {
  222. const target = join(cwd, `.sdk-${basename(source)}`)
  223. const content = (await readFile(source, 'utf8'))
  224. .replaceAll("'@deepseek-ai/dsh-llm-replay'", JSON.stringify(pathToFileURL(replayPlugin).href))
  225. await writeFile(target, content)
  226. return target
  227. }
  228. /**
  229. * Normalize the SDK-visible notification stream: embedded `session.event`
  230. * envelopes get the session-log treatment (times zeroed, headers tokenized),
  231. * then every record is scrubbed like a wire frame.
  232. */
  233. function normalizeNotifications(notifications: readonly HarnessNotification[], ctx: NormalizeContext): string {
  234. const events = notifications
  235. .filter(n => n.method === 'session.event')
  236. .map(n => n.params.event as Record<string, unknown>)
  237. const normalizedEvents = events.length === 0
  238. ? []
  239. : scrubRequestHeaders(normalizeSessionLog(
  240. `${events.map(event => JSON.stringify(event)).join('\n')}\n`,
  241. ctx,
  242. )).trimEnd().split('\n').map(line => JSON.parse(line) as Record<string, unknown>)
  243. let eventIndex = 0
  244. const records = notifications.map((notification) => {
  245. if (notification.method !== 'session.event') return { method: notification.method, params: notification.params }
  246. const event = normalizedEvents[eventIndex++]
  247. return { method: notification.method, params: { ...notification.params, event } }
  248. })
  249. return normalizeStdout(`${records.map(record => JSON.stringify(record)).join('\n')}\n`, ctx)
  250. }
  251. /** Normalize the owned-run projection. */
  252. function normalizeResult(result: RunResult, ctx: NormalizeContext): string {
  253. return normalizeStdout(`${JSON.stringify({
  254. sessionId: result.sessionId,
  255. finalResponse: result.finalResponse,
  256. })}\n`, ctx)
  257. }
  258. /** One SDK turn against a fresh runtime subprocess in an isolated cwd. */
  259. async function runScenario(scenario: SdkScenario): Promise<{
  260. result: RunResult
  261. notifications: HarnessNotification[]
  262. logs: PersistedLog[]
  263. observedFiles: Record<string, string | MissingFile>
  264. cwd: string
  265. }> {
  266. const cwd = await mkdtemp(join(tmpdir(), `sdk-snapshot-${scenario.name}-`))
  267. const dshHome = join(cwd, '.dsh')
  268. const sessionsRoot = join(dshHome, 'sessions')
  269. const replayFixtures = recording ? [] : await hydrateReplayFixtures(scenario, cwd)
  270. const livePatch = scenario.configs?.live ?? liveConfig
  271. const replayPatch = scenario.configs?.replay ?? replayConfig
  272. const resolvedReplayPatch = recording ? undefined : await materializeReplayPatch(replayPatch, cwd)
  273. const additionalPatches = recording
  274. ? scenario.additionalPatches?.live ?? []
  275. : scenario.additionalPatches?.replay ?? []
  276. const [parentFixture, ...childFixtures] = replayFixtures
  277. const env: Record<string, string> = {
  278. ...Object.fromEntries(Object.entries(process.env).filter(([, value]) => value !== undefined)) as Record<string, string>,
  279. DSH_SNAPSHOT: mode,
  280. DSH_TELEMETRY_DISABLED: '1',
  281. NODE_OPTIONS: [process.env.NODE_OPTIONS, '--disable-warning=ExperimentalWarning'].filter(Boolean).join(' '),
  282. ...parentFixture === undefined ? {} : {
  283. DSH_SNAPSHOT_FILE: parentFixture,
  284. ...childFixtures.length > 0 ? { DSH_SNAPSHOT_CHILD_FILES: childFixtures.join(delimiter) } : {},
  285. },
  286. ...scenario.environment,
  287. }
  288. const harness = new DeepSeekHarness({
  289. profile: 'sdk',
  290. patches: [
  291. livePatch,
  292. ...resolvedReplayPatch === undefined ? [] : [resolvedReplayPatch],
  293. ...additionalPatches,
  294. ],
  295. dshHome,
  296. processCwd: cwd,
  297. env,
  298. requestTimeoutMs: 110_000,
  299. cwd,
  300. provider: 'deepseek-official',
  301. model: 'deepseek-v4-flash',
  302. })
  303. try {
  304. const notifications: HarnessNotification[] = []
  305. const result = await harness.run(scenario.prompt.replaceAll('{{cwd}}', cwd), {
  306. sessionId: scenario.sessionId,
  307. onNotification: (notification) => { notifications.push(notification) },
  308. })
  309. await harness.close()
  310. const logs = await persistedLogs(sessionsRoot)
  311. const observedFiles = Object.fromEntries(await Promise.all(
  312. Object.keys(scenario.expectedFiles ?? {}).map(async (path): Promise<[string, string | MissingFile]> => [
  313. path,
  314. await readExpectedFile(join(cwd, path)),
  315. ]),
  316. ))
  317. return { result, notifications, logs, observedFiles, cwd }
  318. } finally {
  319. await harness.close()
  320. await rm(cwd, { recursive: true, force: true })
  321. }
  322. }
  323. /** Order logs parent-first, children by creation time (fixture layout order). */
  324. function orderLogs(logs: PersistedLog[], scenario: SdkScenario): PersistedLog[] {
  325. const parents = logs.filter(log => typeof log.header.parentSession !== 'string')
  326. const children = logs.filter(log => typeof log.header.parentSession === 'string')
  327. .sort((left, right) => Number(left.header.createdAt) - Number(right.header.createdAt))
  328. expect(parents).toHaveLength(1)
  329. expect(children).toHaveLength(scenario.children)
  330. return [...parents, ...children]
  331. }
  332. function fixtureFiles(scenario: SdkScenario): string[] {
  333. const dir = join(snapshotsDir, scenario.name)
  334. return [
  335. join(dir, 'session.jsonl'),
  336. ...Array.from({ length: scenario.children }, (_, index) => join(dir, `session.${index + 1}.jsonl`)),
  337. ]
  338. }
  339. describe('TypeScript SDK snapshots over the jsonrpc runtime', () => {
  340. for (const scenario of SCENARIOS) {
  341. it(`replays ${scenario.name} through the SDK`, async () => {
  342. const scenarioDir = join(snapshotsDir, scenario.name)
  343. const notificationsExpectedPath = join(scenarioDir, 'notifications.expected.jsonl')
  344. const resultExpectedPath = join(scenarioDir, 'result.expected.json')
  345. const { result, notifications, logs, observedFiles, cwd } = await runScenario(scenario)
  346. const ordered = orderLogs(logs, scenario)
  347. const actualContext = contextOf(ordered, cwd)
  348. const files = fixtureFiles(scenario)
  349. if (recording) {
  350. // Fixtures carry tokenized request headers; llm-replay reads only
  351. // assistant output and tool traffic, so scrubbing keeps prompts and
  352. // schemas out of the corpus without affecting replay.
  353. await mkdir(scenarioDir, { recursive: true })
  354. const existing = await Promise.all(files.map(async file => existsSync(file) ? readFile(file, 'utf8') : ''))
  355. const fixtures = stabilizeFixtureMessageIds(
  356. ordered.map(log => scrubSessionSnapshot(tokenizeSessionFixtureCwd(log.content))),
  357. existing,
  358. )
  359. await Promise.all(fixtures.map(async (fixture, index) => {
  360. const file = files[index]
  361. if (file === undefined) throw new Error(`no fixture path for persisted log ${index}`)
  362. await writeFile(file, fixture)
  363. }))
  364. }
  365. let expectedContents = await Promise.all(files.map(file => readFile(file, 'utf8')))
  366. if (refreshing) {
  367. const harvested = ordered.map((log): HarvestedLog => ({
  368. id: String(log.header.id),
  369. createdAt: Number(log.header.createdAt),
  370. ...typeof log.header.parentSession === 'string' ? { parentSession: log.header.parentSession } : {},
  371. content: log.content,
  372. }))
  373. const replacements = refreshFixtureReplacements(harvested, expectedContents)
  374. const refreshed = ordered.map((log, index) => {
  375. const existing = expectedContents[index]
  376. if (existing === undefined) throw new Error(`no fixture for persisted log ${index}`)
  377. return scrubSessionSnapshot(tokenizeSessionFixtureCwd(
  378. stabilizeRefreshLog(log.content, existing, replacements, actualContext),
  379. ))
  380. })
  381. expectedContents = stabilizeFixtureMessageIds(refreshed, expectedContents)
  382. await Promise.all(expectedContents.map(async (stable, index) => {
  383. const file = files[index]
  384. if (file === undefined) throw new Error(`no fixture for persisted log ${index}`)
  385. await writeFile(file, stable)
  386. }))
  387. }
  388. for (const [index, expected] of expectedContents.entries()) {
  389. expect(scrubRequestHeaders(expected), `${scenario.name} session fixture ${index} carries request-header bulk`)
  390. .toBe(expected)
  391. }
  392. // Persisted transcripts match the committed fixtures.
  393. const expectedContext = contextOfContents(expectedContents)
  394. for (const [index, log] of ordered.entries()) {
  395. const expected = expectedContents[index]
  396. if (expected === undefined) throw new Error(`no fixture for persisted log ${index}`)
  397. expect(normalizeSessionSnapshot(log.content, actualContext))
  398. .toBe(normalizeSessionSnapshot(expected, expectedContext))
  399. }
  400. // The SDK-visible wire stream and turn result match their expected outputs.
  401. const normalizedNotifications = normalizeNotifications(notifications, actualContext)
  402. const normalizedResult = normalizeResult(result, actualContext)
  403. if (recording || refreshing) {
  404. await writeFile(notificationsExpectedPath, normalizedNotifications)
  405. await writeFile(resultExpectedPath, normalizedResult)
  406. }
  407. expect(normalizedNotifications).toBe(await readFile(notificationsExpectedPath, 'utf8'))
  408. expect(normalizedResult).toBe(await readFile(resultExpectedPath, 'utf8'))
  409. // Wire-shape invariants that must hold in every mode.
  410. expect(notifications.at(-1)).toMatchObject({
  411. method: 'session.status',
  412. params: { status: 'idle' },
  413. })
  414. expect(observedFiles).toEqual(scenario.expectedFiles ?? {})
  415. if (scenario.expectedTools !== undefined) {
  416. const parent = ordered[0]
  417. if (parent === undefined) throw new Error(`${scenario.name} has no parent session log`)
  418. expect(assembledToolRequirements(parent)).toEqual(scenario.expectedTools)
  419. }
  420. if (scenario.expectedSystem !== undefined) {
  421. const parent = ordered[0]
  422. if (parent === undefined) throw new Error(`${scenario.name} has no parent session log`)
  423. expect(assembledSystem(parent)).toBe(scenario.expectedSystem)
  424. }
  425. if (scenario.expectedToolDescriptions !== undefined) {
  426. const parent = ordered[0]
  427. if (parent === undefined) throw new Error(`${scenario.name} has no parent session log`)
  428. expect(assembledToolDescriptions(parent)).toMatchObject(scenario.expectedToolDescriptions)
  429. }
  430. if (scenario.runtimeContext !== undefined) {
  431. const parent = ordered[0]
  432. if (parent === undefined) throw new Error(`${scenario.name} has no parent session log`)
  433. const contexts = assembledRuntimeContexts(parent)
  434. if (scenario.runtimeContext === false) {
  435. expect(contexts).toEqual([])
  436. } else {
  437. expect(contexts).toHaveLength(1)
  438. const context = contexts[0] as string
  439. for (const clause of scenario.runtimeContext.includes) expect(context).toContain(clause)
  440. for (const clause of scenario.runtimeContext.excludes) expect(context).not.toContain(clause)
  441. const system = assembledSystem(parent)
  442. for (const clause of scenario.runtimeContext.includes) expect(system).not.toContain(clause)
  443. }
  444. }
  445. if (scenario.children > 0) {
  446. expect(notifications.some(n => n.method === 'subagent.started')).toBe(true)
  447. expect(notifications.some(n => n.method === 'subagent.finished')).toBe(true)
  448. }
  449. })
  450. }
  451. })