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
test(release): cover the PyPI attestation checks
jkomyno committed
Nov 5, 2026 at 19:38 UTC
ed2f1ef57133a8b872e26dae2f779cac52194327
4 files changed
+106
-16
scripts/sdk-release/provenance.ts
+14
-7
@@ -1,4 +1,5 @@
1
import { Data, Effect, Schedule, Schema } from 'effect';
2
+import type { Duration } from 'effect';
3
import { Digest } from 'effect/crypto';
4
import { Base64 } from 'effect/encoding';
5
import { FetchHttpClient, HttpClient } from 'effect/http';
@@ -55,7 +56,13 @@ const PypiProvenance = Schema.Struct({
56
/** Provenance can trail an upload by a few seconds, so a missing document is retried. */
57
class ProvenancePending extends Data.TaggedError('ProvenancePending')<{ readonly url: string }> {}
58
58
-const provenanceJson = <S extends Schema.Top>(url: string, schema: S) =>
59
+/** How long to wait for provenance that trails an upload. */
60
+export interface ProvenanceWait {
61
+ readonly attempts?: number;
62
+ readonly spacing?: Duration.Input;
63
+}
64
+
65
+const provenanceJson = <S extends Schema.Top>(url: string, schema: S, wait: ProvenanceWait) =>
66
Effect.gen(function* () {
67
const client = yield* HttpClient.HttpClient;
68
const response = yield* client.get(url);
@@ -65,8 +72,8 @@ const provenanceJson = <S extends Schema.Top>(url: string, schema: S) =>
72
}).pipe(
73
Effect.provideService(FetchHttpClient.RequestInit, { redirect: 'error' }),
74
Effect.retry({
68
- schedule: Schedule.spaced('10 seconds'),
69
- times: 5,
75
+ schedule: Schedule.spaced(wait.spacing ?? '10 seconds'),
76
+ times: (wait.attempts ?? 6) - 1,
77
while: error => error instanceof ProvenancePending,
78
}),
79
Effect.catchTag('ProvenancePending', error =>
@@ -78,10 +85,10 @@ const provenanceJson = <S extends Schema.Top>(url: string, schema: S) =>
85
* The npm SLSA provenance of a published tarball must name this repository, the release
86
* workflow and this batch's tag, and its subject must be the reviewed bytes.
87
*/
81
-export const verifyNpmProvenance = (file: Distribution, id: string) =>
88
+export const verifyNpmProvenance = (file: Distribution, id: string, wait: ProvenanceWait = {}) =>
89
Effect.gen(function* () {
90
const url = `${NPM_REGISTRY}/-/npm/v1/attestations/${encodeURIComponent(file.name)}@${file.version}`;
84
- const { attestations } = yield* provenanceJson(url, NpmAttestations);
91
+ const { attestations } = yield* provenanceJson(url, NpmAttestations, wait);
92
const slsa = attestations.find(attestation => attestation.predicateType === SLSA_PROVENANCE);
93
if (!slsa) return yield* fail(`${file.name}@${file.version} has no SLSA provenance`);
94
const payload = yield* Effect.fromResult(Base64.decodeString(slsa.bundle.dsseEnvelope.payload));
@@ -104,10 +111,10 @@ export const verifyNpmProvenance = (file: Distribution, id: string) =>
111
});
112
113
/** Every PyPI file must carry a PEP 740 attestation from this repository's release workflow. */
107
-export const verifyPypiProvenance = (file: Distribution) =>
114
+export const verifyPypiProvenance = (file: Distribution, wait: ProvenanceWait = {}) =>
115
Effect.gen(function* () {
116
const url = `https://pypi.org/integrity/${file.name}/${file.version}/${file.file}/provenance`;
110
- const { attestation_bundles } = yield* provenanceJson(url, PypiProvenance);
117
+ const { attestation_bundles } = yield* provenanceJson(url, PypiProvenance, wait);
118
yield* ensure(
119
attestation_bundles.some(
120
({ publisher }) =>
scripts/sdk-release/registry.ts
+3
-3
@@ -36,7 +36,7 @@ import {
36
Language,
37
type Language as Lang,
38
} from './lanes';
39
-import { verifyNpmProvenance, verifyPypiProvenance } from './provenance';
39
+import { verifyNpmProvenance, verifyPypiProvenance, type ProvenanceWait } from './provenance';
40
import { discoverPythonPackages } from './python-metadata';
41
import {
42
appendFile,
@@ -481,11 +481,11 @@ export const npmSpecs = (files: ReadonlyArray<Distribution>) =>
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>) =>
484
+export const verifyPypiFiles = (files: ReadonlyArray<Distribution>, wait: ProvenanceWait = {}) =>
485
Effect.gen(function* () {
486
const urls: string[] = [];
487
for (const file of files) {
488
- yield* verifyPypiProvenance(file);
488
+ yield* verifyPypiProvenance(file, wait);
489
const metadata = yield* registryJson(
490
REGISTRY_LANES.python.versionUrl(file.name, file.version),
491
PypiVersion
test/sdk-release-provenance.test.ts
new
+65
@@ -0,0 +1,65 @@
1
+import { describe, expect, test } from 'bun:test';
2
+import { verifyPypiProvenance } from '../scripts/sdk-release/provenance';
3
+import { verifyPypiFiles, type Distribution } from '../scripts/sdk-release/registry';
4
+import { runRelease, type Fetch } from './sdk-release-harness';
5
+
6
+const wheel: Distribution = {
7
+ language: 'python',
8
+ name: 'composio',
9
+ version: '0.31.1b8',
10
+ file: 'composio-0.31.1b8-py3-none-any.whl',
11
+ bytes: new Uint8Array(),
12
+ sha256: '',
13
+};
14
+const fileUrl = 'https://files.pythonhosted.org/packages/ab/cd/composio-0.31.1b8-py3-none-any.whl';
15
+const releasePublisher = {
16
+ kind: 'GitHub',
17
+ repository: 'ComposioHQ/composio',
18
+ workflow: 'sdk.release.yml',
19
+ environment: 'pypi-release',
20
+};
21
+const noWait = { attempts: 2, spacing: '0 millis' } as const;
22
+
23
+/** PyPI's integrity and version metadata endpoints for one wheel, with `publisher` attesting it. */
24
+const pypi =
25
+ (publisher: Record<string, string> | undefined): Fetch =>
26
+ async input => {
27
+ const url = String(input);
28
+ if (url === `https://pypi.org/integrity/composio/0.31.1b8/${wheel.file}/provenance`)
29
+ return publisher
30
+ ? Response.json({ version: 1, attestation_bundles: [{ publisher, attestations: [] }] })
31
+ : new Response('{}', { status: 404 });
32
+ if (url === 'https://pypi.org/pypi/composio/0.31.1b8/json')
33
+ return Response.json({
34
+ urls: [{ filename: wheel.file, url: fileUrl, digests: { sha256: '' } }],
35
+ });
36
+ throw new Error(`Unexpected PyPI request: ${url}`);
37
+ };
38
+
39
+describe('PyPI attestations', () => {
40
+ test('a file attested by the release workflow in pypi-release is accepted', async () => {
41
+ await runRelease(verifyPypiProvenance(wheel, noWait), pypi(releasePublisher));
42
+ });
43
+
44
+ test.each([
45
+ ['another repository', { repository: 'someone/composio' }],
46
+ ['another workflow', { workflow: 'py.release.yml' }],
47
+ ['another environment', { environment: 'pypi' }],
48
+ ])('a file attested by %s is refused', async (_name, change) => {
49
+ await expect(
50
+ runRelease(verifyPypiProvenance(wheel, noWait), pypi({ ...releasePublisher, ...change }))
51
+ ).rejects.toThrow('is not attested by ComposioHQ/composio sdk.release.yml in pypi-release');
52
+ });
53
+
54
+ test('a file without provenance is refused once the wait runs out', async () => {
55
+ await expect(runRelease(verifyPypiProvenance(wheel, noWait), pypi(undefined))).rejects.toThrow(
56
+ 'No provenance is published at https://pypi.org/integrity/composio'
57
+ );
58
+ });
59
+
60
+ test('verified files return the URLs PyPI serves, for the signature check', async () => {
61
+ expect(await runRelease(verifyPypiFiles([wheel], noWait), pypi(releasePublisher))).toEqual([
62
+ fileUrl,
63
+ ]);
64
+ });
65
+});
test/sdk-release-rehearsal.test.ts
+24
-6
@@ -149,12 +149,21 @@ async function rehearse(release: ReleaseBatch, tags: Record<string, string>) {
149
typescript: 'auto',
150
python: 'skip',
151
}),
152
- { actor: 'requester', runId: release.id, sourceSha: base, issueNumber: release.issue },
152
+ {
153
+ actor: 'requester',
154
+ runId: release.id,
155
+ sourceSha: base,
156
+ issueNumber: release.issue,
157
+ appSlug: 'sdk-release-app',
158
+ },
159
() => Effect.succeed(release.plan)
160
),
161
github.fetcher
162
);
157
- expect(planned).toMatchObject({ _tag: 'Planned', batch: { id: release.id, plan: release.plan } });
163
+ expect(planned.outcome).toMatchObject({
164
+ _tag: 'Planned',
165
+ batch: { id: release.id, plan: release.plan },
166
+ });
167
ended.push(
168
await runRelease(
169
openReleasePull(cwd, release, { files: beta ? betaFiles : releaseFiles }),
@@ -272,10 +281,19 @@ describe('release rehearsal', () => {
281
) => {
282
const { fetcher } = fakeController(options);
283
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)
284
+ Effect.map(
285
+ executeReleaseRequest(
286
+ parse ?? Effect.succeed({ channel: 'stable', typescript: 'auto', python: 'skip' }),
287
+ {
288
+ actor: 'requester',
289
+ runId: '8',
290
+ sourceSha,
291
+ issueNumber: 8,
292
+ appSlug: 'sdk-release-app',
293
+ },
294
+ () => Effect.succeed(releases)
295
+ ),
296
+ result => result.outcome
297
),
298
fetcher
299
);