cleanup.ts 1022 B

1234567891011121314151617181920212223
  1. /** Shared teardown for ACP example tests. */
  2. import { rm } from 'node:fs/promises'
  3. import type { LaunchedAcpTestAgent } from '@deepseek-ai/dsh-acp-snapshot'
  4. /**
  5. * Close the test agent, then remove its workspace, attempting both operations
  6. * and reporting every failure instead of allowing the later one to mask the
  7. * earlier one.
  8. */
  9. export async function cleanupAcpExampleTest(
  10. spawned: Pick<LaunchedAcpTestAgent, 'close'> | undefined,
  11. workdir: string | undefined,
  12. ): Promise<void> {
  13. const results: PromiseSettledResult<unknown>[] = []
  14. if (spawned !== undefined) results.push(...await Promise.allSettled([spawned.close('SIGKILL')]))
  15. if (workdir !== undefined) results.push(...await Promise.allSettled([rm(workdir, { recursive: true, force: true })]))
  16. const failures = results
  17. .filter((result): result is PromiseRejectedResult => result.status === 'rejected')
  18. .map(result => result.reason as unknown)
  19. if (failures.length > 0) throw new AggregateError(failures, 'ACP example cleanup failed')
  20. }