Something went wrong. Try again.
Mass Block [bsky] Reposts [and more]
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import { test } from "node:test";import assert from "node:assert/strict";import { createHash } from "node:crypto";import { mkdtemp, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { readReleaseFiles, validateTag, publishRelease } from "./publish-release.js";import { RELEASE_TARGETS } from "./release-config.js";import pkg from "../package.json" with { type: "json" };
test("release: verifies all archive checksums before publishing", async (t) => { const directory = await mkdtemp(join(tmpdir(), "mbr-release-")); t.after(() => rm(directory, { recursive: true, force: true })); const bytes = Buffer.from("synthetic release artifact"); const hash = createHash("sha256").update(bytes).digest("hex"); const names = RELEASE_TARGETS.map((target) => `mbr-v${pkg.version}-${target}.tar.gz`); for (const name of names) await writeFile(join(directory, name), bytes); const lines = names.map((name) => `${hash} ${name}`); await writeFile(join(directory, "SHA256SUMS"), `${lines.join("\n")}\n`); assert.equal((await readReleaseFiles(directory)).length, names.length + 1); await writeFile(join(directory, names[0]), "corrupt"); await assert.rejects(readReleaseFiles(directory), /checksum mismatch/); await writeFile(join(directory, names[0]), bytes); await writeFile(join(directory, "SHA256SUMS"), lines.slice(1).join("\n")); await assert.rejects(readReleaseFiles(directory), /incomplete/); await writeFile(join(directory, "SHA256SUMS"), `${hash} ../outside.tar.gz`); await assert.rejects(readReleaseFiles(directory), /unexpected/);});
test("release: requires a matching annotated tag at HEAD", () => { const git = (args) => args[0] === "cat-file" ? "tag" : args[1].endsWith("^{tag}") ? "a".repeat(40) : "commit"; assert.equal(validateTag(`v${pkg.version}`, git), "a".repeat(40)); assert.throws(() => validateTag("v999.0.0", git), /match package.json/); assert.throws(() => validateTag(`v${pkg.version}`, () => "commit"), /annotated tag/); assert.throws(() => validateTag(`v${pkg.version}`, (args) => args[0] === "cat-file" ? "tag" : args[1] === "HEAD" ? "other" : "commit"), /checked-out commit/);});
test("release: uploads artifacts with stable keys and stops on upload errors", async () => { const calls = []; const options = { files: [{ name: "SHA256SUMS", bytes: Buffer.from("checksum") }], pds: "https://pds.example", identifier: "publisher.example", password: "test-password", repoUrl: "https://tangled.org/publisher.example/mbr", tagHash: "a".repeat(40), request: async (url, init) => { assert.equal(init.redirect, "error"); calls.push({ path: url.pathname, ...init }); if (url.pathname.endsWith("createSession")) return Response.json({ did: "did:plc:publisher", accessJwt: "test-token" }); assert.equal(init.headers.authorization, "Bearer test-token"); if (url.pathname.endsWith("uploadBlob")) return Response.json({ blob: { ref: { $link: "test-cid" }, mimeType: "application/octet-stream", size: init.body.length } }); return Response.json({ uri: "at://artifact" }); }, }; await publishRelease(options); await publishRelease(options); const records = calls.filter((call) => call.path.endsWith("putRecord")).map((call) => JSON.parse(call.body)); assert.equal(records[0].rkey, records[1].rkey); assert.equal(records[0].repo, "did:plc:publisher"); assert.equal(records[0].record.repo, options.repoUrl); assert.equal(records[0].record.name, "SHA256SUMS"); assert.equal(records[0].record.tag.$bytes, Buffer.from(options.tagHash, "hex").toString("base64").replace(/=+$/, "")); let count = 0; await assert.rejects(publishRelease({ ...options, request: async () => { count++; return count === 1 ? Response.json({ did: "did:plc:publisher", accessJwt: "test-token" }) : new Response("private server details", { status: 413 }); } }), /uploadBlob failed \(HTTP 413\)/); assert.equal(count, 2);});