@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, 04:45 UTC

next
ts 167 lines 5.68 KB
Raw
1 import { Schema } from 'effect';
2 import semver from 'semver';
3 import { describe, expect, it } from 'vitest';
4
5 import {
6 ReleaseManifest,
7 RUN_COMPANION_LEGACY_PLACEHOLDER_RELATIVE_PATHS,
8 RUN_COMPANION_MODULE_FILENAMES,
9 } from '../../../src/services/run-companion-modules';
10 import {
11 archiveCompanionEntries,
12 buildReleaseManifest,
13 MINIMUM_UPGRADE_FROM,
14 serializeReleaseManifest,
15 } from '../../../scripts/_release-artifacts';
16
17 /**
18 * Everything `collectExpectedRunCompanionAssetRelativePaths` yields for a fully
19 * populated companions directory: the wrappers and their bundled services.
20 */
21 const LIVE_COMPANION_RELATIVE_PATHS: ReadonlyArray<string> = [
22 ...RUN_COMPANION_MODULE_FILENAMES,
23 ...RUN_COMPANION_MODULE_FILENAMES.map(fileName => `services/${fileName}`),
24 ].sort();
25
26 const LEGACY_WRAPPERS: ReadonlyArray<string> = [
27 'run-subagent-shared.mjs',
28 'run-subagent-acp.mjs',
29 'run-subagent-legacy.mjs',
30 'run-subagent-output-mcp.mjs',
31 ];
32
33 describe('archiveCompanionEntries', () => {
34 // Every archive gets the same entries, whatever platform its binary targets.
35 const entries = archiveCompanionEntries(LIVE_COMPANION_RELATIVE_PATHS);
36
37 const pathsOfKind = (kind: string): ReadonlyArray<string> =>
38 entries.filter(entry => entry.kind === kind).map(entry => entry.relativePath);
39
40 it('writes each of the ten legacy paths as a placeholder', () => {
41 expect(pathsOfKind('placeholder')).toEqual([
42 'run-subagent-shared.mjs',
43 'run-subagent-acp.mjs',
44 'run-subagent-legacy.mjs',
45 'run-subagent-output-mcp.mjs',
46 'acp-adapters/claude-code-acp.mjs',
47 'acp-adapters/cli.js',
48 'acp-adapters/codex/darwin-arm64/codex-acp',
49 'acp-adapters/codex/darwin-x64/codex-acp',
50 'acp-adapters/codex/linux-arm64/codex-acp',
51 'acp-adapters/codex/linux-x64/codex-acp',
52 ]);
53 });
54
55 it('copies the live companions and their bundles, and nothing else', () => {
56 expect(pathsOfKind('copy')).toEqual([
57 'generation-runtime.mjs',
58 'run-helpers-runtime.mjs',
59 'services/generation-runtime.mjs',
60 'services/run-helpers-runtime.mjs',
61 ]);
62 });
63 });
64
65 /**
66 * An already-released CLI verifies a downloaded upgrade package with its own
67 * path list, by existence only. From 0.2.15 it also follows the relative `.mjs`
68 * imports of each wrapper it requires. The lists below are what each range of
69 * stable releases asks for, spelled out because those binaries no longer change.
70 */
71 describe('upgrade from already-released clients', () => {
72 const entries = archiveCompanionEntries(LIVE_COMPANION_RELATIVE_PATHS);
73 const entryPaths = entries.map(entry => entry.relativePath);
74
75 const clientRanges: ReadonlyArray<{
76 readonly range: string;
77 readonly requiredFor: (host: string) => ReadonlyArray<string>;
78 }> = [
79 {
80 range: '0.2.12 - 0.2.14',
81 requiredFor: () => LEGACY_WRAPPERS,
82 },
83 {
84 range: '0.2.15 - 0.3.3',
85 requiredFor: () => [
86 'run-helpers-runtime.mjs',
87 'services/run-helpers-runtime.mjs',
88 ...LEGACY_WRAPPERS,
89 'acp-adapters/claude-code-acp.mjs',
90 'acp-adapters/cli.js',
91 'acp-adapters/codex/darwin-arm64/codex-acp',
92 'acp-adapters/codex/darwin-x64/codex-acp',
93 'acp-adapters/codex/linux-arm64/codex-acp',
94 'acp-adapters/codex/linux-x64/codex-acp',
95 ],
96 },
97 {
98 range: '0.4.0 - 0.4.2',
99 requiredFor: host => [
100 'run-helpers-runtime.mjs',
101 'services/run-helpers-runtime.mjs',
102 'generation-runtime.mjs',
103 'services/generation-runtime.mjs',
104 ...LEGACY_WRAPPERS,
105 'acp-adapters/claude-code-acp.mjs',
106 'acp-adapters/cli.js',
107 `acp-adapters/codex/${host}/codex-acp`,
108 ],
109 },
110 ];
111
112 const cases = clientRanges.flatMap(({ range, requiredFor }) =>
113 ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64'].map(host => ({
114 range,
115 host,
116 required: requiredFor(host),
117 }))
118 );
119
120 it.each(cases)('a $range client finds every path it requires on $host', ({ required }) => {
121 expect(entryPaths).toEqual(expect.arrayContaining([...required]));
122 });
123 });
124
125 describe('buildReleaseManifest', () => {
126 it('lists exactly the live companions under schema version 1', () => {
127 expect(buildReleaseManifest(LIVE_COMPANION_RELATIVE_PATHS)).toEqual({
128 schemaVersion: 1,
129 minimumUpgradeFrom: MINIMUM_UPGRADE_FROM,
130 companions: [
131 'generation-runtime.mjs',
132 'run-helpers-runtime.mjs',
133 'services/generation-runtime.mjs',
134 'services/run-helpers-runtime.mjs',
135 ],
136 });
137 });
138
139 it('serializes to JSON the CLI decodes back to the same manifest', () => {
140 const manifest = buildReleaseManifest(['run-helpers-runtime.mjs']);
141 const serialized = serializeReleaseManifest(manifest);
142
143 expect(Schema.decodeUnknownSync(ReleaseManifest)(JSON.parse(serialized))).toEqual(manifest);
144 expect(serialized.endsWith('}\n')).toBe(true);
145 });
146
147 it('refuses a companion path the CLI would refuse to install', () => {
148 expect(() => buildReleaseManifest(['../run-helpers-runtime.mjs'])).toThrow();
149 });
150 });
151
152 describe('MINIMUM_UPGRADE_FROM', () => {
153 it('keeps every legacy placeholder in the archive while clients up to 0.4.2 may upgrade', () => {
154 const entryPaths = archiveCompanionEntries(LIVE_COMPANION_RELATIVE_PATHS).map(
155 entry => entry.relativePath
156 );
157 const keepsPlaceholders = RUN_COMPANION_LEGACY_PLACEHOLDER_RELATIVE_PATHS.every(relativePath =>
158 entryPaths.includes(relativePath)
159 );
160
161 expect(semver.gt(MINIMUM_UPGRADE_FROM, '0.4.2') || keepsPlaceholders).toBe(true);
162 });
163
164 it('lets a 0.0.0-beta.0 client upgrade, since no release has dropped a required path yet', () => {
165 expect(semver.gte('0.0.0-beta.0', MINIMUM_UPGRADE_FROM)).toBe(true);
166 });
167 });