Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { expect, test } from 'bun:test'; |
| 2 | import { |
| 3 | mkdirSync, |
| 4 | mkdtempSync, |
| 5 | readFileSync, |
| 6 | realpathSync, |
| 7 | rmSync, |
| 8 | symlinkSync, |
| 9 | writeFileSync, |
| 10 | } from 'node:fs'; |
| 11 | import { tmpdir } from 'node:os'; |
| 12 | import { dirname, join, resolve } from 'node:path'; |
| 13 | import { fileURLToPath } from 'node:url'; |
| 14 | |
| 15 | const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); |
| 16 | const oxlint = join(root, 'node_modules/oxlint/bin/oxlint'); |
| 17 | |
| 18 | test('the repository config enforces both Effect rules only in CLI source', () => { |
| 19 | const cwd = realpathSync(mkdtempSync(join(tmpdir(), 'composio-effect-lint-'))); |
| 20 | const config = join(cwd, '.oxlintrc.json'); |
| 21 | symlinkSync(join(root, 'node_modules'), join(cwd, 'node_modules'), 'dir'); |
| 22 | writeFileSync( |
| 23 | config, |
| 24 | readFileSync(join(root, '.oxlintrc.json'), 'utf8').replace( |
| 25 | './tools/oxlint/effect/index.ts', |
| 26 | join(root, 'tools/oxlint/effect/index.ts') |
| 27 | ) |
| 28 | ); |
| 29 | const source = ` |
| 30 | import { Context, Effect, Layer } from 'effect'; |
| 31 | class Client extends Context.Service<Client, {}>()('Client') { |
| 32 | static make = Effect.gen(function* () { |
| 33 | yield* load.pipe(Effect.orDie); |
| 34 | return {}; |
| 35 | }); |
| 36 | } |
| 37 | const result = load.pipe(Effect.mapError(() => new Failed())); |
| 38 | `; |
| 39 | const lint = (filename: string) => { |
| 40 | const file = join(cwd, filename); |
| 41 | mkdirSync(dirname(file), { recursive: true }); |
| 42 | writeFileSync(file, source); |
| 43 | const result = Bun.spawnSync(['node', oxlint, '-c', config, '--format', 'json', filename], { |
| 44 | cwd, |
| 45 | }); |
| 46 | expect(result.stderr.toString()).toBe(''); |
| 47 | const output = JSON.parse(result.stdout.toString()); |
| 48 | return { |
| 49 | status: result.exitCode, |
| 50 | rules: output.diagnostics |
| 51 | .map((diagnostic: { code: string }) => diagnostic.code) |
| 52 | .filter((code: string) => code.startsWith('composio-effect(')), |
| 53 | }; |
| 54 | }; |
| 55 | try { |
| 56 | expect(lint('ts/packages/cli/src/services/lint-fixture.ts')).toEqual({ |
| 57 | status: 1, |
| 58 | rules: expect.arrayContaining([ |
| 59 | 'composio-effect(require-cause-when-narrowing)', |
| 60 | 'composio-effect(no-ordie-in-service-construction)', |
| 61 | ]), |
| 62 | }); |
| 63 | for (const file of [ |
| 64 | 'ts/packages/core/src/lint-fixture.ts', |
| 65 | 'ts/packages/cli/test/lint-fixture.ts', |
| 66 | 'ts/packages/cli/src/services/lint-fixture.test.ts', |
| 67 | 'ts/packages/cli/src/services/__fixtures__/lint-fixture.ts', |
| 68 | ]) { |
| 69 | expect(lint(file).rules).toEqual([]); |
| 70 | } |
| 71 | } finally { |
| 72 | rmSync(cwd, { recursive: true, force: true }); |
| 73 | } |
| 74 | }); |