@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 64 lines 3.45 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import {
3 checkTypeScriptSnippets,
4 collectTypeScriptSnippets,
5 createSnippetTwoslasher,
6 type TypeScriptSnippet,
7 } from '../../scripts/check-typescript-snippets';
8
9 const twoslasher = createSnippetTwoslasher();
10 const snippet = (code: string, line = 100): TypeScriptSnippet => ({
11 path: 'api-overviews/fixture.mdx', line, code, lang: 'ts',
12 });
13 const check = (code: string) => checkTypeScriptSnippets([snippet(code)], twoslasher);
14
15 describe('uncovered TypeScript snippet coverage', () => {
16 test('collects canonical API/reference, FAQ, and KB Markdown without checking build-owned copies twice', () => {
17 const source = '```typescript\nconst value: number = 1;\n```';
18 const files = [
19 'api-overviews/tools.mdx', 'content/reference/errors.mdx',
20 'content/docs/faq.md', 'kb/source/platform/example/public.md', 'kb/articles/example.md',
21 'content/docs/quickstart.mdx', 'content/examples/agent.mdx',
22 ].map((path) => ({ path, source }));
23 expect(collectTypeScriptSnippets(files).map(({ path, line }) => [path, line])).toEqual(
24 files.slice(0, 5).map(({ path }) => [path, 1]),
25 );
26 });
27
28 test('extracts plain Markdown language groups and nested authored-reference wrappers', () => {
29 const snippets = collectTypeScriptSnippets([
30 { path: 'kb/articles/example.md', source: '### Python\n```python\npass\n```\n### TypeScript\n```ts\nconst x = 1;\n```\n### API\nUse REST.' },
31 { path: 'api-overviews/example.mdx', source: '<Callout>\n\n```typescript\nconst y = 2;\n```\n\n</Callout>' },
32 ]);
33 expect(snippets.map(({ code }) => code)).toEqual(['const x = 1;', 'const y = 2;']);
34 });
35 });
36
37 describe('real Twoslash SDK diagnostics', () => {
38 test('checks valid fragments and reports SDK typos at their original source line', () => {
39 expect(check('await composio.create("user_123");')).toEqual([]);
40 const errors = check('// Context\nawait composio.tools.exectue("GMAIL_FETCH_EMAILS", { userId: "u" });');
41 expect(errors.some(({ line, message }) => line === 102 && message.includes('exectue') && /\[TS(?:2339|2551)\]/.test(message))).toBe(true);
42 }, 30000);
43
44 test('uses compiler scope resolution instead of erasing local or nested bindings', () => {
45 expect(check('const composio = { localOnly: () => 1 };\ncomposio.localOnly();')).toEqual([]);
46 const errors = check('function nested(composio: { localOnly(): void }) { composio.localOnly(); }\nawait composio.tools.exectue("X", { userId: "u" });');
47 expect(errors).toHaveLength(1);
48 expect(errors[0]?.line).toBe(102);
49 expect(errors[0]?.message).toContain('exectue');
50 }, 30000);
51
52 test('retains non-SDK diagnostics instead of filtering missing names or incompatible values', () => {
53 const errors = check('const value: number = "wrong";\nmissing_name();');
54 expect(errors.some(({ message }) => message.includes('[TS2322]'))).toBe(true);
55 expect(errors.some(({ message }) => message.includes('[TS2304]'))).toBe(true);
56 }, 30000);
57
58 test('checks hidden cut sections and refuses blanket suppressions without hiding their compiler errors', () => {
59 const errors = check('// @noErrors\nconst value: number = "wrong";\n// ---cut---\nconsole.log(value);');
60 expect(errors.some(({ rule, line }) => rule === 'typescript-directive' && line === 101)).toBe(true);
61 expect(errors.some(({ line, message }) => line === 102 && message.includes('[TS2322]'))).toBe(true);
62 expect(check('const text = "// @noErrors";')).toEqual([]);
63 }, 30000);
64 });