@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 35 lines 1.23 KB
Raw
1 import { afterEach, describe, expect, test } from 'bun:test';
2 import { safeInceptionFetch } from '../../agent/agent';
3
4 const originalFetch = globalThis.fetch;
5 const originalInceptionApiKey = process.env.INCEPTION_API_KEY;
6
7 afterEach(() => {
8 globalThis.fetch = originalFetch;
9 process.env.INCEPTION_API_KEY = originalInceptionApiKey;
10 });
11
12 describe('Inception fetch wrapper', () => {
13 test('preserves abort-like fetch errors for the AI SDK', async () => {
14 process.env.INCEPTION_API_KEY = 'test-key';
15 const abortError = new DOMException('The operation was aborted.', 'AbortError');
16 globalThis.fetch = async () => {
17 throw abortError;
18 };
19
20 await expect(safeInceptionFetch('https://example.com')).rejects.toBe(abortError);
21 });
22
23 test('treats 200 JSON error payloads as upstream model failures', async () => {
24 process.env.INCEPTION_API_KEY = 'test-key';
25 globalThis.fetch = async () =>
26 new Response(JSON.stringify({ error: { message: 'quota exceeded' } }), {
27 status: 200,
28 headers: { 'content-type': 'application/json' },
29 });
30
31 await expect(safeInceptionFetch('https://example.com')).rejects.toThrow(
32 'Docs agent model request failed. Upstream returned an error payload.'
33 );
34 });
35 });