@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 151 lines 5.04 KB
Raw
1 import * as path from 'node:path';
2
3 import { describe, expect, it } from 'vitest';
4
5 import {
6 checkCommandTests,
7 collectCommandTests,
8 COMMAND_TEST_EXEMPTIONS,
9 isGroupEntry,
10 mirroredTestPath,
11 resolveTestCommand,
12 } from '../../../scripts/command-tests';
13
14 const commands = [
15 'login.cmd.ts',
16 'logout/logout.cmd.ts',
17 'setup.cmd.ts',
18 'tools/tools.cmd.ts',
19 'tools/commands/tools.execute.cmd.ts',
20 'tools/list/tools.list.cmd.ts',
21 'triggers/root-triggers.cmd.ts',
22 'triggers/triggers.cmd.ts',
23 'triggers/commands/triggers.create.cmd.ts',
24 ];
25
26 const tests = [
27 'login.cmd.test.ts',
28 'logout/logout.cmd.test.ts',
29 'setup.cmd.test.ts',
30 'setup.telemetry.cmd.test.ts',
31 'tools/tools.execute.cmd.test.ts',
32 'tools/tools.execute.client.cmd.test.ts',
33 'tools/list/tools.list.cmd.test.ts',
34 'triggers/triggers.mutations.cmd.test.ts',
35 ];
36
37 const exemptions = [
38 {
39 command: 'triggers/commands/triggers.create.cmd.ts',
40 reason: 'covered by triggers.mutations.cmd.test.ts; split pending',
41 },
42 ];
43
44 describe('command test layout', () => {
45 it('detects group entries by their parent directory holding other commands', () => {
46 expect(isGroupEntry('tools/tools.cmd.ts', commands)).toBe(true);
47 expect(isGroupEntry('triggers/root-triggers.cmd.ts', commands)).toBe(true);
48 expect(isGroupEntry('triggers/triggers.cmd.ts', commands)).toBe(true);
49 expect(isGroupEntry('login.cmd.ts', commands)).toBe(false);
50 expect(isGroupEntry('tools/commands/tools.list.cmd.ts', commands)).toBe(false);
51 expect(isGroupEntry('tools/list/tools.list.cmd.ts', commands)).toBe(false);
52 });
53
54 it('treats <name>/<name>.cmd.ts with nothing below it as a top-level command', () => {
55 expect(isGroupEntry('logout/logout.cmd.ts', commands)).toBe(false);
56 expect(mirroredTestPath('logout/logout.cmd.ts')).toBe('logout/logout.cmd.test.ts');
57 expect(
58 checkCommandTests({
59 commands,
60 tests: tests.filter(test => test !== 'logout/logout.cmd.test.ts'),
61 exemptions,
62 })
63 ).toEqual([
64 'missing test: src/commands/logout/logout.cmd.ts needs test/src/commands/logout/logout.cmd.test.ts.',
65 ]);
66 });
67
68 it('mirrors both the legacy and the per-command directory layouts', () => {
69 expect(mirroredTestPath('login.cmd.ts')).toBe('login.cmd.test.ts');
70 expect(mirroredTestPath('tools/commands/tools.list.cmd.ts')).toBe(
71 'tools/tools.list.cmd.test.ts'
72 );
73 expect(mirroredTestPath('tools/list/tools.list.cmd.ts')).toBe(
74 'tools/list/tools.list.cmd.test.ts'
75 );
76 expect(mirroredTestPath('ts/commands/ts.generate.cmd.ts')).toBe('ts/ts.generate.cmd.test.ts');
77 });
78
79 it('resolves aspect-suffixed tests to the longest matching command prefix', () => {
80 expect(resolveTestCommand('setup.telemetry.cmd.test.ts', commands)).toBe('setup.cmd.ts');
81 expect(resolveTestCommand('tools/tools.execute.client.cmd.test.ts', commands)).toBe(
82 'tools/commands/tools.execute.cmd.ts'
83 );
84 expect(resolveTestCommand('triggers/triggers.mutations.cmd.test.ts', commands)).toBe(
85 'triggers/triggers.cmd.ts'
86 );
87 expect(resolveTestCommand('nope.cmd.test.ts', commands)).toBeUndefined();
88 });
89
90 it('passes when every command is tested or exempted', () => {
91 expect(checkCommandTests({ commands, tests, exemptions })).toEqual([]);
92 });
93
94 it('reports a command without its mirrored test', () => {
95 expect(
96 checkCommandTests({
97 commands,
98 tests: tests.filter(test => test !== 'tools/list/tools.list.cmd.test.ts'),
99 exemptions,
100 })
101 ).toEqual([
102 'missing test: src/commands/tools/list/tools.list.cmd.ts needs test/src/commands/tools/list/tools.list.cmd.test.ts.',
103 ]);
104 });
105
106 it('reports a test that matches no command', () => {
107 expect(
108 checkCommandTests({
109 commands,
110 tests: [...tests, 'agent/agent.claim.cmd.test.ts'],
111 exemptions,
112 })
113 ).toEqual([
114 'orphan test: test/src/commands/agent/agent.claim.cmd.test.ts matches no <prefix>.cmd.ts under src/commands/.',
115 ]);
116 });
117
118 it('reports an exemption whose command now has its mirrored test', () => {
119 expect(
120 checkCommandTests({
121 commands,
122 tests: [...tests, 'triggers/triggers.create.cmd.test.ts'],
123 exemptions,
124 })
125 ).toEqual([
126 'stale exemption: triggers/commands/triggers.create.cmd.ts now has test/src/commands/triggers/triggers.create.cmd.test.ts; remove it from COMMAND_TEST_EXEMPTIONS.',
127 ]);
128 });
129
130 it('reports an exemption for a command that no longer exists', () => {
131 expect(
132 checkCommandTests({
133 commands,
134 tests,
135 exemptions: [...exemptions, { command: 'gone.cmd.ts', reason: 'no test yet' }],
136 })
137 ).toEqual([
138 'stale exemption: gone.cmd.ts is not a command under src/commands/; remove it from COMMAND_TEST_EXEMPTIONS.',
139 ]);
140 });
141
142 it('holds for the current package tree', () => {
143 const packageRoot = path.resolve(import.meta.dirname, '../../..');
144 expect(
145 checkCommandTests({
146 ...collectCommandTests(packageRoot),
147 exemptions: COMMAND_TEST_EXEMPTIONS,
148 })
149 ).toEqual([]);
150 });
151 });