@devries-cameron20 / composio Mirror · read-only
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, 03:37 UTC

next
ts 1,889 lines 65.3 KB
Raw
1 #!/usr/bin/env node
2 import {
3 chmodSync,
4 existsSync,
5 mkdirSync,
6 mkdtempSync,
7 readdirSync,
8 rmSync,
9 writeFileSync,
10 readFileSync,
11 } from 'node:fs';
12 import { tmpdir } from 'node:os';
13 import { join } from 'node:path';
14 import { spawnSync } from 'node:child_process';
15 import semver from 'semver';
16 import {
17 findIgnoredChangesetReleases,
18 validateChangesets,
19 } from '../ts/scripts/validate-changesets.mjs';
20
21 const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
22 const tsCorePackageJson = JSON.parse(
23 readFileSync(new URL('../ts/packages/core/package.json', import.meta.url), 'utf8')
24 );
25 const changesetConfig = JSON.parse(
26 readFileSync(new URL('../.changeset/config.json', import.meta.url), 'utf8')
27 );
28 const tsReleaseWorkflow = readFileSync(
29 new URL('../.github/workflows/ts.release.yml', import.meta.url),
30 'utf8'
31 );
32 const tsTestWorkflow = readFileSync(
33 new URL('../.github/workflows/ts.test.yml', import.meta.url),
34 'utf8'
35 );
36 const pythonPyproject = readFileSync(new URL('../python/pyproject.toml', import.meta.url), 'utf8');
37 const pythonRuntimeVersionModule = readFileSync(
38 new URL('../python/composio/__version__.py', import.meta.url),
39 'utf8'
40 );
41 const pythonReleaseWorkflow = readFileSync(
42 new URL('../.github/workflows/py.release.yml', import.meta.url),
43 'utf8'
44 );
45 const pythonMakefilePath = new URL('../python/Makefile', import.meta.url).pathname;
46 const changesetBinPath = new URL('../node_modules/.bin/changeset', import.meta.url).pathname;
47 const releaseScriptUrl = new URL('../ts/scripts/changeset-release.sh', import.meta.url);
48 const releaseScriptPath = releaseScriptUrl.pathname;
49 const releaseScript = readFileSync(releaseScriptUrl, 'utf8');
50 const rootInstallGuide = readFileSync(new URL('../INSTALL.md', import.meta.url), 'utf8');
51 const buildCliWorkflow = readFileSync(
52 new URL('../.github/workflows/build-cli-binaries.yml', import.meta.url),
53 'utf8'
54 );
55 const cliBuildSharedScript = readFileSync(
56 new URL('../ts/packages/cli/scripts/_shared.ts', import.meta.url),
57 'utf8'
58 );
59 const installGuide = readFileSync(new URL('../INSTALL.md', import.meta.url), 'utf8');
60 const installHealthCheck = readFileSync(
61 new URL('../.github/workflows/cli.install-health-check.yml', import.meta.url),
62 'utf8'
63 );
64 const cliDocsGuide = readFileSync(new URL('../docs/content/docs/cli.mdx', import.meta.url), 'utf8');
65 const resolveTargetScriptUrl = new URL(
66 '../.github/scripts/cli-release/resolve-release-target.sh',
67 import.meta.url
68 );
69 const resolveTargetScriptPath = resolveTargetScriptUrl.pathname;
70 const resolveTargetScript = readFileSync(resolveTargetScriptUrl, 'utf8');
71 const createDraftScript = readFileSync(
72 new URL('../.github/scripts/cli-release/create-or-resume-draft.sh', import.meta.url),
73 'utf8'
74 );
75 const verifyAssetsScript = readFileSync(
76 new URL('../.github/scripts/cli-release/verify-assets.sh', import.meta.url),
77 'utf8'
78 );
79 const generateChecksumsScriptUrl = new URL(
80 '../ts/packages/cli/scripts/generate-checksums.ts',
81 import.meta.url
82 );
83 const generateChecksumsScriptPath = generateChecksumsScriptUrl.pathname;
84 const generateChecksumsScript = readFileSync(generateChecksumsScriptUrl, 'utf8');
85
86 function requireMatch(text, pattern, label) {
87 const match = text.match(pattern);
88 if (!match?.[1]) {
89 throw new Error(`Could not read ${label}`);
90 }
91 return match[1];
92 }
93
94 function readPyprojectVersion(text, label) {
95 return requireMatch(text, /^\s*version\s*=\s*"([^"]+)"\s*$/m, label);
96 }
97
98 function readSdkVersions(rows) {
99 const versions = new Set();
100 const pythonVersionPattern =
101 /\bv?(\d+(?:\.\d+)+(?:[._-]?(?:a|b|c|rc|alpha|beta|pre|preview)(?:[._-]?\d+)?)?(?:[._-]?(?:post|rev|r)\d*)?(?:[._-]?dev\d*)?(?:\+[a-z0-9]+(?:[._-][a-z0-9]+)*)?)\b/gi;
102
103 for (const row of rows) {
104 const cells = row
105 .split('|')
106 .map(cell => cell.trim())
107 .filter(Boolean);
108 const releaseVersionCell = cells[cells.length - 1];
109 if (!releaseVersionCell) continue;
110
111 for (const version of releaseVersionCell.matchAll(pythonVersionPattern)) {
112 versions.add(version[1]);
113 }
114 }
115
116 return versions;
117 }
118
119 function escapeRegExp(value) {
120 return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
121 }
122
123 function readDocumentedSdkVersions(sdkLabel) {
124 const changelogDir = new URL('../docs/content/changelog/', import.meta.url);
125 const rowPattern = new RegExp(`^\\|\\s*${escapeRegExp(sdkLabel)}\\s*\\|.*$`, 'gm');
126 const rows = [];
127
128 for (const entry of readdirSync(changelogDir, { withFileTypes: true })) {
129 if (!entry.isFile() || !entry.name.endsWith('.mdx')) continue;
130
131 const source = readFileSync(
132 new URL(`../docs/content/changelog/${entry.name}`, import.meta.url),
133 'utf8'
134 );
135 rows.push(...(source.match(rowPattern) ?? []));
136 }
137
138 return readSdkVersions(rows);
139 }
140
141 function readTypeScriptWorkspacePackages() {
142 const workspacePackages = [];
143
144 for (const workspacePattern of packageJson.workspaces ?? []) {
145 if (!workspacePattern.startsWith('ts/packages/')) continue;
146
147 const workspacePaths = workspacePattern.endsWith('/*')
148 ? readdirSync(new URL(`../${workspacePattern.slice(0, -2)}/`, import.meta.url), {
149 withFileTypes: true,
150 })
151 .filter(entry => entry.isDirectory())
152 .map(entry => `${workspacePattern.slice(0, -1)}${entry.name}`)
153 : [workspacePattern];
154
155 for (const workspacePath of workspacePaths) {
156 const manifestUrl = new URL(`../${workspacePath}/package.json`, import.meta.url);
157 if (!existsSync(manifestUrl)) continue;
158
159 workspacePackages.push({
160 manifest: JSON.parse(readFileSync(manifestUrl, 'utf8')),
161 path: `${workspacePath}/package.json`,
162 });
163 }
164 }
165
166 return workspacePackages;
167 }
168
169 function runPythonBuildFixture({
170 providers,
171 providerFiles = [],
172 failingProvider = '',
173 target = 'build',
174 }) {
175 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-python-build-'));
176 const buildLogPath = join(fixtureDir, 'build.log');
177
178 try {
179 mkdirSync(join(fixtureDir, '.venv/bin'), { recursive: true });
180 mkdirSync(join(fixtureDir, 'providers'), { recursive: true });
181 writeFileSync(buildLogPath, '');
182
183 const fakePythonPath = join(fixtureDir, '.venv/bin/python');
184 writeFileSync(
185 fakePythonPath,
186 `#!/usr/bin/env bash
187 set -euo pipefail
188 target="\${3:-}"
189 printf '%s\n' "\${target:-<root>}" >> "$BUILD_LOG"
190
191 if [[ -z "$target" ]]; then
192 mkdir -p dist
193 touch dist/root.whl
194 exit 0
195 fi
196
197 target="\${target%/}"
198 if [[ "$target" == "$FAILING_PROVIDER" ]]; then
199 exit 23
200 fi
201
202 mkdir -p "$target/dist"
203 touch "$target/dist/provider.whl"
204 `
205 );
206 chmodSync(fakePythonPath, 0o755);
207
208 for (const provider of providers) {
209 const providerDir = join(fixtureDir, 'providers', provider);
210 mkdirSync(providerDir, { recursive: true });
211 writeFileSync(join(providerDir, 'pyproject.toml'), '[build-system]\n');
212 }
213 for (const providerFile of providerFiles) {
214 writeFileSync(join(fixtureDir, 'providers', providerFile), 'not a provider package\n');
215 }
216
217 const result = spawnSync('make', ['-f', pythonMakefilePath, target], {
218 cwd: fixtureDir,
219 encoding: 'utf8',
220 env: {
221 ...process.env,
222 BUILD_LOG: buildLogPath,
223 FAILING_PROVIDER: failingProvider ? `providers/${failingProvider}` : '',
224 },
225 });
226
227 return {
228 ...result,
229 invocations: readFileSync(buildLogPath, 'utf8').trim().split('\n'),
230 };
231 } finally {
232 rmSync(fixtureDir, { recursive: true, force: true });
233 }
234 }
235
236 {
237 const result = runPythonBuildFixture({
238 providers: ['provider-must-not-build'],
239 target: 'build-core',
240 });
241
242 if (result.status !== 0) {
243 throw new Error(
244 `Python core-only build fixture failed unexpectedly\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
245 );
246 }
247 if (!result.invocations.includes('<root>')) {
248 throw new Error('Python core-only build must build the root SDK package');
249 }
250 if (result.invocations.includes('providers/provider-must-not-build')) {
251 throw new Error('Python core-only build must not build provider packages');
252 }
253 }
254
255 {
256 const result = runPythonBuildFixture({
257 providers: ['valid'],
258 providerFiles: ['AGENTS.md'],
259 });
260
261 if (result.status !== 0) {
262 throw new Error(
263 `Python package build fixture failed unexpectedly\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
264 );
265 }
266 if (result.invocations.includes('providers/AGENTS.md')) {
267 throw new Error('Python package build must skip non-provider files under python/providers');
268 }
269 if (!result.invocations.includes('providers/valid')) {
270 throw new Error('Python package build must include provider directories with pyproject.toml');
271 }
272 }
273
274 {
275 const result = runPythonBuildFixture({
276 providers: ['a-failing', 'z-valid'],
277 failingProvider: 'a-failing',
278 });
279
280 if (result.status === 0) {
281 throw new Error('Python package build must fail when a provider build fails');
282 }
283 if (!result.invocations.includes('providers/a-failing')) {
284 throw new Error('Python package build fixture did not exercise the failing provider');
285 }
286 if (result.invocations.includes('providers/z-valid')) {
287 throw new Error('Python package build must stop after the first provider failure');
288 }
289 }
290
291 {
292 const directVersion = readSdkVersions(['| Python `composio` | `9.9.9` |']);
293 const versionWithPrevious = readSdkVersions(['| Python `composio` | v9.9.8 | **v9.9.9** |']);
294 const previousVersionOnly = readSdkVersions(['| Python `composio` | v9.9.9 | **v9.9.10** |']);
295 const pep440Versions = readSdkVersions([
296 '| Python `composio` | `9.9.9rc1` |',
297 '| Python `composio` | `9.9.9.post1` |',
298 '| Python `composio` | `9.9.9.dev1` |',
299 ]);
300 const semverPrerelease = readSdkVersions(['| TypeScript `@composio/core` | `1.0.0-beta.0` |']);
301
302 if (!directVersion.has('9.9.9') || !versionWithPrevious.has('9.9.9')) {
303 throw new Error('Python SDK changelog version rows must recognize the released version');
304 }
305 if (previousVersionOnly.has('9.9.9')) {
306 throw new Error(
307 'Python SDK changelog version rows must not treat the previous version as released'
308 );
309 }
310 for (const version of ['9.9.9rc1', '9.9.9.post1', '9.9.9.dev1']) {
311 if (!pep440Versions.has(version)) {
312 throw new Error(
313 `Python SDK changelog version rows must recognize PEP 440 version ${version}`
314 );
315 }
316 }
317 if (!semverPrerelease.has('1.0.0-beta.0')) {
318 throw new Error('SDK changelog version rows must recognize SemVer prerelease versions');
319 }
320 }
321
322 if (!tsReleaseWorkflow.includes('publish-script: pnpm changeset:release')) {
323 throw new Error('ts.release.yml must use the repository-controlled changeset:release script');
324 }
325
326 if (packageJson.scripts?.['changeset:release'] !== 'bash ts/scripts/changeset-release.sh') {
327 throw new Error('changeset:release must use the CLI-release filtering script');
328 }
329
330 if (packageJson.scripts?.['validate:changesets'] !== 'node ts/scripts/validate-changesets.mjs') {
331 throw new Error('validate:changesets must use the ignored-package guard');
332 }
333
334 if (
335 packageJson.scripts?.['check:provider-compatibility'] !==
336 'tsx ts/scripts/check-provider-compatibility.ts'
337 ) {
338 throw new Error('check:provider-compatibility must use the packed consumer harness');
339 }
340
341 const tsTestBuildIdx = tsTestWorkflow.indexOf('run: pnpm run build:packages');
342 const tsTestProviderCompatibilityIdx = tsTestWorkflow.indexOf(
343 'run: pnpm run check:provider-compatibility'
344 );
345 if (
346 tsTestBuildIdx === -1 ||
347 tsTestProviderCompatibilityIdx === -1 ||
348 tsTestBuildIdx > tsTestProviderCompatibilityIdx
349 ) {
350 throw new Error('ts.test.yml must build packages before checking packed provider compatibility');
351 }
352
353 {
354 const violations = findIgnoredChangesetReleases(
355 {
356 changesets: [
357 {
358 id: 'ignored-package-fixture',
359 releases: [
360 { name: '@composio/cli', type: 'patch' },
361 { name: '@composio/core', type: 'patch' },
362 ],
363 },
364 ],
365 },
366 ['@composio/cli']
367 );
368
369 if (
370 violations.length !== 1 ||
371 violations[0].changeset !== 'ignored-package-fixture' ||
372 violations[0].package !== '@composio/cli'
373 ) {
374 throw new Error('changeset validation must identify releases targeting ignored packages');
375 }
376 }
377
378 {
379 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-changeset-validation-'));
380 const changesetDir = join(fixtureDir, '.changeset');
381 const fixturePath = join(changesetDir, 'ignored-package-fixture.md');
382
383 try {
384 mkdirSync(changesetDir, { recursive: true });
385 writeFileSync(join(changesetDir, 'config.json'), JSON.stringify({ ignore: ['@composio/cli'] }));
386 writeFileSync(
387 fixturePath,
388 '---\n"@composio/cli": patch\n"@composio/core": patch\n---\n\nFixture changeset.\n'
389 );
390
391 let validationError = '';
392 try {
393 await validateChangesets(fixtureDir);
394 } catch (error) {
395 validationError = error instanceof Error ? error.message : String(error);
396 }
397
398 if (!validationError.includes('ignored-package-fixture: @composio/cli')) {
399 throw new Error('changeset validation must reject an ignored package outside a git checkout');
400 }
401
402 writeFileSync(fixturePath, '---\n"@composio/core": patch\n---\n\nValid fixture changeset.\n');
403 await validateChangesets(fixtureDir);
404 } finally {
405 rmSync(fixtureDir, { recursive: true, force: true });
406 }
407 }
408
409 const validateChangesetsIdx = tsReleaseWorkflow.indexOf('run: pnpm validate:changesets');
410 const changesetsActionIdx = tsReleaseWorkflow.indexOf('uses: changesets/action@');
411 if (
412 validateChangesetsIdx === -1 ||
413 changesetsActionIdx === -1 ||
414 validateChangesetsIdx > changesetsActionIdx
415 ) {
416 throw new Error('ts.release.yml must validate pending changesets before changesets/action');
417 }
418
419 if (
420 !tsReleaseWorkflow.includes('changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2')
421 ) {
422 throw new Error('ts.release.yml must use changesets/action v2 with Changesets v3');
423 }
424
425 for (const input of [
426 'github-token: ${{ steps.app-token.outputs.token }}',
427 'publish-script: pnpm changeset:release',
428 "commit-message: 'Release: update version'",
429 "pr-title: 'Release: update version'",
430 ]) {
431 if (!tsReleaseWorkflow.includes(input)) {
432 throw new Error(`ts.release.yml must use the changesets/action v2 ${input} input`);
433 }
434 }
435
436 if (!tsReleaseWorkflow.includes('steps.changesets.outputs.published-packages')) {
437 throw new Error('ts.release.yml must read the changesets/action v2 published-packages output');
438 }
439
440 if (changesetConfig.baseBranch !== 'next') {
441 throw new Error('changesets must compare against next, the active release branch');
442 }
443
444 if (
445 changesetConfig.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
446 ?.onlyUpdatePeerDependentsWhenOutOfRange !== true
447 ) {
448 throw new Error(
449 'changesets must only major-bump peer dependents when the new dependency version leaves their declared peer range'
450 );
451 }
452
453 {
454 const MIN_NODE_VERSION = '>=22.22.3';
455 const publicTsReleaseWorkspaces = readTypeScriptWorkspacePackages().filter(
456 ({ manifest }) => manifest.private !== true
457 );
458 // @typesafe-ai/sdk 0.6.0 terminates the process after a handled cancellation on Node
459 // releases before 24.17 (typesafe-ai/typesafe-sdk-js#2), so that provider advertises a
460 // higher floor until the SDK is fixed.
461 const NODE_VERSION_EXCEPTIONS = {
462 '@composio/typesafe': '>=24.17.0',
463 };
464 const invalidNodeEngines = publicTsReleaseWorkspaces.filter(
465 ({ manifest }) =>
466 manifest.engines?.node !== (NODE_VERSION_EXCEPTIONS[manifest.name] ?? MIN_NODE_VERSION)
467 );
468
469 if (publicTsReleaseWorkspaces.length === 0) {
470 throw new Error('Node.js engine validation must discover public TypeScript workspaces');
471 }
472 if (invalidNodeEngines.length > 0) {
473 const details = invalidNodeEngines
474 .map(({ manifest, path }) => `- ${path}: ${manifest.engines?.node ?? '<missing>'}`)
475 .join('\n');
476 throw new Error(
477 `Public TypeScript workspaces must declare engines.node as ${MIN_NODE_VERSION}, or their documented exception:\n${details}`
478 );
479 }
480 }
481
482 // --- Python release metadata: package version, runtime version, and docs changelog must agree ---
483
484 // PEP 440 compact prereleases (0.23.1rc1) and the separator form that
485 // python/scripts/bump.py --pre emits (0.23.1-rc.1) must both count as prereleases,
486 // here and in the workflow's inline detector.
487 const PYTHON_PRERELEASE_PATTERN = /(?:a|b|rc|dev)[-_.]?\d/i;
488 const PYTHON_PRERELEASE_SAMPLES: ReadonlyArray<readonly [string, boolean]> = [
489 ['0.23.0', false],
490 ['0.23.1', false],
491 ['0.23.1rc1', true],
492 ['0.23.1-rc.1', true],
493 ['0.23.1b2', true],
494 ['0.23.1.dev3', true],
495 ['0.23.1a1', true],
496 ];
497 const workflowPrereleaseDetector = requireMatch(
498 pythonReleaseWorkflow,
499 /is_prerelease = re\.search\(r"([^"]+)", version, re\.IGNORECASE\) is not None/,
500 'py.release.yml prerelease detector'
501 );
502 for (const [sample, expected] of PYTHON_PRERELEASE_SAMPLES) {
503 if (PYTHON_PRERELEASE_PATTERN.test(sample) !== expected) {
504 throw new Error(`release-workflow prerelease detector misclassifies ${sample}`);
505 }
506 if (new RegExp(workflowPrereleaseDetector, 'i').test(sample) !== expected) {
507 throw new Error(`py.release.yml prerelease detector misclassifies ${sample}`);
508 }
509 }
510
511 if (!pythonReleaseWorkflow.includes('run: pnpm test:release-workflow')) {
512 throw new Error('py.release.yml must validate release metadata before publishing');
513 }
514 for (const input of ['id: release_mode', 'core_only=']) {
515 if (!pythonReleaseWorkflow.includes(input)) {
516 throw new Error(`py.release.yml must select the core-only build for prereleases: ${input}`);
517 }
518 }
519 if (
520 !/if \[\[ "\$\{\{ steps\.release_mode\.outputs\.core_only \}\}" == "true" \]\]; then\s+make build-core\s+else\s+make build\s+fi/.test(
521 pythonReleaseWorkflow
522 )
523 ) {
524 throw new Error(
525 'py.release.yml must build only the core package for prereleases and all Python packages for stable releases'
526 );
527 }
528 for (const input of ['run: uv sync --locked --only-group release', 'BUILD_ARGS: --no-isolation']) {
529 if (!pythonReleaseWorkflow.includes(input)) {
530 throw new Error(`py.release.yml must build from uv.lock: ${input}`);
531 }
532 }
533 {
534 // Only the publish job may request an OIDC token; build steps must never see it.
535 const workflow = Bun.YAML.parse(pythonReleaseWorkflow);
536 const grantsToken = permissions =>
537 typeof permissions === 'string'
538 ? permissions === 'write-all'
539 : permissions?.['id-token'] === 'write';
540 const tokenJobs = Object.entries(workflow.jobs)
541 .filter(([, job]) => grantsToken(job.permissions))
542 .map(([name]) => name);
543 if (grantsToken(workflow.permissions) || tokenJobs.join() !== 'publish') {
544 throw new Error('py.release.yml must grant id-token: write to the publish job only');
545 }
546 }
547 for (const input of ['make env', 'password:', 'PYPI_PASSWORD', 'PYPI_USERNAME']) {
548 if (pythonReleaseWorkflow.includes(input)) {
549 throw new Error(`py.release.yml must not install unlocked deps or use PyPI tokens: ${input}`);
550 }
551 }
552
553 {
554 const pythonVersion = readPyprojectVersion(pythonPyproject, 'python/pyproject.toml version');
555 const runtimeVersion = requireMatch(
556 pythonRuntimeVersionModule,
557 /^\s*__version__\s*=\s*"([^"]+)"\s*$/m,
558 'python/composio/__version__.py version'
559 );
560
561 if (runtimeVersion !== pythonVersion) {
562 throw new Error(
563 `python/composio/__version__.py must match python/pyproject.toml (${runtimeVersion} !== ${pythonVersion})`
564 );
565 }
566
567 const documentedPythonVersions = readDocumentedSdkVersions('Python `composio`');
568 if (!documentedPythonVersions.has(pythonVersion)) {
569 throw new Error(
570 `docs/content/changelog must document the current Python package version (${pythonVersion})`
571 );
572 }
573
574 const providerDir = new URL('../python/providers/', import.meta.url);
575 const pythonIsPrerelease = PYTHON_PRERELEASE_PATTERN.test(pythonVersion);
576 const providerVersions = new Map<string, string>();
577 for (const entry of readdirSync(providerDir, { withFileTypes: true })) {
578 if (!entry.isDirectory()) continue;
579
580 const pyprojectPath = new URL(
581 `../python/providers/${entry.name}/pyproject.toml`,
582 import.meta.url
583 );
584 const setupPath = new URL(`../python/providers/${entry.name}/setup.py`, import.meta.url);
585 if (!existsSync(pyprojectPath)) continue;
586
587 const providerPyprojectVersion = readPyprojectVersion(
588 readFileSync(pyprojectPath, 'utf8'),
589 `python/providers/${entry.name}/pyproject.toml version`
590 );
591 providerVersions.set(entry.name, providerPyprojectVersion);
592 const providerIsPrerelease = PYTHON_PRERELEASE_PATTERN.test(providerPyprojectVersion);
593 if (pythonIsPrerelease && providerIsPrerelease) {
594 throw new Error(
595 `python/providers/${entry.name}/pyproject.toml must remain stable during a composio prerelease (${providerPyprojectVersion})`
596 );
597 }
598 if (!pythonIsPrerelease && providerPyprojectVersion !== pythonVersion) {
599 throw new Error(
600 `python/providers/${entry.name}/pyproject.toml must match python/pyproject.toml (${providerPyprojectVersion} !== ${pythonVersion})`
601 );
602 }
603
604 if (!existsSync(setupPath)) continue;
605
606 const providerSetupVersion = requireMatch(
607 readFileSync(setupPath, 'utf8'),
608 /version\s*=\s*"([^"]+)"/,
609 `python/providers/${entry.name}/setup.py version`
610 );
611 if (providerSetupVersion !== providerPyprojectVersion) {
612 throw new Error(
613 `python/providers/${entry.name}/setup.py must match its pyproject.toml (${providerSetupVersion} !== ${providerPyprojectVersion})`
614 );
615 }
616 const providerSetupIsPrerelease = PYTHON_PRERELEASE_PATTERN.test(providerSetupVersion);
617 if (pythonIsPrerelease && providerSetupIsPrerelease) {
618 throw new Error(
619 `python/providers/${entry.name}/setup.py must remain stable during a composio prerelease (${providerSetupVersion})`
620 );
621 }
622 if (!pythonIsPrerelease && providerSetupVersion !== pythonVersion) {
623 throw new Error(
624 `python/providers/${entry.name}/setup.py must match python/pyproject.toml (${providerSetupVersion} !== ${pythonVersion})`
625 );
626 }
627 }
628
629 const distinctProviderVersions = new Set(providerVersions.values());
630 if (distinctProviderVersions.size > 1) {
631 const details = [...providerVersions]
632 .map(([provider, version]) => `- ${provider}: ${version}`)
633 .join('\n');
634 throw new Error(`Python providers must share one stable version:\n${details}`);
635 }
636 }
637
638 {
639 const documentedTsCoreVersions = readDocumentedSdkVersions('TypeScript `@composio/core`');
640 if (!documentedTsCoreVersions.has(tsCorePackageJson.version)) {
641 throw new Error(
642 `docs/content/changelog must document the current TypeScript core package version (${tsCorePackageJson.version})`
643 );
644 }
645 }
646
647 if (!releaseScript.includes('pnpm changeset publish')) {
648 throw new Error('release script must still publish non-CLI changeset packages');
649 }
650
651 if (!releaseScript.includes('CHANGESETS_OUTPUT')) {
652 throw new Error(
653 'release script must filter @composio/cli Changesets v3 output before changesets/action creates GitHub releases'
654 );
655 }
656
657 // --- build-cli-binaries.yml: the CLI binary workflow is the sole, hardened release writer ---
658
659 const canonicalWindowsInstallGuidance = requireMatch(
660 rootInstallGuide,
661 /^(- Windows: .+)$/m,
662 'canonical Windows install guidance'
663 );
664 const generatedInstallGuide = requireMatch(
665 buildCliWorkflow,
666 /cat > INSTALL\.md << 'EOF'\n([\s\S]*?)\n\s+EOF/,
667 'generated CLI release INSTALL.md'
668 );
669 const generatedWindowsInstallGuidance = requireMatch(
670 generatedInstallGuide,
671 /^\s*(- Windows: .+)$/m,
672 'generated Windows install guidance'
673 );
674
675 if (!canonicalWindowsInstallGuidance.includes('PowerShell')) {
676 throw new Error('INSTALL.md must document native Windows x64 PowerShell installation');
677 }
678 if (generatedWindowsInstallGuidance !== canonicalWindowsInstallGuidance) {
679 throw new Error(
680 'build-cli-binaries.yml generated INSTALL.md must match the canonical Windows guidance'
681 );
682 }
683
684 // A single failed platform must never publish a partial set: fail-fast: false makes the build
685 // job `success` only when every matrix leg passes, gating the release job.
686 if (!buildCliWorkflow.includes('fail-fast: false')) {
687 throw new Error('build-cli-binaries.yml build matrix must set fail-fast: false');
688 }
689
690 // The release must be built as a draft and only flipped to published after verification, so no
691 // anonymous consumer can observe a release before its assets are attached. The draft and verify
692 // logic live in standalone scripts checked out from the workflow revision; the workflow must
693 // invoke them in helper checkout → draft → verify → publish order.
694 const helperCheckoutIdx = buildCliWorkflow.indexOf('name: Checkout workflow release helpers');
695 const draftStepIdx = buildCliWorkflow.indexOf(
696 'bash "$RELEASE_HELPERS_DIR/create-or-resume-draft.sh"'
697 );
698 const verifyStepIdx = buildCliWorkflow.indexOf('bash "$RELEASE_HELPERS_DIR/verify-assets.sh"');
699 const publishIdx = buildCliWorkflow.indexOf('gh release edit "$RELEASE_TAG" --draft=false');
700
701 if (!buildCliWorkflow.includes("- '.github/scripts/cli-release/**'")) {
702 throw new Error('build-cli-binaries.yml must trigger when CLI release helper scripts change');
703 }
704 if (helperCheckoutIdx === -1) {
705 throw new Error(
706 'build-cli-binaries.yml must checkout workflow release helpers before publishing'
707 );
708 }
709 if (!buildCliWorkflow.includes('ref: ${{ github.workflow_sha }}')) {
710 throw new Error(
711 'build-cli-binaries.yml must checkout release helpers from the workflow revision'
712 );
713 }
714 if (draftStepIdx === -1) {
715 throw new Error('build-cli-binaries.yml must create the draft via create-or-resume-draft.sh');
716 }
717 if (verifyStepIdx === -1) {
718 throw new Error('build-cli-binaries.yml must verify assets via verify-assets.sh');
719 }
720 if (publishIdx === -1) {
721 throw new Error(
722 'build-cli-binaries.yml must publish by flipping the draft (gh release edit --draft=false)'
723 );
724 }
725 if (!(
726 helperCheckoutIdx < draftStepIdx &&
727 draftStepIdx < verifyStepIdx &&
728 verifyStepIdx < publishIdx
729 )) {
730 throw new Error(
731 'build-cli-binaries.yml must order steps helper checkout → draft → verify → publish'
732 );
733 }
734
735 // The draft script must actually create a draft, and the verify gate must require fully-uploaded
736 // assets (not merely present) — that distinction is what stops a release serving 404s.
737 if (!createDraftScript.includes('--draft')) {
738 throw new Error('create-or-resume-draft.sh must create the release as a draft (--draft)');
739 }
740 if (!verifyAssetsScript.includes('select(.state == "uploaded")')) {
741 throw new Error('verify-assets.sh must require assets be fully uploaded (state == "uploaded")');
742 }
743
744 // Windows must be uploaded before a release becomes public, just like existing platforms.
745 {
746 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-windows-release-assets-'));
747 try {
748 const fakeBin = join(fixtureDir, 'bin');
749 mkdirSync(fakeBin);
750 const fixturePath = join(fixtureDir, 'assets.json');
751 const ghPath = join(fakeBin, 'gh');
752 writeFileSync(ghPath, '#!/bin/sh\ncat "$CLI_RELEASE_ASSETS_FIXTURE"\n');
753 chmodSync(ghPath, 0o755);
754 const assets = [
755 'composio-linux-x64.zip',
756 'composio-linux-aarch64.zip',
757 'composio-darwin-x64.zip',
758 'composio-darwin-aarch64.zip',
759 'composio-windows-x64.zip',
760 'composio-skill.zip',
761 'checksums.txt',
762 ].map(name => ({ name, state: 'uploaded' }));
763 const verify = (rows, extraEnv = {}) => {
764 writeFileSync(fixturePath, JSON.stringify({ assets: rows }));
765 return spawnSync(
766 'bash',
767 [new URL('../.github/scripts/cli-release/verify-assets.sh', import.meta.url).pathname],
768 {
769 encoding: 'utf8',
770 env: {
771 ...process.env,
772 PATH: `${fakeBin}:${process.env.PATH}`,
773 CLI_RELEASE_ASSETS_FIXTURE: fixturePath,
774 RELEASE_TAG: '@composio/cli@1.2.3',
775 VERIFY_ATTEMPTS: '1',
776 VERIFY_SLEEP_SECONDS: '0',
777 ...extraEnv,
778 },
779 }
780 );
781 };
782 const complete = verify(assets);
783 if (complete.status !== 0) {
784 throw new Error(`complete CLI release must pass verification: ${complete.stderr}`);
785 }
786 const withoutWindows = assets.filter(asset => asset.name !== 'composio-windows-x64.zip');
787 const missing = verify(withoutWindows);
788 // Windows is experimental: when its native checks fail, the release ships without it.
789 const unverified = verify(withoutWindows, { WINDOWS_VERIFIED: 'false' });
790 if (unverified.status !== 0) {
791 throw new Error(
792 `a release without the unverified Windows archive must pass: ${unverified.stdout}`
793 );
794 }
795 // A Windows archive left on a resumed draft has no checksum entry, so it must not ship.
796 const stale = verify(assets, { WINDOWS_VERIFIED: 'false' });
797 if (stale.status === 0 || !stale.stdout.includes('unexpected assets')) {
798 throw new Error('CLI release verification must reject an unverified Windows archive');
799 }
800 const pending = verify(
801 assets.map(asset =>
802 asset.name === 'composio-windows-x64.zip' ? { ...asset, state: 'new' } : asset
803 )
804 );
805 for (const result of [missing, pending]) {
806 if (result.status === 0 || !result.stdout.includes('composio-windows-x64.zip')) {
807 throw new Error(
808 'CLI release verification must reject a missing or pending Windows archive'
809 );
810 }
811 }
812 } finally {
813 rmSync(fixtureDir, { recursive: true, force: true });
814 }
815 }
816
817 // Resuming a draft must remove assets the current run does not ship: the regenerated
818 // checksums.txt no longer covers them.
819 {
820 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-resume-draft-'));
821 try {
822 const fakeBin = join(fixtureDir, 'bin');
823 const binariesDir = join(fixtureDir, 'binaries');
824 mkdirSync(fakeBin);
825 mkdirSync(binariesDir);
826 for (const name of ['composio-linux-x64.zip', 'checksums.txt']) {
827 writeFileSync(join(binariesDir, name), '');
828 }
829 const ghLog = join(fixtureDir, 'gh.log');
830 const ghPath = join(fakeBin, 'gh');
831 writeFileSync(
832 ghPath,
833 [
834 '#!/bin/sh',
835 'echo "$*" >> "$GH_LOG"',
836 'case "$*" in',
837 ' *isDraft*) echo true ;;',
838 ' *assets*) printf "%s\\n" composio-linux-x64.zip composio-windows-x64.zip checksums.txt ;;',
839 'esac',
840 '',
841 ].join('\n')
842 );
843 chmodSync(ghPath, 0o755);
844 const resumed = spawnSync(
845 'bash',
846 [
847 new URL('../.github/scripts/cli-release/create-or-resume-draft.sh', import.meta.url)
848 .pathname,
849 ],
850 {
851 encoding: 'utf8',
852 env: {
853 ...process.env,
854 PATH: `${fakeBin}:${process.env.PATH}`,
855 GH_LOG: ghLog,
856 BINARIES_DIR: binariesDir,
857 RELEASE_TAG: '@composio/cli@1.2.3',
858 RELEASE_NAME: 'CLI 1.2.3',
859 CHECKOUT_REF: 'abc123',
860 PRERELEASE: 'false',
861 },
862 }
863 );
864 const deletions = readFileSync(ghLog, 'utf8')
865 .split('\n')
866 .filter(line => line.startsWith('release delete-asset'));
867 if (
868 resumed.status !== 0 ||
869 deletions.length !== 1 ||
870 !deletions[0].includes('composio-windows-x64.zip')
871 ) {
872 throw new Error(
873 `a resumed draft must drop only the assets this run does not ship: ${resumed.stderr}${deletions}`
874 );
875 }
876 } finally {
877 rmSync(fixtureDir, { recursive: true, force: true });
878 }
879 }
880
881 // Beta status must survive the draft→publish flip (regression: the old single create set
882 // --prerelease at creation; the new flow must set it on the draft).
883 if (!createDraftScript.includes('flags+=(--prerelease)')) {
884 throw new Error(
885 'create-or-resume-draft.sh must preserve --prerelease on the draft for beta releases'
886 );
887 }
888
889 // Skills must be packaged BEFORE checksums are generated, so composio-skill.zip is hashed into
890 // checksums.txt rather than shipping unverifiable.
891 const packageSkillsIdx = buildCliWorkflow.indexOf('name: Package skill files');
892 const generateChecksumsIdx = buildCliWorkflow.indexOf('name: Generate checksums');
893 if (packageSkillsIdx === -1 || generateChecksumsIdx === -1) {
894 throw new Error('build-cli-binaries.yml must package skills and generate checksums');
895 }
896 if (!(packageSkillsIdx < generateChecksumsIdx)) {
897 throw new Error(
898 'build-cli-binaries.yml must package skills before generating checksums so the skill zip is checksummed'
899 );
900 }
901
902 if (
903 !generateChecksumsScript.includes("from './_teardown'") ||
904 generateChecksumsScript.includes("from './_shared'")
905 ) {
906 throw new Error(
907 'CLI checksum generation must use the dependency-light teardown without loading CLI runtime helpers'
908 );
909 }
910
911 // The release job runs checksum generation in a fresh checkout where workspace packages have not
912 // been built. Exercise the script from an unrelated working directory to prevent imports from
913 // pulling in the CLI runtime and its unbuilt @composio/core dependency.
914 {
915 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-cli-checksums-'));
916 try {
917 const binariesDir = join(fixtureDir, 'dist/binaries');
918 mkdirSync(binariesDir, { recursive: true });
919 writeFileSync(join(binariesDir, 'composio-linux-x64.zip'), 'release archive fixture\n');
920
921 const result = spawnSync(process.execPath, [generateChecksumsScriptPath], {
922 cwd: fixtureDir,
923 encoding: 'utf8',
924 env: process.env,
925 });
926
927 if (result.status !== 0) {
928 throw new Error(
929 `CLI checksum generation must run without built workspace packages\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
930 );
931 }
932
933 const checksums = readFileSync(join(binariesDir, 'checksums.txt'), 'utf8');
934 if (!/^[a-f0-9]{64} composio-linux-x64\.zip\n$/.test(checksums)) {
935 throw new Error(`CLI checksum generation wrote an invalid manifest:\n${checksums}`);
936 }
937 } finally {
938 rmSync(fixtureDir, { recursive: true, force: true });
939 }
940 }
941
942 // Per-tag concurrency prevents two runs clobbering the same release without serializing betas.
943 if (!buildCliWorkflow.includes('group: cli-release-${{ needs.prepare.outputs.release_tag }}')) {
944 throw new Error(
945 'build-cli-binaries.yml release job must use per-tag concurrency keyed on the release tag'
946 );
947 }
948
949 // Release-target resolution lives in a standalone, unit-tested script (see executable tests
950 // below) rather than inline YAML bash, so the branching logic is reviewable and testable.
951 if (!buildCliWorkflow.includes('bash .github/scripts/cli-release/resolve-release-target.sh')) {
952 throw new Error('build-cli-binaries.yml prepare job must delegate to resolve-release-target.sh');
953 }
954 if (buildCliWorkflow.includes('needs.prepare.outputs.checkout_ref')) {
955 throw new Error('CLI release jobs must not execute a ref derived from workflow inputs');
956 }
957 if ((buildCliWorkflow.match(/ref: \$\{\{ github\.sha \}\}/g) ?? []).length < 2) {
958 throw new Error('CLI build and release jobs must check out the selected workflow commit');
959 }
960 if (buildCliWorkflow.includes('beta_tag:')) {
961 throw new Error('stable promotion must select the beta through the immutable workflow ref');
962 }
963
964 // Release archives contain a composio-<target>/ bundle with runtime support files next to the
965 // executable. Both the checked-in guide and the workflow-generated guide must preserve that
966 // directory contents and create the same two-directory layout as the installer.
967 const manualInstallGuides = [
968 {
969 label: 'INSTALL.md',
970 source: requireMatch(
971 installGuide,
972 /## Manual Installation([\s\S]*?)## Verification/,
973 'INSTALL.md manual installation section'
974 ),
975 },
976 {
977 label: 'build-cli-binaries.yml generated INSTALL.md',
978 source: requireMatch(
979 buildCliWorkflow,
980 /## Manual Installation([\s\S]*?)## Usage/,
981 'generated INSTALL.md manual installation section'
982 ),
983 },
984 ];
985
986 for (const guide of manualInstallGuides) {
987 if (!guide.source.includes('cp -Rp "$bundle"/. "$COMPOSIO_INSTALL_DIR/"')) {
988 throw new Error(`${guide.label} must install the complete CLI release bundle`);
989 }
990 if (!guide.source.includes('mkdir -p "$COMPOSIO_BIN_DIR"')) {
991 throw new Error(`${guide.label} must create the CLI entry-point directory`);
992 }
993 if (
994 !guide.source.includes('ln -sf "$COMPOSIO_INSTALL_DIR/composio" "$COMPOSIO_BIN_DIR/composio"')
995 ) {
996 throw new Error(`${guide.label} must link the CLI entry point to the release bundle`);
997 }
998 }
999
1000 // The "latest stable" lookup must sort by numeric semver, not lexically: a lexical sort ranks
1001 // @composio/cli@0.2.9 above 0.2.10 and would regress beta versioning once a patch hits 2 digits.
1002 if (!resolveTargetScript.includes('map(tonumber)')) {
1003 throw new Error(
1004 'resolve-release-target.sh must sort releases by numeric semver (map(tonumber)), not lexically'
1005 );
1006 }
1007 if (!resolveTargetScript.includes('--exclude-drafts')) {
1008 throw new Error(
1009 'resolve-release-target.sh must exclude draft stable releases from beta base selection'
1010 );
1011 }
1012 if (!buildCliWorkflow.includes('RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}')) {
1013 throw new Error('CLI binary builds must receive the resolved GitHub release tag');
1014 }
1015 if (
1016 !cliBuildSharedScript.includes('...buildCliReleaseVersionDefineArgs(process.env.RELEASE_TAG)')
1017 ) {
1018 throw new Error('CLI binary compilation must embed the resolved GitHub release version');
1019 }
1020 if (
1021 !buildCliWorkflow.includes(
1022 "- name: Verify binary version\n if: matrix.target == 'bun-linux-x64'"
1023 )
1024 ) {
1025 throw new Error('CLI binary version verification must run only on a native target');
1026 }
1027 if (!buildCliWorkflow.includes('expected_version#@composio/cli@')) {
1028 throw new Error('CLI binary version verification must strip the release tag prefix');
1029 }
1030
1031 // --- cli.install-health-check.yml: canary must exercise the failure-prone pinned path ---
1032
1033 // The bare no-arg `curl | bash` is asset-aware and self-heals to the previous good release, so
1034 // the canary must additionally install the newest PUBLISHED release PINNED to actually catch a
1035 // release shipped with missing assets.
1036 //
1037 // It must resolve the newest *published* GitHub release (drafts excluded), NOT `npm view`: npm's
1038 // latest is bumped minutes before the binary workflow publishes the GitHub release, so pinning to
1039 // it would 404 during the healthy publish gap and false-page.
1040 if (installHealthCheck.includes('$(npm view')) {
1041 throw new Error(
1042 'cli.install-health-check.yml must not pin to npm (races ahead of the GitHub release)'
1043 );
1044 }
1045 if (!installHealthCheck.includes('gh release list')) {
1046 throw new Error(
1047 'cli.install-health-check.yml must resolve the newest published release (drafts excluded)'
1048 );
1049 }
1050 if (!installHealthCheck.includes('--repo "${{ github.repository }}"')) {
1051 throw new Error('cli.install-health-check.yml must pass repository context to gh release list');
1052 }
1053 if (!installHealthCheck.includes('--limit 1000')) {
1054 throw new Error(
1055 'cli.install-health-check.yml must look beyond the gh release list default limit'
1056 );
1057 }
1058 if (
1059 !installHealthCheck.includes('--exclude-drafts') ||
1060 !installHealthCheck.includes('--exclude-pre-releases')
1061 ) {
1062 throw new Error(
1063 'cli.install-health-check.yml must resolve the newest published release (drafts excluded)'
1064 );
1065 }
1066 if (installHealthCheck.includes('.[0].tagName')) {
1067 throw new Error('cli.install-health-check.yml must not let jq null bypass the empty tag guard');
1068 }
1069 if (!installHealthCheck.includes("| sed -n '1p'")) {
1070 throw new Error(
1071 'cli.install-health-check.yml must convert no matching release into empty output'
1072 );
1073 }
1074 if (!installHealthCheck.includes('sh -s -- "${{ steps.resolve.outputs.tag }}"')) {
1075 throw new Error('cli.install-health-check.yml must install the resolved tag via the pinned path');
1076 }
1077 if (!installHealthCheck.includes('echo "$HOME/.local/bin" >> "$GITHUB_PATH"')) {
1078 throw new Error('cli.install-health-check.yml must expose the installer entry-point directory');
1079 }
1080 if (!installHealthCheck.includes('test -L "$HOME/.local/bin/composio"')) {
1081 throw new Error('cli.install-health-check.yml must verify the installer entry-point symlink');
1082 }
1083 if (installHealthCheck.includes('rm -rf "$HOME/.composio"')) {
1084 throw new Error('cli.install-health-check.yml must preserve CLI user state between install legs');
1085 }
1086
1087 // --- uninstall file lists: the hand-maintained copies must stay in sync ---
1088
1089 // The uninstall file list mirrors the release bundle layout and is duplicated in INSTALL.md,
1090 // docs/content/docs/cli.mdx, and cli.install-health-check.yml. Drift between them ships
1091 // uninstall guidance (or a health-check reset) that leaves release artifacts behind.
1092 function readUninstallEntries(source, command, label) {
1093 const block = requireMatch(
1094 source,
1095 new RegExp(`${command} \\\\\\n((?:[ \\t]*"[^"]+"(?: \\\\)?\\n)+)`),
1096 `${label} ${command} uninstall block`
1097 );
1098 return [...block.matchAll(/"([^"]+)"/g)].map(entry =>
1099 entry[1]
1100 .replace(/^\$install_dir\//, '')
1101 .replace(/^\$bin_dir\//, '')
1102 .replace(/^\$HOME\/\.composio\//, '')
1103 .replace(/^\$HOME\/\.local\/bin\//, '')
1104 );
1105 }
1106
1107 const uninstallGuides = [
1108 { label: 'INSTALL.md', source: installGuide },
1109 { label: 'docs/content/docs/cli.mdx', source: cliDocsGuide },
1110 { label: 'cli.install-health-check.yml', source: installHealthCheck },
1111 ].map(({ label, source }) => ({
1112 label,
1113 files: readUninstallEntries(source, 'rm -f', label),
1114 directories: readUninstallEntries(source, 'rm -rf', label),
1115 }));
1116
1117 const [canonicalUninstall, ...mirroredUninstallGuides] = uninstallGuides;
1118
1119 // Guard the parser itself: a mis-anchored match must not pass vacuously.
1120 if (
1121 !canonicalUninstall.files.includes('run-helpers-runtime.mjs') ||
1122 !canonicalUninstall.directories.includes('services')
1123 ) {
1124 throw new Error('INSTALL.md uninstall list must cover the release bundle layout');
1125 }
1126
1127 for (const guide of mirroredUninstallGuides) {
1128 if (JSON.stringify(guide.files) !== JSON.stringify(canonicalUninstall.files)) {
1129 throw new Error(
1130 `${guide.label} uninstall file list drifted from INSTALL.md:\n` +
1131 ` ${guide.label}: ${JSON.stringify(guide.files)}\n` +
1132 ` INSTALL.md: ${JSON.stringify(canonicalUninstall.files)}`
1133 );
1134 }
1135 if (JSON.stringify(guide.directories) !== JSON.stringify(canonicalUninstall.directories)) {
1136 throw new Error(
1137 `${guide.label} uninstall directory list drifted from INSTALL.md:\n` +
1138 ` ${guide.label}: ${JSON.stringify(guide.directories)}\n` +
1139 ` INSTALL.md: ${JSON.stringify(canonicalUninstall.directories)}`
1140 );
1141 }
1142 }
1143
1144 const fakeBin = mkdtempSync(join(tmpdir(), 'composio-release-test-'));
1145 try {
1146 const fakePnpmPath = join(fakeBin, 'pnpm');
1147 const changesetsOutputPath = join(fakeBin, 'changesets-output.ndjson');
1148 const commandLogPath = join(fakeBin, 'commands.log');
1149 writeFileSync(commandLogPath, '');
1150 writeFileSync(
1151 fakePnpmPath,
1152 `#!/usr/bin/env bash
1153 set -euo pipefail
1154 printf '%s\n' "$*" >> "$COMMAND_LOG"
1155 case "$*" in
1156 "run build:packages")
1157 exit 0
1158 ;;
1159 "run check:provider-compatibility")
1160 if [[ "\${FAIL_PROVIDER_COMPATIBILITY:-}" == "1" ]]; then
1161 exit 42
1162 fi
1163 exit 0
1164 ;;
1165 "changeset publish")
1166 printf '%s\\n' '{"type":"git-tag","tag":"@composio/core@1.2.3","packageName":"@composio/core"}' > "$CHANGESETS_OUTPUT"
1167 printf '%s\\n' '{"type":"git-tag","tag":"@composio/cli@9.9.9","packageName":"@composio/cli"}' >> "$CHANGESETS_OUTPUT"
1168 echo 'release warning preserved' >&2
1169 exit 0
1170 ;;
1171 *)
1172 echo "unexpected pnpm invocation: $*" >&2
1173 exit 1
1174 ;;
1175 esac
1176 `
1177 );
1178 chmodSync(fakePnpmPath, 0o755);
1179
1180 const result = spawnSync('bash', [releaseScriptPath], {
1181 encoding: 'utf8',
1182 env: {
1183 ...process.env,
1184 CHANGESETS_OUTPUT: changesetsOutputPath,
1185 COMMAND_LOG: commandLogPath,
1186 PATH: `${fakeBin}:${process.env.PATH}`,
1187 },
1188 });
1189
1190 if (result.status !== 0) {
1191 throw new Error(
1192 `release script failed unexpectedly\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
1193 );
1194 }
1195
1196 const outputEvents = readFileSync(changesetsOutputPath, 'utf8')
1197 .trim()
1198 .split('\n')
1199 .map(line => JSON.parse(line));
1200 if (
1201 outputEvents.length !== 1 ||
1202 outputEvents[0].packageName !== '@composio/core' ||
1203 outputEvents[0].tag !== '@composio/core@1.2.3'
1204 ) {
1205 throw new Error('release script must retain only non-CLI Changesets v3 git-tag events');
1206 }
1207
1208 if (!result.stderr.includes('release warning preserved')) {
1209 throw new Error('release script must preserve changeset publish stderr');
1210 }
1211
1212 const commands = readFileSync(commandLogPath, 'utf8').trim().split('\n');
1213 if (
1214 JSON.stringify(commands) !==
1215 JSON.stringify(['run build:packages', 'run check:provider-compatibility', 'changeset publish'])
1216 ) {
1217 throw new Error(
1218 `release script must run build → provider compatibility → publish: ${commands}`
1219 );
1220 }
1221
1222 writeFileSync(commandLogPath, '');
1223 const failedCompatibility = spawnSync('bash', [releaseScriptPath], {
1224 encoding: 'utf8',
1225 env: {
1226 ...process.env,
1227 CHANGESETS_OUTPUT: changesetsOutputPath,
1228 COMMAND_LOG: commandLogPath,
1229 FAIL_PROVIDER_COMPATIBILITY: '1',
1230 PATH: `${fakeBin}:${process.env.PATH}`,
1231 },
1232 });
1233 const failedCommands = readFileSync(commandLogPath, 'utf8').trim().split('\n');
1234 if (failedCompatibility.status !== 42) {
1235 throw new Error('release script must preserve a provider compatibility gate failure');
1236 }
1237 if (failedCommands.includes('changeset publish')) {
1238 throw new Error('release script must not publish after provider compatibility fails');
1239 }
1240 } finally {
1241 rmSync(fakeBin, { recursive: true, force: true });
1242 }
1243
1244 // Private workspaces still receive version bumps, but must never get release tags.
1245 {
1246 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-private-release-'));
1247 const packages = [
1248 { directory: 'sdk', name: '@composio/core', private: false },
1249 { directory: 'example', name: 'release-example', private: true },
1250 { directory: 'test', name: '@e2e-tests/release', private: true },
1251 ];
1252 try {
1253 mkdirSync(join(fixtureDir, '.changeset'), { recursive: true });
1254 writeFileSync(
1255 join(fixtureDir, 'package.json'),
1256 JSON.stringify({ name: 'private-release-fixture', private: true, workspaces: ['packages/*'] })
1257 );
1258 writeFileSync(join(fixtureDir, 'pnpm-workspace.yaml'), "packages:\n - 'packages/*'\n");
1259 writeFileSync(
1260 join(fixtureDir, '.changeset/config.json'),
1261 JSON.stringify({ ...changesetConfig, changelog: false, fixed: [], ignore: [] })
1262 );
1263 writeFileSync(
1264 join(fixtureDir, '.changeset/release.md'),
1265 ['---', ...packages.map(pkg => `"${pkg.name}": patch`), '---', '', 'Release fixture.'].join(
1266 '\n'
1267 )
1268 );
1269 for (const pkg of packages) {
1270 const directory = join(fixtureDir, 'packages', pkg.directory);
1271 mkdirSync(directory, { recursive: true });
1272 writeFileSync(
1273 join(directory, 'package.json'),
1274 JSON.stringify({ name: pkg.name, version: '0.1.0', private: pkg.private })
1275 );
1276 }
1277 const commands = [
1278 [changesetBinPath, ['version']],
1279 ['git', ['init', '--quiet', '--initial-branch=next']],
1280 ['git', ['config', 'user.name', 'Release test']],
1281 ['git', ['config', 'user.email', 'release-test@example.invalid']],
1282 ['git', ['add', '.']],
1283 ['git', ['commit', '-qm', 'Prepare fixture']],
1284 ['git', ['tag', '@e2e-tests/release@0.1.0']],
1285 [changesetBinPath, ['tag']],
1286 ] as const;
1287 for (const [command, args] of commands) {
1288 const result = spawnSync(command, args, { cwd: fixtureDir, encoding: 'utf8' });
1289 if (result.status !== 0) {
1290 throw new Error(
1291 `private release fixture failed: ${command} ${args.join(' ')}\n${result.stderr}`
1292 );
1293 }
1294 }
1295 for (const pkg of packages) {
1296 const manifest = JSON.parse(
1297 readFileSync(join(fixtureDir, 'packages', pkg.directory, 'package.json'), 'utf8')
1298 );
1299 if (manifest.version !== '0.1.1') {
1300 throw new Error(`release must still version ${pkg.name}, got ${manifest.version}`);
1301 }
1302 }
1303 const tags = spawnSync('git', ['tag', '--list'], { cwd: fixtureDir, encoding: 'utf8' });
1304 if (
1305 tags.status !== 0 ||
1306 tags.stdout.trim() !== '@composio/core@0.1.1\n@e2e-tests/release@0.1.0'
1307 ) {
1308 throw new Error(
1309 `release must tag only public SDK updates and preserve existing tags, got:\n${tags.stdout}`
1310 );
1311 }
1312 } finally {
1313 rmSync(fixtureDir, { recursive: true, force: true });
1314 }
1315 }
1316
1317 if (!tsReleaseWorkflow.includes('create-github-releases: false')) {
1318 throw new Error('SDK publication must not create GitHub Releases; the CLI workflow owns them');
1319 }
1320
1321 // A core minor release must not force every provider package to 1.0.0 while the
1322 // provider peer range still accepts the new core version. This protects the
1323 // @composio/core 0.10.0 → 0.11.0 release train from accidentally promoting
1324 // provider packages from 0.9.x to 1.0.0.
1325 {
1326 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-changeset-peer-'));
1327 try {
1328 mkdirSync(join(fixtureDir, '.changeset'), { recursive: true });
1329 mkdirSync(join(fixtureDir, 'packages/core'), { recursive: true });
1330 mkdirSync(join(fixtureDir, 'packages/openai'), { recursive: true });
1331
1332 writeFileSync(
1333 join(fixtureDir, 'package.json'),
1334 JSON.stringify(
1335 {
1336 name: 'changeset-peer-fixture',
1337 private: true,
1338 workspaces: ['packages/*'],
1339 },
1340 null,
1341 2
1342 )
1343 );
1344 writeFileSync(join(fixtureDir, 'pnpm-workspace.yaml'), "packages:\n - 'packages/*'\n");
1345 writeFileSync(
1346 join(fixtureDir, '.changeset/config.json'),
1347 JSON.stringify(
1348 {
1349 changelog: false,
1350 commit: false,
1351 fixed: [],
1352 linked: [],
1353 access: 'restricted',
1354 baseBranch: 'next',
1355 updateInternalDependencies: 'patch',
1356 ___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
1357 onlyUpdatePeerDependentsWhenOutOfRange: true,
1358 },
1359 ignore: [],
1360 },
1361 null,
1362 2
1363 )
1364 );
1365 writeFileSync(
1366 join(fixtureDir, '.changeset/core-minor-provider-patch.md'),
1367 [
1368 '---',
1369 '"@composio/core": minor',
1370 '"@composio/openai": patch',
1371 '---',
1372 '',
1373 'Release a core minor and a provider patch without forcing a provider major.',
1374 '',
1375 ].join('\n')
1376 );
1377 writeFileSync(
1378 join(fixtureDir, 'packages/core/package.json'),
1379 JSON.stringify(
1380 {
1381 name: '@composio/core',
1382 version: '0.10.0',
1383 },
1384 null,
1385 2
1386 )
1387 );
1388 writeFileSync(
1389 join(fixtureDir, 'packages/openai/package.json'),
1390 JSON.stringify(
1391 {
1392 name: '@composio/openai',
1393 version: '0.9.2',
1394 peerDependencies: {
1395 '@composio/core': '>=0.10.0 <1.0.0',
1396 },
1397 devDependencies: {
1398 '@composio/core': 'workspace:*',
1399 },
1400 },
1401 null,
1402 2
1403 )
1404 );
1405
1406 const result = spawnSync(changesetBinPath, ['version'], {
1407 cwd: fixtureDir,
1408 encoding: 'utf8',
1409 env: process.env,
1410 });
1411
1412 if (result.status !== 0) {
1413 throw new Error(
1414 `changeset peer-dependent fixture failed\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
1415 );
1416 }
1417
1418 const coreFixturePackage = JSON.parse(
1419 readFileSync(join(fixtureDir, 'packages/core/package.json'), 'utf8')
1420 );
1421 const providerFixturePackage = JSON.parse(
1422 readFileSync(join(fixtureDir, 'packages/openai/package.json'), 'utf8')
1423 );
1424
1425 if (coreFixturePackage.version !== '0.11.0') {
1426 throw new Error(`fixture core version should be 0.11.0, got ${coreFixturePackage.version}`);
1427 }
1428 if (providerFixturePackage.version !== '0.9.3') {
1429 throw new Error(
1430 `fixture provider version should remain on the 0.9.x train as 0.9.3, got ${providerFixturePackage.version}`
1431 );
1432 }
1433 if (providerFixturePackage.peerDependencies['@composio/core'] !== '>=0.10.0 <1.0.0') {
1434 throw new Error(
1435 `fixture provider peer range should still accept core 0.11.0 without widening, got ${providerFixturePackage.peerDependencies['@composio/core']}`
1436 );
1437 }
1438 } finally {
1439 rmSync(fixtureDir, { recursive: true, force: true });
1440 }
1441 }
1442
1443 // Entering the core 1.0 beta must leave stable providers unversioned when their
1444 // peer range explicitly accepts the prerelease. Providers should use the beta
1445 // only when consumers install it at the workspace root.
1446 {
1447 const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-changeset-beta-peer-'));
1448 try {
1449 mkdirSync(join(fixtureDir, '.changeset'), { recursive: true });
1450 mkdirSync(join(fixtureDir, 'packages/core'), { recursive: true });
1451 mkdirSync(join(fixtureDir, 'packages/openai'), { recursive: true });
1452
1453 writeFileSync(
1454 join(fixtureDir, 'package.json'),
1455 JSON.stringify(
1456 {
1457 name: 'changeset-beta-peer-fixture',
1458 private: true,
1459 workspaces: ['packages/*'],
1460 },
1461 null,
1462 2
1463 )
1464 );
1465 writeFileSync(join(fixtureDir, 'pnpm-workspace.yaml'), "packages:\n - 'packages/*'\n");
1466 writeFileSync(
1467 join(fixtureDir, '.changeset/config.json'),
1468 JSON.stringify(
1469 {
1470 changelog: false,
1471 commit: false,
1472 fixed: [],
1473 linked: [],
1474 access: 'restricted',
1475 baseBranch: 'next',
1476 updateInternalDependencies: 'patch',
1477 ___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
1478 onlyUpdatePeerDependentsWhenOutOfRange: true,
1479 },
1480 ignore: [],
1481 },
1482 null,
1483 2
1484 )
1485 );
1486 writeFileSync(
1487 join(fixtureDir, '.changeset/pre.json'),
1488 JSON.stringify(
1489 {
1490 mode: 'pre',
1491 tag: 'beta',
1492 initialVersions: {
1493 '@composio/core': '0.18.0',
1494 '@composio/openai': '0.12.1',
1495 },
1496 changesets: [],
1497 },
1498 null,
1499 2
1500 )
1501 );
1502 writeFileSync(
1503 join(fixtureDir, '.changeset/core-beta.md'),
1504 ['---', '"@composio/core": major', '---', '', 'Release the core 1.0 beta.', ''].join('\n')
1505 );
1506 writeFileSync(
1507 join(fixtureDir, 'packages/core/package.json'),
1508 JSON.stringify(
1509 {
1510 name: '@composio/core',
1511 version: '0.18.0',
1512 },
1513 null,
1514 2
1515 )
1516 );
1517 writeFileSync(
1518 join(fixtureDir, 'packages/openai/package.json'),
1519 JSON.stringify(
1520 {
1521 name: '@composio/openai',
1522 version: '0.12.1',
1523 peerDependencies: {
1524 '@composio/core': '>=0.10.0 <1.0.0 || >=1.0.0-beta.0 <1.0.0',
1525 },
1526 devDependencies: {
1527 '@composio/core': 'workspace:*',
1528 },
1529 },
1530 null,
1531 2
1532 )
1533 );
1534
1535 const result = spawnSync(changesetBinPath, ['version'], {
1536 cwd: fixtureDir,
1537 encoding: 'utf8',
1538 env: process.env,
1539 });
1540
1541 if (result.status !== 0) {
1542 throw new Error(
1543 `changeset beta peer fixture failed\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
1544 );
1545 }
1546
1547 const coreFixturePackage = JSON.parse(
1548 readFileSync(join(fixtureDir, 'packages/core/package.json'), 'utf8')
1549 );
1550 const providerFixturePackage = JSON.parse(
1551 readFileSync(join(fixtureDir, 'packages/openai/package.json'), 'utf8')
1552 );
1553
1554 if (coreFixturePackage.version !== '1.0.0-beta.0') {
1555 throw new Error(
1556 `fixture core version should be 1.0.0-beta.0, got ${coreFixturePackage.version}`
1557 );
1558 }
1559 if (providerFixturePackage.version !== '0.12.1') {
1560 throw new Error(
1561 `fixture provider should stay at 0.12.1, got ${providerFixturePackage.version}`
1562 );
1563 }
1564 } finally {
1565 rmSync(fixtureDir, { recursive: true, force: true });
1566 }
1567 }
1568
1569 // --- resolve-release-target.sh: executable tests for the release-target branching ---
1570 //
1571 // The script shells out to `gh` and `curl`; we stub both on PATH and feed fixtures, so these
1572 // exercise the real branching/version logic (not just substring presence). `jq`/`python3` stay
1573 // real because the script's correctness depends on them.
1574
1575 const FAKE_GH = `#!/usr/bin/env bash
1576 set -euo pipefail
1577 if [[ "\${1:-}" == "release" && "\${2:-}" == "list" ]]; then
1578 shift 2
1579 jqexpr=""
1580 exclude_drafts=false
1581 limit=""
1582 while [[ \$# -gt 0 ]]; do
1583 if [[ "\$1" == "--exclude-drafts" ]]; then exclude_drafts=true; shift; continue; fi
1584 if [[ "\$1" == "--limit" ]]; then limit="\$2"; shift 2; continue; fi
1585 if [[ "\$1" == "--jq" ]]; then jqexpr="\$2"; shift 2; continue; fi
1586 shift
1587 done
1588 if [[ "\$exclude_drafts" != "true" ]]; then
1589 echo "release list must pass --exclude-drafts" >&2
1590 exit 1
1591 fi
1592 if [[ "\$limit" != "1000" ]]; then
1593 echo "release list must pass --limit 1000" >&2
1594 exit 1
1595 fi
1596 jq -r '[.[] | select(.isDraft != true)] | '"\$jqexpr" "\$GH_RELEASES_FIXTURE"
1597 exit 0
1598 fi
1599 if [[ "\${1:-}" == "release" && "\${2:-}" == "view" ]]; then
1600 # An existing release: echo its isDraft flag. Unset fixture ⇒ exit non-zero (release absent).
1601 if [[ -n "\${GH_VIEW_ISDRAFT:-}" ]]; then
1602 echo "\$GH_VIEW_ISDRAFT"
1603 exit 0
1604 fi
1605 exit 1
1606 fi
1607 echo "unexpected gh invocation: \$*" >&2
1608 exit 1
1609 `;
1610
1611 const FAKE_CURL = `#!/usr/bin/env bash
1612 set -euo pipefail
1613 cat "\$CURL_FIXTURE"
1614 `;
1615
1616 function parseOutputs(text) {
1617 const outputs = {};
1618 for (const line of text.split('\n')) {
1619 const idx = line.indexOf('=');
1620 if (idx === -1) continue;
1621 outputs[line.slice(0, idx)] = line.slice(idx + 1);
1622 }
1623 return outputs;
1624 }
1625
1626 function runResolver({ env, releasesFixture, curlFixture, ghViewIsDraft }) {
1627 const fakeBin = mkdtempSync(join(tmpdir(), 'composio-fakebin-'));
1628 const workdir = mkdtempSync(join(tmpdir(), 'composio-resolver-'));
1629 try {
1630 for (const [name, body] of [
1631 ['gh', FAKE_GH],
1632 ['curl', FAKE_CURL],
1633 ]) {
1634 const p = join(fakeBin, name);
1635 writeFileSync(p, body);
1636 chmodSync(p, 0o755);
1637 }
1638
1639 const outputPath = join(workdir, 'github_output');
1640 writeFileSync(outputPath, '');
1641
1642 const fixtures = {};
1643 if (releasesFixture !== undefined) {
1644 const fixturePath = join(workdir, 'releases.json');
1645 writeFileSync(fixturePath, JSON.stringify(releasesFixture));
1646 fixtures.GH_RELEASES_FIXTURE = fixturePath;
1647 }
1648 if (curlFixture !== undefined) {
1649 const fixturePath = join(workdir, 'curl.json');
1650 writeFileSync(fixturePath, JSON.stringify(curlFixture));
1651 fixtures.CURL_FIXTURE = fixturePath;
1652 }
1653 if (ghViewIsDraft !== undefined) fixtures.GH_VIEW_ISDRAFT = ghViewIsDraft;
1654
1655 const result = spawnSync('bash', [resolveTargetScriptPath], {
1656 encoding: 'utf8',
1657 env: {
1658 ...process.env,
1659 PATH: `${fakeBin}:${process.env.PATH}`,
1660 GITHUB_OUTPUT: outputPath,
1661 ...fixtures,
1662 ...env,
1663 },
1664 });
1665
1666 const output = readFileSync(outputPath, 'utf8');
1667 return { ...result, output, outputs: parseOutputs(output) };
1668 } finally {
1669 rmSync(fakeBin, { recursive: true, force: true });
1670 rmSync(workdir, { recursive: true, force: true });
1671 }
1672 }
1673
1674 // Pushes to next are always betas, regardless of private package metadata.
1675 {
1676 const r = runResolver({
1677 env: {
1678 EVENT_NAME: 'push',
1679 REPOSITORY: 'ComposioHQ/composio',
1680 RUN_NUMBER: '43',
1681 COMMIT_SHA: 'deadbeef',
1682 },
1683 releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
1684 });
1685 if (r.status !== 0) {
1686 throw new Error(`resolve-release-target.sh push failed\nstderr:\n${r.stderr}`);
1687 }
1688 if (r.outputs.release_tag !== '@composio/cli@0.2.34-beta.43') {
1689 throw new Error(`push must produce the next rolling beta, got ${r.outputs.release_tag}`);
1690 }
1691 if (r.outputs.prerelease !== 'true') {
1692 throw new Error('push must never publish a stable release directly');
1693 }
1694 }
1695
1696 // Release owners can choose an intentional minor/major base without changing package.json.
1697 {
1698 const r = runResolver({
1699 env: {
1700 EVENT_NAME: 'workflow_dispatch',
1701 ACTION_INPUT: 'build-beta',
1702 VERSION_INPUT: '0.3.0',
1703 REPOSITORY: 'ComposioHQ/composio',
1704 RUN_NUMBER: '44',
1705 COMMIT_SHA: 'deadbeef',
1706 },
1707 releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
1708 });
1709 if (r.status !== 0) {
1710 throw new Error(`explicitly versioned build-beta failed\nstderr:\n${r.stderr}`);
1711 }
1712 if (r.outputs.release_tag !== '@composio/cli@0.3.0-beta.44') {
1713 throw new Error(`explicit build-beta version was not honored: ${r.outputs.release_tag}`);
1714 }
1715 }
1716
1717 {
1718 const r = runResolver({
1719 env: {
1720 EVENT_NAME: 'workflow_dispatch',
1721 ACTION_INPUT: 'build-beta',
1722 VERSION_INPUT: '0.2.33',
1723 REPOSITORY: 'ComposioHQ/composio',
1724 RUN_NUMBER: '45',
1725 COMMIT_SHA: 'deadbeef',
1726 },
1727 releasesFixture: [{ tagName: '@composio/cli@0.2.33', isPrerelease: false }],
1728 });
1729 if (r.status === 0 || !r.stderr.includes('must be newer than latest stable')) {
1730 throw new Error('build-beta must reject an explicit version at or below latest stable');
1731 }
1732 }
1733
1734 {
1735 const r = runResolver({
1736 env: {
1737 EVENT_NAME: 'workflow_dispatch',
1738 ACTION_INPUT: 'build-beta',
1739 VERSION_INPUT: 'next',
1740 REPOSITORY: 'ComposioHQ/composio',
1741 RUN_NUMBER: '46',
1742 COMMIT_SHA: 'deadbeef',
1743 },
1744 });
1745 if (r.status === 0 || !r.stderr.includes('Beta version must match')) {
1746 throw new Error('build-beta must reject a non-semver explicit version');
1747 }
1748 }
1749
1750 // build-beta bumps off the NUMERIC-latest stable release. The fixture deliberately interleaves
1751 // 0.2.10 and 0.2.9: a lexical sort would pick 0.2.9 and resolve 0.2.10 here — regression lock.
1752 {
1753 const r = runResolver({
1754 env: {
1755 EVENT_NAME: 'workflow_dispatch',
1756 ACTION_INPUT: 'build-beta',
1757 REPOSITORY: 'ComposioHQ/composio',
1758 RUN_NUMBER: '42',
1759 COMMIT_SHA: 'deadbeef',
1760 },
1761 releasesFixture: [
1762 { tagName: '@composio/cli@0.2.2', isPrerelease: false },
1763 { tagName: '@composio/cli@0.2.10', isPrerelease: false },
1764 { tagName: '@composio/cli@0.2.9', isPrerelease: false },
1765 // Draft stables must not become the base for rolling betas.
1766 { tagName: '@composio/cli@0.2.11', isPrerelease: false, isDraft: true },
1767 { tagName: '@composio/cli@0.3.0-beta.1', isPrerelease: true },
1768 ],
1769 });
1770 if (r.status !== 0) {
1771 throw new Error(`resolve-release-target.sh build-beta failed\nstderr:\n${r.stderr}`);
1772 }
1773 if (r.outputs.release_version !== '0.2.11') {
1774 throw new Error(
1775 `build-beta must bump off the numeric-latest stable (0.2.10 → 0.2.11), got release_version=${r.outputs.release_version}. A lexical sort would regress.`
1776 );
1777 }
1778 if (r.outputs.release_tag !== '@composio/cli@0.2.11-beta.42') {
1779 throw new Error(`build-beta release_tag wrong: ${r.outputs.release_tag}`);
1780 }
1781 if (r.outputs.prerelease !== 'true' || r.outputs.make_latest !== 'false') {
1782 throw new Error('build-beta must emit prerelease=true and make_latest=false');
1783 }
1784 }
1785
1786 // promote-stable must run at a beta tag, never accept a release candidate through an input.
1787 {
1788 const r = runResolver({
1789 env: {
1790 EVENT_NAME: 'workflow_dispatch',
1791 ACTION_INPUT: 'promote-stable',
1792 REF_TYPE: 'branch',
1793 REF_NAME: 'next',
1794 GITHUB_TOKEN: 'fake-token',
1795 REPOSITORY: 'ComposioHQ/composio',
1796 RUN_NUMBER: '1',
1797 COMMIT_SHA: 'abc123',
1798 },
1799 });
1800 if (r.status === 0 || !r.stderr.includes('must be dispatched at the beta tag')) {
1801 throw new Error('promote-stable must reject branch-scoped dispatches');
1802 }
1803 }
1804
1805 // promote-stable must REFUSE a tag that is already published (isDraft=false) and emit nothing.
1806 {
1807 const r = runResolver({
1808 env: {
1809 EVENT_NAME: 'workflow_dispatch',
1810 ACTION_INPUT: 'promote-stable',
1811 REF_TYPE: 'tag',
1812 REF_NAME: '@composio/cli@0.3.0-beta.5',
1813 GITHUB_TOKEN: 'fake-token',
1814 REPOSITORY: 'ComposioHQ/composio',
1815 RUN_NUMBER: '1',
1816 COMMIT_SHA: 'abc123',
1817 },
1818 curlFixture: { prerelease: true, target_commitish: 'abc123' },
1819 ghViewIsDraft: 'false',
1820 });
1821 if (r.status === 0) {
1822 throw new Error('promote-stable must refuse an already-published stable tag');
1823 }
1824 if (!r.stderr.includes('already published')) {
1825 throw new Error(`promote-stable refusal must explain itself\nstderr:\n${r.stderr}`);
1826 }
1827 if (r.output.trim() !== '') {
1828 throw new Error('a refused promotion must not emit release outputs');
1829 }
1830 }
1831
1832 // promote-stable happy path: the selected beta tag and release target the same commit.
1833 {
1834 const r = runResolver({
1835 env: {
1836 EVENT_NAME: 'workflow_dispatch',
1837 ACTION_INPUT: 'promote-stable',
1838 REF_TYPE: 'tag',
1839 REF_NAME: '@composio/cli@0.3.0-beta.5',
1840 GITHUB_TOKEN: 'fake-token',
1841 REPOSITORY: 'ComposioHQ/composio',
1842 RUN_NUMBER: '1',
1843 COMMIT_SHA: 'abc123',
1844 },
1845 releasesFixture: [
1846 { tagName: '@composio/cli@0.2.33', isPrerelease: false },
1847 { tagName: '@composio/cli@0.3.0-beta.5', isPrerelease: true },
1848 ],
1849 curlFixture: { prerelease: true, target_commitish: 'abc123' },
1850 // ghViewIsDraft unset ⇒ `gh release view` exits non-zero ⇒ no existing release to refuse.
1851 });
1852 if (r.status !== 0) {
1853 throw new Error(`resolve-release-target.sh promote-stable failed\nstderr:\n${r.stderr}`);
1854 }
1855 if (r.outputs.release_tag !== '@composio/cli@0.3.0' || r.outputs.release_version !== '0.3.0') {
1856 throw new Error(`promote-stable must strip the -beta suffix, got ${r.outputs.release_tag}`);
1857 }
1858 if (r.outputs.prerelease !== 'false' || r.outputs.make_latest !== 'true') {
1859 throw new Error('promote-stable must emit prerelease=false and make_latest=true');
1860 }
1861 if (r.outputs.previous_stable_tag !== '@composio/cli@0.2.33') {
1862 throw new Error('promote-stable must start release notes at the previous published stable tag');
1863 }
1864 if ('checkout_ref' in r.outputs) {
1865 throw new Error('promote-stable must not emit an input-derived checkout ref');
1866 }
1867 }
1868
1869 // A tag/release mismatch must fail before any build can run from the selected commit.
1870 {
1871 const r = runResolver({
1872 env: {
1873 EVENT_NAME: 'workflow_dispatch',
1874 ACTION_INPUT: 'promote-stable',
1875 REF_TYPE: 'tag',
1876 REF_NAME: '@composio/cli@0.3.0-beta.5',
1877 GITHUB_TOKEN: 'fake-token',
1878 REPOSITORY: 'ComposioHQ/composio',
1879 RUN_NUMBER: '1',
1880 COMMIT_SHA: 'selected123',
1881 },
1882 curlFixture: { prerelease: true, target_commitish: 'release456' },
1883 });
1884 if (r.status === 0 || !r.stderr.includes('but its release targets')) {
1885 throw new Error('promote-stable must reject a beta tag/release commit mismatch');
1886 }
1887 }
1888
1889 console.log('release workflow test passed');