Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 84 lines 2.57 KB
Raw
1 import { describe, expect, it } from '@effect/vitest';
2 import { Effect } from 'effect';
3 import { HttpClient, HttpClientResponse } from 'effect/http';
4 import { fetchLatestCliRelease, type GitHubRelease } from 'src/effects/resolve-cli-release';
5
6 const githubConfig = {
7 apiBaseUrl: 'https://api.github.test',
8 owner: 'ComposioHQ',
9 repo: 'composio',
10 };
11
12 const stubHttpClient = (body: unknown) =>
13 HttpClient.make(request =>
14 Effect.succeed(
15 HttpClientResponse.fromWeb(
16 request,
17 new Response(JSON.stringify(body), {
18 status: 200,
19 headers: { 'Content-Type': 'application/json' },
20 })
21 )
22 )
23 );
24
25 const hasRequiredAsset = (release: GitHubRelease) =>
26 release.assets.some(asset => asset.name === 'composio-darwin-arm64');
27
28 describe('fetchLatestCliRelease', () => {
29 it.effect('skips malformed release entries instead of failing resolution', () =>
30 Effect.gen(function* () {
31 const malformedDraft = {
32 tag_name: '@composio/cli@0.3.0',
33 draft: true,
34 assets: [{ name: 'composio-darwin-arm64', browser_download_url: null }],
35 };
36 const wellFormed = {
37 tag_name: '@composio/cli@0.2.9',
38 prerelease: false,
39 assets: [
40 { name: 'composio-darwin-arm64', browser_download_url: 'https://example.test/cli' },
41 ],
42 };
43 const unrelated = { something: 'else entirely' };
44
45 const latest = yield* fetchLatestCliRelease({
46 assetDescription: 'darwin-arm64 binary',
47 channel: 'stable',
48 githubConfig,
49 hasRequiredAsset,
50 httpClient: stubHttpClient([malformedDraft, unrelated, wellFormed]),
51 });
52
53 expect(latest.tag_name).toBe('@composio/cli@0.2.9');
54 })
55 );
56
57 it.effect('still fails with a decode error when the body is not an array', () =>
58 Effect.gen(function* () {
59 const failure = yield* fetchLatestCliRelease({
60 assetDescription: 'darwin-arm64 binary',
61 channel: 'stable',
62 githubConfig,
63 hasRequiredAsset,
64 httpClient: stubHttpClient({ message: 'rate limited' }),
65 }).pipe(Effect.flip);
66
67 expect(failure.reason).toBe('decode');
68 })
69 );
70
71 it.effect('reports not-found when every entry is malformed', () =>
72 Effect.gen(function* () {
73 const failure = yield* fetchLatestCliRelease({
74 assetDescription: 'darwin-arm64 binary',
75 channel: 'stable',
76 githubConfig,
77 hasRequiredAsset,
78 httpClient: stubHttpClient([{ tag_name: '' }, { assets: 'nope' }]),
79 }).pipe(Effect.flip);
80
81 expect(failure.reason).toBe('not-found');
82 })
83 );
84 });