58
Effect.runPromise
59
);
60
61
+const runUpgradeSuccess = (configEntries: ReadonlyArray<[string, string]>) =>
62
+ Effect.gen(function* () {
63
+ const service = yield* UpgradeBinary;
64
+ return yield* service.upgrade();
65
+ }).pipe(
66
+ Effect.provide(UpgradeBinary.Default),
67
+ Effect.provide(FetchHttpClient.layer),
68
+ Effect.provide(BunFileSystem.layer),
69
+ Effect.provide(TerminalUINoop),
70
+ Effect.provide(NodeOsTest),
71
+ Effect.withConfigProvider(ConfigProvider.fromMap(new Map(configEntries))),
72
+ Effect.scoped,
73
+ Effect.runPromise
74
+ );
75
+
76
describe('UpgradeBinary', () => {
77
it('wraps non-2xx releases fetch failures with fetch context (no tag branch)', async () => {
78
vi.stubGlobal('Bun', { which: vi.fn(() => null) });
168
vi.restoreAllMocks();
169
}
170
});
171
+
172
+ it('skips newer releases that do not yet contain a binary for the current platform', async () => {
173
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
174
+
175
+ try {
176
+ await withHttpServer(
177
+ (req, res) => {
178
+ if (req.url === '/repos/test-owner/test-repo/releases?per_page=100') {
179
+ res.writeHead(200, { 'content-type': 'application/json' });
180
+ res.end(
181
+ JSON.stringify([
182
+ {
183
+ tag_name: '@composio/cli@9.9.9',
184
+ prerelease: false,
185
+ draft: false,
186
+ assets: [],
187
+ },
188
+ {
189
+ tag_name: '@composio/cli@0.0.1',
190
+ prerelease: false,
191
+ draft: false,
192
+ assets: [],
193
+ },
194
+ ])
195
+ );
196
+ return;
197
+ }
198
+
199
+ res.writeHead(404, { 'content-type': 'application/json' });
200
+ res.end(JSON.stringify({ message: 'not found' }));
201
+ },
202
+ async apiBaseUrl => {
203
+ const result = await runUpgradeSuccess([
204
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
205
+ ['GITHUB_OWNER', 'test-owner'],
206
+ ['GITHUB_REPO', 'test-repo'],
207
+ ]);
208
+
209
+ expect(result).toBeUndefined();
210
+ }
211
+ );
212
+ } finally {
213
+ vi.unstubAllGlobals();
214
+ vi.restoreAllMocks();
215
+ }
216
+ });
217
+
218
+ it('treats an explicitly requested release without binaries as no upgrade', async () => {
219
+ vi.stubGlobal('Bun', { which: vi.fn(() => null) });
220
+
221
+ try {
222
+ await withHttpServer(
223
+ (req, res) => {
224
+ if (
225
+ req.url ===
226
+ `/repos/test-owner/test-repo/releases/tags/${encodeURIComponent('@composio/cli@9.9.9')}`
227
+ ) {
228
+ res.writeHead(200, { 'content-type': 'application/json' });
229
+ res.end(
230
+ JSON.stringify({
231
+ tag_name: '@composio/cli@9.9.9',
232
+ prerelease: false,
233
+ draft: false,
234
+ assets: [],
235
+ })
236
+ );
237
+ return;
238
+ }
239
+
240
+ res.writeHead(404, { 'content-type': 'application/json' });
241
+ res.end(JSON.stringify({ message: 'not found' }));
242
+ },
243
+ async apiBaseUrl => {
244
+ const result = await runUpgradeSuccess([
245
+ ['GITHUB_API_BASE_URL', apiBaseUrl],
246
+ ['GITHUB_OWNER', 'test-owner'],
247
+ ['GITHUB_REPO', 'test-repo'],
248
+ ['GITHUB_TAG', '@composio/cli@9.9.9'],
249
+ ]);
250
+
251
+ expect(result).toBeUndefined();
252
+ }
253
+ );
254
+ } finally {
255
+ vi.unstubAllGlobals();
256
+ vi.restoreAllMocks();
257
+ }
258
+ });
259
});