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
| 1 | import { describe, expect, layer } from '@effect/vitest'; |
| 2 | import { Effect } from 'effect'; |
| 3 | import { afterEach, vi } from 'vitest'; |
| 4 | import { APP_VERSION } from 'src/constants'; |
| 5 | import { installSkillSafe } from 'src/effects/install-skill'; |
| 6 | import { UpgradeBinary, UpgradeBinaryError } from 'src/services/upgrade-binary'; |
| 7 | import { cli, TestLive } from 'test/__utils__'; |
| 8 | |
| 9 | vi.mock('src/effects/install-skill', async original => ({ |
| 10 | ...(await original<typeof import('src/effects/install-skill')>()), |
| 11 | installSkillSafe: vi.fn(() => Effect.void), |
| 12 | })); |
| 13 | |
| 14 | type UpgradeOptions = Parameters<UpgradeBinary['Service']['upgrade']>[0]; |
| 15 | |
| 16 | /** An upgrader that records its options and answers with `result`. */ |
| 17 | const recordingUpgrader = (result: Effect.Effect<string | undefined, UpgradeBinaryError>) => { |
| 18 | const calls: Array<UpgradeOptions> = []; |
| 19 | const service = UpgradeBinary.of({ |
| 20 | upgrade: options => { |
| 21 | calls.push(options); |
| 22 | return result; |
| 23 | }, |
| 24 | }); |
| 25 | return { calls, service }; |
| 26 | }; |
| 27 | |
| 28 | describe('CLI: composio upgrade', () => { |
| 29 | afterEach(() => vi.clearAllMocks()); |
| 30 | |
| 31 | layer(TestLive())(it => { |
| 32 | it.effect.each([ |
| 33 | { args: [], prerelease: false, tag: undefined }, |
| 34 | { args: ['--beta'], prerelease: true, tag: undefined }, |
| 35 | { args: ['-b'], prerelease: true, tag: undefined }, |
| 36 | { args: ['0.13.1'], prerelease: false, tag: '@composio/cli@0.13.1' }, |
| 37 | { args: ['v0.13.1'], prerelease: false, tag: '@composio/cli@0.13.1' }, |
| 38 | { args: ['0.13.1-beta.42'], prerelease: false, tag: '@composio/cli@0.13.1-beta.42' }, |
| 39 | { args: ['@composio/cli@0.13.1'], prerelease: false, tag: '@composio/cli@0.13.1' }, |
| 40 | { args: ['--beta', '0.13.1'], prerelease: true, tag: '@composio/cli@0.13.1' }, |
| 41 | ])( |
| 42 | '[Given] upgrade $args [Then] asks for prerelease=$prerelease and tag $tag', |
| 43 | ({ args, prerelease, tag }) => |
| 44 | Effect.gen(function* () { |
| 45 | const upgrader = recordingUpgrader(Effect.succeed('@composio/cli@9.9.9')); |
| 46 | |
| 47 | yield* cli(['upgrade', ...args]).pipe( |
| 48 | Effect.provideService(UpgradeBinary, upgrader.service) |
| 49 | ); |
| 50 | |
| 51 | expect(upgrader.calls).toEqual([{ prerelease, tag }]); |
| 52 | expect(installSkillSafe).toHaveBeenCalledExactlyOnceWith({ |
| 53 | releaseTag: '@composio/cli@9.9.9', |
| 54 | }); |
| 55 | }) |
| 56 | ); |
| 57 | |
| 58 | it.effect('[Given] no upgrade happened and no version [Then] installs the running skill', () => |
| 59 | Effect.gen(function* () { |
| 60 | const upgrader = recordingUpgrader(Effect.succeed(undefined)); |
| 61 | |
| 62 | yield* cli(['upgrade']).pipe(Effect.provideService(UpgradeBinary, upgrader.service)); |
| 63 | |
| 64 | expect(installSkillSafe).toHaveBeenCalledExactlyOnceWith({ |
| 65 | releaseTag: `@composio/cli@${APP_VERSION}`, |
| 66 | }); |
| 67 | }) |
| 68 | ); |
| 69 | |
| 70 | it.effect( |
| 71 | '[Given] no upgrade happened for a version [Then] installs that version’s skill', |
| 72 | () => |
| 73 | Effect.gen(function* () { |
| 74 | const upgrader = recordingUpgrader(Effect.succeed(undefined)); |
| 75 | |
| 76 | yield* cli(['upgrade', '0.13.1']).pipe( |
| 77 | Effect.provideService(UpgradeBinary, upgrader.service) |
| 78 | ); |
| 79 | |
| 80 | expect(installSkillSafe).toHaveBeenCalledExactlyOnceWith({ |
| 81 | releaseTag: '@composio/cli@0.13.1', |
| 82 | }); |
| 83 | }) |
| 84 | ); |
| 85 | |
| 86 | it.effect('[Given] the upgrade fails [Then] fails with its error and installs no skill', () => |
| 87 | Effect.gen(function* () { |
| 88 | const upgrader = recordingUpgrader( |
| 89 | Effect.fail(new UpgradeBinaryError({ message: 'download failed' })) |
| 90 | ); |
| 91 | |
| 92 | const error = yield* cli(['upgrade']).pipe( |
| 93 | Effect.provideService(UpgradeBinary, upgrader.service), |
| 94 | Effect.flip |
| 95 | ); |
| 96 | |
| 97 | expect(error).toMatchObject({ |
| 98 | _tag: 'services/UpgradeBinaryError', |
| 99 | message: 'download failed', |
| 100 | }); |
| 101 | expect(installSkillSafe).not.toHaveBeenCalled(); |
| 102 | }) |
| 103 | ); |
| 104 | }); |
| 105 | }); |