@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, 04:45 UTC

next
ts 69 lines 2.67 KB
Raw
1 import { spawnSync } from 'node:child_process';
2 import { describe, expect, it } from 'vitest';
3
4 /**
5 * Modules that must never be evaluated by merely building the command tree.
6 * The TypeScript compiler and the generation pipeline ship as a companion
7 * module that `composio run` and `composio generate` load on demand, the same
8 * list the binary build guard in `scripts/_shared.ts` checks. A static import anywhere on the
9 * startup path silently puts that cost back on every invocation, so this test
10 * loads the command tree in a fresh Bun process and inspects what it pulled in.
11 */
12 const FORBIDDEN_AT_STARTUP: ReadonlyArray<string> = [
13 '/node_modules/typescript/',
14 '/openapi-typescript/',
15 '/packages/ts-builders/',
16 '/src/generation/',
17 '/src/commands/run-source-transforms',
18 '/src/services/generation-runtime',
19 ];
20
21 /**
22 * The CLI rebuilds the generation companion's failures as its own error
23 * classes, so this compiler-free module stays on the startup path. The binary
24 * build guard in `scripts/_shared.ts` makes the same exception.
25 */
26 const ALLOWED_AT_STARTUP: ReadonlyArray<string> = ['/src/generation/errors.ts'];
27
28 /**
29 * Runs inside `bun -e`. Bun's module registry lists every evaluated file, ESM
30 * and CommonJS alike. The probe reports only the verdict: the full registry is
31 * ~1000 paths, past what Bun flushes to a pipe before exiting.
32 */
33 const PROBE = [
34 "await import('./src/commands/index.ts');",
35 'const forbidden = JSON.parse(process.env.FORBIDDEN_AT_STARTUP);',
36 'const allowed = JSON.parse(process.env.ALLOWED_AT_STARTUP);',
37 'const loaded = Object.keys(require.cache);',
38 'console.log(JSON.stringify({',
39 " loadedCommandTree: loaded.some(file => file.endsWith('/src/commands/index.ts')),",
40 ' eagerlyLoaded: loaded.filter(',
41 ' file =>',
42 ' forbidden.some(fragment => file.includes(fragment)) &&',
43 ' !allowed.some(suffix => file.endsWith(suffix))',
44 ' ),',
45 '}));',
46 ].join('\n');
47
48 describe('CLI startup imports', () => {
49 it('builds the command tree without evaluating the compiler or generation pipeline', () => {
50 const result = spawnSync('bun', ['-e', PROBE], {
51 cwd: process.cwd(),
52 encoding: 'utf8',
53 env: {
54 ...process.env,
55 CI: '1',
56 NO_COLOR: '1',
57 FORBIDDEN_AT_STARTUP: JSON.stringify(FORBIDDEN_AT_STARTUP),
58 ALLOWED_AT_STARTUP: JSON.stringify(ALLOWED_AT_STARTUP),
59 },
60 });
61
62 expect(result.status, result.stderr).toBe(0);
63 const verdict: { loadedCommandTree: boolean; eagerlyLoaded: ReadonlyArray<string> } =
64 JSON.parse(result.stdout.trim().split('\n').at(-1) ?? '{}');
65
66 expect(verdict.loadedCommandTree).toBe(true);
67 expect(verdict.eagerlyLoaded).toEqual([]);
68 }, 30_000);
69 });