@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 107 lines 4.6 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { Effect, Exit } from 'effect';
3 import { regateRelease, releaseToRegate } from '../scripts/sdk-release/batch';
4 import {
5 APP_SLUG,
6 fakeController,
7 head,
8 merge,
9 type ControllerOptions,
10 } from './sdk-release-controller-fixture';
11 import { json, readText, runRelease } from './sdk-release-harness';
12
13 /** Regate as the workflow runs it: `next` at batch 8's merge commit, dispatched by the requester. */
14 const regate = (fetcher: ReturnType<typeof fakeController>['fetcher'], actor = 'requester') =>
15 runRelease(
16 Effect.exit(
17 Effect.flatMap(releaseToRegate(actor, merge), ({ pull, batch }) =>
18 regateRelease(pull, batch, APP_SLUG)
19 )
20 ),
21 fetcher
22 );
23
24 const pull = 'https://github.com/ComposioHQ/composio/pull/9';
25 const tagged = Exit.succeed({ _tag: 'Tagged', tag: 'sdk-release/8' } as const);
26 const controller = (options: ControllerOptions = {}) => fakeController(options);
27
28 describe('regate', () => {
29 test('accepts an admin requester approval when re-gating a merged release', async () => {
30 const github = controller({ reviewer: 'requester', reviewerPermission: 'admin' });
31 expect(await regate(github.fetcher)).toEqual(tagged);
32 expect(github.writes).toEqual([
33 { method: 'POST', path: '/git/refs', body: { ref: 'refs/tags/sdk-release/8', sha: head } },
34 ]);
35 });
36
37 test('tags the merged, untagged release on next at its reviewed head', async () => {
38 const github = controller();
39 expect(await regate(github.fetcher)).toEqual(tagged);
40 expect(github.writes).toEqual([
41 { method: 'POST', path: '/git/refs', body: { ref: 'refs/tags/sdk-release/8', sha: head } },
42 ]);
43 });
44
45 test('reports Tagged without writing when the tag is already on the reviewed head', async () => {
46 const github = controller({ existingTag: head });
47 expect(await regate(github.fetcher)).toEqual(tagged);
48 expect(github.writes).toEqual([]);
49 });
50
51 test("leaves an already-tagged release alone, even one today's gate would refuse", async () => {
52 const github = controller({ existingTag: head, docs: 'missing' });
53 expect(await regate(github.fetcher)).toEqual(tagged);
54 expect(github.writes).toEqual([]);
55 });
56
57 test('refuses a tag that points at another commit', async () => {
58 const github = controller({ existingTag: merge });
59 expect(String(await regate(github.fetcher))).toContain('already points to another source');
60 expect(github.writes).toEqual([]);
61 });
62
63 test('fails with nothing to re-gate when next carries no release plan', async () => {
64 const github = controller({ noPlanOnNext: true });
65 expect(String(await regate(github.fetcher))).toContain('Nothing to re-gate');
66 expect(github.writes).toEqual([]);
67 });
68
69 test('reports a release PR closed without merging as abandoned', async () => {
70 const github = controller({ closedUnmerged: true });
71 expect(await regate(github.fetcher)).toEqual(Exit.succeed({ _tag: 'Abandoned', pull }));
72 expect(github.writes).toEqual([]);
73 });
74
75 test('refuses a release that fails the gate, exactly as the tag job does', async () => {
76 const github = controller({ oldReview: true });
77 expect(await regate(github.fetcher)).toEqual(
78 Exit.succeed({ _tag: 'Refused', pull, reason: expect.stringContaining('lacks an approval') })
79 );
80 expect(github.writes.map(write => write.path)).toEqual(['/issues/9/comments']);
81 });
82
83 test('requires an active ComposioHQ member', async () => {
84 const github = controller();
85 const outsider: typeof github.fetcher = (input, init) =>
86 new URL(String(input)).pathname === '/orgs/ComposioHQ/memberships/outsider'
87 ? Promise.resolve(json({ message: 'Not Found' }, 404))
88 : github.fetcher(input, init);
89 expect(String(await regate(outsider, 'outsider'))).toContain('(404)');
90 expect(github.writes).toEqual([]);
91 });
92 });
93
94 describe('regate job', () => {
95 test('runs only for a regate dispatch on next, in the tag job concurrency group', async () => {
96 const workflow = Bun.YAML.parse(await readText('.github/workflows/sdk.release.yml')) as {
97 on: { workflow_dispatch: { inputs: { action: { options: string[] } } } };
98 jobs: Record<string, { if?: string; concurrency?: { group: string } }>;
99 };
100 expect(workflow.on.workflow_dispatch.inputs.action.options).toEqual(['request', 'regate']);
101 const { regate, tag, plan } = workflow.jobs;
102 expect(regate.if).toContain("github.ref == 'refs/heads/next'");
103 expect(regate.if).toContain("inputs.action == 'regate'");
104 expect(plan.if).toContain("inputs.action == 'request'");
105 expect(regate.concurrency?.group).toBe(tag.concurrency?.group);
106 });
107 });