@devries-cameron20 / composio-1 / commits / 38e98b84f
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.

refactor(cli): move `upgrade` into the directory shape (#4976)

This PR: - moves `upgrade.cmd.ts` to `upgrade/upgrade.{cmd,handler}.ts`. The command file keeps `--beta`/`-b`, the optional `version` argument, and the description; `runUpgrade` and `normalizeReleaseTag` move to the handler unchanged - leaves `UpgradeBinary`, `run-companion-modules.ts`, and the legacy companion placeholders that CLIs 0.2.12 to 0.4.2 check for untouched, so the contract with installed binaries does not move - adds `upgrade.cmd.test.ts`, which runs argv against an `UpgradeBinary` double: the `prerelease`/`tag` table, the skill tag fallback (new release, then requested tag, then running version), and an upgrade failure that installs no skill - adds `upgrade.handler.test.ts` with the `normalizeReleaseTag` table - removes `upgrade.cmd.ts` from `COMMAND_TEST_EXEMPTIONS` (15 to 14) Part of U9 of the CLI command-layout series. No user-visible change, so no CHANGELOG entry. Verified locally on the branch tip: | Check | Result | | --- | --- | | `pnpm --filter @composio/cli typecheck` | passes | | `pnpm --filter @composio/cli test` (skills, boundaries, command tests, Vitest) | 162 files, 1916 passed, 1 skipped | | `validate:command-tests` | 14 exemptions (was 15) | | `lint:effect` | 0 diagnostics | | `oxlint`, prettier on touched files | clean | | Binary smoke | `upgrade --help`, `upgrade --bogus`, root `--help`: identical to an `origin/next` (231122de1) binary. A local `upgrade` with `DEBUG_OVERRIDE_UPGRADE_TARGET` and a release-shaped source directory (live companions plus empty legacy placeholders) exits 0 and replaces the executable inode, as the `origin/next` binary does | The Docker upgrade E2E (`ts/e2e-tests/cli/upgrade`) was not run locally.

Alberto Schiabel committed Oct 20, 2026 at 17:48 UTC 38e98b84f2f38b54f6b3671308a136316b7ea953
6 files changed +163 -25
ts/packages/cli/scripts/command-tests.ts
-1
@@ -20,7 +20,6 @@ const TEST_SUFFIX = '.cmd.test.ts';
20 export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
21 { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
22 { command: 'triggers/commands/triggers.listen.cmd.ts', reason: 'no test yet' },
23 - { command: 'upgrade.cmd.ts', reason: 'no test yet' },
23 ];
24
25 // A group entry is `<dir>.cmd.ts` or `root-<dir>.cmd.ts` inside `<dir>/` when
ts/packages/cli/src/commands/index.ts
+1 -1
@@ -3,7 +3,7 @@ import { CliOutput, Command } from 'effect/cli';
3 import { $defaultCmd, withRootLogLevel } from './$default.cmd';
4 import { getVersion } from 'src/effects/version';
5 import { versionCmd } from './version.cmd';
6 -import { upgradeCmd } from './upgrade.cmd';
6 +import { upgradeCmd } from './upgrade/upgrade.cmd';
7 import { whoamiCmd } from './whoami.cmd';
8 import { loginCmd } from './login/login.cmd';
9 import { signupCmd } from './signup/signup.cmd';
ts/packages/cli/src/commands/upgrade/upgrade.cmd.ts renamed
+2 -23
@@ -1,8 +1,5 @@
1 import { Argument, Command, Flag } from 'effect/cli';
2 -import { Effect, Option } from 'effect';
3 -import { APP_VERSION } from 'src/constants';
4 -import { UpgradeBinary } from 'src/services/upgrade-binary';
5 -import { installSkillSafe } from 'src/effects/install-skill';
2 +import { runUpgrade } from './upgrade.handler';
3
4 const betaOpt = Flag.Boolean('beta').pipe(
5 Flag.withAlias('b'),
@@ -17,16 +14,6 @@ const versionArg = Argument.String('version').pipe(
14 Argument.optional
15 );
16
20 -const RELEASE_TAG_PREFIX = '@composio/cli@';
21 -
22 -const normalizeReleaseTag = (input: string): string => {
23 - const trimmed = input.trim();
24 - if (trimmed.startsWith(RELEASE_TAG_PREFIX)) return trimmed;
25 - // Allow leading "v" for friendliness, e.g. "v0.13.1"
26 - const stripped = trimmed.replace(/^v/, '');
27 - return `${RELEASE_TAG_PREFIX}${stripped}`;
28 -};
29 -
17 /**
18 * CLI command to upgrade the CLI to the latest available version,
19 * or to install a specific version when one is provided.
@@ -42,15 +29,7 @@ const normalizeReleaseTag = (input: string): string => {
29 export const upgradeCmd = Command.make(
30 'upgrade',
31 { beta: betaOpt, version: versionArg },
45 - ({ beta, version }) =>
46 - Effect.gen(function* () {
47 - const upgradeBinary = yield* UpgradeBinary;
48 - const tag = Option.getOrUndefined(Option.map(version, normalizeReleaseTag));
49 - const newReleaseTag = yield* upgradeBinary.upgrade({ prerelease: beta, tag });
50 - yield* installSkillSafe({
51 - releaseTag: newReleaseTag ?? tag ?? `@composio/cli@${APP_VERSION}`,
52 - });
53 - })
32 + runUpgrade
33 ).pipe(
34 Command.withDescription(
35 'Upgrade your Composio CLI. Pass a version (e.g. "0.13.1" or "0.13.1-beta.42") to install a specific release, or omit it to install the latest.'
ts/packages/cli/src/commands/upgrade/upgrade.handler.ts new
+38
@@ -0,0 +1,38 @@
1 +import { Effect, Option } from 'effect';
2 +import { APP_VERSION } from 'src/constants';
3 +import { installSkillSafe } from 'src/effects/install-skill';
4 +import { UpgradeBinary } from 'src/services/upgrade-binary';
5 +
6 +/** The flags and argument of `composio upgrade`. */
7 +export type UpgradeParams = {
8 + readonly beta: boolean;
9 + readonly version: Option.Option<string>;
10 +};
11 +
12 +const RELEASE_TAG_PREFIX = '@composio/cli@';
13 +
14 +/**
15 + * The release tag a version argument names: a full `@composio/cli@…` tag as given, otherwise the
16 + * version (a leading `v` allowed, e.g. `v0.13.1`) under the CLI's tag prefix.
17 + */
18 +export const normalizeReleaseTag = (input: string): string => {
19 + const trimmed = input.trim();
20 + if (trimmed.startsWith(RELEASE_TAG_PREFIX)) return trimmed;
21 + const stripped = trimmed.replace(/^v/, '');
22 + return `${RELEASE_TAG_PREFIX}${stripped}`;
23 +};
24 +
25 +/**
26 + * Replaces the running binary with the requested release, or the latest one on the chosen
27 + * channel, then installs the skill of whichever release is now installed: the new one, else the
28 + * requested one, else the running version's.
29 + */
30 +export const runUpgrade = ({ beta, version }: UpgradeParams) =>
31 + Effect.gen(function* () {
32 + const upgradeBinary = yield* UpgradeBinary;
33 + const tag = Option.getOrUndefined(Option.map(version, normalizeReleaseTag));
34 + const newReleaseTag = yield* upgradeBinary.upgrade({ prerelease: beta, tag });
35 + yield* installSkillSafe({
36 + releaseTag: newReleaseTag ?? tag ?? `${RELEASE_TAG_PREFIX}${APP_VERSION}`,
37 + });
38 + });
ts/packages/cli/test/src/commands/upgrade/upgrade.cmd.test.ts new
+105
@@ -0,0 +1,105 @@
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 +});
ts/packages/cli/test/src/commands/upgrade/upgrade.handler.test.ts new
+17
@@ -0,0 +1,17 @@
1 +import { describe, expect, it } from 'vitest';
2 +import { normalizeReleaseTag } from 'src/commands/upgrade/upgrade.handler';
3 +
4 +describe('upgrade handler: normalizeReleaseTag', () => {
5 + it.each([
6 + { input: '0.13.1', expected: '@composio/cli@0.13.1' },
7 + { input: '0.13.1-beta.42', expected: '@composio/cli@0.13.1-beta.42' },
8 + { input: 'v0.13.1', expected: '@composio/cli@0.13.1' },
9 + { input: ' 0.13.1 ', expected: '@composio/cli@0.13.1' },
10 + { input: '@composio/cli@0.13.1', expected: '@composio/cli@0.13.1' },
11 + { input: ' @composio/cli@0.13.1-beta.42 ', expected: '@composio/cli@0.13.1-beta.42' },
12 + // Only one leading `v` is dropped; the rest is passed through for the release lookup to reject.
13 + { input: 'vv1', expected: '@composio/cli@v1' },
14 + ])('[Given] "$input" [Then] returns "$expected"', ({ input, expected }) => {
15 + expect(normalizeReleaseTag(input)).toBe(expected);
16 + });
17 +});