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 302 lines 11.4 KB
Raw
1 import { BATCH_PATH, type ReleaseBatch } from '../scripts/sdk-release/source';
2 import type { Fetch } from './sdk-release-harness';
3
4 export const base = 'a'.repeat(40);
5 export const head = 'b'.repeat(40);
6 export const merge = 'c'.repeat(40);
7 export const APP_SLUG = 'sdk-release-app';
8
9 /** Keys follow the schema order, as a decoded batch does, so the committed plan compares equal. */
10 export const batch: ReleaseBatch = {
11 id: '8',
12 inputBase: base,
13 requestedBy: 'requester',
14 issue: 8,
15 date: '2026-11-03',
16 plan: {
17 schemaVersion: 1,
18 inputFingerprint: 'frozen',
19 choices: { typescript: 'auto', python: 'skip', channel: 'stable' },
20 recommended: [],
21 releases: [
22 {
23 name: '@composio/core',
24 type: 'patch',
25 oldVersion: '1.0.0',
26 newVersion: '1.0.1',
27 changesets: [],
28 language: 'typescript',
29 },
30 ],
31 changesets: [],
32 retainedChangesets: [],
33 },
34 };
35 /** Batch 8 as a beta: same request and source, snapshot versions, and nothing consumed. */
36 export const betaBatch: ReleaseBatch = {
37 ...batch,
38 plan: {
39 ...batch.plan,
40 choices: { ...batch.plan.choices, channel: 'beta', run: '8' },
41 releases: batch.plan.releases.map(release => ({
42 ...release,
43 newVersion: `${release.newVersion}-beta.8`,
44 })),
45 },
46 };
47 /** The only file a beta release PR commits. */
48 export const betaFiles = [{ path: BATCH_PATH, before: null, after: JSON.stringify(betaBatch) }];
49 export const oldManifest = JSON.stringify({
50 name: '@composio/core',
51 version: '1.0.0',
52 dependencies: { client: '1.0.0' },
53 });
54 export const newManifest = JSON.stringify({
55 name: '@composio/core',
56 version: '1.0.1',
57 dependencies: { client: '1.0.0' },
58 });
59 /** The release-only files batch 8 prepares: its plan, the core version and the docs changelog. */
60 export const releaseFiles = [
61 { path: BATCH_PATH, before: null, after: JSON.stringify(batch) },
62 { path: 'ts/packages/core/package.json', before: oldManifest, after: newManifest },
63 { path: 'docs/content/changelog/11-03-26-sdk-8.mdx', before: null, after: 'Release notes' },
64 ];
65
66 export interface ControllerOptions {
67 /** `next` carries batch 8's plan without its tag: a release merged and failed its gate. */
68 readonly untaggedNext?: boolean;
69 /** `next` at the merge commit carries no release plan. */
70 readonly noPlanOnNext?: boolean;
71 /** Serve batch 8 as a beta release PR. */
72 readonly beta?: boolean;
73 readonly deletedReviewer?: boolean;
74 readonly oldReview?: boolean;
75 readonly reviewer?: string;
76 readonly reviewerPermission?: string;
77 readonly mergeKind?: 'squash' | 'merge';
78 readonly existingTag?: string;
79 readonly failedCandidate?: boolean;
80 readonly failedSmoke?: boolean;
81 /** A re-run of this check failed after its first run succeeded. */
82 readonly rerunFailed?: string;
83 readonly closedUnmerged?: boolean;
84 readonly existingBranch?: boolean;
85 /** Head branch of a release PR that is already open into next. */
86 readonly openRelease?: string;
87 /** The `SDK candidate docs` check on the head. */
88 readonly docs?: 'success' | 'failure' | 'pending' | 'missing';
89 /** Who authored the release PR head; the release App by default. */
90 readonly headAuthor?: string;
91 /** Who last moved the release branch; the release App by default. */
92 readonly branchSetter?: string;
93 readonly unverifiedHead?: boolean;
94 /** Parent of the release PR head; the planned source by default. */
95 readonly headParent?: string;
96 }
97
98 /** A fake GitHub API for release PR #9 of batch 8 that records every write. */
99 export function fakeController(options: ControllerOptions = {}) {
100 const writes: { method: string; path: string; body: unknown }[] = [];
101 const merged = !options.closedUnmerged;
102 /** A pull as list endpoints return it: GitHub sends `merged` only on the detail endpoint. */
103 const listedPull = () => ({
104 number: 9,
105 html_url: 'https://github.com/ComposioHQ/composio/pull/9',
106 state: 'closed',
107 user: { login: `${APP_SLUG}[bot]` },
108 head: { sha: head, ref: 'sdk-release/batch-8', repo: { full_name: 'ComposioHQ/composio' } },
109 base: { ref: 'next' },
110 });
111 const pull = () => ({ ...listedPull(), merged });
112 /** GitHub numbers check runs in creation order, so a re-run has a higher `id`. */
113 const check = (name: string, conclusion: string | null, id = 1) => ({
114 id,
115 name,
116 head_sha: head,
117 app: { slug: 'github-actions' },
118 conclusion,
119 });
120 const fetcher: Fetch = async (input, init) => {
121 const url = new URL(String(input));
122 const path = url.pathname.replace('/repos/ComposioHQ/composio', '') + url.search;
123 const method = init?.method ?? 'GET';
124 const response = (data: unknown, status = 200) =>
125 new Response(JSON.stringify(data), { status });
126 if (method !== 'GET') {
127 writes.push({ method, path, body: JSON.parse(String(init?.body)) });
128 if (/^\/git\/(blobs|trees|commits)$/.test(path)) return response({ sha: 'e'.repeat(40) });
129 if (path.startsWith('/git/refs')) return response({ ref: 'refs/heads/sdk-release/batch-8' });
130 if (path === '/pulls') return response({ ...pull(), state: 'open', merged: false });
131 if (/^\/issues\/\d+\/comments$/.test(path)) return response({ id: 1 });
132 throw new Error(`Unexpected write ${method} ${path}`);
133 }
134 if (path === '/orgs/ComposioHQ/memberships/requester') return response({ state: 'active' });
135 // The closed release PRs from batch 8's branch, as a regate looks them up.
136 if (path.startsWith('/pulls?state=closed&')) return response([listedPull()]);
137 if (path.startsWith('/pulls?'))
138 return response(
139 options.openRelease
140 ? [
141 {
142 ...listedPull(),
143 number: 5,
144 html_url: 'https://github.com/ComposioHQ/composio/pull/5',
145 state: 'open',
146 head: { ...listedPull().head, ref: options.openRelease },
147 },
148 ]
149 : []
150 );
151 if (path === '/pulls/9' || path === '/pulls/5') return response(pull());
152 if (path.startsWith('/pulls/9/reviews'))
153 return response([
154 ...(options.deletedReviewer ? [{ user: null, state: 'APPROVED', commit_id: head }] : []),
155 {
156 user: { login: options.reviewer ?? 'reviewer' },
157 state: 'APPROVED',
158 commit_id: options.oldReview ? base : head,
159 },
160 ]);
161 if (path === `/collaborators/${options.reviewer ?? 'reviewer'}/permission`)
162 return response({ permission: options.reviewerPermission ?? 'write' });
163 if (path.startsWith(`/commits/${head}/check-runs`))
164 return response({
165 check_runs: [
166 check('SDK candidate (typescript)', options.failedCandidate ? 'failure' : 'success'),
167 check('SDK candidate smoke (typescript)', options.failedSmoke ? 'failure' : 'success'),
168 ...(options.docs === 'missing'
169 ? []
170 : [
171 check(
172 'SDK candidate docs',
173 options.docs === 'pending' ? null : (options.docs ?? 'success')
174 ),
175 ]),
176 ...(options.rerunFailed ? [check(options.rerunFailed, 'failure', 2)] : []),
177 ],
178 });
179 if (path === `/commits/${head}`)
180 return response({
181 author: { login: options.headAuthor ?? `${APP_SLUG}[bot]` },
182 // GitHub commits and signs every commit made through its API.
183 committer: { login: 'web-flow' },
184 commit: { verification: { verified: !options.unverifiedHead } },
185 parents: [{ sha: options.headParent ?? base }],
186 });
187 if (path.startsWith('/activity?ref=refs%2Fheads%2Fsdk-release%2Fbatch-8&'))
188 return response([
189 { after: '0'.repeat(40), actor: { login: 'merger' } },
190 { after: head, actor: { login: options.branchSetter ?? `${APP_SLUG}[bot]` } },
191 ]);
192 if (path.startsWith('/issues/9/events?'))
193 return response(
194 merged
195 ? [
196 { event: 'merged', commit_id: merge },
197 { event: 'closed', commit_id: null },
198 ]
199 : [{ event: 'closed', commit_id: null }]
200 );
201 if (path === `/git/commits/${base}`)
202 return response({ sha: base, tree: { sha: base }, parents: [] });
203 if (path === `/git/commits/${merge}`)
204 return response({
205 sha: merge,
206 tree: { sha: merge },
207 parents:
208 options.mergeKind === 'merge'
209 ? [{ sha: 'd'.repeat(40) }, { sha: head }]
210 : [{ sha: 'd'.repeat(40) }],
211 });
212 if (path.startsWith('/contents/')) {
213 if (options.noPlanOnNext && url.searchParams.get('ref') === merge) return response({}, 404);
214 const filename = url.pathname.split('/contents/')[1];
215 const file = (options.beta ? betaFiles : releaseFiles).find(file => file.path === filename);
216 const data = url.searchParams.get('ref') === base ? file?.before : file?.after;
217 if (data == null) return response({}, 404);
218 return new Response(data);
219 }
220 if (path === '/git/ref/heads/next')
221 return response({ object: { type: 'commit', sha: options.untaggedNext ? head : base } });
222 if (path === '/git/ref/heads/sdk-release/batch-8')
223 return options.existingBranch
224 ? response({ ref: 'refs/heads/sdk-release/batch-8' })
225 : response({}, 404);
226 if (path === '/git/ref/tags/sdk-release/8')
227 return options.existingTag
228 ? response({ object: { type: 'commit', sha: options.existingTag } })
229 : response({}, 404);
230 throw new Error(`Unexpected read ${path}`);
231 };
232 return { fetcher, writes };
233 }
234
235 /**
236 * The reads a tag run makes to pin release-PR run 41's candidate for batch 8, keyed by path
237 * suffix. `digest` is the uploaded archive's digest.
238 */
239 export const candidateRoutes = (
240 digest: string,
241 options: { expired?: boolean; headAuthor?: string } = {}
242 ) => {
243 const app = 'sdk-release-app[bot]';
244 return {
245 [`/commits/${head}`]: {
246 author: { login: options.headAuthor ?? app },
247 committer: { login: 'web-flow' },
248 commit: { verification: { verified: true } },
249 parents: [{ sha: batch.inputBase }],
250 },
251 '/activity': [{ after: head, actor: { login: app } }],
252 '/actions/workflows/sdk.release.candidates.yml/runs': {
253 workflow_runs: [
254 {
255 id: 41,
256 path: '.github/workflows/sdk.release.candidates.yml',
257 head_branch: 'sdk-release/batch-8',
258 head_sha: head,
259 event: 'pull_request',
260 repository: { full_name: 'ComposioHQ/composio' },
261 status: 'completed',
262 conclusion: 'success',
263 created_at: '2026-11-03T00:00:00Z',
264 run_attempt: 1,
265 html_url: 'https://github.com/ComposioHQ/composio/actions/runs/41',
266 },
267 ],
268 },
269 '/actions/runs/41/jobs': {
270 jobs: [
271 {
272 name: 'SDK candidate (typescript)',
273 status: 'completed',
274 conclusion: 'success',
275 started_at: '2026-11-03T00:01:00Z',
276 completed_at: '2026-11-03T00:10:00Z',
277 steps: [
278 {
279 name: 'Retain candidate bytes for publication',
280 conclusion: 'success',
281 started_at: '2026-11-03T00:04:00Z',
282 completed_at: '2026-11-03T00:06:00Z',
283 },
284 ],
285 },
286 ],
287 },
288 '/actions/runs/41/artifacts': {
289 artifacts: [
290 {
291 id: 77,
292 name: 'sdk-candidate-typescript',
293 digest: digest,
294 expired: options.expired ?? false,
295 created_at: '2026-11-03T00:05:00Z',
296 expires_at: '2099-12-01T00:00:00Z',
297 workflow_run: { id: 41, head_sha: head },
298 },
299 ],
300 },
301 };
302 };