Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import assert from 'node:assert/strict'; |
| 2 | import { z } from 'zod'; |
| 3 | |
| 4 | const batchSchema = z.object({ |
| 5 | results: z.array( |
| 6 | z.object({ |
| 7 | error: z.string().nullish(), |
| 8 | response: z.object({ successful: z.boolean(), error: z.string().nullish() }).nullish(), |
| 9 | }) |
| 10 | ), |
| 11 | total_count: z.number(), |
| 12 | success_count: z.number(), |
| 13 | error_count: z.number(), |
| 14 | }); |
| 15 | // Session execution returns the tool data; MCP returns the tool's response wrapper. |
| 16 | const batchResponseSchema = z.union([ |
| 17 | batchSchema, |
| 18 | z.object({ data: batchSchema }).transform(wrapper => wrapper.data), |
| 19 | ]); |
| 20 | |
| 21 | export function assertBatch(data: unknown, successes: number, failures: number) { |
| 22 | const batch = batchResponseSchema.parse(data); |
| 23 | assert.equal(batch.total_count, successes + failures); |
| 24 | assert.equal(batch.results.length, successes + failures); |
| 25 | assert.equal(batch.success_count, successes); |
| 26 | assert.equal(batch.error_count, failures); |
| 27 | let denied = 0; |
| 28 | for (const result of batch.results) { |
| 29 | const error = result.error ?? result.response?.error; |
| 30 | if (error) { |
| 31 | assertDenied(error); |
| 32 | denied++; |
| 33 | } else { |
| 34 | assert.ok(result.response?.successful, 'Tool did not succeed and has no approval denial'); |
| 35 | } |
| 36 | } |
| 37 | assert.equal(denied, failures); |
| 38 | } |
| 39 | |
| 40 | export function assertDenied(error: unknown) { |
| 41 | assert.match(JSON.stringify(error), /approv|deni|declin|cancel|reject/i); |
| 42 | } |