Harden release flow with registry verification and dist-tag checks (#4800)

## Thinking Path

> - Paperclip orchestrates AI agents for zero-human companies
> - Paperclip is distributed as npm packages, including plugins like
`plugin-e2b`
> - The release process publishes canary and stable builds via npm
dist-tags
> - But there was no automated verification that published packages
actually landed with the correct dist-tags, and broken canary publishes
could silently ship to users
> - This PR adds a registry verification script that checks published
packages match their expected dist-tags, and wires it into PR CI so
regressions are caught before merge
> - The benefit is release integrity is verified automatically, and
broken dist-tag states are caught early

## What Changed

- Added `scripts/verify-release-registry-state.mjs` — verifies that
published npm packages have correct dist-tag assignments and detects
orphaned or mispointed tags
- Added `scripts/verify-release-registry-state.test.mjs` — test coverage
for the verification logic
- Updated `scripts/release.sh` to include canary dist-tag safety checks
before publishing
- Updated `.github/workflows/pr.yml` to run registry verification as a
CI step
- Updated `doc/PUBLISHING.md` and `doc/RELEASING.md` with the new
verification workflow

## Verification

- `pnpm test` — all tests pass including new verification script tests
- `node scripts/verify-release-registry-state.mjs` — runs against the
live npm registry and reports current state
- CI: the new PR workflow step runs on every PR push

## Risks

- Low risk. This is additive CI and tooling — no runtime code changes.
The registry verification is read-only (queries npm, does not publish).
The release script changes add safety checks that abort before
publishing if state is unexpected.

## Model Used

Codex GPT 5.4 high via Paperclip.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
This commit is contained in:
Devin Foley
2026-04-29 15:56:20 -07:00
committed by GitHub
parent 367d4cab72
commit a0f5cbffd7
7 changed files with 465 additions and 2 deletions
+32 -2
View File
@@ -11,6 +11,7 @@ release_date=""
dry_run=false
skip_verify=false
print_version_only=false
allow_canary_latest=false
tag_name=""
cleanup_on_exit=false
@@ -18,11 +19,12 @@ cleanup_on_exit=false
usage() {
cat <<'EOF'
Usage:
./scripts/release.sh <canary|stable> [--date YYYY-MM-DD] [--dry-run] [--skip-verify] [--print-version]
./scripts/release.sh <canary|stable> [--date YYYY-MM-DD] [--dry-run] [--skip-verify] [--print-version] [--allow-canary-latest]
Examples:
./scripts/release.sh canary
./scripts/release.sh canary --date 2026-03-17 --dry-run
./scripts/release.sh canary --allow-canary-latest
./scripts/release.sh stable
./scripts/release.sh stable --date 2026-03-17 --dry-run
./scripts/release.sh stable --date 2026-03-18 --print-version
@@ -32,6 +34,9 @@ Notes:
zero-padded UTC day, and P is the same-day stable patch slot.
- Canary releases publish YYYY.MDD.P-canary.N under the npm dist-tag
"canary" and create the git tag canary/vYYYY.MDD.P-canary.N.
- Canary releases fail by default if npm leaves the "latest" dist-tag
pointing at any canary. Pass --allow-canary-latest only when that is an
intentional first-publish or migration state.
- Stable releases publish YYYY.MDD.P under the npm dist-tag "latest" and
create the git tag vYYYY.MDD.P.
- Stable release notes must already exist at releases/vYYYY.MDD.P.md.
@@ -99,6 +104,7 @@ while [ $# -gt 0 ]; do
--dry-run) dry_run=true ;;
--skip-verify) skip_verify=true ;;
--print-version) print_version_only=true ;;
--allow-canary-latest) allow_canary_latest=true ;;
-h|--help)
usage
exit 0
@@ -115,6 +121,10 @@ done
exit 1
}
if [ "$allow_canary_latest" = true ] && [ "$channel" != "canary" ]; then
release_fail "--allow-canary-latest can only be used with the canary channel."
fi
PUBLISH_REMOTE="$(resolve_release_remote)"
fetch_release_remote "$PUBLISH_REMOTE"
@@ -187,6 +197,11 @@ release_info " Release date (UTC): $RELEASE_DATE"
release_info " Target stable version: $TARGET_STABLE_VERSION"
if [ "$channel" = "canary" ]; then
release_info " Canary version: $TARGET_PUBLISH_VERSION"
if [ "$allow_canary_latest" = true ]; then
release_info " latest dist-tag policy: allow canary"
else
release_info " latest dist-tag policy: fail if npm leaves latest on a canary"
fi
else
release_info " Stable version: $TARGET_PUBLISH_VERSION"
fi
@@ -263,7 +278,7 @@ release_info ""
if [ "$dry_run" = true ]; then
release_info "==> Step 6/7: Skipping npm verification in dry-run mode..."
else
release_info "==> Step 6/7: Confirming npm package availability..."
release_info "==> Step 6/7: Confirming npm package availability and dist-tag integrity..."
VERIFY_ATTEMPTS="${NPM_PUBLISH_VERIFY_ATTEMPTS:-12}"
VERIFY_DELAY_SECONDS="${NPM_PUBLISH_VERIFY_DELAY_SECONDS:-5}"
MISSING_PUBLISHED_PACKAGES=""
@@ -285,6 +300,21 @@ else
[ -z "$MISSING_PUBLISHED_PACKAGES" ] || release_fail "publish completed but npm never exposed: $MISSING_PUBLISHED_PACKAGES"
release_info " ✓ Verified all versioned packages are available on npm"
verify_args=(
--channel "$channel"
--dist-tag "$DIST_TAG"
--target-version "$TARGET_PUBLISH_VERSION"
)
if [ "$allow_canary_latest" = true ]; then
verify_args+=(--allow-canary-latest)
fi
while IFS=$'\t' read -r _pkg_dir pkg_name _pkg_version; do
[ -z "$pkg_name" ] && continue
verify_args+=(--package "$pkg_name")
done <<< "$VERSIONED_PACKAGE_INFO"
node "$REPO_ROOT/scripts/verify-release-registry-state.mjs" "${verify_args[@]}"
fi
release_info ""
+292
View File
@@ -0,0 +1,292 @@
#!/usr/bin/env node
import { pathToFileURL } from "node:url";
const CANARY_VERSION_RE = /-canary\.\d+$/;
export function isCanaryVersion(version) {
return CANARY_VERSION_RE.test(version);
}
function usage() {
process.stderr.write(
[
"Usage:",
" node scripts/verify-release-registry-state.mjs --channel <canary|stable> --dist-tag <tag> --target-version <version> --package <name> [--package <name> ...] [--allow-canary-latest]",
"",
].join("\n"),
);
}
function parseArgs(argv) {
const options = {
channel: "",
distTag: "",
targetVersion: "",
allowCanaryLatest: false,
packages: [],
};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
switch (arg) {
case "--channel":
options.channel = argv[index + 1] ?? "";
index += 1;
break;
case "--dist-tag":
options.distTag = argv[index + 1] ?? "";
index += 1;
break;
case "--target-version":
options.targetVersion = argv[index + 1] ?? "";
index += 1;
break;
case "--package":
options.packages.push(argv[index + 1] ?? "");
index += 1;
break;
case "--allow-canary-latest":
options.allowCanaryLatest = true;
break;
case "-h":
case "--help":
usage();
process.exit(0);
default:
throw new Error(`unexpected argument: ${arg}`);
}
}
if (options.channel !== "canary" && options.channel !== "stable") {
throw new Error("--channel must be canary or stable");
}
if (!options.distTag) {
throw new Error("--dist-tag is required");
}
if (!options.targetVersion) {
throw new Error("--target-version is required");
}
if (options.packages.length === 0 || options.packages.some((name) => !name)) {
throw new Error("at least one non-empty --package value is required");
}
if (options.allowCanaryLatest && options.channel !== "canary") {
throw new Error("--allow-canary-latest only applies to canary releases");
}
return options;
}
function createRegistryUrl(packageName) {
const registry = process.env.npm_config_registry ?? process.env.NPM_CONFIG_REGISTRY ?? "https://registry.npmjs.org/";
return new URL(encodeURIComponent(packageName), registry.endsWith("/") ? registry : `${registry}/`);
}
async function fetchPackageDocument(packageName, { allowMissing = false } = {}) {
const url = createRegistryUrl(packageName);
const response = await fetch(url, {
headers: {
accept: "application/vnd.npm.install-v1+json, application/json;q=0.9",
},
});
if (response.status === 404 && allowMissing) {
return null;
}
if (!response.ok) {
throw new Error(`npm registry request failed for ${packageName}: ${response.status} ${response.statusText}`);
}
return response.json();
}
export function collectInternalDependencyProblems(manifest, packageDocsByName) {
const problems = [];
const sections = [
["dependencies", manifest.dependencies ?? {}],
["optionalDependencies", manifest.optionalDependencies ?? {}],
["peerDependencies", manifest.peerDependencies ?? {}],
];
for (const [sectionName, deps] of sections) {
for (const [dependencyName, dependencyVersion] of Object.entries(deps)) {
if (!dependencyName.startsWith("@paperclipai/")) {
continue;
}
if (typeof dependencyVersion !== "string" || !dependencyVersion) {
problems.push(
`${sectionName} declares ${dependencyName} with a non-string version: ${JSON.stringify(dependencyVersion)}`,
);
continue;
}
const dependencyDoc = packageDocsByName.get(dependencyName);
if (!dependencyDoc) {
problems.push(`${sectionName} requires ${dependencyName}@${dependencyVersion}, but that package is not published`);
continue;
}
if (!(dependencyVersion in (dependencyDoc.versions ?? {}))) {
problems.push(
`${sectionName} requires ${dependencyName}@${dependencyVersion}, but npm does not expose that version`,
);
}
}
}
return problems;
}
function requireManifest(packageName, version, packageDoc, problems) {
const manifest = packageDoc.versions?.[version];
if (!manifest) {
if (problems) {
problems.push(`${packageName}: npm registry is missing manifest data for ${version}`);
}
return null;
}
return manifest;
}
export function verifyPackageRegistryState({
packageName,
packageDoc,
packageDocsByName,
channel,
distTag,
targetVersion,
allowCanaryLatest,
}) {
const problems = [];
const distTags = packageDoc["dist-tags"] ?? {};
const taggedVersion = distTags[distTag];
if (taggedVersion !== targetVersion) {
problems.push(
`${packageName}: dist-tag ${distTag} resolves to ${taggedVersion ?? "<missing>"}, expected ${targetVersion}`,
);
}
const targetManifest = requireManifest(packageName, targetVersion, packageDoc, problems);
if (targetManifest) {
for (const problem of collectInternalDependencyProblems(targetManifest, packageDocsByName)) {
problems.push(`${packageName}@${targetVersion}: ${problem}`);
}
}
if (channel === "canary") {
const latestVersion = distTags.latest;
if (latestVersion && isCanaryVersion(latestVersion) && !allowCanaryLatest) {
problems.push(
`${packageName}: latest dist-tag still resolves to canary ${latestVersion}; rerun with --allow-canary-latest only when that state is intentional`,
);
}
if (latestVersion && isCanaryVersion(latestVersion)) {
const latestManifest = requireManifest(packageName, latestVersion, packageDoc, problems);
if (latestManifest) {
for (const problem of collectInternalDependencyProblems(latestManifest, packageDocsByName)) {
problems.push(`${packageName}@${latestVersion} via latest: ${problem}`);
}
}
}
}
return problems;
}
async function main() {
const options = parseArgs(process.argv.slice(2));
const packageNames = [...new Set(options.packages)];
const packageDocsByName = new Map();
await Promise.all(
packageNames.map(async (packageName) => {
packageDocsByName.set(packageName, await fetchPackageDocument(packageName));
}),
);
const additionalInternalDeps = new Set();
for (const packageDoc of packageDocsByName.values()) {
const versionsToCheck = new Set([options.targetVersion]);
const latestVersion = packageDoc["dist-tags"]?.latest;
if (latestVersion && isCanaryVersion(latestVersion)) {
versionsToCheck.add(latestVersion);
}
for (const version of versionsToCheck) {
const manifest = packageDoc.versions?.[version];
if (!manifest) {
continue;
}
for (const deps of [
manifest.dependencies ?? {},
manifest.optionalDependencies ?? {},
manifest.peerDependencies ?? {},
]) {
for (const dependencyName of Object.keys(deps)) {
if (dependencyName.startsWith("@paperclipai/")) {
additionalInternalDeps.add(dependencyName);
}
}
}
}
}
const missingDeps = [...additionalInternalDeps].filter((dep) => !packageDocsByName.has(dep));
await Promise.all(
missingDeps.map(async (dependencyName) => {
packageDocsByName.set(
dependencyName,
await fetchPackageDocument(dependencyName, { allowMissing: true }),
);
}),
);
const problems = [];
for (const packageName of packageNames) {
process.stdout.write(` Verifying ${packageName} on dist-tag ${options.distTag}\n`);
const packageProblems = verifyPackageRegistryState({
packageName,
packageDoc: packageDocsByName.get(packageName),
packageDocsByName,
channel: options.channel,
distTag: options.distTag,
targetVersion: options.targetVersion,
allowCanaryLatest: options.allowCanaryLatest,
});
if (packageProblems.length === 0) {
process.stdout.write(` ✓ dist-tag and published internal dependencies are consistent\n`);
continue;
}
for (const problem of packageProblems) {
process.stderr.write(`${problem}\n`);
problems.push(problem);
}
}
if (problems.length > 0) {
throw new Error(`npm registry verification failed for ${problems.length} problem(s)`);
}
}
const isDirectRun = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
if (isDirectRun) {
main().catch((error) => {
process.stderr.write(`Error: ${error.message}\n`);
process.exit(1);
});
}
@@ -0,0 +1,128 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
collectInternalDependencyProblems,
isCanaryVersion,
verifyPackageRegistryState,
} from "./verify-release-registry-state.mjs";
test("isCanaryVersion matches release canaries", () => {
assert.equal(isCanaryVersion("2026.427.0-canary.3"), true);
assert.equal(isCanaryVersion("2026.427.0"), false);
});
test("collectInternalDependencyProblems flags missing internal versions", () => {
const manifest = {
dependencies: {
"@paperclipai/plugin-sdk": "2026.425.0-canary.5",
e2b: "^2.19.0",
},
};
const packageDocsByName = new Map([
[
"@paperclipai/plugin-sdk",
{
versions: {
"2026.427.0-canary.3": {},
},
},
],
]);
assert.deepEqual(collectInternalDependencyProblems(manifest, packageDocsByName), [
"dependencies requires @paperclipai/plugin-sdk@2026.425.0-canary.5, but npm does not expose that version",
]);
});
test("verifyPackageRegistryState fails when canary latest is left in place by default", () => {
const packageDocsByName = new Map([
[
"@paperclipai/plugin-e2b",
{
"dist-tags": {
latest: "2026.425.0-canary.5",
canary: "2026.427.0-canary.3",
},
versions: {
"2026.425.0-canary.5": {
dependencies: {
"@paperclipai/plugin-sdk": "2026.425.0-canary.5",
},
},
"2026.427.0-canary.3": {
dependencies: {
"@paperclipai/plugin-sdk": "2026.427.0-canary.3",
},
},
},
},
],
[
"@paperclipai/plugin-sdk",
{
versions: {
"2026.427.0-canary.3": {},
},
},
],
]);
assert.deepEqual(
verifyPackageRegistryState({
packageName: "@paperclipai/plugin-e2b",
packageDoc: packageDocsByName.get("@paperclipai/plugin-e2b"),
packageDocsByName,
channel: "canary",
distTag: "canary",
targetVersion: "2026.427.0-canary.3",
allowCanaryLatest: false,
}),
[
"@paperclipai/plugin-e2b: latest dist-tag still resolves to canary 2026.425.0-canary.5; rerun with --allow-canary-latest only when that state is intentional",
"@paperclipai/plugin-e2b@2026.425.0-canary.5 via latest: dependencies requires @paperclipai/plugin-sdk@2026.425.0-canary.5, but npm does not expose that version",
],
);
});
test("verifyPackageRegistryState allows intentional canary latest but still checks dependencies", () => {
const packageDocsByName = new Map([
[
"paperclipai",
{
"dist-tags": {
latest: "2026.427.0-canary.3",
canary: "2026.427.0-canary.3",
},
versions: {
"2026.427.0-canary.3": {
dependencies: {
"@paperclipai/server": "2026.427.0-canary.3",
},
},
},
},
],
[
"@paperclipai/server",
{
versions: {
"2026.427.0-canary.3": {},
},
},
],
]);
assert.deepEqual(
verifyPackageRegistryState({
packageName: "paperclipai",
packageDoc: packageDocsByName.get("paperclipai"),
packageDocsByName,
channel: "canary",
distTag: "canary",
targetVersion: "2026.427.0-canary.3",
allowCanaryLatest: true,
}),
[],
);
});