@devries-cameron20 / composio Mirror · read-only / commits / ab5c105bc
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, 06:00 UTC

fix(release): keep release status on the right issue and stage

- Only a release plan the App committed names the request issue the status job writes to; a hand-pushed sdk-release/batch-* branch could otherwise make the bot comment on, label or close any issue. - Opening a release PR re-checks the current next, so a release that merged and failed its gate after this one was planned blocks it. - A status comment records the stage that wrote it, so a late or re-run earlier stage never replaces a later result. - A re-run of a dispatched request finds its issue in its own release PR, and outputs a failed job never wrote are read as absent.

jkomyno committed Nov 5, 2026 at 19:33 UTC ab5c105bcdc26470d7724b68fa72b1f705f4e7ef
9 files changed +238 -45
.github/workflows/sdk.release.yml
+1
@@ -71,6 +71,7 @@ jobs:
71 id: plan
72 env:
73 SDK_RELEASE_TOKEN: ${{ steps.app.outputs.token }}
74 + SDK_RELEASE_APP_SLUG: ${{ vars.SDK_RELEASE_APP_SLUG }}
75 run: bun scripts/sdk-release/batch.ts plan
76
77 # Runs the docs generators, which install third-party packages, so it gets no credentials.
scripts/sdk-release/approval.ts
+26 -7
@@ -115,6 +115,31 @@ export const readReleasePull = (number: number) =>
115 return { pull, batch };
116 });
117
118 +/**
119 + * Whether the release PR head is the release App's own verified commit on the planned source. A
120 + * person can sign a commit that names the bot as author, but not one it committed.
121 + */
122 +export const isReleaseAppHead = (pull: Pull, batch: ReleaseBatch, appSlug: string) =>
123 + Effect.map(
124 + request('GET', `${REPOSITORY_PATH}/commits/${pull.head.sha}`, HeadCommit),
125 + head =>
126 + head.author?.login === `${appSlug}[bot]` &&
127 + head.committer?.login === `${appSlug}[bot]` &&
128 + head.commit.verification.verified &&
129 + head.parents.length === 1 &&
130 + head.parents[0].sha === batch.inputBase
131 + );
132 +
133 +/**
134 + * The request issue named by a release PR's plan, only when the release App committed that plan.
135 + * Anyone with write access can push a `sdk-release/batch-*` branch, so its plan cannot pick the
136 + * issue the bot comments on, labels and closes.
137 + */
138 +export const trustedIssue = (pull: Pull, batch: ReleaseBatch, appSlug: string) =>
139 + Effect.map(isReleaseAppHead(pull, batch, appSlug), trusted =>
140 + trusted ? Option.some(batch.issue) : Option.none<number>()
141 + );
142 +
143 /**
144 * The checks a release PR must pass before its head is tagged:
145 * - the head is the release App's own commit on the frozen source, so nobody added changes the
@@ -124,14 +149,8 @@ export const readReleasePull = (number: number) =>
149 */
150 export const verifyReleaseGate = (pull: Pull, batch: ReleaseBatch, appSlug: string) =>
151 Effect.gen(function* () {
127 - const head = yield* request('GET', `${REPOSITORY_PATH}/commits/${pull.head.sha}`, HeadCommit);
152 yield* ensure(
129 - // A person can sign a commit that names the bot as author, but not one it committed.
130 - head.author?.login === `${appSlug}[bot]` &&
131 - head.committer?.login === `${appSlug}[bot]` &&
132 - head.commit.verification.verified &&
133 - head.parents.length === 1 &&
134 - head.parents[0].sha === batch.inputBase,
153 + yield* isReleaseAppHead(pull, batch, appSlug),
154 'The release PR head must be the release App commit on the planned source; request a new release instead of pushing to its branch'
155 );
156 const reviews = yield* reviewsWithPermissions(pull.number);
scripts/sdk-release/batch.ts
+50 -15
@@ -1,6 +1,6 @@
1 import { Config, Effect, Option, Path, Schema, Stdio, Stream } from 'effect';
2 import { Base64 } from 'effect/encoding';
3 -import { readReleasePull, verifyReleaseGate } from './approval';
3 +import { readReleasePull, trustedIssue, verifyReleaseGate } from './approval';
4 import {
5 CONTENT_CONCURRENCY,
6 CreatedSha,
@@ -77,12 +77,20 @@ export interface ReleaseRequestContext {
77 readonly runId: string;
78 readonly sourceSha: string;
79 readonly issueNumber?: number;
80 + /** The release App, whose commits alone may name a request issue. */
81 + readonly appSlug: string;
82 }
83
84 /** A request either ends the request stage or plans a batch for the release PR jobs. */
85 export type RequestOutcome =
86 { readonly _tag: 'Planned'; readonly batch: ReleaseBatch } | ReleaseState;
87
88 +/** The outcome, and the request issue the status job shows it on, when there is one. */
89 +export interface RequestResult {
90 + readonly outcome: RequestOutcome;
91 + readonly issue: Option.Option<number>;
92 +}
93 +
94 /** Opens the tracking issue for a dispatch-started release; issue-form requests already have one. */
95 const createRequestIssue = (run: string) =>
96 Effect.map(
@@ -108,7 +116,10 @@ export const executeReleaseRequest = <E, R>(
116 return yield* parse.pipe(
117 Effect.matchEffect({
118 onFailure: reason =>
111 - Effect.succeed<RequestOutcome>(ReleaseState.make({ _tag: 'NeedsInput', reason })),
119 + Effect.succeed<RequestResult>({
120 + outcome: ReleaseState.make({ _tag: 'NeedsInput', reason }),
121 + issue: Option.fromNullishOr(context.issueNumber),
122 + }),
123 onSuccess: releaseRequest => decideRequest(releaseRequest, context, plan),
124 })
125 );
@@ -120,17 +131,28 @@ const decideRequest = <E, R>(
131 plan: (request: ReleaseRequest) => Effect.Effect<SdkReleasePlan, E, R>
132 ) =>
133 Effect.gen(function* () {
134 + const requestIssue = Option.fromNullishOr(context.issueNumber);
135 + const decided = (outcome: ReleaseState, issue = requestIssue): RequestResult => ({
136 + outcome,
137 + issue,
138 + });
139 const current = yield* activeRelease;
140 + if (Option.isSome(current) && current.value.head.ref === releaseBranch(context.runId)) {
141 + // A re-run of a dispatch has no issue in its event; its release PR's plan names it.
142 + const issue = Option.isSome(requestIssue)
143 + ? requestIssue
144 + : yield* Effect.flatMap(readReleasePull(current.value.number), ({ pull, batch }) =>
145 + trustedIssue(pull, batch, context.appSlug)
146 + );
147 + return decided(ReleaseState.make({ _tag: 'InReview', pull: current.value.html_url }), issue);
148 + }
149 if (Option.isSome(current))
125 - return ReleaseState.make({
126 - _tag: current.value.head.ref === releaseBranch(context.runId) ? 'InReview' : 'Waiting',
127 - pull: current.value.html_url,
128 - });
150 + return decided(ReleaseState.make({ _tag: 'Waiting', pull: current.value.html_url }));
151 const untagged = yield* untaggedRelease(context.sourceSha);
152 if (Option.isSome(untagged))
131 - return ReleaseState.make({ _tag: 'Blocked', release: untagged.value });
153 + return decided(ReleaseState.make({ _tag: 'Blocked', release: untagged.value }));
154 const selected = yield* plan(releaseRequest);
133 - if (!selected.releases.length) return ReleaseState.make({ _tag: 'Empty' });
155 + if (!selected.releases.length) return decided(ReleaseState.make({ _tag: 'Empty' }));
156 const issue = context.issueNumber ?? (yield* createRequestIssue(context.runId));
157 const batch = yield* Schema.decodeUnknownEffect(ReleaseBatch)({
158 id: context.runId,
@@ -145,7 +167,7 @@ const decideRequest = <E, R>(
167 new TextEncoder().encode(JSON.stringify(batch)).length < 120_000,
168 'Release batch is too large to pass between jobs'
169 );
148 - return { _tag: 'Planned', batch } as RequestOutcome;
170 + return { outcome: { _tag: 'Planned', batch }, issue: Option.some(issue) } as RequestResult;
171 });
172
173 // 2. release PR --------------------------------------------------------------------------------
@@ -218,6 +240,11 @@ export const openReleasePull = (cwd: string, planned: ReleaseBatch, value: unkno
240 _tag: current.value.head.ref === releaseBranch(batch.id) ? 'InReview' : 'Waiting',
241 pull: current.value.html_url,
242 });
243 + // Another release may have merged and failed its gate since this one was planned.
244 + const next = yield* request('GET', `${REPOSITORY_PATH}/git/ref/heads/next`, TagRef);
245 + const untagged = yield* untaggedRelease(next.object.sha);
246 + if (Option.isSome(untagged))
247 + return ReleaseState.make({ _tag: 'Blocked', release: untagged.value });
248 const frozen = yield* Effect.forEach(
249 patch.files,
250 file => fileAtOrNull(file.path, batch.inputBase),
@@ -325,6 +352,13 @@ type Mode = (
352 envelope: typeof EventEnvelope.Type
353 ) => Effect.Effect<void, unknown, GitHub | ReleaseServices>;
354
355 +/** Writes the request issue, when known, for the stage's status job. */
356 +const outputIssue = (env: Environment, issue: Option.Option<number>) =>
357 + Option.match(issue, {
358 + onNone: () => Effect.void,
359 + onSome: number => appendFile(env.outputPath, `issue=${number}\n`),
360 + });
361 +
362 /** Writes a stage outcome as a job output for the stage's status job. */
363 const outputState = (env: Environment, state: ReleaseState) =>
364 appendFile(env.outputPath, `state=${JSON.stringify(state)}\n`);
@@ -335,7 +369,8 @@ const MODES: Record<'plan' | 'release-pr' | 'tag', Mode> = {
369 const cwd = (yield* Path.Path).resolve('.');
370 // Known before planning, so a failure is still reported on the request issue.
371 if (envelope.issue) yield* appendFile(env.outputPath, `issue=${envelope.issue.number}\n`);
338 - const outcome = yield* executeReleaseRequest(
372 + const appSlug = yield* Config.String('SDK_RELEASE_APP_SLUG');
373 + const { outcome, issue } = yield* executeReleaseRequest(
374 Effect.try({
375 try: () => parseReleaseRequest(env.eventName, event),
376 catch: error => (error instanceof Error ? error.message : 'Unreadable request'),
@@ -344,16 +379,15 @@ const MODES: Record<'plan' | 'release-pr' | 'tag', Mode> = {
379 actor: envelope.sender.login,
380 runId: env.runId,
381 sourceSha: env.sha,
382 + appSlug,
383 ...(envelope.issue ? { issueNumber: envelope.issue.number } : {}),
384 },
385 choices => createSdkReleasePlan(cwd, choices)
386 );
387 yield* outcome._tag === 'Planned'
352 - ? appendFile(
353 - env.outputPath,
354 - `batch=${JSON.stringify(outcome.batch)}\nissue=${outcome.batch.issue}\n`
355 - )
388 + ? appendFile(env.outputPath, `batch=${JSON.stringify(outcome.batch)}\n`)
389 : outputState(env, outcome);
390 + yield* outputIssue(env, issue);
391 }),
392 'release-pr': (env: Environment) =>
393 Effect.gen(function* () {
@@ -371,7 +405,8 @@ const MODES: Record<'plan' | 'release-pr' | 'tag', Mode> = {
405 if (!envelope.pull_request) return yield* fail('Expected a closed release PR event');
406 const appSlug = yield* Config.String('SDK_RELEASE_APP_SLUG');
407 const { pull, batch } = yield* readReleasePull(envelope.pull_request.number);
374 - yield* appendFile(env.outputPath, `issue=${batch.issue}\n`);
408 + const issue = yield* trustedIssue(pull, batch, appSlug);
409 + yield* outputIssue(env, issue);
410 yield* outputState(env, yield* authorizeSourceTag(pull, batch, appSlug));
411 }),
412 };
scripts/sdk-release/report.ts
+38 -10
@@ -16,7 +16,10 @@ import { DISPLAY, ReleaseState, STATUS_LABELS, Stage, describe, endsStage } from
16
17 /** Status comments come from the workflow token, so nobody else's comment is ever edited. */
18 const STATUS_AUTHOR = 'github-actions[bot]';
19 -const STATUS_MARKER = '<!-- sdk-release-status -->';
19 +const STATUS_MARKER = '<!-- sdk-release-status';
20 +const marker = (stage: Stage) => `${STATUS_MARKER} stage=${stage} -->`;
21 +const MARKED_STAGE = /^<!-- sdk-release-status stage=(request|review|publish) -->/;
22 +const STAGE_ORDER = Stage.literals;
23
24 const IssueComment = Schema.Struct({
25 id: PositiveInt,
@@ -28,12 +31,14 @@ const Written = Schema.Unknown;
31
32 /**
33 * Shows `state` on the request issue: one status comment edited in place, one status label, and
31 - * the issue closed once the release can no longer advance. Nothing here is read back as state.
34 + * the issue closed once the release can no longer advance. The comment records which stage wrote
35 + * it, so a late or re-run earlier stage never replaces a later stage's result; nothing else is
36 + * read back.
37 */
33 -export const showStatus = (issue: number, state: ReleaseState, run: string) =>
38 +export const showStatus = (issue: number, state: ReleaseState, run: string, stage: Stage) =>
39 Effect.gen(function* () {
40 const display = DISPLAY[state._tag];
36 - const body = `${STATUS_MARKER}\n**SDK release: ${display.label.replace('sdk-release:', '')}**\n\n${describe(state)}\n\n<sub>Updated by ${runUrl(run)}</sub>`;
41 + const body = `${marker(stage)}\n**SDK release: ${display.label.replace('sdk-release:', '')}**\n\n${describe(state)}\n\n<sub>Updated by ${runUrl(run)}</sub>`;
42 const issuePath = `${REPOSITORY_PATH}/issues/${issue}`;
43 const existing = yield* paginateArray(`${issuePath}/comments`, IssueComment).pipe(
44 Stream.filter(
@@ -42,6 +47,15 @@ export const showStatus = (issue: number, state: ReleaseState, run: string) =>
47 ),
48 Stream.runHead
49 );
50 + const shown = Option.flatMap(existing, comment =>
51 + Option.fromNullishOr(MARKED_STAGE.exec(comment.body ?? '')?.[1] as Stage | undefined)
52 + );
53 + const later = Option.filter(
54 + shown,
55 + shownStage => STAGE_ORDER.indexOf(shownStage) > STAGE_ORDER.indexOf(stage)
56 + );
57 + if (Option.isSome(later))
58 + return yield* Console.log(`The ${later.value} stage already reported; keeping its status`);
59 yield* Option.match(existing, {
60 onSome: comment =>
61 request('PATCH', `${REPOSITORY_PATH}/issues/comments/${comment.id}`, Written, { body }),
@@ -94,13 +108,20 @@ const publishedState = (batch: ReleaseBatch) =>
108 })),
109 });
110
97 -const StatusEnvironment = Config.all({
111 +/**
112 + * A job output the status job reads. GitHub passes an output that a failed or skipped job never
113 + * wrote as an empty string, so empty means absent.
114 + */
115 +export const jobOutput = <A, E>(decode: (text: string) => Effect.Effect<A, E>, text: string) =>
116 + text === '' ? Effect.succeedNone : Effect.asSome(decode(text));
117 +
118 +export const StatusEnvironment = Config.all({
119 token: Config.schema(Schema.NonEmptyString, 'GITHUB_TOKEN'),
120 runId: Config.schema(RunId, 'GITHUB_RUN_ID'),
121 summaryPath: Config.String('GITHUB_STEP_SUMMARY'),
122 results: Config.schema(Schema.fromJsonString(Results), 'RESULTS'),
102 - recorded: Config.option(Config.schema(Schema.fromJsonString(ReleaseState), 'OUTCOME')),
103 - issue: Config.option(Config.schema(Schema.NumberFromString.check(Schema.isInt()), 'ISSUE')),
123 + outcome: Config.String('OUTCOME').pipe(Config.withDefault('')),
124 + issue: Config.String('ISSUE').pipe(Config.withDefault('')),
125 });
126
127 /**
@@ -110,18 +131,25 @@ const StatusEnvironment = Config.all({
131 const statusMode = (stage: Stage) =>
132 Effect.gen(function* () {
133 const env = yield* StatusEnvironment;
134 + const issue = yield* jobOutput(
135 + Schema.decodeUnknownEffect(Schema.NumberFromString.check(Schema.isInt())),
136 + env.issue
137 + );
138 const state = yield* stageOutcome(
139 stage,
140 env.results,
116 - env.recorded,
141 + yield* jobOutput(
142 + Schema.decodeUnknownEffect(Schema.fromJsonString(ReleaseState)),
143 + env.outcome
144 + ),
145 Effect.map(readJson(ReleaseBatch, BATCH_PATH), publishedState),
146 env.runId
147 );
148 yield* appendFile(env.summaryPath, `${describe(state)}\n`);
121 - yield* Option.match(env.issue, {
149 + yield* Option.match(issue, {
150 onNone: () => Console.log('No request issue to update'),
151 onSome: issue =>
124 - showStatus(issue, state, env.runId).pipe(Effect.provide(GitHub.layer(env.token))),
152 + showStatus(issue, state, env.runId, stage).pipe(Effect.provide(GitHub.layer(env.token))),
153 });
154 });
155
test/sdk-release-approval.test.ts
+17 -2
@@ -1,6 +1,6 @@
1 import { describe, expect, test } from 'bun:test';
2 -import { Effect } from 'effect';
3 -import { eligibleApproval, readReleasePull } from '../scripts/sdk-release/approval';
2 +import { Effect, Option } from 'effect';
3 +import { eligibleApproval, readReleasePull, trustedIssue } from '../scripts/sdk-release/approval';
4 import { authorizeSourceTag } from '../scripts/sdk-release/batch';
5 import {
6 APP_SLUG,
@@ -90,6 +90,21 @@ describe('source tag', () => {
90 expect(writes).toEqual([tagWrite]);
91 });
92
93 + test("only the release App's plan may name the request issue the status job writes to", async () => {
94 + const issueOf = (options: Parameters<typeof fakeController>[0]) => {
95 + const { fetcher } = fakeController(options);
96 + return runRelease(
97 + Effect.flatMap(readReleasePull(9), ({ pull, batch }) =>
98 + trustedIssue(pull, batch, APP_SLUG)
99 + ),
100 + fetcher
101 + );
102 + };
103 + expect(await issueOf({})).toEqual(Option.some(8));
104 + expect(await issueOf({ closedUnmerged: true, headAuthor: 'writer' })).toEqual(Option.none());
105 + expect(await issueOf({ headCommitter: 'writer' })).toEqual(Option.none());
106 + });
107 +
108 test('a release PR closed without merging is abandoned and creates no tag', async () => {
109 const { fetcher, writes } = fakeController({ closedUnmerged: true });
110 expect(await tag(fetcher)).toEqual({ _tag: 'Abandoned', pull });
test/sdk-release-batch.test.ts
+24 -1
@@ -1,5 +1,6 @@
1 import { describe, expect, test } from 'bun:test';
2 -import { openReleasePull } from '../scripts/sdk-release/batch';
2 +import { Effect, Option } from 'effect';
3 +import { executeReleaseRequest, openReleasePull } from '../scripts/sdk-release/batch';
4 import { BATCH_PATH, validateReleaseDiff, type ReleaseFile } from '../scripts/sdk-release/source';
5 import {
6 base,
@@ -93,6 +94,28 @@ describe('release PR', () => {
94 expect(writes).toEqual([]);
95 });
96
97 + test('a re-run of a dispatched request finds its issue in its own release PR', async () => {
98 + const { fetcher } = fakeController({ openRelease: 'sdk-release/batch-8' });
99 + const result = await runRelease(
100 + executeReleaseRequest(
101 + Effect.succeed({ channel: 'stable', typescript: 'auto', python: 'skip' }),
102 + { actor: 'requester', runId: '8', sourceSha: base, appSlug: 'sdk-release-app' },
103 + () => Effect.die('must not plan')
104 + ),
105 + fetcher
106 + );
107 + expect(result).toEqual({
108 + outcome: { _tag: 'InReview', pull: 'https://github.com/ComposioHQ/composio/pull/5' },
109 + issue: Option.some(8),
110 + });
111 + });
112 +
113 + test('a release that merged and failed its gate since planning blocks this one', async () => {
114 + const { fetcher, writes } = fakeController({ untaggedNext: true });
115 + expect(await open(fetcher)).toEqual({ _tag: 'Blocked', release: '8' });
116 + expect(writes).toEqual([]);
117 + });
118 +
119 test('another open release PR opens nothing and the request waits for it', async () => {
120 const { fetcher, writes } = fakeController({ openRelease: 'sdk-release/batch-7' });
121 expect(await open(fetcher)).toEqual({
test/sdk-release-controller-fixture.ts
+6 -1
@@ -50,6 +50,8 @@ export const releaseFiles = [
50 ];
51
52 export interface ControllerOptions {
53 + /** `next` carries batch 8's plan without its tag: a release merged and failed its gate. */
54 + readonly untaggedNext?: boolean;
55 readonly deletedReviewer?: boolean;
56 readonly oldReview?: boolean;
57 readonly reviewer?: string;
@@ -105,6 +107,7 @@ export function fakeController(options: ControllerOptions = {}) {
107 if (/^\/issues\/\d+\/comments$/.test(path)) return response({ id: 1 });
108 throw new Error(`Unexpected write ${method} ${path}`);
109 }
110 + if (path === '/orgs/ComposioHQ/memberships/requester') return response({ state: 'active' });
111 if (path.startsWith('/pulls?'))
112 return response(
113 options.openRelease
@@ -121,7 +124,7 @@ export function fakeController(options: ControllerOptions = {}) {
124 ]
125 : []
126 );
124 - if (path === '/pulls/9') return response(pull());
127 + if (path === '/pulls/9' || path === '/pulls/5') return response(pull());
128 if (path.startsWith('/pulls/9/reviews'))
129 return response([
130 ...(options.deletedReviewer ? [{ user: null, state: 'APPROVED', commit_id: head }] : []),
@@ -173,6 +176,8 @@ export function fakeController(options: ControllerOptions = {}) {
176 if (data == null) return response({}, 404);
177 return new Response(data);
178 }
179 + if (path === '/git/ref/heads/next')
180 + return response({ object: { type: 'commit', sha: options.untaggedNext ? head : base } });
181 if (path === '/git/ref/heads/sdk-release/batch-8')
182 return options.existingBranch
183 ? response({ ref: 'refs/heads/sdk-release/batch-8' })
test/sdk-release-request.test.ts
+30 -3
@@ -1,12 +1,18 @@
1 import { describe, expect, test } from 'bun:test';
2 -import { Effect } from 'effect';
2 +import { Effect, Option } from 'effect';
3 import { executeReleaseRequest, type ReleaseRequestContext } from '../scripts/sdk-release/batch';
4 import type { SdkReleasePlan } from '../scripts/sdk-release/plan';
5 import { parseReleaseRequest, type ReleaseRequest } from '../scripts/sdk-release/request';
6 import { runRelease, type Fetch } from './sdk-release-harness';
7
8 const sha = 'a'.repeat(40);
9 -const context = { actor: 'member', runId: '21', sourceSha: sha, issueNumber: 7 };
9 +const context = {
10 + actor: 'member',
11 + runId: '21',
12 + sourceSha: sha,
13 + issueNumber: 7,
14 + appSlug: 'sdk-release-app',
15 +};
16 const plan: SdkReleasePlan = {
17 schemaVersion: 1,
18 inputFingerprint: 'frozen',
@@ -36,7 +42,11 @@ const execute = (
42 requestContext: ReleaseRequestContext,
43 plan: () => Effect.Effect<SdkReleasePlan>,
44 parse: Effect.Effect<ReleaseRequest, string> = Effect.succeed(request)
39 -) => runRelease(executeReleaseRequest(parse, requestContext, plan), fetch);
45 +) =>
46 + runRelease(
47 + Effect.map(executeReleaseRequest(parse, requestContext, plan), result => result.outcome),
48 + fetch
49 + );
50
51 const openRelease = {
52 number: 9,
@@ -190,6 +200,23 @@ describe('SDK release member request', () => {
200 expect(writes()).toEqual([]);
201 });
202
203 + test('the request issue travels with every outcome, so the status job can show it', async () => {
204 + const waiting = client({ open: 'sdk-release/batch-8' });
205 + const result = await runRelease(
206 + executeReleaseRequest(Effect.succeed(request), context, failing('must not plan')),
207 + waiting.fetcher
208 + );
209 + expect(result.issue).toEqual(Option.some(7));
210 + const dispatched = client();
211 + const planned = await runRelease(
212 + executeReleaseRequest(Effect.succeed(request), { ...context, issueNumber: undefined }, () =>
213 + Effect.succeed(plan)
214 + ),
215 + dispatched.fetcher
216 + );
217 + expect(planned.issue).toEqual(Option.some(31));
218 + });
219 +
220 test('a dispatch-started release opens its tracking issue', async () => {
221 const { fetcher, writes } = client();
222 const outcome = await execute(fetcher, { ...context, issueNumber: undefined }, planned(plan));
test/sdk-release-state.test.ts
+46 -6
@@ -1,4 +1,4 @@
1 -import { describe, expect, test } from 'bun:test';
1 +import { afterEach, describe, expect, test } from 'bun:test';
2 import { Effect, Option } from 'effect';
3 import { showStatus, stageOutcome } from '../scripts/sdk-release/report';
4 import {
@@ -9,7 +9,18 @@ import {
9 type Stage,
10 type StateName,
11 } from '../scripts/sdk-release/state';
12 -import { runRelease, type Fetch } from './sdk-release-harness';
12 +import { spawn } from '../scripts/sdk-release/runtime';
13 +import {
14 + readText,
15 + resolvePath,
16 + runRelease,
17 + temporaryDirectories,
18 + writeText,
19 + type Fetch,
20 +} from './sdk-release-harness';
21 +
22 +const roots = temporaryDirectories('sdk-release-status-');
23 +afterEach(() => roots.cleanup());
24
25 const pull = 'https://github.com/ComposioHQ/composio/pull/9';
26 const run = '77';
@@ -161,12 +172,12 @@ function requestIssue(comments: { id: number; login: string; body: string }[] =
172 describe('status on the request issue', () => {
173 test('one status comment and one label follow the release, and a final state closes it', async () => {
174 const issue = requestIssue();
164 - await runRelease(showStatus(8, EXAMPLES.InReview, run), issue.fetcher);
175 + await runRelease(showStatus(8, EXAMPLES.InReview, run, 'request'), issue.fetcher);
176 expect(issue.comments).toHaveLength(1);
177 expect([...issue.labels]).toEqual(['SDK release', 'sdk-release:in-review']);
178 expect(issue.state()).toBe('open');
179
169 - await runRelease(showStatus(8, EXAMPLES.Published, run), issue.fetcher);
180 + await runRelease(showStatus(8, EXAMPLES.Published, run, 'publish'), issue.fetcher);
181 expect(issue.comments).toHaveLength(1);
182 expect(issue.comments[0].body).toContain('`@composio/core` 1.0.1');
183 expect([...issue.labels]).toEqual(['SDK release', 'sdk-release:published']);
@@ -175,11 +186,40 @@ describe('status on the request issue', () => {
186
187 test('a comment that copies the status marker is never edited unless the workflow wrote it', async () => {
188 const issue = requestIssue([
178 - { id: 1, login: 'someone', body: '<!-- sdk-release-status -->\nfake status' },
189 + { id: 1, login: 'someone', body: '<!-- sdk-release-status stage=publish -->\nfake status' },
190 ]);
180 - await runRelease(showStatus(8, EXAMPLES.Waiting, run), issue.fetcher);
191 + await runRelease(showStatus(8, EXAMPLES.Waiting, run, 'request'), issue.fetcher);
192 expect(issue.comments[0].body).toContain('fake status');
193 expect(issue.comments).toHaveLength(2);
194 expect(issue.writes).toContain('POST /issues/8/comments');
195 });
196 +
197 + test('a late or re-run earlier stage never replaces a later stage result', async () => {
198 + const issue = requestIssue();
199 + await runRelease(showStatus(8, EXAMPLES.Published, run, 'publish'), issue.fetcher);
200 + const published = issue.comments[0].body;
201 + await runRelease(showStatus(8, EXAMPLES.Tagged, run, 'review'), issue.fetcher);
202 + expect(issue.comments).toEqual([expect.objectContaining({ body: published })]);
203 + expect([...issue.labels]).toEqual(['SDK release', 'sdk-release:published']);
204 + });
205 +});
206 +
207 +/** The status job as the workflow runs it, with the job outputs GitHub passes. */
208 +const statusRun = async (env: Record<string, string>) => {
209 + const directory = await roots.create();
210 + const summary = `${directory}/summary`;
211 + await writeText(summary, '');
212 + const result = await runRelease(
213 + spawn('bun', [await resolvePath('scripts/sdk-release/report.ts'), 'status', 'request'], {
214 + cwd: directory,
215 + env: { GITHUB_TOKEN: 'fixture', GITHUB_RUN_ID: '77', GITHUB_STEP_SUMMARY: summary, ...env },
216 + })
217 + );
218 + return { exitCode: result.exitCode, stderr: result.stderr, summary: await readText(summary) };
219 +};
220 +
221 +test('outputs a failed job never wrote arrive empty, and the status still records the failure', async () => {
222 + const run = await statusRun({ RESULTS: '{"plan": "failure"}', OUTCOME: '', ISSUE: '' });
223 + expect({ exitCode: run.exitCode, stderr: run.stderr }).toMatchObject({ exitCode: 0 });
224 + expect(run.summary).toContain('The request stage failed in: plan.');
225 });