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 * as BunFileSystem from '@effect/platform-bun/BunFileSystem'; |
| 2 | import * as BunPath from '@effect/platform-bun/BunPath'; |
| 3 | import { describe, expect, it, layer } from '@effect/vitest'; |
| 4 | import { Effect, FileSystem, Layer, Path } from 'effect'; |
| 5 | import * as tempy from 'tempy'; |
| 6 | import { discoverSkillRoots } from 'src/effects/discover-skill-roots'; |
| 7 | import { cli, TestLive } from 'test/__utils__'; |
| 8 | |
| 9 | const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer); |
| 10 | |
| 11 | const providePlatform = <A, E>(effect: Effect.Effect<A, E, FileSystem.FileSystem | Path.Path>) => |
| 12 | effect.pipe(Effect.provide(TestPlatform)); |
| 13 | |
| 14 | const expectRootsExactlyOnce = (actual: ReadonlyArray<string>, expected: ReadonlyArray<string>) => { |
| 15 | expect(actual).toEqual(expected); |
| 16 | expect(new Set(actual).size).toBe(actual.length); |
| 17 | }; |
| 18 | |
| 19 | describe('config experimental skill discovery', () => { |
| 20 | it.effect('discovers only the canonical skill root', () => |
| 21 | providePlatform( |
| 22 | Effect.gen(function* () { |
| 23 | const fs = yield* FileSystem.FileSystem; |
| 24 | const path = yield* Path.Path; |
| 25 | const home = tempy.temporaryDirectory(); |
| 26 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 27 | yield* fs.makeDirectory(path.join(canonicalRoot, 'composio-cli'), { recursive: true }); |
| 28 | |
| 29 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [canonicalRoot]); |
| 30 | }) |
| 31 | ) |
| 32 | ); |
| 33 | |
| 34 | it.effect('discovers canonical and real Claude skill copies', () => |
| 35 | providePlatform( |
| 36 | Effect.gen(function* () { |
| 37 | const fs = yield* FileSystem.FileSystem; |
| 38 | const path = yield* Path.Path; |
| 39 | const home = tempy.temporaryDirectory(); |
| 40 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 41 | const claudeRoot = path.join(home, '.claude', 'skills'); |
| 42 | yield* fs.makeDirectory(path.join(canonicalRoot, 'composio-cli'), { recursive: true }); |
| 43 | yield* fs.makeDirectory(path.join(claudeRoot, 'composio-cli'), { recursive: true }); |
| 44 | |
| 45 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [canonicalRoot, claudeRoot]); |
| 46 | }) |
| 47 | ) |
| 48 | ); |
| 49 | |
| 50 | it.effect('deduplicates a Claude symlink to the canonical skill', () => |
| 51 | providePlatform( |
| 52 | Effect.gen(function* () { |
| 53 | const fs = yield* FileSystem.FileSystem; |
| 54 | const path = yield* Path.Path; |
| 55 | const home = tempy.temporaryDirectory(); |
| 56 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 57 | const canonicalSkill = path.join(canonicalRoot, 'composio-cli'); |
| 58 | const claudeSkill = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 59 | yield* fs.makeDirectory(canonicalSkill, { recursive: true }); |
| 60 | yield* fs.makeDirectory(path.dirname(claudeSkill), { recursive: true }); |
| 61 | yield* fs.symlink(path.relative(path.dirname(claudeSkill), canonicalSkill), claudeSkill); |
| 62 | |
| 63 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [canonicalRoot]); |
| 64 | }) |
| 65 | ) |
| 66 | ); |
| 67 | |
| 68 | it.effect('ignores a broken Claude symlink and keeps the canonical fallback', () => |
| 69 | providePlatform( |
| 70 | Effect.gen(function* () { |
| 71 | const fs = yield* FileSystem.FileSystem; |
| 72 | const path = yield* Path.Path; |
| 73 | const home = tempy.temporaryDirectory(); |
| 74 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 75 | const claudeSkill = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 76 | yield* fs.makeDirectory(path.dirname(claudeSkill), { recursive: true }); |
| 77 | yield* fs.symlink('../missing-composio-cli', claudeSkill); |
| 78 | |
| 79 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [canonicalRoot]); |
| 80 | }) |
| 81 | ) |
| 82 | ); |
| 83 | |
| 84 | it.effect('uses the canonical fallback when neither skill root exists', () => |
| 85 | providePlatform( |
| 86 | Effect.gen(function* () { |
| 87 | const path = yield* Path.Path; |
| 88 | const home = tempy.temporaryDirectory(); |
| 89 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 90 | |
| 91 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [canonicalRoot]); |
| 92 | }) |
| 93 | ) |
| 94 | ); |
| 95 | |
| 96 | it.effect('keeps an external symlink target and the canonical fallback once each', () => |
| 97 | providePlatform( |
| 98 | Effect.gen(function* () { |
| 99 | const fs = yield* FileSystem.FileSystem; |
| 100 | const path = yield* Path.Path; |
| 101 | const home = tempy.temporaryDirectory(); |
| 102 | const canonicalRoot = path.join(home, '.agents', 'skills'); |
| 103 | const externalRoot = path.join(home, 'shared-skills'); |
| 104 | const externalSkill = path.join(externalRoot, 'composio-cli'); |
| 105 | const claudeSkill = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 106 | yield* fs.makeDirectory(externalSkill, { recursive: true }); |
| 107 | yield* fs.makeDirectory(path.dirname(claudeSkill), { recursive: true }); |
| 108 | yield* fs.symlink(path.relative(path.dirname(claudeSkill), externalSkill), claudeSkill); |
| 109 | |
| 110 | expectRootsExactlyOnce(yield* discoverSkillRoots(home), [externalRoot, canonicalRoot]); |
| 111 | }) |
| 112 | ) |
| 113 | ); |
| 114 | }); |
| 115 | |
| 116 | layer(TestLive())('config experimental state validation', it => { |
| 117 | it.effect('reports an invalid state as a structured domain failure', () => |
| 118 | Effect.gen(function* () { |
| 119 | const failure = yield* cli(['config', 'experimental', 'listen', 'sometimes']).pipe( |
| 120 | Effect.flip |
| 121 | ); |
| 122 | |
| 123 | expect(failure).toMatchObject({ |
| 124 | _tag: 'commands/CommandInputError', |
| 125 | option: '<state>', |
| 126 | message: 'Invalid state "sometimes". Use "on" or "off".', |
| 127 | }); |
| 128 | }) |
| 129 | ); |
| 130 | }); |