Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
test(cli): guard the startup path against eager compiler imports
A static import of typescript or src/generation anywhere on the command tree silently restores ~165ms of module evaluation to every invocation, and nothing failed. The test loads the command tree in a fresh Bun process and asserts, via the module registry, that neither the compiler nor the generation pipeline nor the run source transforms were evaluated. Verified it fails on a stray static import. Claude-Session: https://claude.ai/code/session_01MTb47vexN35pLGsSZwBmrJ
jkomyno committed
Sep 14, 2026 at 16:11 UTC
c0053d7eebf1e190aa33ccc6e998f85820ed21c5
1 file changed
+55
ts/packages/cli/test/src/commands/startup-imports.test.ts
new
+55
@@ -0,0 +1,55 @@
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 cost ~165ms of module
7
+ * evaluation and are only needed by `composio run` and `composio generate`,
8
+ * which import them from inside their handlers. 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
+];
19
+
20
+/**
21
+ * Runs inside `bun -e`. Bun's module registry lists every evaluated file, ESM
22
+ * and CommonJS alike. The probe reports only the verdict: the full registry is
23
+ * ~1000 paths, past what Bun flushes to a pipe before exiting.
24
+ */
25
+const PROBE = [
26
+ "await import('./src/commands/index.ts');",
27
+ 'const forbidden = JSON.parse(process.env.FORBIDDEN_AT_STARTUP);',
28
+ 'const loaded = Object.keys(require.cache);',
29
+ 'console.log(JSON.stringify({',
30
+ " loadedCommandTree: loaded.some(file => file.endsWith('/src/commands/index.ts')),",
31
+ ' eagerlyLoaded: loaded.filter(file => forbidden.some(fragment => file.includes(fragment))),',
32
+ '}));',
33
+].join('\n');
34
+
35
+describe('CLI startup imports', () => {
36
+ it('builds the command tree without evaluating the compiler or generation pipeline', () => {
37
+ const result = spawnSync('bun', ['-e', PROBE], {
38
+ cwd: process.cwd(),
39
+ encoding: 'utf8',
40
+ env: {
41
+ ...process.env,
42
+ CI: '1',
43
+ NO_COLOR: '1',
44
+ FORBIDDEN_AT_STARTUP: JSON.stringify(FORBIDDEN_AT_STARTUP),
45
+ },
46
+ });
47
+
48
+ expect(result.status, result.stderr).toBe(0);
49
+ const verdict: { loadedCommandTree: boolean; eagerlyLoaded: ReadonlyArray<string> } =
50
+ JSON.parse(result.stdout.trim().split('\n').at(-1) ?? '{}');
51
+
52
+ expect(verdict.loadedCommandTree).toBe(true);
53
+ expect(verdict.eagerlyLoaded).toEqual([]);
54
+ }, 30_000);
55
+});