@a2f0/agent-tool 0.1.41 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/release/commands.ts +9 -1
package/package.json
CHANGED
package/src/release/commands.ts
CHANGED
|
@@ -6,12 +6,19 @@ import { assert, flag, json, oid, option, output, poll, repository, timeoutOptio
|
|
|
6
6
|
|
|
7
7
|
function packageName(name: unknown): asserts name is string { assert(typeof name === "string" && /^(?:@[a-z0-9._-]+\/)?[a-z0-9][a-z0-9._-]*$/.test(name), "Invalid npm package name."); }
|
|
8
8
|
export interface ReleaseRun { databaseId: number; status: string; conclusion: string; headSha: string; url: string }
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Downloads and checks the published tarball. Resolves null only when the
|
|
11
|
+
* registry answers 404 or 410: npm can list a version minutes before its
|
|
12
|
+
* tarball is served, so absence is a propagation delay. Any other failure,
|
|
13
|
+
* including a tarball that downloads but does not match, throws.
|
|
14
|
+
*/
|
|
15
|
+
export async function verifyTarball(metadata: { name: string; version: string; dist: { tarball: string; integrity: string } }): Promise<{ tarball: string; integrity: string } | null> {
|
|
10
16
|
const url = new URL(metadata.dist.tarball);
|
|
11
17
|
assert(url.protocol === "https:" && url.hostname === "registry.npmjs.org", "Expected an HTTPS npm registry tarball.");
|
|
12
18
|
const integrity = /^sha512-([A-Za-z0-9+/]+={0,2})$/.exec(metadata.dist.integrity);
|
|
13
19
|
assert(integrity, "Package must have SHA-512 tarball integrity.");
|
|
14
20
|
const response = await fetch(url, { signal: AbortSignal.timeout(60_000), redirect: "error" });
|
|
21
|
+
if (response.status === 404 || response.status === 410) { await response.body?.cancel(); return null; }
|
|
15
22
|
assert(response.ok && response.body, "Could not download the published tarball.");
|
|
16
23
|
const chunks: Uint8Array[] = []; let size = 0;
|
|
17
24
|
for await (const chunk of response.body) { size += chunk.length; assert(size <= 100 * 1024 * 1024, "Tarball exceeds the 100 MiB verification limit."); chunks.push(chunk); }
|
|
@@ -39,6 +46,7 @@ export async function inspectRelease(
|
|
|
39
46
|
assert(metadata.name === expected.name && metadata.version === expected.version, "Registry returned a different package version.");
|
|
40
47
|
assert(!metadata.gitHead || metadata.gitHead === expected.commit, "Registry gitHead differs from the publishing merge commit.");
|
|
41
48
|
const artifact = await checkArtifact(metadata);
|
|
49
|
+
if (!artifact) return { done: false, value: { ok: false, reason: "Tarball has not propagated to npm.", run } };
|
|
42
50
|
return { done: true, value: { ok: true, reason: "Workflow and published tarball verified.", run, ...artifact, gitHead: metadata.gitHead ?? null } };
|
|
43
51
|
}
|
|
44
52
|
|