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 FileSystem from 'effect/FileSystem'; |
| 2 | import { HttpClient, HttpClientResponse } from 'effect/http'; |
| 3 | import * as Path from 'effect/Path'; |
| 4 | import * as BunFileSystem from '@effect/platform-bun/BunFileSystem'; |
| 5 | import * as BunPath from '@effect/platform-bun/BunPath'; |
| 6 | import { describe, expect, layer } from '@effect/vitest'; |
| 7 | import { Effect, Layer } from 'effect'; |
| 8 | import * as tempy from 'tempy'; |
| 9 | import { SKILL_RELEASE_TAG_FILENAME } from 'src/effects/install-skill'; |
| 10 | import { |
| 11 | hasManagedClaudeSkill, |
| 12 | isClaudeSkillCurrent, |
| 13 | removeManagedClaudeSkill, |
| 14 | resolveSetupSkillReleaseTag, |
| 15 | } from 'src/services/setup-skill-installer'; |
| 16 | |
| 17 | const TestHttpClient = Layer.succeed( |
| 18 | HttpClient.HttpClient, |
| 19 | HttpClient.make(request => |
| 20 | Effect.succeed( |
| 21 | HttpClientResponse.fromWeb( |
| 22 | request, |
| 23 | new Response( |
| 24 | JSON.stringify([ |
| 25 | { |
| 26 | tag_name: '@composio/cli@0.2.21', |
| 27 | prerelease: false, |
| 28 | assets: [ |
| 29 | { |
| 30 | name: 'composio-skill.zip', |
| 31 | browser_download_url: 'https://example.test/composio-skill.zip', |
| 32 | }, |
| 33 | ], |
| 34 | }, |
| 35 | ]), |
| 36 | { |
| 37 | status: 200, |
| 38 | headers: { 'Content-Type': 'application/json' }, |
| 39 | } |
| 40 | ) |
| 41 | ) |
| 42 | ) |
| 43 | ) |
| 44 | ); |
| 45 | |
| 46 | const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer, TestHttpClient); |
| 47 | |
| 48 | describe('SetupSkillInstaller', () => { |
| 49 | layer(TestPlatform)(it => { |
| 50 | it.effect('uses the packaged CLI release tag', () => |
| 51 | Effect.gen(function* () { |
| 52 | const fs = yield* FileSystem.FileSystem; |
| 53 | const path = yield* Path.Path; |
| 54 | const installDir = tempy.temporaryDirectory(); |
| 55 | const execPath = path.join(installDir, 'composio'); |
| 56 | yield* fs.writeFileString( |
| 57 | path.join(installDir, 'release-tag.txt'), |
| 58 | '@composio/cli@0.2.20-beta.42\n' |
| 59 | ); |
| 60 | |
| 61 | expect(yield* resolveSetupSkillReleaseTag(execPath, '0.3.0')).toBe( |
| 62 | '@composio/cli@0.2.20-beta.42' |
| 63 | ); |
| 64 | }) |
| 65 | ); |
| 66 | |
| 67 | it.effect('uses the running package fallback outside a packaged install', () => |
| 68 | Effect.gen(function* () { |
| 69 | const path = yield* Path.Path; |
| 70 | const installDir = tempy.temporaryDirectory(); |
| 71 | |
| 72 | expect(yield* resolveSetupSkillReleaseTag(path.join(installDir, 'composio'), '0.3.0')).toBe( |
| 73 | '@composio/cli@0.3.0' |
| 74 | ); |
| 75 | }) |
| 76 | ); |
| 77 | |
| 78 | it.effect('only accepts a Claude skill installed from the running CLI release', () => |
| 79 | Effect.gen(function* () { |
| 80 | const fs = yield* FileSystem.FileSystem; |
| 81 | const path = yield* Path.Path; |
| 82 | const home = tempy.temporaryDirectory(); |
| 83 | const target = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 84 | const skillDir = path.join(home, '.agents', 'skills', 'composio-cli'); |
| 85 | yield* fs.makeDirectory(skillDir, { recursive: true }); |
| 86 | yield* fs.makeDirectory(path.dirname(target), { recursive: true }); |
| 87 | yield* fs.symlink(path.relative(path.dirname(target), skillDir), target); |
| 88 | yield* fs.writeFileString( |
| 89 | path.join(skillDir, SKILL_RELEASE_TAG_FILENAME), |
| 90 | '@composio/cli@0.2.20-beta.42\n' |
| 91 | ); |
| 92 | yield* fs.writeFileString(path.join(skillDir, 'SKILL.md'), '# composio-cli\n'); |
| 93 | |
| 94 | expect(yield* isClaudeSkillCurrent(home, '@composio/cli@0.2.20-beta.42')).toBe(true); |
| 95 | expect(yield* isClaudeSkillCurrent(home, '@composio/cli@0.2.20-beta.43')).toBe(false); |
| 96 | }) |
| 97 | ); |
| 98 | |
| 99 | it.effect('treats an unversioned existing Claude skill as stale', () => |
| 100 | Effect.gen(function* () { |
| 101 | const fs = yield* FileSystem.FileSystem; |
| 102 | const path = yield* Path.Path; |
| 103 | const home = tempy.temporaryDirectory(); |
| 104 | yield* fs.makeDirectory(path.join(home, '.claude', 'skills', 'composio-cli'), { |
| 105 | recursive: true, |
| 106 | }); |
| 107 | |
| 108 | expect(yield* isClaudeSkillCurrent(home, '@composio/cli@0.3.0')).toBe(false); |
| 109 | }) |
| 110 | ); |
| 111 | |
| 112 | it.effect('treats a release marker without a readable skill as stale', () => |
| 113 | Effect.gen(function* () { |
| 114 | const fs = yield* FileSystem.FileSystem; |
| 115 | const path = yield* Path.Path; |
| 116 | const home = tempy.temporaryDirectory(); |
| 117 | const target = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 118 | yield* fs.makeDirectory(target, { recursive: true }); |
| 119 | yield* fs.writeFileString( |
| 120 | path.join(target, SKILL_RELEASE_TAG_FILENAME), |
| 121 | '@composio/cli@0.3.0\n' |
| 122 | ); |
| 123 | |
| 124 | expect(yield* isClaudeSkillCurrent(home, '@composio/cli@0.3.0')).toBe(false); |
| 125 | }) |
| 126 | ); |
| 127 | |
| 128 | it.effect('removes the CLI-managed Claude skill and canonical copy', () => |
| 129 | Effect.gen(function* () { |
| 130 | const fs = yield* FileSystem.FileSystem; |
| 131 | const path = yield* Path.Path; |
| 132 | const home = tempy.temporaryDirectory(); |
| 133 | const canonical = path.join(home, '.agents', 'skills', 'composio-cli'); |
| 134 | const claude = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 135 | yield* fs.makeDirectory(canonical, { recursive: true }); |
| 136 | yield* fs.writeFileString( |
| 137 | path.join(canonical, SKILL_RELEASE_TAG_FILENAME), |
| 138 | '@composio/cli@0.3.0\n' |
| 139 | ); |
| 140 | yield* fs.makeDirectory(path.dirname(claude), { recursive: true }); |
| 141 | yield* fs.symlink(path.relative(path.dirname(claude), canonical), claude); |
| 142 | |
| 143 | expect(yield* hasManagedClaudeSkill(home)).toBe(true); |
| 144 | expect(yield* removeManagedClaudeSkill(home)).toBe(true); |
| 145 | expect(yield* hasManagedClaudeSkill(home)).toBe(false); |
| 146 | expect(yield* fs.exists(claude)).toBe(false); |
| 147 | expect(yield* fs.exists(canonical)).toBe(false); |
| 148 | }) |
| 149 | ); |
| 150 | |
| 151 | it.effect('keeps the canonical skill while another agent references it', () => |
| 152 | Effect.gen(function* () { |
| 153 | const fs = yield* FileSystem.FileSystem; |
| 154 | const path = yield* Path.Path; |
| 155 | const home = tempy.temporaryDirectory(); |
| 156 | const canonical = path.join(home, '.agents', 'skills', 'composio-cli'); |
| 157 | const claude = path.join(home, '.claude', 'skills', 'composio-cli'); |
| 158 | const openclaw = path.join(home, '.openclaw', 'skills', 'composio-cli'); |
| 159 | yield* fs.makeDirectory(canonical, { recursive: true }); |
| 160 | yield* fs.writeFileString( |
| 161 | path.join(canonical, SKILL_RELEASE_TAG_FILENAME), |
| 162 | '@composio/cli@0.3.0\n' |
| 163 | ); |
| 164 | yield* fs.makeDirectory(path.dirname(claude), { recursive: true }); |
| 165 | yield* fs.makeDirectory(path.dirname(openclaw), { recursive: true }); |
| 166 | yield* fs.symlink(path.relative(path.dirname(claude), canonical), claude); |
| 167 | yield* fs.symlink(path.relative(path.dirname(openclaw), canonical), openclaw); |
| 168 | |
| 169 | expect(yield* hasManagedClaudeSkill(home)).toBe(true); |
| 170 | expect(yield* removeManagedClaudeSkill(home)).toBe(true); |
| 171 | expect(yield* hasManagedClaudeSkill(home)).toBe(false); |
| 172 | expect(yield* fs.exists(claude)).toBe(false); |
| 173 | expect(yield* fs.exists(canonical)).toBe(true); |
| 174 | expect(yield* fs.exists(openclaw)).toBe(true); |
| 175 | }) |
| 176 | ); |
| 177 | }); |
| 178 | }); |