@devries-cameron20 / composio Mirror · read-only / commits / 7bf09cdbb
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, 17:15 UTC

fix(cli): make GitHub releases the version authority (#3993)

This PR: - fixes https://github.com/ComposioHQ/composio/issues/3932 - replaces the private CLI package semver with the non-release `0.0.0-development` sentinel - injects the exact GitHub release tag version into every standalone binary and verifies it during the build - makes every push to `next` a beta, with explicit semver selection for intentional minor or major betas and stable releases only through beta promotion - resolves skill installation, setup repair, companion repair, and upgrades from packaged `release-tag.txt` metadata - adds regression coverage for release selection, compiled version identity, and packaged-tag asset lookup; all 1,009 CLI tests and the monorepo typecheck pass - updates the direct CLI changelog and release guidance; no Changeset is added because CLI packages are excluded from Changesets

Alberto Schiabel committed Jul 30, 2026 at 21:20 UTC 7bf09cdbb8d2d328dd0925975bb886bd05e1d97c
21 files changed +559 -131
.agents/skills/cli-release/SKILL.md
+3 -1
@@ -13,7 +13,9 @@ Read `references/release-workflow.md` before selecting a candidate or dispatchin
13
14 - Never add a Changeset for `@composio/cli` or `@composio/cli-local-tools`; both packages are ignored by Changesets and such files wedge `ts.release.yml`.
15 - Treat a merge to `next` that touches CLI paths as a beta build. Promote a tested beta with the `promote-stable` workflow action for the normal stable-release path.
16 -- Treat a direct CLI `package.json` version bump as a release-owner-only recovery path, not the contributor default.
16 +- Never bump the private CLI `package.json` to select a binary version. For an
17 + intentional minor or major, build an explicitly versioned beta and promote
18 + that tested beta through the same stable path.
19 - Resolve beta tags and workflow state from GitHub immediately before acting. Never invent or reuse a stale candidate from memory.
20 - A stable promotion is a production write. If the user did not name the exact beta tag, present the resolved candidate and obtain explicit confirmation before dispatching it.
21 - Follow the release through asset verification and installation tests. Do not stop after the dispatch succeeds.
.agents/skills/cli-release/references/release-workflow.md
+23 -8
@@ -23,14 +23,16 @@
23
24 ## Choose The Path
25
26 -| Goal | Path | Result |
27 -| --- | --- | --- |
28 -| Ship an ordinary CLI change | Merge the reviewed PR to `next` | The push builds a rolling beta automatically. |
29 -| Build a beta from a branch | Dispatch `build-beta` at that branch | A prerelease is built from the branch commit. |
30 -| Publish a stable CLI | Promote an existing tested beta | The beta's source commit is rebuilt and published under the stable tag. |
31 -| Resume a failed promotion | Re-run or re-dispatch the same beta after inspecting the draft | An unpublished draft can be resumed and its assets replaced. |
26 +| Goal | Path | Result |
27 +| --------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------- |
28 +| Ship an ordinary CLI change | Merge the reviewed PR to `next` | The push builds a rolling beta automatically. |
29 +| Build a beta from a branch | Dispatch `build-beta` at that branch | A prerelease is built from the branch commit. |
30 +| Publish a stable CLI | Promote an existing tested beta | The beta's source commit is rebuilt and published under the stable tag. |
31 +| Resume a failed promotion | Re-run or re-dispatch the same beta after inspecting the draft | An unpublished draft can be resumed and its assets replaced. |
32
33 -The resolver also treats a CLI `package.json` version change pushed to `next` as a stable release. Do not use that as the normal contributor procedure. It bypasses beta selection and is reserved for explicit release-owner recovery or migration work.
33 +The private CLI `package.json` uses a development sentinel and never selects a
34 +binary version. If a release owner needs an intentional minor or major version,
35 +dispatch an explicitly versioned beta, verify it, and promote that exact beta.
36
37 ## Changeset Rule
38
@@ -94,7 +96,10 @@ If the user asked for a stable release without naming a beta, show the candidate
96
97 ## Build A Manual Beta
98
97 -Use this only when an explicit beta build is requested. The selected ref supplies both the workflow definition and source commit.
99 +Use this only when an explicit beta build is requested. The selected ref
100 +supplies both the workflow definition and source commit. Omit `version` for the
101 +normal next-patch beta, or provide an exact `major.minor.patch` base for an
102 +intentional minor or major release.
103
104 ```bash
105 SOURCE_BRANCH='replace-with-branch'
@@ -105,6 +110,16 @@ gh workflow run build-cli-binaries.yml \
110 --raw-field action=build-beta
111 ```
112
113 +For an intentional minor or major, add a version newer than the latest stable:
114 +
115 +```bash
116 +gh workflow run build-cli-binaries.yml \
117 + --repo "$REPOSITORY" \
118 + --ref "$SOURCE_BRANCH" \
119 + --raw-field action=build-beta \
120 + --raw-field version=0.3.0
121 +```
122 +
123 Watch the returned run through publication and installation tests. A beta is not a stable release.
124
125 ## Promote A Beta To Stable
.github/scripts/cli-release/resolve-release-target.sh
+48 -25
@@ -3,12 +3,12 @@
3 # Resolve the CLI release target and write its metadata to $GITHUB_OUTPUT for the
4 # build/release jobs of build-cli-binaries.yml. Three modes:
5 #
6 -# - push to `next` with a ts/packages/cli/package.json version bump → stable release
7 -# - push to `next` without a bump, or workflow_dispatch build-beta → rolling beta
8 -# - workflow_dispatch promote-stable <beta tag> → stable promotion
6 +# - push to `next` → rolling beta
7 +# - workflow_dispatch build-beta [version] → rolling or explicitly versioned beta
8 +# - workflow_dispatch promote-stable <beta tag> → stable promotion
9 #
10 -# Inputs (env): EVENT_NAME, ACTION_INPUT, BETA_TAG_INPUT, GITHUB_TOKEN,
11 -# REPOSITORY, RUN_NUMBER, COMMIT_SHA
10 +# Inputs (env): EVENT_NAME, ACTION_INPUT, BETA_TAG_INPUT, VERSION_INPUT,
11 +# GITHUB_TOKEN, REPOSITORY, RUN_NUMBER, COMMIT_SHA
12 # Output: key=value lines appended to $GITHUB_OUTPUT
13 set -euo pipefail
14
@@ -30,26 +30,57 @@ latest_stable_tag() {
30 | last | .tagName // empty'
31 }
32
33 -# Echo the next "<major>.<minor>.<patch+1>" off the latest stable release, falling
34 -# back to the working-tree package.json when no stable release exists yet.
33 +# Echo the next "<major>.<minor>.<patch+1>" off the latest stable release.
34 next_beta_base_version() {
35 local latest current
36 latest=$(latest_stable_tag)
37 if [[ -z "$latest" ]]; then
39 - echo "No stable @composio/cli release found, falling back to package.json" >&2
40 - current=$(node -p "require('./ts/packages/cli/package.json').version")
41 - else
42 - current=${latest#@composio/cli@}
38 + echo "No stable @composio/cli release found; provide VERSION_INPUT for the first beta" >&2
39 + return 1
40 fi
41 + current=${latest#@composio/cli@}
42
43 local major minor patch
44 IFS='.' read -r major minor patch <<<"$current"
45 echo "${major}.${minor}.$((patch + 1))"
46 }
47
48 +version_is_greater() {
49 + local candidate=$1 baseline=$2
50 + local candidate_major candidate_minor candidate_patch
51 + local baseline_major baseline_minor baseline_patch
52 + IFS='.' read -r candidate_major candidate_minor candidate_patch <<<"$candidate"
53 + IFS='.' read -r baseline_major baseline_minor baseline_patch <<<"$baseline"
54 +
55 + ((candidate_major > baseline_major)) ||
56 + ((candidate_major == baseline_major && candidate_minor > baseline_minor)) ||
57 + ((
58 + candidate_major == baseline_major &&
59 + candidate_minor == baseline_minor &&
60 + candidate_patch > baseline_patch
61 + ))
62 +}
63 +
64 emit_beta_target() {
51 - local next_version release_tag
52 - next_version=$(next_beta_base_version)
65 + local requested_version=${1:-}
66 + local latest latest_version next_version release_tag
67 + if [[ -n "$requested_version" ]]; then
68 + if [[ ! "$requested_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
69 + echo "Beta version must match <major>.<minor>.<patch>" >&2
70 + return 1
71 + fi
72 + next_version=$requested_version
73 + latest=$(latest_stable_tag)
74 + if [[ -n "$latest" ]]; then
75 + latest_version=${latest#@composio/cli@}
76 + if ! version_is_greater "$next_version" "$latest_version"; then
77 + echo "Beta version ${next_version} must be newer than latest stable ${latest_version}" >&2
78 + return 1
79 + fi
80 + fi
81 + else
82 + next_version=$(next_beta_base_version)
83 + fi
84 release_tag="@composio/cli@${next_version}-beta.${RUN_NUMBER}"
85 {
86 echo "checkout_ref=${COMMIT_SHA}"
@@ -73,24 +104,16 @@ emit_stable_target() {
104 } >>"$GITHUB_OUTPUT"
105 }
106
76 -# ── Push to next ──
107 +# Every push to next is a beta. Stable releases always promote an already-tested
108 +# beta, so package metadata can never create a second version authority.
109 if [[ "$EVENT_NAME" == "push" ]]; then
78 - current_version=$(node -p "require('./ts/packages/cli/package.json').version")
79 - previous_version=$(git show HEAD^:ts/packages/cli/package.json 2>/dev/null \
80 - | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version" 2>/dev/null || echo "")
81 -
82 - # A version bump on push is a stable release; anything else is a rolling beta.
83 - if [[ -n "$previous_version" && "$current_version" != "$previous_version" ]]; then
84 - emit_stable_target "@composio/cli@${current_version}" "$current_version" "$COMMIT_SHA"
85 - else
86 - emit_beta_target
87 - fi
110 + emit_beta_target
111 exit 0
112 fi
113
114 # ── workflow_dispatch: build-beta ──
115 if [[ "$EVENT_NAME" == "workflow_dispatch" && "$ACTION_INPUT" == "build-beta" ]]; then
93 - emit_beta_target
116 + emit_beta_target "${VERSION_INPUT:-}"
117 exit 0
118 fi
119
.github/workflows/build-cli-binaries.yml
+13
@@ -23,6 +23,9 @@ on:
23 beta_tag:
24 description: 'Existing beta release tag to promote (only for promote-stable, e.g. @composio/cli@0.2.20-beta.42)'
25 required: false
26 + version:
27 + description: 'Optional semver base for a manual beta (e.g. 0.3.0); omit for the next patch after latest stable'
28 + required: false
29
30 # Least privilege by default: only the release job creates/edits releases and uploads assets.
31 # `prepare` reads releases (gh release list) and `build` uploads workflow artifacts — both work
@@ -58,6 +61,7 @@ jobs:
61 EVENT_NAME: ${{ github.event_name }}
62 ACTION_INPUT: ${{ inputs.action }}
63 BETA_TAG_INPUT: ${{ inputs.beta_tag }}
64 + VERSION_INPUT: ${{ inputs.version }}
65 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66 REPOSITORY: ${{ github.repository }}
67 RUN_NUMBER: ${{ github.run_number }}
@@ -132,6 +136,8 @@ jobs:
136
137 - name: Cross-compile CLI binary
138 working-directory: ts/packages/cli
139 + env:
140 + RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
141 run: pnpm build:binary:cross --target ${{ matrix.target }}
142
143 - name: Verify binary
@@ -140,6 +146,13 @@ jobs:
146 ls -la dist/binaries/${{ matrix.artifact }}
147 file dist/binaries/${{ matrix.artifact }}
148
149 + - name: Verify binary version
150 + if: matrix.target == 'bun-linux-x64'
151 + working-directory: ts/packages/cli
152 + run: |
153 + expected_version='${{ needs.prepare.outputs.release_tag }}'
154 + test "$(./dist/binaries/${{ matrix.artifact }} --version)" = "${expected_version#@composio/cli@}"
155 +
156 - name: Test binary
157 if: matrix.target == 'bun-linux-x64'
158 working-directory: ts/packages/cli
test/release-workflow.test.ts
+100
@@ -47,6 +47,10 @@ const buildCliWorkflow = readFileSync(
47 new URL('../.github/workflows/build-cli-binaries.yml', import.meta.url),
48 'utf8'
49 );
50 +const buildAllCliBinariesScript = readFileSync(
51 + new URL('../ts/packages/cli/scripts/build-all-binaries.ts', import.meta.url),
52 + 'utf8'
53 +);
54 const installGuide = readFileSync(new URL('../INSTALL.md', import.meta.url), 'utf8');
55 const installHealthCheck = readFileSync(
56 new URL('../.github/workflows/cli.install-health-check.yml', import.meta.url),
@@ -629,6 +633,26 @@ if (!resolveTargetScript.includes('--exclude-drafts')) {
633 'resolve-release-target.sh must exclude draft stable releases from beta base selection'
634 );
635 }
636 +if (!buildCliWorkflow.includes('RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}')) {
637 + throw new Error('CLI binary builds must receive the resolved GitHub release tag');
638 +}
639 +if (
640 + !buildAllCliBinariesScript.includes(
641 + '...buildCliReleaseVersionDefineArgs(process.env.RELEASE_TAG)'
642 + )
643 +) {
644 + throw new Error('the all-target CLI build must embed the resolved GitHub release version');
645 +}
646 +if (
647 + !buildCliWorkflow.includes(
648 + "- name: Verify binary version\n if: matrix.target == 'bun-linux-x64'"
649 + )
650 +) {
651 + throw new Error('CLI binary version verification must run only on a native target');
652 +}
653 +if (!buildCliWorkflow.includes('expected_version#@composio/cli@')) {
654 + throw new Error('CLI binary version verification must strip the release tag prefix');
655 +}
656
657 // --- cli.install-health-check.yml: canary must exercise the failure-prone pinned path ---
658
@@ -955,6 +979,82 @@ function runResolver({ env, releasesFixture, curlFixture, ghViewIsDraft }) {
979 }
980 }
981
982 +// Pushes to next are always betas, regardless of private package metadata.
983 +{
984 + const r = runResolver({
985 + env: {
986 + EVENT_NAME: 'push',
987 + REPOSITORY: 'ComposioHQ/composio',
988 + RUN_NUMBER: '43',
989 + COMMIT_SHA: 'deadbeef',
990 + },
991 + releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
992 + });
993 + if (r.status !== 0) {
994 + throw new Error(`resolve-release-target.sh push failed\nstderr:\n${r.stderr}`);
995 + }
996 + if (r.outputs.release_tag !== '@composio/cli@0.2.34-beta.43') {
997 + throw new Error(`push must produce the next rolling beta, got ${r.outputs.release_tag}`);
998 + }
999 + if (r.outputs.prerelease !== 'true') {
1000 + throw new Error('push must never publish a stable release directly');
1001 + }
1002 +}
1003 +
1004 +// Release owners can choose an intentional minor/major base without changing package.json.
1005 +{
1006 + const r = runResolver({
1007 + env: {
1008 + EVENT_NAME: 'workflow_dispatch',
1009 + ACTION_INPUT: 'build-beta',
1010 + VERSION_INPUT: '0.3.0',
1011 + REPOSITORY: 'ComposioHQ/composio',
1012 + RUN_NUMBER: '44',
1013 + COMMIT_SHA: 'deadbeef',
1014 + },
1015 + releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
1016 + });
1017 + if (r.status !== 0) {
1018 + throw new Error(`explicitly versioned build-beta failed\nstderr:\n${r.stderr}`);
1019 + }
1020 + if (r.outputs.release_tag !== '@composio/cli@0.3.0-beta.44') {
1021 + throw new Error(`explicit build-beta version was not honored: ${r.outputs.release_tag}`);
1022 + }
1023 +}
1024 +
1025 +{
1026 + const r = runResolver({
1027 + env: {
1028 + EVENT_NAME: 'workflow_dispatch',
1029 + ACTION_INPUT: 'build-beta',
1030 + VERSION_INPUT: '0.2.33',
1031 + REPOSITORY: 'ComposioHQ/composio',
1032 + RUN_NUMBER: '45',
1033 + COMMIT_SHA: 'deadbeef',
1034 + },
1035 + releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
1036 + });
1037 + if (r.status === 0 || !r.stderr.includes('must be newer than latest stable')) {
1038 + throw new Error('build-beta must reject an explicit version at or below latest stable');
1039 + }
1040 +}
1041 +
1042 +{
1043 + const r = runResolver({
1044 + env: {
1045 + EVENT_NAME: 'workflow_dispatch',
1046 + ACTION_INPUT: 'build-beta',
1047 + VERSION_INPUT: 'next',
1048 + REPOSITORY: 'ComposioHQ/composio',
1049 + RUN_NUMBER: '46',
1050 + COMMIT_SHA: 'deadbeef',
1051 + },
1052 + });
1053 + if (r.status === 0 || !r.stderr.includes('Beta version must match')) {
1054 + throw new Error('build-beta must reject a non-semver explicit version');
1055 + }
1056 +}
1057 +
1058 // build-beta bumps off the NUMERIC-latest stable release. The fixture deliberately interleaves
1059 // 0.2.10 and 0.2.9: a lexical sort would pick 0.2.9 and resolve 0.2.10 here — regression lock.
1060 {
ts/packages/cli/AGENTS.md
+4 -1
@@ -228,7 +228,10 @@ Use the repo-local `cli-release` skill before building or publishing first-party
228 - A push to `next` touching CLI paths publishes a rolling beta automatically.
229 - The normal stable path promotes an existing tested beta through the `promote-stable` workflow action.
230 - `@composio/cli` and `@composio/cli-local-tools` are ignored by Changesets. Never add a changeset targeting either package; it wedges the TypeScript SDK release action. Put human-facing CLI notes in `CHANGELOG.md` directly.
231 -- A direct `package.json` version bump is supported by the resolver only as an explicit release-owner recovery path, not the contributor default.
231 +- `package.json` uses a private development sentinel and is never a
232 + binary-release authority. For an intentional minor or major release,
233 + dispatch `build-beta` with its optional version input, verify that beta, then
234 + promote it normally.
235
236 ### Key Workflow Files
237
ts/packages/cli/CHANGELOG.md
+10 -1
@@ -1,6 +1,15 @@
1 # @composio/cli
2
3 -## 0.3.0
3 +## Unreleased
4 +
5 +### Patch Changes
6 +
7 +- Make GitHub release metadata the sole version authority for standalone CLI
8 + binaries. Release builds now embed their exact tag version, manual skill
9 + installation follows the packaged release tag, and stable releases can only
10 + promote a tested beta.
11 +
12 +## 0.2.33
13
14 ### Security
15
ts/packages/cli/package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/cli",
3 - "version": "0.3.0",
3 + "version": "0.0.0-development",
4 "description": "Composio CLI",
5 "main": "./dist/bin.mjs",
6 "private": true,
ts/packages/cli/scripts/build-all-binaries.ts
+2
@@ -17,6 +17,7 @@ import { Command } from '@effect/platform';
17 import { BunContext, BunRuntime } from '@effect/platform-bun';
18 import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
19 import { BinaryBuildError } from './build-error';
20 +import { buildCliReleaseVersionDefineArgs } from '../src/utils/cli-release-version';
21
22 /**
23 * All cross-compilation targets and their artifact names.
@@ -36,6 +37,7 @@ function runBunBuild(target: string, outfile: string) {
37 './src/bin.ts',
38 '--env',
39 'DEBUG_OVERRIDE_*',
40 + ...buildCliReleaseVersionDefineArgs(process.env.RELEASE_TAG),
41 '--compile',
42 '--production',
43 '--target',
ts/packages/cli/scripts/build-binary-cross.ts
+2
@@ -20,6 +20,7 @@ import { Command } from '@effect/platform';
20 import { BunContext, BunRuntime } from '@effect/platform-bun';
21 import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
22 import { BinaryBuildError } from './build-error';
23 +import { buildCliReleaseVersionDefineArgs } from '../src/utils/cli-release-version';
24
25 /**
26 * Maps Bun cross-compilation targets to Composio artifact names.
@@ -67,6 +68,7 @@ export function buildBinaryCross() {
68 './src/bin.ts',
69 '--env',
70 'DEBUG_OVERRIDE_*',
71 + ...buildCliReleaseVersionDefineArgs(process.env.RELEASE_TAG),
72 '--compile',
73 '--production',
74 '--target',
ts/packages/cli/scripts/build-binary.ts
+3
@@ -4,6 +4,7 @@ import { Command } from '@effect/platform';
4 import { BunContext, BunRuntime } from '@effect/platform-bun';
5 import { buildCompanionModules, copyLocalToolBinaryAssets, teardown } from './_shared';
6 import { BinaryBuildError } from './build-error';
7 +import { buildCliReleaseVersionDefineArgs } from '../src/utils/cli-release-version';
8
9 /**
10 * Usage: `bun scripts/build-binary.ts`
@@ -27,6 +28,8 @@ export function buildBinary() {
28 '--env',
29 'DEBUG_OVERRIDE_*',
30
31 + ...buildCliReleaseVersionDefineArgs(process.env.RELEASE_TAG),
32 +
33 /**
34 * Generate a standalone Bun executable containing your bundled code.
35 */
ts/packages/cli/src/constants.ts
+11 -2
@@ -1,6 +1,8 @@
1 import { constants } from '@composio/core';
2 import pkg from '../package.json' with { type: 'json' };
3
4 +declare const __COMPOSIO_CLI_RELEASE_VERSION__: string | undefined;
5 +
6 const { DEFAULT_BASE_URL, DEFAULT_WEB_URL } = constants;
7
8 export { DEFAULT_BASE_URL, DEFAULT_WEB_URL };
@@ -53,9 +55,16 @@ export const CACHE_FILENAMES = {
55 };
56
57 /**
56 - * Version of the Composio CLI, read from `package.json` at build time.
58 + * Version of the running Composio CLI.
59 + *
60 + * Release builds replace `__COMPOSIO_CLI_RELEASE_VERSION__` with the exact
61 + * GitHub release version. The private package version is only a source/dev
62 + * fallback and must never drive binary release selection.
63 */
58 -export const APP_VERSION = pkg.version;
64 +export const APP_VERSION =
65 + typeof __COMPOSIO_CLI_RELEASE_VERSION__ === 'undefined'
66 + ? pkg.version
67 + : __COMPOSIO_CLI_RELEASE_VERSION__;
68
69 /**
70 * Name of the Composio CLI application, read from `package.json` at build time.
ts/packages/cli/src/effects/install-skill.ts
+7 -3
@@ -4,6 +4,7 @@ import { NodeOs } from 'src/services/node-os';
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { GITHUB_CONFIG } from 'src/effects/github-config';
6 import { APP_VERSION, type CliReleaseChannel } from 'src/constants';
7 +import { readInstalledReleaseTag } from 'src/services/run-companion-modules';
8 import {
9 fetchLatestCliRelease,
10 fetchCliReleaseByTag,
@@ -81,11 +82,13 @@ export const resolveSkillReleaseTag = ({
82 channel,
83 githubConfig,
84 httpClient,
85 + installedReleaseTag,
86 releaseTag,
87 }: {
88 channel?: SkillReleaseChannel;
89 githubConfig: GitHubConfig;
90 httpClient: HttpClient.HttpClient;
91 + installedReleaseTag?: string;
92 releaseTag?: string;
93 }) =>
94 Effect.gen(function* () {
@@ -98,13 +101,13 @@ export const resolveSkillReleaseTag = ({
101 return configTag;
102 }
103
101 - if (!channel) {
102 - return `@composio/cli@${APP_VERSION}`;
104 + if (installedReleaseTag) {
105 + return installedReleaseTag;
106 }
107
108 const latest = yield* fetchLatestCliRelease({
109 assetDescription: SKILL_ASSET_NAME,
107 - channel,
110 + channel: channel ?? inferSkillReleaseChannel(APP_VERSION),
111 githubConfig,
112 hasRequiredAsset: hasSkillAsset,
113 httpClient,
@@ -147,6 +150,7 @@ export const installSkill = (options?: {
150 channel: options?.channel,
151 githubConfig,
152 httpClient,
153 + installedReleaseTag: yield* readInstalledReleaseTag(process.execPath),
154 releaseTag: options?.releaseTag,
155 });
156
ts/packages/cli/src/services/run-companion-modules.ts
+15 -4
@@ -10,6 +10,7 @@ import extractZip from 'extract-zip';
10 import { GitHubRelease } from 'src/effects/resolve-cli-release';
11 import { BaseConfigProviderLive, extendConfigProvider } from 'src/services/config';
12 import { parseChecksumsText, sha256Hex } from 'src/utils/checksums';
13 +import { CLI_RELEASE_TAG_PREFIX } from 'src/utils/cli-release-version';
14
15 export const RUN_COMPANION_MODULE_BASENAMES: ReadonlyArray<string> = [
16 'run-helpers-runtime',
@@ -295,8 +296,8 @@ export const readInstalledReleaseTag = (
296
297 export const normalizeCliReleaseVersion = (releaseIdentifier: string): string => {
298 const trimmed = releaseIdentifier.trim();
298 - if (trimmed.startsWith('@composio/cli@')) {
299 - return trimmed.slice('@composio/cli@'.length);
299 + if (trimmed.startsWith(CLI_RELEASE_TAG_PREFIX)) {
300 + return trimmed.slice(CLI_RELEASE_TAG_PREFIX.length);
301 }
302 if (/^v\d+\.\d+\.\d+(?:[-+].*)?$/.test(trimmed)) {
303 return trimmed.slice(1);
@@ -304,6 +305,9 @@ export const normalizeCliReleaseVersion = (releaseIdentifier: string): string =>
305 return trimmed;
306 };
307
308 +export const normalizeCliReleaseTag = (releaseIdentifier: string): string =>
309 + `${CLI_RELEASE_TAG_PREFIX}${normalizeCliReleaseVersion(releaseIdentifier)}`;
310 +
311 export const resolveInstalledCliVersion = (
312 execPath: string,
313 fallbackVersion: string
@@ -312,6 +316,14 @@ export const resolveInstalledCliVersion = (
316 normalizeCliReleaseVersion(releaseTag ?? fallbackVersion)
317 );
318
319 +export const resolveInstalledCliReleaseTag = (
320 + execPath: string,
321 + fallbackVersion: string
322 +): Effect.Effect<string, never, FileSystem.FileSystem | Path.Path> =>
323 + Effect.map(readInstalledReleaseTag(execPath), releaseTag =>
324 + normalizeCliReleaseTag(releaseTag ?? fallbackVersion)
325 + );
326 +
327 export const writeInstalledReleaseTag = (
328 installDir: string,
329 releaseTag: string
@@ -439,8 +451,7 @@ const resolveRepairReleaseTag = ({
451 return pinnedTag;
452 }
453
442 - const installedTag = yield* readInstalledReleaseTag(execPath);
443 - return installedTag || `@composio/cli@${appVersion}`;
454 + return yield* resolveInstalledCliReleaseTag(execPath, appVersion);
455 });
456
457 const nonEmptyConfigWithFallback = (name: string, fallback: string) =>
ts/packages/cli/src/services/setup-skill-installer.ts
+27 -14
@@ -1,11 +1,14 @@
1 -import { FileSystem, Path } from '@effect/platform';
2 -import { Effect } from 'effect';
1 +import { FileSystem, HttpClient, Path } from '@effect/platform';
2 +import { Config, Effect } from 'effect';
3 import {
4 + inferSkillReleaseChannel,
5 installSkill,
6 resolveInstalledSkillName,
7 + resolveSkillReleaseTag,
8 resolveTargetSkillPath,
9 SKILL_RELEASE_TAG_FILENAME,
10 } from 'src/effects/install-skill';
11 +import { GITHUB_CONFIG } from 'src/effects/github-config';
12 import { APP_VERSION } from 'src/constants';
13 import { readInstalledReleaseTag } from 'src/services/run-companion-modules';
14 import { NodeOs } from './node-os';
@@ -13,11 +16,19 @@ import { NodeOs } from './node-os';
16 export const resolveSetupSkillReleaseTag = (
17 execPath = process.execPath,
18 fallbackVersion = APP_VERSION
16 -): Effect.Effect<string, never, FileSystem.FileSystem | Path.Path> =>
17 - Effect.map(
18 - readInstalledReleaseTag(execPath),
19 - releaseTag => releaseTag ?? `@composio/cli@${fallbackVersion}`
20 - );
19 +) =>
20 + Effect.gen(function* () {
21 + const httpClient = yield* HttpClient.HttpClient;
22 + const githubConfig = yield* Config.all(GITHUB_CONFIG);
23 + const installedReleaseTag = yield* readInstalledReleaseTag(execPath);
24 +
25 + return yield* resolveSkillReleaseTag({
26 + channel: inferSkillReleaseChannel(fallbackVersion),
27 + githubConfig,
28 + httpClient,
29 + installedReleaseTag,
30 + });
31 + });
32
33 const checkClaudeSkillCurrent = (
34 fs: FileSystem.FileSystem,
@@ -115,21 +126,23 @@ export class SetupSkillInstaller extends Effect.Service<SetupSkillInstaller>()(
126 const os = yield* NodeOs;
127 const isCurrent = (releaseTag: string) =>
128 checkClaudeSkillCurrent(fs, path, os.homedir, releaseTag);
118 - const installedReleaseTag = resolveSetupSkillReleaseTag().pipe(
119 - Effect.provideService(FileSystem.FileSystem, fs),
120 - Effect.provideService(Path.Path, path)
129 + const releaseTag = yield* Effect.cached(
130 + resolveSetupSkillReleaseTag().pipe(
131 + Effect.provideService(FileSystem.FileSystem, fs),
132 + Effect.provideService(Path.Path, path)
133 + )
134 );
135
136 return {
124 - isClaudeSkillReady: Effect.flatMap(installedReleaseTag, isCurrent),
137 + isClaudeSkillReady: Effect.flatMap(releaseTag, isCurrent),
138 hasManagedClaudeSkill: hasManagedClaudeSkill(os.homedir),
139 ensureClaudeSkill: Effect.gen(function* () {
127 - const releaseTag = yield* installedReleaseTag;
128 - if (yield* isCurrent(releaseTag)) return false;
140 + const targetReleaseTag = yield* releaseTag;
141 + if (yield* isCurrent(targetReleaseTag)) return false;
142
143 yield* installSkill({
144 target: 'claude',
132 - releaseTag,
145 + releaseTag: targetReleaseTag,
146 silent: true,
147 });
148 return true;
ts/packages/cli/src/services/upgrade-binary.ts
+2 -4
@@ -14,7 +14,7 @@ import { renderPrettyError } from './utils/pretty-error';
14 import { TerminalUI } from './terminal-ui';
15 import {
16 collectExpectedRunCompanionAssetRelativePaths,
17 - readInstalledReleaseTag,
17 + resolveInstalledCliReleaseTag,
18 writeInstalledReleaseTag,
19 } from './run-companion-modules';
20
@@ -173,9 +173,7 @@ const provideFsAndPath = <A, E>(
173 * Check if update is available
174 */
175 const resolveCurrentReleaseIdentifier = (ctx: UpgradeBinaryContext, currentPath: string) =>
176 - provideFsAndPath(ctx, readInstalledReleaseTag(currentPath)).pipe(
177 - Effect.map(releaseTag => releaseTag || `@composio/cli@${APP_VERSION}`)
178 - );
176 + provideFsAndPath(ctx, resolveInstalledCliReleaseTag(currentPath, APP_VERSION));
177
178 const isUpdateAvailable = (
179 release: GitHubRelease,
ts/packages/cli/src/utils/cli-release-version.ts new
+21
@@ -0,0 +1,21 @@
1 +export const CLI_RELEASE_TAG_PREFIX = '@composio/cli@';
2 +export const CLI_RELEASE_VERSION_DEFINE = '__COMPOSIO_CLI_RELEASE_VERSION__';
3 +
4 +const CLI_RELEASE_TAG_PATTERN =
5 + /^@composio\/cli@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/u;
6 +
7 +export const extractCliReleaseVersion = (releaseTag: string): string | undefined =>
8 + CLI_RELEASE_TAG_PATTERN.exec(releaseTag.trim())?.[1];
9 +
10 +export const buildCliReleaseVersionDefineArgs = (
11 + releaseTag: string | undefined
12 +): ReadonlyArray<string> => {
13 + if (!releaseTag?.trim()) return [];
14 +
15 + const releaseVersion = extractCliReleaseVersion(releaseTag);
16 + if (!releaseVersion) {
17 + throw new Error(`Invalid Composio CLI release tag: ${releaseTag}`);
18 + }
19 +
20 + return ['--define', `${CLI_RELEASE_VERSION_DEFINE}=${JSON.stringify(releaseVersion)}`] as const;
21 +};
ts/packages/cli/test/src/effects/install-skill.test.ts
+122 -2
@@ -30,8 +30,12 @@ const TEST_SKILL_ZIP = Uint8Array.from(
30
31 const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer);
32
33 -const makeInstallEffect = (home: string, apiBaseUrl: string) =>
34 - installSkill({ target: 'claude', releaseTag: TEST_RELEASE_TAG }).pipe(
33 +const makeInstallEffect = (
34 + home: string,
35 + apiBaseUrl: string,
36 + options: { readonly releaseTag?: string } = { releaseTag: TEST_RELEASE_TAG }
37 +) =>
38 + installSkill({ target: 'claude', ...options }).pipe(
39 Effect.provide(
40 Layer.mergeAll(
41 TestPlatform,
@@ -159,6 +163,7 @@ const makeResolveEffect = (
163 configEntries: ReadonlyArray<[string, string]>,
164 options: {
165 channel?: SkillReleaseChannel;
166 + installedReleaseTag?: string;
167 releaseTag?: string;
168 } = {}
169 ) =>
@@ -170,6 +175,7 @@ const makeResolveEffect = (
175 channel: options.channel,
176 githubConfig,
177 httpClient,
178 + installedReleaseTag: options.installedReleaseTag,
179 releaseTag: options.releaseTag,
180 });
181 }).pipe(
@@ -235,6 +241,7 @@ describe('install-skill', () => {
241 const releaseTag = '@composio/cli@0.3.0-beta.123';
242 const tag = yield* makeResolveEffect([], {
243 channel: 'stable',
244 + installedReleaseTag: '@composio/cli@0.2.33-beta.322',
245 releaseTag,
246 });
247
@@ -242,6 +249,119 @@ describe('install-skill', () => {
249 })
250 );
251
252 + it.effect('prefers the configured release tag over packaged metadata', () =>
253 + Effect.gen(function* () {
254 + const tag = yield* makeResolveEffect([['GITHUB_TAG', '@composio/cli@0.2.34-beta.1']], {
255 + installedReleaseTag: '@composio/cli@0.2.33',
256 + });
257 +
258 + expect(tag).toBe('@composio/cli@0.2.34-beta.1');
259 + })
260 + );
261 +
262 + it.effect('uses the packaged release tag when no explicit selector is provided', () =>
263 + Effect.gen(function* () {
264 + const tag = yield* makeResolveEffect([], {
265 + installedReleaseTag: '@composio/cli@0.2.33-beta.322',
266 + });
267 +
268 + expect(tag).toBe('@composio/cli@0.2.33-beta.322');
269 + })
270 + );
271 +
272 + it.scoped('installs from the packaged release tag when package metadata differs', () => {
273 + const installDir = tempy.temporaryDirectory();
274 + const execPathSpy = vi
275 + .spyOn(process, 'execPath', 'get')
276 + .mockReturnValue(`${installDir}/composio`);
277 + let requestedReleasePath = '';
278 +
279 + return Effect.gen(function* () {
280 + const fs = yield* FileSystem.FileSystem;
281 + const path = yield* Path.Path;
282 + const packagedReleaseTag = '@composio/cli@0.2.33';
283 + yield* fs.writeFileString(path.join(installDir, 'release-tag.txt'), packagedReleaseTag);
284 +
285 + const apiBaseUrl = yield* startTestHttpServer((req, res) => {
286 + if (req.url === '/skill.zip') {
287 + res.writeHead(200, { 'content-type': 'application/zip' });
288 + res.end(TEST_SKILL_ZIP);
289 + return;
290 + }
291 +
292 + requestedReleasePath = req.url ?? '';
293 + res.writeHead(200, { 'content-type': 'application/json' });
294 + res.end(
295 + JSON.stringify({
296 + tag_name: packagedReleaseTag,
297 + assets: [
298 + {
299 + name: 'composio-skill.zip',
300 + browser_download_url: `http://${req.headers.host}/skill.zip`,
301 + },
302 + ],
303 + })
304 + );
305 + });
306 +
307 + const home = tempy.temporaryDirectory();
308 + yield* makeInstallEffect(home, apiBaseUrl, {});
309 +
310 + expect(requestedReleasePath).toContain(encodeURIComponent(packagedReleaseTag));
311 + expect(
312 + yield* fs.readFileString(
313 + path.join(home, '.agents', 'skills', 'composio-cli', SKILL_RELEASE_TAG_FILENAME)
314 + )
315 + ).toBe(`${packagedReleaseTag}\n`);
316 + }).pipe(
317 + Effect.provide(TestPlatform),
318 + Effect.ensuring(Effect.sync(() => execPathSpy.mockRestore()))
319 + );
320 + });
321 +
322 + it.scoped('falls back to the latest inferred channel for source and development runs', () =>
323 + Effect.gen(function* () {
324 + yield* stubBunWhichMiss;
325 + const apiBaseUrl = yield* startTestHttpServer((_req, res) => {
326 + res.writeHead(200, { 'content-type': 'application/json' });
327 + res.end(
328 + JSON.stringify([
329 + {
330 + tag_name: '@composio/cli@0.2.33-beta.322',
331 + draft: false,
332 + prerelease: true,
333 + assets: [
334 + {
335 + name: 'composio-skill.zip',
336 + browser_download_url: 'http://127.0.0.1/beta-skill.zip',
337 + },
338 + ],
339 + },
340 + {
341 + tag_name: '@composio/cli@0.2.33',
342 + draft: false,
343 + prerelease: false,
344 + assets: [
345 + {
346 + name: 'composio-skill.zip',
347 + browser_download_url: 'http://127.0.0.1/stable-skill.zip',
348 + },
349 + ],
350 + },
351 + ])
352 + );
353 + });
354 +
355 + const tag = yield* makeResolveEffect([
356 + ['GITHUB_API_BASE_URL', apiBaseUrl],
357 + ['GITHUB_OWNER', 'test-owner'],
358 + ['GITHUB_REPO', 'test-repo'],
359 + ]);
360 +
361 + expect(tag).toBe('@composio/cli@0.2.33');
362 + })
363 + );
364 +
365 it.scoped('fails with a typed decode error for malformed GitHub release lists', () =>
366 Effect.gen(function* () {
367 const apiBaseUrl = yield* startTestHttpServer((_req, res) => {
ts/packages/cli/test/src/services/setup-skill-installer.test.ts
+33 -4
@@ -1,4 +1,4 @@
1 -import { FileSystem, Path } from '@effect/platform';
1 +import { FileSystem, HttpClient, HttpClientResponse, Path } from '@effect/platform';
2 import { BunFileSystem, BunPath } from '@effect/platform-bun';
3 import { describe, expect, layer } from '@effect/vitest';
4 import { Effect, Layer } from 'effect';
@@ -11,7 +11,36 @@ import {
11 resolveSetupSkillReleaseTag,
12 } from 'src/services/setup-skill-installer';
13
14 -const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer);
14 +const TestHttpClient = Layer.succeed(
15 + HttpClient.HttpClient,
16 + HttpClient.make(request =>
17 + Effect.succeed(
18 + HttpClientResponse.fromWeb(
19 + request,
20 + new Response(
21 + JSON.stringify([
22 + {
23 + tag_name: '@composio/cli@0.2.21',
24 + prerelease: false,
25 + assets: [
26 + {
27 + name: 'composio-skill.zip',
28 + browser_download_url: 'https://example.test/composio-skill.zip',
29 + },
30 + ],
31 + },
32 + ]),
33 + {
34 + status: 200,
35 + headers: { 'Content-Type': 'application/json' },
36 + }
37 + )
38 + )
39 + )
40 + )
41 +);
42 +
43 +const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer, TestHttpClient);
44
45 describe('SetupSkillInstaller', () => {
46 layer(TestPlatform)(it => {
@@ -32,13 +61,13 @@ describe('SetupSkillInstaller', () => {
61 })
62 );
63
35 - it.effect('falls back to the build version outside a packaged install', () =>
64 + it.effect('discovers the latest stable release outside a packaged install', () =>
65 Effect.gen(function* () {
66 const path = yield* Path.Path;
67 const installDir = tempy.temporaryDirectory();
68
69 expect(yield* resolveSetupSkillReleaseTag(path.join(installDir, 'composio'), '0.3.0')).toBe(
41 - '@composio/cli@0.3.0'
70 + '@composio/cli@0.2.21'
71 );
72 })
73 );
ts/packages/cli/test/src/services/upgrade-binary.test.ts
+91 -61
@@ -1,10 +1,7 @@
1 import { describe, expect, it, vi } from '@effect/vitest';
2 import { ConfigProvider, Effect, Layer } from 'effect';
3 -import { FetchHttpClient, Path } from '@effect/platform';
4 -import { BunFileSystem } from '@effect/platform-bun';
5 -import { existsSync, mkdirSync, readFileSync, mkdtempSync, writeFileSync } from 'node:fs';
6 -import { tmpdir } from 'node:os';
7 -import path from 'node:path';
3 +import { FetchHttpClient, FileSystem, Path } from '@effect/platform';
4 +import { BunFileSystem, BunPath } from '@effect/platform-bun';
5 import { withHttpServer } from 'test/__utils__/http-server';
6 import { getTerminalCapabilities, TerminalUI } from 'src/services/terminal-ui';
7 import { UpgradeBinary, UpgradeBinaryError } from 'src/services/upgrade-binary';
@@ -56,6 +53,8 @@ const NodeOsTest = Layer.succeed(
53 })
54 );
55
56 +const TestPlatform = Layer.mergeAll(BunFileSystem.layer, BunPath.layer);
57 +
58 const makeUpgradeEffect = (
59 configEntries: ReadonlyArray<[string, string]>,
60 options?: {
@@ -230,6 +229,15 @@ describe('UpgradeBinary', () => {
229 vi.stubGlobal('Bun', { which: vi.fn(() => null) });
230
231 return Effect.gen(function* () {
232 + const fs = yield* FileSystem.FileSystem;
233 + const path = yield* Path.Path;
234 + const installDir = yield* fs.makeTempDirectoryScoped({
235 + prefix: 'composio-upgrade-current-',
236 + });
237 + const fakeExecPath = path.join(installDir, 'composio');
238 + yield* fs.writeFileString(path.join(installDir, 'release-tag.txt'), '@composio/cli@0.2.14\n');
239 + vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
240 +
241 const apiBaseUrl = yield* scopedHttpServer((_req, res) => {
242 res.writeHead(200, { 'content-type': 'application/json' });
243 res.end(
@@ -267,13 +275,22 @@ describe('UpgradeBinary', () => {
275 ]);
276
277 expect(result).toBeUndefined();
270 - }).pipe(Effect.ensuring(restoreStubsAndMocks));
278 + }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
279 });
280
281 it.scoped('ignores prereleases when checking the stable channel', () => {
282 vi.stubGlobal('Bun', { which: vi.fn(() => null) });
283
284 return Effect.gen(function* () {
285 + const fs = yield* FileSystem.FileSystem;
286 + const path = yield* Path.Path;
287 + const installDir = yield* fs.makeTempDirectoryScoped({
288 + prefix: 'composio-upgrade-current-',
289 + });
290 + const fakeExecPath = path.join(installDir, 'composio');
291 + yield* fs.writeFileString(path.join(installDir, 'release-tag.txt'), '@composio/cli@0.2.17\n');
292 + vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
293 +
294 const apiBaseUrl = yield* scopedHttpServer((_req, res) => {
295 res.writeHead(200, { 'content-type': 'application/json' });
296 res.end(
@@ -311,17 +328,25 @@ describe('UpgradeBinary', () => {
328 ]);
329
330 expect(result).toBeUndefined();
314 - }).pipe(Effect.ensuring(restoreStubsAndMocks));
331 + }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
332 });
333
334 it.scoped('selects the latest prerelease when beta upgrades are requested', () => {
318 - const installDir = mkdtempSync(path.join(tmpdir(), 'composio-beta-select-'));
319 - const fakeExecPath = path.join(installDir, 'composio');
320 - writeFileSync(path.join(installDir, 'release-tag.txt'), '@composio/cli@0.1.0-beta.0\n');
335 vi.stubGlobal('Bun', { which: vi.fn(() => null) });
322 - const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
336
337 return Effect.gen(function* () {
338 + const fs = yield* FileSystem.FileSystem;
339 + const path = yield* Path.Path;
340 + const installDir = yield* fs.makeTempDirectoryScoped({
341 + prefix: 'composio-beta-select-',
342 + });
343 + const fakeExecPath = path.join(installDir, 'composio');
344 + yield* fs.writeFileString(
345 + path.join(installDir, 'release-tag.txt'),
346 + '@composio/cli@0.1.0-beta.0\n'
347 + );
348 + vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
349 +
350 const apiBaseUrl = yield* scopedHttpServer((_req, res) => {
351 res.writeHead(200, { 'content-type': 'application/json' });
352 res.end(
@@ -378,48 +403,51 @@ describe('UpgradeBinary', () => {
403 }
404 expect(error.message).toBe('Failed to download binary: composio-darwin-aarch64.zip');
405 expect(String(error.cause)).toContain('beta-3.zip');
381 - }).pipe(
382 - Effect.ensuring(Effect.sync(() => execPathSpy.mockRestore())),
383 - Effect.ensuring(restoreStubsAndMocks)
384 - );
406 + }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
407 });
408
387 - it.effect('copies local-tool bundled binary assets during local-target upgrades', () => {
388 - const installDir = mkdtempSync(path.join(tmpdir(), 'composio-local-tool-upgrade-target-'));
389 - const sourceDir = mkdtempSync(path.join(tmpdir(), 'composio-local-tool-upgrade-source-'));
390 - const fakeExecPath = path.join(installDir, 'composio');
391 - const sourceBinaryPath = path.join(sourceDir, 'composio');
392 - const sourceLocalToolPath = path.join(
393 - sourceDir,
394 - 'local-tools-binaries',
395 - 'beeper-imessage',
396 - 'darwin-arm64',
397 - 'imessage-cli'
398 - );
399 - const installedLocalToolPath = path.join(
400 - installDir,
401 - 'local-tools-binaries',
402 - 'beeper-imessage',
403 - 'darwin-arm64',
404 - 'imessage-cli'
405 - );
406 -
407 - writeFileSync(fakeExecPath, 'old-binary');
408 - writeFileSync(sourceBinaryPath, 'new-binary');
409 - mkdirSync(path.dirname(sourceLocalToolPath), { recursive: true });
410 - writeFileSync(sourceLocalToolPath, 'imessage-sidecar');
411 -
409 + it.scoped('copies local-tool bundled binary assets during local-target upgrades', () => {
410 vi.stubGlobal('Bun', { which: vi.fn(() => null) });
413 - const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
411
412 return Effect.gen(function* () {
416 - const companionRelativePaths = yield* collectExpectedRunCompanionAssetRelativePaths(
417 - sourceDir
418 - ).pipe(Effect.provide(Layer.mergeAll(BunFileSystem.layer, Path.layer)));
413 + const fs = yield* FileSystem.FileSystem;
414 + const path = yield* Path.Path;
415 + const installDir = yield* fs.makeTempDirectoryScoped({
416 + prefix: 'composio-local-tool-upgrade-target-',
417 + });
418 + const sourceDir = yield* fs.makeTempDirectoryScoped({
419 + prefix: 'composio-local-tool-upgrade-source-',
420 + });
421 + const fakeExecPath = path.join(installDir, 'composio');
422 + const sourceBinaryPath = path.join(sourceDir, 'composio');
423 + const sourceLocalToolPath = path.join(
424 + sourceDir,
425 + 'local-tools-binaries',
426 + 'beeper-imessage',
427 + 'darwin-arm64',
428 + 'imessage-cli'
429 + );
430 + const installedLocalToolPath = path.join(
431 + installDir,
432 + 'local-tools-binaries',
433 + 'beeper-imessage',
434 + 'darwin-arm64',
435 + 'imessage-cli'
436 + );
437 +
438 + yield* fs.writeFileString(fakeExecPath, 'old-binary');
439 + yield* fs.writeFileString(sourceBinaryPath, 'new-binary');
440 + yield* fs.makeDirectory(path.dirname(sourceLocalToolPath), { recursive: true });
441 + yield* fs.writeFileString(sourceLocalToolPath, 'imessage-sidecar');
442 +
443 + vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
444 +
445 + const companionRelativePaths =
446 + yield* collectExpectedRunCompanionAssetRelativePaths(sourceDir);
447 for (const relativePath of companionRelativePaths) {
448 const companionPath = path.join(sourceDir, relativePath);
421 - mkdirSync(path.dirname(companionPath), { recursive: true });
422 - writeFileSync(companionPath, 'support-file');
449 + yield* fs.makeDirectory(path.dirname(companionPath), { recursive: true });
450 + yield* fs.writeFileString(companionPath, 'support-file');
451 }
452
453 const result = yield* runUpgradeSuccess([
@@ -427,23 +455,28 @@ describe('UpgradeBinary', () => {
455 ]);
456
457 expect(result).toBeUndefined();
430 - expect(readFileSync(fakeExecPath, 'utf8')).toBe('new-binary');
431 - expect(existsSync(installedLocalToolPath)).toBe(true);
432 - expect(readFileSync(installedLocalToolPath, 'utf8')).toBe('imessage-sidecar');
433 - }).pipe(
434 - Effect.ensuring(Effect.sync(() => execPathSpy.mockRestore())),
435 - Effect.ensuring(restoreStubsAndMocks)
436 - );
458 + expect(yield* fs.readFileString(fakeExecPath)).toBe('new-binary');
459 + expect(yield* fs.exists(installedLocalToolPath)).toBe(true);
460 + expect(yield* fs.readFileString(installedLocalToolPath)).toBe('imessage-sidecar');
461 + }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
462 });
463
464 it.scoped('uses the installed beta release tag when comparing beta updates', () => {
440 - const installDir = mkdtempSync(path.join(tmpdir(), 'composio-beta-upgrade-'));
441 - const fakeExecPath = path.join(installDir, 'composio');
442 - writeFileSync(path.join(installDir, 'release-tag.txt'), '@composio/cli@0.2.17-beta.1\n');
465 vi.stubGlobal('Bun', { which: vi.fn(() => null) });
444 - const execPathSpy = vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
466
467 return Effect.gen(function* () {
468 + const fs = yield* FileSystem.FileSystem;
469 + const path = yield* Path.Path;
470 + const installDir = yield* fs.makeTempDirectoryScoped({
471 + prefix: 'composio-beta-upgrade-',
472 + });
473 + const fakeExecPath = path.join(installDir, 'composio');
474 + yield* fs.writeFileString(
475 + path.join(installDir, 'release-tag.txt'),
476 + '@composio/cli@0.2.17-beta.1\n'
477 + );
478 + vi.spyOn(process, 'execPath', 'get').mockReturnValue(fakeExecPath);
479 +
480 const apiBaseUrl = yield* scopedHttpServer((_req, res) => {
481 res.writeHead(200, { 'content-type': 'application/json' });
482 res.end(
@@ -478,9 +511,6 @@ describe('UpgradeBinary', () => {
511 }
512 expect(error.message).toBe('Failed to download binary: composio-darwin-aarch64.zip');
513 expect(String(error.cause)).toContain('beta-3.zip');
481 - }).pipe(
482 - Effect.ensuring(Effect.sync(() => execPathSpy.mockRestore())),
483 - Effect.ensuring(restoreStubsAndMocks)
484 - );
514 + }).pipe(Effect.provide(TestPlatform), Effect.ensuring(restoreStubsAndMocks));
515 });
516 });
ts/packages/cli/test/src/utils/cli-release-version.test.ts new
+21
@@ -0,0 +1,21 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import cliPackageJson from '../../../package.json' with { type: 'json' };
3 +import {
4 + buildCliReleaseVersionDefineArgs,
5 + extractCliReleaseVersion,
6 +} from 'src/utils/cli-release-version';
7 +
8 +describe('CLI release version authority', () => {
9 + it('uses a non-release development sentinel', () => {
10 + expect(cliPackageJson.version).toBe('0.0.0-development');
11 + });
12 +
13 + it('derives the exact GitHub release version', () => {
14 + expect(extractCliReleaseVersion('@composio/cli@0.2.33-beta.322')).toBe('0.2.33-beta.322');
15 + expect(extractCliReleaseVersion('@composio/core@0.2.33')).toBeUndefined();
16 + expect(buildCliReleaseVersionDefineArgs('@composio/cli@0.2.33-beta.322')).toEqual([
17 + '--define',
18 + '__COMPOSIO_CLI_RELEASE_VERSION__="0.2.33-beta.322"',
19 + ]);
20 + });
21 +});