@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 129 lines 4.17 KB
Raw
1 import * as fs from 'node:fs';
2 import * as os from 'node:os';
3 import * as path from 'node:path';
4
5 import { afterEach, describe, expect, it } from 'vitest';
6
7 import {
8 collectBoundaryManifest,
9 compareBoundaryManifests,
10 parseBoundarySites,
11 } from '../../../scripts/lint-boundaries';
12
13 const temporaryDirectories: string[] = [];
14
15 afterEach(() => {
16 temporaryDirectories
17 .splice(0)
18 .forEach(directory => fs.rmSync(directory, { force: true, recursive: true }));
19 });
20
21 describe('lint boundary manifest', () => {
22 it('includes both TypeScript and TSX source files', () => {
23 const packageRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'composio-lint-boundaries-'));
24 const sourceRoot = path.join(packageRoot, 'src');
25 temporaryDirectories.push(packageRoot);
26 fs.mkdirSync(sourceRoot);
27 fs.writeFileSync(path.join(sourceRoot, 'plain.ts'), 'export const plain = true;\n');
28 fs.writeFileSync(
29 path.join(sourceRoot, 'component.tsx'),
30 [
31 '// eslint-disable-next-line no-restricted-syntax -- import-time runtime bridge',
32 'export const Component = () => process.env.COMPONENT_NAME;',
33 ].join('\n')
34 );
35 fs.writeFileSync(
36 path.join(sourceRoot, 'ignored.js'),
37 [
38 '// eslint-disable-next-line no-restricted-syntax -- should not be scanned',
39 'export const ignored = process.env.IGNORED;',
40 ].join('\n')
41 );
42
43 expect(collectBoundaryManifest(packageRoot, sourceRoot)).toEqual({
44 errors: [],
45 manifest: {
46 'src/component.tsx': [
47 {
48 reason: 'import-time runtime bridge',
49 rule: 'no-restricted-syntax',
50 target: 'export const Component = () => process.env.COMPONENT_NAME;',
51 },
52 ],
53 },
54 });
55 });
56
57 it('rejects the oxlint-disable spelling instead of letting it bypass the manifest', () => {
58 const parsed = parseBoundarySites(
59 'src/example.ts',
60 [
61 '// oxlint-disable-next-line eslint-js/no-restricted-syntax -- sneaky bypass',
62 'const apiKey = process.env.COMPOSIO_API_KEY;',
63 ].join('\n')
64 );
65
66 expect(parsed.sites).toHaveLength(0);
67 expect(parsed.errors).toEqual([
68 expect.stringContaining('src/example.ts:1: only "// eslint-disable-next-line'),
69 ]);
70 });
71
72 it('rejects a file-wide oxlint-disable comment', () => {
73 const parsed = parseBoundarySites(
74 'src/example.ts',
75 ['/* oxlint-disable */', 'const apiKey = process.env.COMPOSIO_API_KEY;'].join('\n')
76 );
77
78 expect(parsed.sites).toHaveLength(0);
79 expect(parsed.errors).toHaveLength(1);
80 });
81
82 it('rejects moving a registered disable to another target in the same file', () => {
83 const registered = parseBoundarySites(
84 'src/example.ts',
85 [
86 '// eslint-disable-next-line no-restricted-syntax -- runtime environment bridge',
87 'const apiKey = process.env.COMPOSIO_API_KEY;',
88 ].join('\n')
89 );
90 const relocated = parseBoundarySites(
91 'src/example.ts',
92 [
93 '// eslint-disable-next-line no-restricted-syntax -- runtime environment bridge',
94 'const debug = process.env.DEBUG;',
95 ].join('\n')
96 );
97
98 const errors = compareBoundaryManifests(
99 { 'src/example.ts': [...relocated.sites] },
100 { 'src/example.ts': [...registered.sites] }
101 );
102
103 expect(errors).toHaveLength(2);
104 expect(errors).toEqual(
105 expect.arrayContaining([
106 expect.stringContaining('process.env.COMPOSIO_API_KEY'),
107 expect.stringContaining('process.env.DEBUG'),
108 ])
109 );
110 });
111
112 it('preserves duplicate semantic sites as a deterministic multiset', () => {
113 const directive =
114 '// eslint-disable-next-line no-restricted-syntax -- runtime environment bridge';
115 const target = 'process.env.COMPOSIO_API_KEY = apiKey;';
116 const registered = parseBoundarySites(
117 'src/example.ts',
118 [directive, target, directive, target].join('\n')
119 );
120 const found = parseBoundarySites('src/example.ts', [directive, target].join('\n'));
121
122 expect(
123 compareBoundaryManifests(
124 { 'src/example.ts': [...found.sites] },
125 { 'src/example.ts': [...registered.sites] }
126 )
127 ).toEqual([expect.stringContaining('manifest registers 2x "no-restricted-syntax"')]);
128 });
129 });