@devries-cameron20 / composio Mirror · read-only / commits / a2f477851
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, 14:45 UTC

fix(ci): isolate toolkit resolver tests

jkomyno committed Aug 25, 2026 at 04:23 UTC a2f477851202184a738309fe1056e1327895fe7d
2 files changed +34 -23
docs/lib/toolkit-resolution.ts
+17 -5
@@ -3,11 +3,23 @@ import { getToolkitBySlug } from '@/lib/toolkit-data';
3 import { isPublicToolkitSlug } from '@/lib/public-toolkit-policy';
4 import type { Toolkit } from '@/types/toolkit';
5
6 -export async function resolveToolkit(slug: string): Promise<Toolkit | null> {
7 - if (!isPublicToolkitSlug(slug)) return null;
6 +interface ToolkitResolutionDependencies {
7 + getToolkitBySlug(slug: string): Promise<Toolkit | null>;
8 + fetchToolkitFromProduction(slug: string): Promise<Toolkit | null>;
9 +}
10 +
11 +export function createToolkitResolver(dependencies: ToolkitResolutionDependencies) {
12 + return async function resolveToolkit(slug: string): Promise<Toolkit | null> {
13 + if (!isPublicToolkitSlug(slug)) return null;
14
9 - const snapshotToolkit = await getToolkitBySlug(slug);
10 - if (snapshotToolkit) return snapshotToolkit;
15 + const snapshotToolkit = await dependencies.getToolkitBySlug(slug);
16 + if (snapshotToolkit) return snapshotToolkit;
17
12 - return fetchToolkitFromProduction(slug);
18 + return dependencies.fetchToolkitFromProduction(slug);
19 + };
20 }
21 +
22 +export const resolveToolkit = createToolkitResolver({
23 + getToolkitBySlug,
24 + fetchToolkitFromProduction,
25 +});
docs/tests/static/toolkit-fallback.test.ts
+17 -18
@@ -1,4 +1,5 @@
1 -import { beforeAll, beforeEach, describe, expect, mock, test } from 'bun:test';
1 +import { describe, expect, mock, test } from 'bun:test';
2 +import { createToolkitResolver } from '../../lib/toolkit-resolution';
3 import type { Toolkit } from '../../types/toolkit';
4
5 const snapshotToolkit: Toolkit = {
@@ -24,27 +25,22 @@ const liveToolkit: Toolkit = {
25 version: null,
26 };
27
27 -const getToolkitBySlug = mock(async (_slug: string): Promise<Toolkit | null> => null);
28 -const fetchToolkitFromProduction = mock(
29 - async (_slug: string): Promise<Toolkit | null> => null
30 -);
31 -
32 -mock.module('@/lib/toolkit-data', () => ({ getToolkitBySlug }));
33 -mock.module('@/lib/toolkit-api', () => ({ fetchToolkitFromProduction }));
34 -
35 -let resolveToolkit: typeof import('../../lib/toolkit-resolution').resolveToolkit;
36 -
37 -beforeAll(async () => {
38 - ({ resolveToolkit } = await import('../../lib/toolkit-resolution'));
39 -});
28 +function createTestResolver() {
29 + const getToolkitBySlug = mock(async (_slug: string): Promise<Toolkit | null> => null);
30 + const fetchToolkitFromProduction = mock(
31 + async (_slug: string): Promise<Toolkit | null> => null
32 + );
33 + const resolveToolkit = createToolkitResolver({
34 + getToolkitBySlug,
35 + fetchToolkitFromProduction,
36 + });
37
41 -beforeEach(() => {
42 - getToolkitBySlug.mockReset();
43 - fetchToolkitFromProduction.mockReset();
44 -});
38 + return { resolveToolkit, getToolkitBySlug, fetchToolkitFromProduction };
39 +}
40
41 describe('resolveToolkit', () => {
42 test('returns a snapshot hit without calling production', async () => {
43 + const { resolveToolkit, getToolkitBySlug, fetchToolkitFromProduction } = createTestResolver();
44 getToolkitBySlug.mockResolvedValue(snapshotToolkit);
45
46 expect(await resolveToolkit('github')).toEqual(snapshotToolkit);
@@ -53,6 +49,7 @@ describe('resolveToolkit', () => {
49 });
50
51 test('returns a production toolkit after a snapshot miss', async () => {
52 + const { resolveToolkit, getToolkitBySlug, fetchToolkitFromProduction } = createTestResolver();
53 getToolkitBySlug.mockResolvedValue(null);
54 fetchToolkitFromProduction.mockResolvedValue(liveToolkit);
55
@@ -61,6 +58,7 @@ describe('resolveToolkit', () => {
58 });
59
60 test('returns null when both snapshot and production miss', async () => {
61 + const { resolveToolkit, getToolkitBySlug, fetchToolkitFromProduction } = createTestResolver();
62 getToolkitBySlug.mockResolvedValue(null);
63 fetchToolkitFromProduction.mockResolvedValue(null);
64
@@ -68,6 +66,7 @@ describe('resolveToolkit', () => {
66 });
67
68 test('rejects test_app without reading the snapshot or production', async () => {
69 + const { resolveToolkit, getToolkitBySlug, fetchToolkitFromProduction } = createTestResolver();
70 expect(await resolveToolkit('TEST_APP')).toBeNull();
71 expect(getToolkitBySlug).not.toHaveBeenCalled();
72 expect(fetchToolkitFromProduction).not.toHaveBeenCalled();