@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 42 lines 1.63 KB
Raw
1 import path from 'node:path';
2 import { describe, expect, it, assert } from '@effect/vitest';
3 import * as BunPath from '@effect/platform-bun/BunPath';
4 import { Effect, Result } from 'effect';
5 import { safeOutputPath, SafeOutputPathError } from 'src/generation/safe-output-path';
6
7 describe('safeOutputPath', () => {
8 it.effect(
9 '[Given] a relative output directory and normal filename [Then] it returns a path in the same coordinate space',
10 Effect.fn(function* () {
11 const outputDir = 'generated';
12 const filePath = yield* safeOutputPath(outputDir, 'gmail.ts');
13
14 expect(filePath).toBe(path.join(outputDir, 'gmail.ts'));
15 expect(path.isAbsolute(filePath)).toBe(false);
16 }, Effect.provide(BunPath.layer))
17 );
18
19 it.effect(
20 '[Given] an absolute generated filename [Then] it fails through the Effect error channel',
21 Effect.fn(function* () {
22 const result = yield* safeOutputPath('generated', path.resolve('gmail.ts')).pipe(
23 Effect.result
24 );
25
26 assert(Result.isFailure(result));
27 expect(result.failure).toBeInstanceOf(SafeOutputPathError);
28 expect(result.failure.filename).toBe(path.resolve('gmail.ts'));
29 }, Effect.provide(BunPath.layer))
30 );
31
32 it.effect(
33 '[Given] a parent-directory generated filename [Then] it fails through the Effect error channel',
34 Effect.fn(function* () {
35 const result = yield* safeOutputPath('generated', '../gmail.ts').pipe(Effect.result);
36
37 assert(Result.isFailure(result));
38 expect(result.failure).toBeInstanceOf(SafeOutputPathError);
39 expect(result.failure.filename).toBe('../gmail.ts');
40 }, Effect.provide(BunPath.layer))
41 );
42 });