@devries-cameron20 / composio Mirror · read-only / commits / 3b1329d30
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

feat(release): verify releases end to end

A rehearsal test runs the production handlers through every stage for a stable and a beta release: the request plans the batch, the release PR opens, the merged PR is tagged, and the reviewed tarball reaches a fake npm registry through a fake npm CLI. It checks that a re-run uploads nothing, that a beta never reads or moves latest, and that every state a stage can end in is reached by a handler. After publishing, the release now checks what users get. Each npm tarball's SLSA provenance must name sdk.release.yml at this batch's tag and describe the reviewed bytes, and npm audit signatures runs on a fresh install. Each PyPI file's attestation must come from sdk.release.yml in pypi-release, and pypi-attestations verifies its signature. A new SDK release lint workflow runs pinned actionlint and zizmor on the release workflows. The template injections zizmor found are fixed, and the two accepted findings are suppressed inline with their reasons.

jkomyno committed Nov 5, 2026 at 19:06 UTC 3b1329d30c69b6023fdf2686a9cf49b658b6110a
6 files changed +587 -22
.github/workflows/sdk.release.candidates.yml
+7 -3
@@ -63,7 +63,8 @@ jobs:
63 - name: Build and check the candidate
64 env:
65 SDK_SOURCE_SHA: ${{ github.event.pull_request.head.sha }}
66 - run: bun scripts/sdk-release/candidates.ts ${{ matrix.language }}
66 + LANGUAGE: ${{ matrix.language }}
67 + run: bun scripts/sdk-release/candidates.ts "$LANGUAGE"
68 - name: Retain candidate bytes for publication
69 id: upload
70 uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
@@ -79,7 +80,8 @@ jobs:
80 ARTIFACT_DIGEST: ${{ steps.upload.outputs.artifact-digest }}
81 SOURCE_SHA: ${{ github.event.pull_request.head.sha }}
82 SDK_READ_TOKEN: ${{ github.token }}
82 - run: bun scripts/sdk-release/candidates.ts report ${{ matrix.language }}
83 + LANGUAGE: ${{ matrix.language }}
84 + run: bun scripts/sdk-release/candidates.ts report "$LANGUAGE"
85
86 # Installs third-party packages from the registries, so it runs apart from the build job and
87 # has no upload step. Code it runs still holds this run's runtime token, so the tag run refuses
@@ -113,4 +115,6 @@ jobs:
115 name: sdk-candidate-${{ matrix.language }}
116 path: sdk-candidate/${{ matrix.language }}
117 - name: Install and import the candidate like a user
116 - run: bun scripts/sdk-release/consumers.ts sdk-candidate/${{ matrix.language }}
118 + env:
119 + LANGUAGE: ${{ matrix.language }}
120 + run: bun scripts/sdk-release/consumers.ts "sdk-candidate/$LANGUAGE"
.github/workflows/sdk.release.lint.yml new
+37
@@ -0,0 +1,37 @@
1 +name: SDK release lint
2 +
3 +# Checks the release workflows before they can run: actionlint for syntax, expressions and
4 +# shell, and zizmor for security problems such as template injection, unpinned actions and
5 +# dangerous triggers. Each accepted zizmor finding is suppressed inline with its reason.
6 +on:
7 + pull_request:
8 + paths:
9 + - '.github/workflows/sdk.release*.yml'
10 + - '.github/ISSUE_TEMPLATE/sdk-release.yml'
11 + - '.github/actions/**'
12 +
13 +permissions:
14 + contents: read
15 +
16 +jobs:
17 + workflows:
18 + runs-on: ubuntu-latest
19 + steps:
20 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
21 + with:
22 + persist-credentials: false
23 + - uses: ./.github/actions/setup-python-uv
24 + with:
25 + enable-caching: 'false'
26 + # actionlint 1.7.12 predates the concurrency `queue` key, which GitHub accepts.
27 + - name: actionlint
28 + run: >-
29 + uvx --from actionlint-py==1.7.12.24 actionlint
30 + -ignore 'unexpected key "queue" for "concurrency" section'
31 + .github/workflows/sdk.release*.yml
32 + - name: zizmor
33 + env:
34 + GH_TOKEN: ${{ github.token }}
35 + run: >-
36 + uvx zizmor==1.31.1 --min-severity medium --format github
37 + .github/workflows/sdk.release*.yml
.github/workflows/sdk.release.yml
+34 -7
@@ -32,7 +32,8 @@ on:
32 type: choice
33 options: [auto, patch, minor, major, skip]
34 default: auto
35 - pull_request_target:
35 + # The tag job checks out the base commit, never the PR, and its gate only reads the PR.
36 + pull_request_target: # zizmor: ignore[dangerous-triggers]
37 branches: [next]
38 types: [closed]
39 push:
@@ -65,7 +66,8 @@ jobs:
66 persist-credentials: false
67 - uses: ./.github/actions/setup-node-pnpm-bun
68 - run: pnpm install --frozen-lockfile --ignore-scripts
68 - - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510
69 + # A dedicated release App, installed with only the permissions the runbook lists.
70 + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # zizmor: ignore[github-app]
71 id: app
72 with:
73 client-id: ${{ vars.SDK_RELEASE_APP_CLIENT_ID }}
@@ -130,7 +132,8 @@ jobs:
132 with:
133 name: sdk-release-patch
134 path: /tmp/sdk-release
133 - - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510
135 + # A dedicated release App, installed with only the permissions the runbook lists.
136 + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # zizmor: ignore[github-app]
137 id: app
138 with:
139 client-id: ${{ vars.SDK_RELEASE_APP_CLIENT_ID }}
@@ -189,7 +192,8 @@ jobs:
192 persist-credentials: false
193 - uses: ./.github/actions/setup-node-pnpm-bun
194 - run: pnpm install --frozen-lockfile --ignore-scripts
192 - - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510
195 + # A dedicated release App, installed with only the permissions the runbook lists.
196 + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # zizmor: ignore[github-app]
197 id: app
198 with:
199 client-id: ${{ vars.SDK_RELEASE_APP_CLIENT_ID }}
@@ -276,11 +280,21 @@ jobs:
280 - run: pnpm install --frozen-lockfile --ignore-scripts
281 - name: Pin npm with native dist-tag OIDC support
282 run: npm install --global npm@11.21.0 --ignore-scripts --registry=https://registry.npmjs.org
279 - - name: Upload missing npm files, move latest, then drop the release-only tag
283 + - name: Upload missing npm files, move the channel tag and check their provenance
284 + id: publish
285 env:
286 SDK_READ_TOKEN: ${{ github.token }}
287 APPROVED_CANDIDATES: ${{ needs.candidates.outputs.approved }}
288 run: bun scripts/sdk-release/registry.ts publish typescript
289 + - name: Check registry signatures on a fresh install, as a user would
290 + env:
291 + SPECS: ${{ steps.publish.outputs.specs }}
292 + run: |
293 + cd "$(mktemp -d)"
294 + npm init --yes > /dev/null
295 + # shellcheck disable=SC2086 # one argument per package
296 + npm install --ignore-scripts --registry=https://registry.npmjs.org $SPECS
297 + npm audit signatures
298
299 publish-pypi:
300 needs: candidates
@@ -308,11 +322,23 @@ jobs:
322 uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086
323 with:
324 packages-dir: sdk-publication/missing-python/
311 - - name: Wait until PyPI serves every file
325 + - name: Wait until PyPI serves every file, then check each attestation's publisher
326 + id: verify
327 env:
328 SDK_READ_TOKEN: ${{ github.token }}
329 APPROVED_CANDIDATES: ${{ needs.candidates.outputs.approved }}
330 run: bun scripts/sdk-release/registry.ts verify python
331 + - uses: ./.github/actions/setup-python-uv
332 + with:
333 + enable-caching: 'false'
334 + - name: Check the attestation signatures, as a user would
335 + env:
336 + FILES: ${{ steps.verify.outputs.files }}
337 + run: |
338 + for url in $FILES; do
339 + uvx pypi-attestations==0.0.30 verify pypi \
340 + --repository https://github.com/ComposioHQ/composio "$url"
341 + done
342
343 # Pins the docs to the released npm versions. It follows the npm job, so a Python-only release,
344 # which skips that job, skips this one too.
@@ -346,7 +372,8 @@ jobs:
372 sleep 30
373 done
374 exit 1
349 - - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510
375 + # A dedicated release App, installed with only the permissions the runbook lists.
376 + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # zizmor: ignore[github-app]
377 id: app
378 with:
379 client-id: ${{ vars.RELEASE_BOT_CLIENT_ID }}
scripts/sdk-release/provenance.ts new
+121
@@ -0,0 +1,121 @@
1 +import { Data, Effect, Schedule, Schema } from 'effect';
2 +import { Digest } from 'effect/crypto';
3 +import { Base64 } from 'effect/encoding';
4 +import { FetchHttpClient, HttpClient } from 'effect/http';
5 +import { SDK_RELEASE_REPOSITORY } from './github';
6 +import { NPM_REGISTRY } from './lanes';
7 +import type { Distribution } from './registry';
8 +import { ensure, fail } from './runtime';
9 +import { releaseTag } from './source';
10 +
11 +/** The publisher every released file must name: this repository, workflow and release tag. */
12 +export const RELEASE_PUBLISHER = {
13 + repository: SDK_RELEASE_REPOSITORY,
14 + workflow: 'sdk.release.yml',
15 + pypiEnvironment: 'pypi-release',
16 +} as const;
17 +
18 +const SLSA_PROVENANCE = 'https://slsa.dev/provenance/v1';
19 +
20 +const NpmAttestations = Schema.Struct({
21 + attestations: Schema.Array(
22 + Schema.Struct({
23 + predicateType: Schema.String,
24 + bundle: Schema.Struct({ dsseEnvelope: Schema.Struct({ payload: Schema.String }) }),
25 + })
26 + ),
27 +});
28 +const SlsaStatement = Schema.Struct({
29 + subject: Schema.Array(Schema.Struct({ digest: Schema.Struct({ sha512: Schema.String }) })),
30 + predicate: Schema.Struct({
31 + buildDefinition: Schema.Struct({
32 + externalParameters: Schema.Struct({
33 + workflow: Schema.Struct({
34 + ref: Schema.String,
35 + repository: Schema.String,
36 + path: Schema.String,
37 + }),
38 + }),
39 + }),
40 + }),
41 +});
42 +const PypiProvenance = Schema.Struct({
43 + attestation_bundles: Schema.Array(
44 + Schema.Struct({
45 + publisher: Schema.Struct({
46 + kind: Schema.String,
47 + repository: Schema.String,
48 + workflow: Schema.String,
49 + environment: Schema.optionalKey(Schema.NullOr(Schema.String)),
50 + }),
51 + })
52 + ),
53 +});
54 +
55 +/** Provenance can trail an upload by a few seconds, so a missing document is retried. */
56 +class ProvenancePending extends Data.TaggedError('ProvenancePending')<{ readonly url: string }> {}
57 +
58 +const provenanceJson = <S extends Schema.Top>(url: string, schema: S) =>
59 + Effect.gen(function* () {
60 + const client = yield* HttpClient.HttpClient;
61 + const response = yield* client.get(url);
62 + if (response.status === 404) return yield* new ProvenancePending({ url });
63 + yield* ensure(response.status === 200, `Provenance lookup failed: ${url} (${response.status})`);
64 + return yield* Schema.decodeUnknownEffect(Schema.fromJsonString(schema))(yield* response.text);
65 + }).pipe(
66 + Effect.provideService(FetchHttpClient.RequestInit, { redirect: 'error' }),
67 + Effect.retry({
68 + schedule: Schedule.spaced('10 seconds'),
69 + times: 5,
70 + while: error => error instanceof ProvenancePending,
71 + }),
72 + Effect.catchTag('ProvenancePending', error =>
73 + fail(`No provenance is published at ${error.url}`)
74 + )
75 + );
76 +
77 +/**
78 + * The npm SLSA provenance of a published tarball must name this repository, the release
79 + * workflow and this batch's tag, and its subject must be the reviewed bytes.
80 + */
81 +export const verifyNpmProvenance = (file: Distribution, id: string) =>
82 + Effect.gen(function* () {
83 + const url = `${NPM_REGISTRY}/-/npm/v1/attestations/${encodeURIComponent(file.name)}@${file.version}`;
84 + const { attestations } = yield* provenanceJson(url, NpmAttestations);
85 + const slsa = attestations.find(attestation => attestation.predicateType === SLSA_PROVENANCE);
86 + if (!slsa) return yield* fail(`${file.name}@${file.version} has no SLSA provenance`);
87 + const payload = yield* Effect.fromResult(Base64.decodeString(slsa.bundle.dsseEnvelope.payload));
88 + const statement = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(SlsaStatement))(
89 + payload
90 + );
91 + const { workflow } = statement.predicate.buildDefinition.externalParameters;
92 + yield* ensure(
93 + workflow.repository === `https://github.com/${RELEASE_PUBLISHER.repository}` &&
94 + workflow.path === `.github/workflows/${RELEASE_PUBLISHER.workflow}` &&
95 + workflow.ref === `refs/tags/${releaseTag(id)}`,
96 + `${file.name}@${file.version} was built by ${workflow.repository} ${workflow.path} at ${workflow.ref}, not by this release`
97 + );
98 + const digest = yield* Digest.Digest;
99 + const sha512 = yield* digest.digestHex(Digest.sha512, file.bytes);
100 + yield* ensure(
101 + statement.subject.some(subject => subject.digest.sha512 === sha512),
102 + `${file.name}@${file.version} provenance describes other bytes than the reviewed tarball`
103 + );
104 + });
105 +
106 +/** Every PyPI file must carry a PEP 740 attestation from this repository's release workflow. */
107 +export const verifyPypiProvenance = (file: Distribution) =>
108 + Effect.gen(function* () {
109 + const url = `https://pypi.org/integrity/${file.name}/${file.version}/${file.file}/provenance`;
110 + const { attestation_bundles } = yield* provenanceJson(url, PypiProvenance);
111 + yield* ensure(
112 + attestation_bundles.some(
113 + ({ publisher }) =>
114 + publisher.kind === 'GitHub' &&
115 + publisher.repository === RELEASE_PUBLISHER.repository &&
116 + publisher.workflow === RELEASE_PUBLISHER.workflow &&
117 + publisher.environment === RELEASE_PUBLISHER.pypiEnvironment
118 + ),
119 + `${file.file} is not attested by ${RELEASE_PUBLISHER.repository} ${RELEASE_PUBLISHER.workflow} in ${RELEASE_PUBLISHER.pypiEnvironment}`
120 + );
121 + });
scripts/sdk-release/registry.ts
+84 -12
@@ -1,4 +1,17 @@
1 -import { Config, Data, Effect, FileSystem, Option, Path, Schedule, Schema, Stdio } from 'effect';
1 +import {
2 + Config,
3 + Context,
4 + Data,
5 + Effect,
6 + FileSystem,
7 + Layer,
8 + Option,
9 + Path,
10 + Schedule,
11 + Schema,
12 + Stdio,
13 +} from 'effect';
14 +import { ChildProcessSpawner } from 'effect/process';
15 import type { Duration } from 'effect';
16 import { FetchHttpClient, HttpClient } from 'effect/http';
17 import semver from 'semver';
@@ -23,6 +36,7 @@ import {
36 Language,
37 type Language as Lang,
38 } from './lanes';
39 +import { verifyNpmProvenance, verifyPypiProvenance } from './provenance';
40 import { discoverPythonPackages } from './python-metadata';
41 import {
42 appendFile,
@@ -403,16 +417,36 @@ export const loadOriginalDistributions = (
417 });
418 });
419
420 +/** The npm CLI, which publishes through trusted publishing and moves dist-tags. */
421 +export class NpmCli extends Context.Service<
422 + NpmCli,
423 + { readonly run: (args: ReadonlyArray<string>) => Effect.Effect<string, unknown> }
424 +>()('sdk-release/NpmCli') {
425 + static readonly layer = (cwd: string) =>
426 + Layer.effect(
427 + NpmCli,
428 + Effect.gen(function* () {
429 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
430 + return {
431 + run: (args: ReadonlyArray<string>) =>
432 + run('npm', args, { cwd, env: withoutReleaseTokens }).pipe(
433 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)
434 + ),
435 + };
436 + })
437 + );
438 +}
439 +
440 /**
441 * Publishes under a release-only dist-tag, moves the channel's tag once the upload is visible,
408 - * then drops the release-only tag.
442 + * drops the release-only tag, and checks that each tarball's provenance names this release.
443 */
444 export const publishNpm = (cwd: string, batch: ReleaseBatch, files: ReadonlyArray<Distribution>) =>
445 Effect.gen(function* () {
446 const path = yield* Path.Path;
447 const channel = batch.plan.choices.channel;
414 - const npm = (args: ReadonlyArray<string>) =>
415 - run('npm', args, { cwd, env: withoutReleaseTokens });
448 + const cli = yield* NpmCli;
449 + const npm = cli.run;
450 for (const file of (yield* reconcileRegistry(files, channel)).missing)
451 yield* npm([
452 'publish',
@@ -436,6 +470,33 @@ export const publishNpm = (cwd: string, batch: ReleaseBatch, files: ReadonlyArra
470 if (Option.exists(tags, value => releaseOnly in value))
471 yield* npm(['dist-tag', 'rm', file.name, releaseOnly]);
472 }
473 + for (const file of files) yield* verifyNpmProvenance(file, batch.id);
474 + });
475 +
476 +/** The `name@version` specs of the published tarballs, for a fresh install. */
477 +export const npmSpecs = (files: ReadonlyArray<Distribution>) =>
478 + files.map(file => `${file.name}@${file.version}`).join(' ');
479 +
480 +/**
481 + * Checks that every PyPI file is attested by this release, and returns the file URLs for the
482 + * signature check that `pypi-attestations` runs next.
483 + */
484 +export const verifyPypiFiles = (files: ReadonlyArray<Distribution>) =>
485 + Effect.gen(function* () {
486 + const urls: string[] = [];
487 + for (const file of files) {
488 + yield* verifyPypiProvenance(file);
489 + const metadata = yield* registryJson(
490 + REGISTRY_LANES.python.versionUrl(file.name, file.version),
491 + PypiVersion
492 + );
493 + const served = Option.flatMap(metadata, ({ urls: served }) =>
494 + Option.fromNullishOr(served.find(entry => entry.filename === file.file))
495 + );
496 + if (Option.isNone(served)) return yield* fail(`PyPI does not serve ${file.file}`);
497 + urls.push(served.value.url);
498 + }
499 + return urls;
500 });
501
502 /** Stages only the missing Python files for the trusted-publisher upload step. */
@@ -459,12 +520,16 @@ const Environment = Config.all({
520 approved: Config.schema(Schema.fromJsonString(ApprovedCandidates), 'APPROVED_CANDIDATES'),
521 });
522
462 -const Arguments = Schema.Tuple([Schema.Literals(['publish', 'verify']), Language]);
523 +const Arguments = Schema.Union([
524 + Schema.Tuple([Schema.Literal('publish'), Language]),
525 + Schema.Tuple([Schema.Literal('verify'), Schema.Literal('python')]),
526 +]);
527
528 /**
465 - * `registry.ts publish typescript` uploads to npm and moves `latest`; `publish python` stages
466 - * the missing PyPI files for the upload action; `verify <language>` waits until every file is
467 - * served.
529 + * `registry.ts publish typescript` uploads to npm, moves the channel tag, checks provenance and
530 + * outputs the specs for a signature check; `publish python` stages the missing PyPI files for the
531 + * upload action; `verify python` waits until PyPI serves every file, checks each attestation's
532 + * publisher and outputs the file URLs for the signature check.
533 */
534 const main = Effect.gen(function* () {
535 const [mode, language] = yield* Schema.decodeUnknownEffect(Arguments)(
@@ -481,10 +546,17 @@ const main = Effect.gen(function* () {
546 const files = yield* loadOriginalDistributions(cwd, batch, env.sha, env.approved, language).pipe(
547 Effect.provide(GitHub.layer(env.token))
548 );
484 - if (mode === 'verify')
485 - return yield* waitForRegistry(files, { channel: batch.plan.choices.channel });
486 - if (language === 'typescript') return yield* publishNpm(cwd, batch, files);
487 - yield* stageMissingPython(cwd, files, env.output);
549 + yield* Effect.gen(function* () {
550 + if (mode === 'verify') {
551 + yield* waitForRegistry(files, { channel: batch.plan.choices.channel });
552 + return yield* appendFile(env.output, `files=${(yield* verifyPypiFiles(files)).join(' ')}\n`);
553 + }
554 + if (language === 'typescript') {
555 + yield* publishNpm(cwd, batch, files);
556 + return yield* appendFile(env.output, `specs=${npmSpecs(files)}\n`);
557 + }
558 + yield* stageMissingPython(cwd, files, env.output);
559 + }).pipe(Effect.provide(NpmCli.layer(cwd)));
560 });
561
562 if (import.meta.main) runMain(main);
test/sdk-release-rehearsal.test.ts new
+304
@@ -0,0 +1,304 @@
1 +import { describe, expect, test } from 'bun:test';
2 +import { Effect, Layer, Option } from 'effect';
3 +import { Digest } from 'effect/crypto';
4 +import { Base64 } from 'effect/encoding';
5 +import semver from 'semver';
6 +import { readReleasePull } from '../scripts/sdk-release/approval';
7 +import {
8 + authorizeSourceTag,
9 + executeReleaseRequest,
10 + openReleasePull,
11 +} from '../scripts/sdk-release/batch';
12 +import { NpmCli, publishNpm, type Distribution } from '../scripts/sdk-release/registry';
13 +import { stageOutcome } from '../scripts/sdk-release/report';
14 +import { sha256Hex } from '../scripts/sdk-release/runtime';
15 +import type { ReleaseBatch } from '../scripts/sdk-release/source';
16 +import { STAGES, type ReleaseState, type StateName } from '../scripts/sdk-release/state';
17 +import {
18 + base,
19 + batch,
20 + betaBatch,
21 + betaFiles,
22 + fakeController,
23 + head,
24 + releaseFiles,
25 +} from './sdk-release-controller-fixture';
26 +import { resolvePath, runRelease, type Fetch } from './sdk-release-harness';
27 +
28 +const NPM = 'https://registry.npmjs.org';
29 +
30 +/**
31 + * A fake npm registry with its dist-tags, and the npm CLI that writes to it. Uploads record SLSA
32 + * provenance the way trusted publishing does, from `ref` (the release tag unless a test forges
33 + * another one).
34 + */
35 +function npmRegistry(
36 + tags: Record<string, string>,
37 + options: { ref?: string; otherBytes?: boolean } = {}
38 +) {
39 + const versions = new Map<string, Uint8Array>();
40 + const commands: string[] = [];
41 + const pending = new Map<string, Distribution>();
42 + const sha512 = (bytes: Uint8Array) =>
43 + runRelease(
44 + Effect.gen(function* () {
45 + return yield* (yield* Digest.Digest).digestHex(Digest.sha512, bytes);
46 + })
47 + );
48 + const provenance = new Map<string, string>();
49 + const cli = Layer.succeed(NpmCli, {
50 + run: (args: ReadonlyArray<string>) =>
51 + Effect.promise(async () => {
52 + commands.push(args.join(' '));
53 + const [command, target] = args;
54 + if (command === 'publish') {
55 + const file = [...pending.values()].find(candidate => target.endsWith(candidate.file));
56 + if (!file) throw new Error(`Unexpected upload ${target}`);
57 + versions.set(file.version, file.bytes);
58 + const releaseOnly = args.find(arg => arg.startsWith('--tag='))!.slice('--tag='.length);
59 + tags[releaseOnly] = file.version;
60 + const statement = {
61 + subject: [
62 + {
63 + digest: {
64 + sha512: await sha512(options.otherBytes ? new Uint8Array([1]) : file.bytes),
65 + },
66 + },
67 + ],
68 + predicate: {
69 + buildDefinition: {
70 + externalParameters: {
71 + workflow: {
72 + ref:
73 + options.ref ??
74 + `refs/tags/sdk-release/${releaseOnly.slice('sdk-release-'.length)}`,
75 + repository: 'https://github.com/ComposioHQ/composio',
76 + path: '.github/workflows/sdk.release.yml',
77 + },
78 + },
79 + },
80 + },
81 + };
82 + provenance.set(file.version, Base64.encode(JSON.stringify(statement)));
83 + }
84 + if (command === 'dist-tag' && target === 'add') tags[args[3]] = args[2].split('@').at(-1)!;
85 + if (command === 'dist-tag' && target === 'rm') delete tags[args[3]];
86 + return '';
87 + }),
88 + });
89 + const fetcher: Fetch = async input => {
90 + const url = String(input);
91 + const respond = (data: unknown) => new Response(JSON.stringify(data));
92 + const notFound = new Response('{}', { status: 404 });
93 + if (url === `${NPM}/-/package/%40composio%2Fcore/dist-tags`) return respond(tags);
94 + const attestation = /\/-\/npm\/v1\/attestations\/%40composio%2Fcore@(.+)$/.exec(url);
95 + if (attestation)
96 + return provenance.has(attestation[1])
97 + ? respond({
98 + attestations: [
99 + {
100 + predicateType: 'https://slsa.dev/provenance/v1',
101 + bundle: { dsseEnvelope: { payload: provenance.get(attestation[1]) } },
102 + },
103 + ],
104 + })
105 + : notFound;
106 + const tarball = /\/@composio\/core\/-\/core-(.+)\.tgz$/.exec(url);
107 + if (tarball) return new Response((versions.get(tarball[1]) ?? new Uint8Array()).slice());
108 + const document = /^https:\/\/registry\.npmjs\.org\/%40composio%2Fcore\/(.+)$/.exec(url);
109 + if (document && semver.valid(document[1]))
110 + return versions.has(document[1])
111 + ? respond({
112 + name: '@composio/core',
113 + version: document[1],
114 + dist: { tarball: `${NPM}/@composio/core/-/core-${document[1]}.tgz` },
115 + })
116 + : notFound;
117 + if (document) return document[1] in tags ? respond({ version: tags[document[1]] }) : notFound;
118 + throw new Error(`Unexpected registry request: ${url}`);
119 + };
120 + const stage = (file: Distribution) => pending.set(file.file, file);
121 + return { cli, fetcher, commands, tags, stage };
122 +}
123 +
124 +const tarballOf = async (release: ReleaseBatch): Promise<Distribution> => {
125 + const version = release.plan.releases[0].newVersion;
126 + const bytes = new TextEncoder().encode(`reviewed tarball ${version}`);
127 + return {
128 + language: 'typescript',
129 + name: '@composio/core',
130 + version,
131 + file: `composio-core-${version}.tgz`,
132 + bytes,
133 + sha256: await runRelease(sha256Hex(bytes)),
134 + };
135 +};
136 +
137 +/** One release through every stage, with the production handlers and fakes at the edges. */
138 +async function rehearse(release: ReleaseBatch, tags: Record<string, string>) {
139 + const beta = release.plan.choices.channel === 'beta';
140 + const github = fakeController({ beta });
141 + const ended: ReleaseState[] = [];
142 + const cwd = await resolvePath('.');
143 +
144 + // 1. request: an active member's request plans the batch.
145 + const planned = await runRelease(
146 + executeReleaseRequest(
147 + Effect.succeed({
148 + channel: release.plan.choices.channel,
149 + typescript: 'auto',
150 + python: 'skip',
151 + }),
152 + { actor: 'requester', runId: release.id, sourceSha: base, issueNumber: release.issue },
153 + () => Effect.succeed(release.plan)
154 + ),
155 + github.fetcher
156 + );
157 + expect(planned).toMatchObject({ _tag: 'Planned', batch: { id: release.id, plan: release.plan } });
158 + ended.push(
159 + await runRelease(
160 + openReleasePull(cwd, release, { files: beta ? betaFiles : releaseFiles }),
161 + github.fetcher
162 + )
163 + );
164 +
165 + // 2. review: the merged, approved release PR is tagged.
166 + ended.push(
167 + await runRelease(
168 + Effect.flatMap(readReleasePull(9), ({ pull, batch: committed }) =>
169 + authorizeSourceTag(pull, committed, 'sdk-release-app')
170 + ),
171 + github.fetcher
172 + )
173 + );
174 + expect(github.writes.at(-1)).toEqual({
175 + method: 'POST',
176 + path: '/git/refs',
177 + body: { ref: 'refs/tags/sdk-release/8', sha: head },
178 + });
179 +
180 + // 3. publish: the reviewed tarball reaches npm, and a re-run uploads nothing.
181 + const registry = npmRegistry(tags);
182 + const tarball = await tarballOf(release);
183 + registry.stage(tarball);
184 + const publish = publishNpm(cwd, release, [tarball]).pipe(Effect.provide(registry.cli));
185 + await runRelease(publish, registry.fetcher);
186 + const firstRun = [...registry.commands];
187 + await runRelease(publish, registry.fetcher);
188 + ended.push(
189 + await runRelease(
190 + stageOutcome(
191 + 'publish',
192 + { candidates: 'success', 'publish-npm': 'success' },
193 + Option.none(),
194 + Effect.succeed({ _tag: 'Published', versions: [] } as ReleaseState),
195 + '77'
196 + )
197 + )
198 + );
199 + return { ended, firstRun, registry, tarball };
200 +}
201 +
202 +describe('release rehearsal', () => {
203 + test('a stable release goes from request to npm latest, and a re-run changes nothing', async () => {
204 + const { ended, firstRun, registry } = await rehearse(batch, { latest: '1.0.0' });
205 + expect(ended.map(state => state._tag)).toEqual(['InReview', 'Tagged', 'Published']);
206 + expect(firstRun).toEqual([
207 + `publish ${await resolvePath('sdk-publication/typescript/composio-core-1.0.1.tgz')} --ignore-scripts --provenance --access=public --tag=sdk-release-8`,
208 + 'dist-tag add @composio/core@1.0.1 latest',
209 + 'dist-tag rm @composio/core sdk-release-8',
210 + ]);
211 + expect(registry.commands).toEqual(firstRun);
212 + expect(registry.tags).toEqual({ latest: '1.0.1' });
213 + });
214 +
215 + test('a beta reaches npm next and never reads or moves latest', async () => {
216 + const { ended, registry } = await rehearse(betaBatch, {
217 + latest: '1.0.0',
218 + next: '0.1.36-next.13',
219 + });
220 + expect(ended.map(state => state._tag)).toEqual(['InReview', 'Tagged', 'Published']);
221 + expect(registry.tags).toEqual({ latest: '1.0.0', next: '1.0.1-beta.8' });
222 + expect(registry.commands.some(command => command.includes('latest'))).toBe(false);
223 + });
224 +
225 + test('provenance from another ref fails the publication after upload', async () => {
226 + const registry = npmRegistry({ latest: '1.0.0' }, { ref: 'refs/heads/next' });
227 + const tarball = await tarballOf(batch);
228 + registry.stage(tarball);
229 + await expect(
230 + runRelease(
231 + publishNpm(await resolvePath('.'), batch, [tarball]).pipe(Effect.provide(registry.cli)),
232 + registry.fetcher
233 + )
234 + ).rejects.toThrow('was built by https://github.com/ComposioHQ/composio');
235 + });
236 +
237 + test('provenance that describes other bytes fails the publication', async () => {
238 + const registry = npmRegistry({ latest: '1.0.0' }, { otherBytes: true });
239 + const tarball = await tarballOf(batch);
240 + registry.stage(tarball);
241 + await expect(
242 + runRelease(
243 + publishNpm(await resolvePath('.'), batch, [tarball]).pipe(Effect.provide(registry.cli)),
244 + registry.fetcher
245 + )
246 + ).rejects.toThrow('provenance describes other bytes than the reviewed tarball');
247 + });
248 +
249 + test('every state a stage can end in is reached by a production handler', async () => {
250 + const reached = new Set<StateName>();
251 + for (const { ended } of [
252 + await rehearse(batch, { latest: '1.0.0' }),
253 + await rehearse(betaBatch, { next: '0.1.36-next.13' }),
254 + ])
255 + for (const state of ended) reached.add(state._tag);
256 + const review = async (options: Parameters<typeof fakeController>[0]) => {
257 + const { fetcher } = fakeController(options);
258 + return runRelease(
259 + Effect.flatMap(readReleasePull(9), ({ pull, batch: committed }) =>
260 + authorizeSourceTag(pull, committed, 'sdk-release-app')
261 + ),
262 + fetcher
263 + );
264 + };
265 + reached.add((await review({ closedUnmerged: true }))._tag);
266 + reached.add((await review({ reviewer: 'requester' }))._tag);
267 + const request = async (
268 + options: Parameters<typeof fakeController>[0],
269 + sourceSha: string,
270 + parse: Effect.Effect<never, string> | undefined,
271 + releases = batch.plan
272 + ) => {
273 + const { fetcher } = fakeController(options);
274 + return runRelease(
275 + executeReleaseRequest(
276 + parse ?? Effect.succeed({ channel: 'stable', typescript: 'auto', python: 'skip' }),
277 + { actor: 'requester', runId: '8', sourceSha, issueNumber: 8 },
278 + () => Effect.succeed(releases)
279 + ),
280 + fetcher
281 + );
282 + };
283 + reached.add((await request({}, base, Effect.fail('Use the form')))._tag as StateName);
284 + reached.add(
285 + (await request({ openRelease: 'sdk-release/batch-7' }, base, undefined))._tag as StateName
286 + );
287 + reached.add((await request({}, head, undefined))._tag as StateName);
288 + reached.add(
289 + (await request({}, base, undefined, { ...batch.plan, releases: [] }))._tag as StateName
290 + );
291 + reached.add(
292 + (
293 + await runRelease(
294 + stageOutcome('request', { plan: 'cancelled' }, Option.none(), Effect.never, '77')
295 + )
296 + )._tag
297 + );
298 + const ends = new Set<StateName>([
299 + ...Object.values(STAGES).flatMap(stage => stage.to as ReadonlyArray<StateName>),
300 + 'Failed',
301 + ]);
302 + expect([...reached].toSorted()).toEqual([...ends].toSorted());
303 + });
304 +});