From 1c4353c99ec03ed7f32f48f1ce04ebe06390090b Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 01:35:57 -0500 Subject: [PATCH 1/6] feat(prerelease): publish the four Rust crates to the private Cargo registry --- docs/features/prerelease.md | 42 +++++++++++++++--- scripts/lib/rust-release.mjs | 18 ++++++++ scripts/prerelease.mjs | 82 ++++++++++++++++++++++++++++++++--- scripts/test-rust-release.mjs | 11 ++++- 4 files changed, 140 insertions(+), 13 deletions(-) diff --git a/docs/features/prerelease.md b/docs/features/prerelease.md index 9280fdf8e..0c50c5624 100644 --- a/docs/features/prerelease.md +++ b/docs/features/prerelease.md @@ -46,7 +46,7 @@ to be talked out of it. One forgotten flag burns a version number permanently. `` is a **monotonic iteration counter**, derived from what the registry already holds across all -four ecosystems so that `--only npm` today and `--only csharp` tomorrow cannot collide. +five ecosystems so that `--only npm` today and `--only csharp` tomorrow cannot collide. **Why a counter and not a commit sha.** npm *strips* SemVer build metadata: `0.24.0-rc.1+aaa` and `0.24.0-rc.1+bbb` compare **equal**, so the second publish is refused @@ -104,7 +104,7 @@ Then: ```bash bun run prerelease:publish # next iteration, npm + Maven (the default scope) bun run prerelease:publish --only python,csharp # pick ports -bun run prerelease:publish --only all # all four +bun run prerelease:publish --only all # all five (npm, python, csharp, java, rust) bun run prerelease:publish --iter 7 # pin the iteration number bun run prerelease:publish --base 0.25.0 # target a different in-development version bun run prerelease:publish --dry-run # build + normalize + gate, publish nothing @@ -150,7 +150,7 @@ check that gates the final cut (`docs/RELEASING.md`, Step 0). bun run prerelease:candidate # = bun run prerelease:publish --only all ``` -The default scope is npm and Maven only, so a Python or a C# estate gets nothing from a bare +The default scope is npm and Maven only, so a Python, C# or Rust estate gets nothing from a bare `prerelease:publish`. Use the full command for any candidate an estate in those ports will run; name a narrower `--only` only for a fix you are iterating on one port. @@ -172,9 +172,39 @@ pushed: a sha nobody can fetch is not a record. ### Rust -There is no Rust candidate on the private registry: the four crates are ready to publish and not -published, and the registry serves npm, PyPI, NuGet and Maven. A Rust consumer **pins the commit** the -candidate's row in the log names: +The four crates (`metaobjects`, `metaobjects-render`, `metaobjects-codegen`, `metaobjects-cli`) publish +to the registry's Cargo index with the other ports: `--only rust` (or its alias `--only cargo`) alone, +and `--only all` as part of a full candidate, after the other ecosystems. They publish in the order +`scripts/release.mjs` uses for crates.io (each crate after the ones it depends on), at the candidate's +SemVer form, `1.3.0-rc.N`. The run edits the manifests for the publish and restores them on exit: it +adds `registry = "mo-prerelease"` to each sibling-crate dependency, so a published crate's siblings +resolve from the private registry and never from crates.io or git. The publish names the registry +explicitly, the crates.io token variable is removed from cargo's environment, and a dry run of the whole +workspace must report the private index before anything is uploaded. Before any ecosystem publishes, the +run also refuses a candidate number the registry already holds for any crate. + +Add the registry to the consumer's `.cargo/config.toml` (reads are anonymous; `` and +`` are the same values `registry.env` carries): + +```toml +[registries.mo-prerelease] +index = "sparse+/api/packages//cargo/" +``` + +```toml +[dependencies] +metaobjects = { version = "=1.3.0-rc.6", registry = "mo-prerelease" } +``` + +```bash +cargo install metaobjects-cli --version 1.3.0-rc.6 --registry mo-prerelease +``` + +A crate's other dependencies still come from crates.io; only the `metaobjects*` crates come from the +private registry. Cargo resolves a candidate only for an exact requirement such as `=1.3.0-rc.6`. + +**Fallback: pin the commit.** A candidate published before the crates joined it (`1.3.0-rc.5` and earlier) +has no crates on the registry, and the commit its row in the log names still works: ```toml [dependencies] diff --git a/scripts/lib/rust-release.mjs b/scripts/lib/rust-release.mjs index 8776bcc1f..5eddc8cb2 100644 --- a/scripts/lib/rust-release.mjs +++ b/scripts/lib/rust-release.mjs @@ -180,6 +180,24 @@ export function bumpRustManifest(text, version) { return out; } +/** + * A crate manifest cut as a pre-release candidate for a PRIVATE registry: `bumpRustManifest`'s + * version edit, plus `registry = ""` on every sibling dependency given by `path`. Without + * it a published crate's sibling dependency names no registry at all, and cargo resolves it from + * crates.io, where no candidate exists. Nothing else in the text changes. + * + * @param {string} text + * @param {string} version + * @param {string} registry the name the private registry is configured under in cargo + * @returns {string} + */ +export function candidateRustManifest(text, version, registry) { + return bumpRustManifest(text, version).split(/(?<=\n)/).map((line) => + /\bpath\s*=/.test(line) && !/\bregistry\s*=/.test(line) + ? line.replace(/(\bversion\s*=\s*"[^"]*")/, `$1, registry = "${registry}"`) + : line).join(""); +} + /** * Whether crates.io already holds `version` of a crate, from the JSON its * `/api/v1/crates/` endpoint answers. A crate that does not exist answers 404, which diff --git a/scripts/prerelease.mjs b/scripts/prerelease.mjs index c243b54d3..b8e108c02 100644 --- a/scripts/prerelease.mjs +++ b/scripts/prerelease.mjs @@ -5,7 +5,8 @@ // // bun run prerelease:publish # next iteration, npm + Maven (the default scope) // bun run prerelease:publish --only npm,csharp # pick ports -// bun run prerelease:publish --only all # all four +// bun run prerelease:publish --only all # all five (npm, python, csharp, java, rust) +// bun run prerelease:publish --only rust # just the four Rust crates (alias: cargo) // bun run prerelease:candidate # the same: a FULL candidate, every registry // bun run prerelease:publish --iter 5 # pin the iteration number // bun run prerelease:publish --base 0.25.0 # override the in-development version @@ -29,6 +30,7 @@ // NuGet 0.24.0-rc.3 SemVer2, verbatim // PyPI 0.24.0rc3 PEP 440 canonical form // Maven 7.24.0-rc.3 same minor.patch, major = npm major + 7 (1.1.0-rc.2 -> 8.1.0-rc.2) +// Cargo 0.24.0-rc.3 SemVer2, verbatim (the four crates, published in dependency order) // // The iteration counter — not a commit sha — is the collision breaker, because npm STRIPS // SemVer build metadata: `0.24.0-rc.1+aaa` and `0.24.0-rc.1+bbb` compare EQUAL, so the @@ -59,12 +61,17 @@ // bare `mvn deploy` has no target at all. // 6. Version declarations are edited in place and ALWAYS restored on exit; the script // refuses to start if any of them is already dirty. +// 7. Cargo publishes with an explicit `--registry` naming the private registry, whose index +// address cargo is given through the environment, so crates.io is never the target; the +// crates.io token variable is removed from the child environment, and the sibling-crate +// dependencies are pinned to that same registry in the edited manifests. import { execSync } from "node:child_process"; import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from "node:fs"; -import { join } from "node:path"; +import { join, relative } from "node:path"; import { FRAGMENT_DIR, readFragments, unfoldedFragmentsProblem } from "./lib/changelog-fragments.mjs"; import { mavenVersion } from "./maven-coordinate.mjs"; import { TIER_ORDER } from "./publish-set.mjs"; +import { RUST_DIR, candidateRustManifest, rustPublishOrder } from "./lib/rust-release.mjs"; import { appendCandidateLog, candidateLogRow, candidateRegistries, changelogVersions, collectPages, decideBase, installRestoreHandlers, releasedVersion, run as runStep, } from "./prerelease-version.mjs"; @@ -131,6 +138,9 @@ const NPM_REG = assertTarget(`${BASE}/api/packages/${OWNER}/npm/`, "npm"); const PYPI_URL = assertTarget(`${BASE}/api/packages/${OWNER}/pypi`, "pypi"); const NUGET_SRC = assertTarget(`${BASE}/api/packages/${OWNER}/nuget/index.json`, "nuget"); const MAVEN_URL = assertTarget(`${BASE}/api/packages/${OWNER}/maven`, "maven"); +// Gitea's Cargo registry is a sparse index; cargo is handed it by name through the environment. +const CARGO_URL = assertTarget(`${BASE}/api/packages/${OWNER}/cargo/`, "cargo"); +const CARGO_REGISTRY = "mo-prerelease"; // ── version scheme ──────────────────────────────────────────────────────────────────── // What the repository says it is: the lockstep set is every package carrying this version. @@ -189,7 +199,7 @@ const LOCKSTEP = sh("ls -d server/typescript/packages/*/ client/web/packages/*/" const ITER_RE = new RegExp(`^\\d+\\.${BASEVER.split(".").slice(1).join("\\.")}(?:-rc\\.|rc)(\\d+)$`); -// Iteration: explicit, else 1 + the highest already taken — across ALL FOUR ecosystems on +// Iteration: explicit, else 1 + the highest already taken — across ALL FIVE ecosystems on // the pre-release registry, so `--only npm` today and `--only csharp` tomorrow cannot // collide (a used number is a hard 409 on every one of them). Every page: the registry serves // 50 per page whatever `limit` asks, and a used number past the first page was invisible. @@ -246,14 +256,16 @@ const V = { nuget: CANON, pypi: `${BASEVER}rc${ITER}`, maven: mavenVersion(CANON), + cargo: CANON, }; -const ALL = ["npm", "python", "csharp", "java"]; +const ALL = ["npm", "python", "csharp", "java", "rust"]; // The default is npm AND Maven: a JVM adopter cannot test a candidate that exists only on npm, and // the one that tried had to build the Maven artifacts from source by hand. Python and C# stay opt-in. const DEFAULT_ONLY = "npm,java"; const onlyArg = flag("only", DEFAULT_ONLY); -const ONLY = onlyArg === "all" ? ALL : onlyArg.split(",").map((s) => s.trim()); +// `cargo` is accepted for `rust`: the registry calls it that, the port is called this. +const ONLY = onlyArg === "all" ? ALL : onlyArg.split(",").map((s) => s.trim()).map((s) => (s === "cargo" ? "rust" : s)); const unknown = ONLY.filter((p) => !ALL.includes(p)); if (unknown.length) die(`--only expects ${ALL.join("|")}|all, got '${unknown.join(",")}'`); const wants = (p) => ONLY.includes(p); @@ -262,7 +274,7 @@ console.log(`\n── pre-release ${CANON}${DRY ? " (DRY RUN)" : ""} → ${expe // Name where the base came from. A version number is spent permanently the moment it is // published, so the one value worth reading before the run is the one that was inferred. info(`released: ${RELEASED ?? "unknown"} committed: ${COMMITTED} base: ${BASEVER} (from ${BASE_SOURCE}) iteration: ${ITER}`); -info(`npm ${V.npm} · pypi ${V.pypi} · nuget ${V.nuget} · maven ${V.maven}`); +info(`npm ${V.npm} · pypi ${V.pypi} · nuget ${V.nuget} · maven ${V.maven} · cargo ${V.cargo}`); info(`ports: ${ONLY.join(", ")}\n`); ok(`publish target verified: ${expectedHost} (configured registry; not a public one)`); @@ -274,6 +286,7 @@ const VERSION_FILES = [ // the Java step if it lags, so the candidate bump has to reach it too. "examples/showcase/jvm/pom.xml", "server/python/pyproject.toml", "server/csharp/Directory.Build.props", + "server/rust/Cargo.toml", "server/rust/*/Cargo.toml", "server/rust/Cargo.lock", "bun.lock", ]; const dirty = sh(`git status --porcelain -- ${VERSION_FILES.map((f) => `'${f}'`).join(" ")}`).trim(); @@ -293,6 +306,21 @@ if (ONLY.length === ALL.length) { const CANDIDATE_LOG = "tools/prerelease/candidates.md"; const builtFromDirtyTree = sh("git status --porcelain --untracked-files=all").split("\n") .some((l) => l.trim() && l.slice(3) !== CANDIDATE_LOG); +// The crates, in the order the release publishes them (scripts/lib/rust-release.mjs). Read before +// anything is edited or published, so a candidate number the registry already holds for a crate stops +// the run BEFORE npm or Maven have published theirs: a used number is a hard 409 on every ecosystem. +const RUST_CRATES = wants("rust") + ? rustPublishOrder(JSON.parse(sh(`cd ${RUST_DIR} && cargo metadata --format-version 1 --no-deps --locked`))) + : []; +for (const name of RUST_CRATES) { + let status; + try { + status = sh(`curl -sS --max-time 10 -o /dev/null -w "%{http_code}" -u "${OWNER}:${TOKEN}" "${BASE}/api/v1/packages/${OWNER}/cargo/${name}/${V.cargo}"`).trim(); + } catch (e) { die(`could not ask the pre-release registry whether ${name}@${V.cargo} exists: ${e.message}`); } + if (status === "200") die(`${name}@${V.cargo} is already on the pre-release registry — pick the next free iteration (--iter)`); + if (status !== "404") die(`the pre-release registry answered HTTP ${status} for ${name}@${V.cargo}; cannot tell whether it is free`); +} +if (RUST_CRATES.length) ok(`cargo: ${RUST_CRATES.length} crates (${RUST_CRATES.join(" → ")}) free at ${V.cargo}`); const published = []; // registries this run published to completely, in order const started = []; // registries whose first publish call began; one that is not in `published` was cut short const begin = (eco) => { if (!DRY) started.push(eco); }; @@ -460,6 +488,48 @@ if (wants("java")) { if (!DRY) published.push("java"); } +// ── rust ────────────────────────────────────────────────────────────────────────────── +// The four crates, to the registry's Cargo index, in dependency order. This is the path the final +// release takes to crates.io, run first against a registry where a mistake can be undone. +if (wants("rust")) { + const manifests = [join(RUST_DIR, "Cargo.toml"), + ...JSON.parse(await run(`cd ${RUST_DIR} && cargo metadata --format-version 1 --no-deps --locked`)).packages + .map((p) => relative(ROOT, p.manifest_path))]; + touch(...manifests, join(RUST_DIR, "Cargo.lock")); + for (const m of manifests) + writeFileSync(join(ROOT, m), candidateRustManifest(readFileSync(join(ROOT, m), "utf8"), V.cargo, CARGO_REGISTRY)); + const env = { ...process.env, + CARGO_REGISTRIES_MO_PRERELEASE_INDEX: `sparse+${CARGO_URL}`, + CARGO_REGISTRIES_MO_PRERELEASE_TOKEN: `Bearer ${TOKEN}`, + CARGO_TARGET_DIR: keptScratch("rust-target"), + CARGO_INCREMENTAL: "0", CARGO_PROFILE_DEV_DEBUG: "0" }; + delete env.CARGO_REGISTRY_TOKEN; // the crates.io token variable: never in this child + delete env.CARGO_REGISTRY_DEFAULT; delete env.CARGO_REGISTRIES_CRATES_IO_TOKEN; + + // Offline: re-pin the workspace's own crates in the lockfile, fetching nothing. + await run(`cd ${RUST_DIR} && cargo update --workspace --offline`, { env }); + ok(`rust manifests → ${V.cargo} (${manifests.length} files, siblings pinned to the private registry)`); + + // GATE 8 — the crates must pack and build from their own tarballs, the siblings resolving from + // the private registry. `--workspace` resolves a sibling from the tarball it just made, which is + // what lets a crate that depends on an unpublished sibling verify at all. + const probe = await run(`cd ${RUST_DIR} && cargo publish --dry-run --workspace --locked --allow-dirty --registry ${CARGO_REGISTRY} 2>&1`, { env }); + // Believe only what cargo reports: it must have read the private index, and must name no + // upload to crates.io. (Reading crates.io for third-party dependencies is ordinary and expected.) + if (!probe.includes("Updating `mo-prerelease` index") || /Uploading .* to crates\.io|registry `crates-io`/.test(probe)) + die(`cargo's dry run did not target ${CARGO_REGISTRY} — aborting:\n${probe}`); + ok(`cargo publish dry run passed against ${expectedHost}`); + + begin("rust"); + if (!DRY) for (const name of RUST_CRATES) { + // cargo waits for each crate to appear in the index before it returns, so the next can resolve it. + await run(`cd ${RUST_DIR} && cargo publish -p ${name} --locked --allow-dirty --registry ${CARGO_REGISTRY}`, { env, stdio: "inherit" }); + info(`published ${name}@${V.cargo}`); + } + ok(DRY ? "rust: dry run, nothing published" : `rust: ${RUST_CRATES.length} crates @ ${V.cargo} → ${expectedHost}`); + if (!DRY) published.push("rust"); +} + restoreAndRecord(); if (DRY) { console.log(`\n\x1b[32m\x1b[1m✔ dry run of ${CANON} passed; nothing was published.\x1b[0m\n`); diff --git a/scripts/test-rust-release.mjs b/scripts/test-rust-release.mjs index c96098281..6c6fd5182 100644 --- a/scripts/test-rust-release.mjs +++ b/scripts/test-rust-release.mjs @@ -9,7 +9,7 @@ // after its dependencies, and a version once taken is taken. import { - isRustProductPath, newestRustTag, rustPublishDecision, rustPublishOrder, bumpRustManifest, + isRustProductPath, newestRustTag, rustPublishDecision, rustPublishOrder, bumpRustManifest, candidateRustManifest, crateVersionTaken, EXPECTED_REGISTRY, } from "./lib/rust-release.mjs"; @@ -107,6 +107,15 @@ check(bumpedMember.includes('metaobjects = { path = "../metaobjects", version = check(bumpedMember.includes('clap = { version = "4.5", features = ["derive"] }'), "a registry dependency is left alone"); check(bumpedMember.includes("version.workspace = true"), "an inherited version stays inherited"); +// A candidate manifest for a private registry: siblings resolve from it, nothing else changes. +const cand = candidateRustManifest(member, "1.3.0-rc.6", "mo-prerelease"); +check(cand.includes('metaobjects = { path = "../metaobjects", version = "1.3.0-rc.6", registry = "mo-prerelease" }') + && cand.includes('metaobjects-codegen = { path = "../metaobjects-codegen", version = "1.3.0-rc.6", registry = "mo-prerelease" }'), + "a candidate names the private registry on each sibling dependency"); +check(cand.includes('clap = { version = "4.5", features = ["derive"] }'), "a candidate leaves a crates.io dependency on crates.io"); +check(candidateRustManifest(cand, "1.3.0-rc.6", "mo-prerelease") === cand, "the registry key is not added twice"); +check(candidateRustManifest(root, "1.3.0-rc.6", "mo-prerelease").includes('version = "1.3.0-rc.6"'), "the workspace version moves"); + // What crates.io answers. check(crateVersionTaken({ versions: [{ num: "1.3.0" }, { num: "1.2.0" }] }, "1.3.0"), "a published version is taken"); check(!crateVersionTaken({ versions: [{ num: "1.3.0-rc.1" }] }, "1.3.0"), "a candidate does not take the final number"); From 508b632a06cbfef29fba87ce274cfa2a9133db5c Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 01:37:28 -0500 Subject: [PATCH 2/6] chore(prerelease): record the 1.3.0-rc.6 Rust crates --- tools/prerelease/candidates.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/prerelease/candidates.md b/tools/prerelease/candidates.md index 174e88b3f..b7c7bae70 100644 --- a/tools/prerelease/candidates.md +++ b/tools/prerelease/candidates.md @@ -10,3 +10,4 @@ to commit each row, are in docs/features/prerelease.md, section 2a. | 1.3.0-rc.3 | `5b524d2692a5` | 2026-11-28 23:31 | npm, python, csharp, java | | 1.3.0-rc.4 | `90ae22ee288c` | 2026-11-29 08:49 | npm, python, csharp, java | | 1.3.0-rc.5 | `0f1e8055b6d1` | 2026-11-30 16:14 | npm, python, csharp, java | +| 1.3.0-rc.6 | `94e4475ffa7d` | 2026-12-01 06:36 | rust | From cfaf98d948d90656a2d0db40f74670f859f4f88f Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 01:54:48 -0500 Subject: [PATCH 3/6] no-mistakes(document): Document Rust prerelease candidates --- changelog.d/prerelease-rust-candidates.md | 7 +++++++ docs/features/prerelease.md | 4 +++- scripts/prerelease-version.mjs | 2 +- scripts/prerelease.mjs | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelog.d/prerelease-rust-candidates.md diff --git a/changelog.d/prerelease-rust-candidates.md b/changelog.d/prerelease-rust-candidates.md new file mode 100644 index 000000000..6f1eea1a8 --- /dev/null +++ b/changelog.d/prerelease-rust-candidates.md @@ -0,0 +1,7 @@ +- **Pre-release candidates publish the four Rust crates.** `bun run prerelease:publish --only rust` + (alias `cargo`, and part of `--only all`) publishes `metaobjects`, `metaobjects-render`, + `metaobjects-codegen` and `metaobjects-cli` to the private registry's Cargo index in dependency + order, so the sibling-crate publish path is proven before the crates.io cut. Sibling dependencies + are pinned to the private registry for the publish and restored afterwards. A Rust consumer adds + the registry in `.cargo/config.toml` (see `docs/features/prerelease.md`, "Rust"); candidates + before `1.3.0-rc.6` still pin a commit. diff --git a/docs/features/prerelease.md b/docs/features/prerelease.md index 0c50c5624..3e88dc3a6 100644 --- a/docs/features/prerelease.md +++ b/docs/features/prerelease.md @@ -12,7 +12,7 @@ releases with a verified one-command revert. | | | |---|---| -| Registry | one Gitea instance serving npm, PyPI, NuGet and Maven — the address is configuration (`MO_REGISTRY_BASE`), never a committed default; see [§7](#7-running-your-own-registry) | +| Registry | one Gitea instance serving npm, PyPI, NuGet, Maven and Cargo — the address is configuration (`MO_REGISTRY_BASE`), never a committed default; see [§7](#7-running-your-own-registry) | | Reads | **anonymous** — a consumer needs the URL and the owner, no account and no token | | Writes | token only, in gitignored local config, never in a committed file | | Publisher | `bun run prerelease:publish` (`scripts/prerelease.mjs`) | @@ -243,6 +243,8 @@ Everything else keeps resolving from the public registry — verified: `zod` and still come from npmjs.org and pypi.org while the vendor packages come from the pre-release registry. +`link` does not configure Cargo: a Rust consumer adds the registry by hand, as [§2a Rust](#rust) shows. + Everything it writes is delimited by managed markers, so `unlink` removes exactly what `link` added: diff --git a/scripts/prerelease-version.mjs b/scripts/prerelease-version.mjs index ca9813b2b..230c713a8 100644 --- a/scripts/prerelease-version.mjs +++ b/scripts/prerelease-version.mjs @@ -110,7 +110,7 @@ export const CANDIDATE_LOG_HEADER = /** * One row of the candidate log. `candidate` is the canonical `-rc.`; `registries` the - * ecosystems actually published (npm, python, csharp, java). + * ecosystems actually published (npm, python, csharp, java, rust). */ export function candidateLogRow({ candidate, commit, dirty, date, registries }) { if (!/^\d+\.\d+\.\d+-rc\.\d+$/.test(candidate)) throw new Error(`not a candidate version: ${candidate}`); diff --git a/scripts/prerelease.mjs b/scripts/prerelease.mjs index b8e108c02..a3dcad94f 100644 --- a/scripts/prerelease.mjs +++ b/scripts/prerelease.mjs @@ -234,7 +234,7 @@ const burnedPublicIters = async () => { const explicitIter = flag("iter", null); const burned = await burnedPublicIters(); -// The next free iteration across all four ecosystems. The `??` above skips this whole +// The next free iteration across all five ecosystems. The `??` above skips this whole // call — including its registry fetches — when --iter was given. const nextIter = async () => { const taken = [...await usedIters(), ...burned]; From 6cc1cda8c8ee3043a4f8b6664f45cd9f21677fff Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 02:01:20 -0500 Subject: [PATCH 4/6] fix(prerelease): prove the Cargo publish target from the invocation and cargo's report --- scripts/lib/rust-release.mjs | 47 +++++++++++++++++++++++++++++++++++ scripts/prerelease.mjs | 23 +++++++++++------ scripts/test-rust-release.mjs | 30 ++++++++++++++++++++++ 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/scripts/lib/rust-release.mjs b/scripts/lib/rust-release.mjs index 5eddc8cb2..0ef30811a 100644 --- a/scripts/lib/rust-release.mjs +++ b/scripts/lib/rust-release.mjs @@ -210,3 +210,50 @@ export function candidateRustManifest(text, version, registry) { export function crateVersionTaken(json, version) { return (json.versions ?? []).some((v) => v.num === version); } + +/** The environment variable cargo reads a named registry's index address from. */ +export const cargoIndexVar = (registry) => `CARGO_REGISTRIES_${registry.toUpperCase().replaceAll("-", "_")}_INDEX`; + +/** Where crates.io lives, in each form cargo accepts: the sparse index and the retired git index. */ +const CRATES_IO = /(^|[/@.])(crates\.io|index\.crates\.io|crates-io)([/:.]|$)|rust-lang\/crates\.io-index/; + +/** + * Refuse a `cargo publish` invocation that could reach anywhere but the private registry. + * `args` is the argument list after `cargo publish`; `env` is the child environment. + * It proves the target from what cargo will be GIVEN, because a dry run prints no target. + * + * @param {{args: string[], env: Record, registry: string, expectedIndex: string}} input + * @throws when the invocation is not bound to exactly the expected private registry. + */ +export function assertCargoPublishTarget({ args, env, registry, expectedIndex }) { + const at = args.indexOf("--registry"); + if (at === -1 || args[at + 1] !== registry || args.indexOf("--registry", at + 1) !== -1) + throw new Error(`cargo publish must name exactly one --registry, "${registry}"; got [${args.join(" ")}]`); + const banned = args.filter((a) => a === "--index" || a === "--token" || a.startsWith("--index=") || a.startsWith("--token=")); + if (banned.length) throw new Error(`cargo publish must not set ${banned.join(", ")}: the target is the named registry`); + const index = env[cargoIndexVar(registry)]; + if (index !== expectedIndex) + throw new Error(`cargo would read registry "${registry}" from ${index ?? "nothing"}, not the configured ${expectedIndex}`); + if (CRATES_IO.test(expectedIndex)) throw new Error(`the expected index ${expectedIndex} is crates.io`); + for (const v of ["CARGO_REGISTRY_TOKEN", "CARGO_REGISTRY_DEFAULT", "CARGO_REGISTRIES_CRATES_IO_TOKEN", "CARGO_REGISTRIES_CRATES_IO_INDEX"]) + if (env[v]) throw new Error(`${v} is set in the cargo environment: it could redirect or authorize a crates.io publish`); +} + +/** + * Read what cargo printed and refuse anything that names a target other than the private registry. + * Cargo reports a publish as ``Uploaded to registry `` `` and + * ``Published at registry `` ``, and states a registry's index address in a + * ``name of alternative registry `` `` note; each must match. A dry run prints none of the + * first two, so `published` demands them for a real publish. + * + * @param {{output: string, registry: string, expectedIndex: string, published?: boolean}} input + * @throws when the output names another registry, or a real publish never confirms this one. + */ +export function assertCargoPublishOutput({ output, registry, expectedIndex, published = false }) { + for (const m of output.matchAll(/\b(?:Uploaded|Published)\b[^\n]*?\b(?:to|at) registry `([^`]*)`/g)) + if (m[1] !== registry) throw new Error(`cargo reports a publish to registry \`${m[1]}\`, not \`${registry}\`: ${m[0].trim()}`); + for (const m of output.matchAll(/alternative registry `([^`]*)`/g)) + if (m[1] !== expectedIndex) throw new Error(`cargo reports registry index ${m[1]}, not the configured ${expectedIndex}`); + if (published && !new RegExp(`Published [^\\n]* at registry \`${registry}\``).test(output)) + throw new Error(`cargo never confirmed a publish to registry \`${registry}\``); +} diff --git a/scripts/prerelease.mjs b/scripts/prerelease.mjs index a3dcad94f..d8fe01785 100644 --- a/scripts/prerelease.mjs +++ b/scripts/prerelease.mjs @@ -71,7 +71,7 @@ import { join, relative } from "node:path"; import { FRAGMENT_DIR, readFragments, unfoldedFragmentsProblem } from "./lib/changelog-fragments.mjs"; import { mavenVersion } from "./maven-coordinate.mjs"; import { TIER_ORDER } from "./publish-set.mjs"; -import { RUST_DIR, candidateRustManifest, rustPublishOrder } from "./lib/rust-release.mjs"; +import { RUST_DIR, assertCargoPublishOutput, assertCargoPublishTarget, candidateRustManifest, rustPublishOrder } from "./lib/rust-release.mjs"; import { appendCandidateLog, candidateLogRow, candidateRegistries, changelogVersions, collectPages, decideBase, installRestoreHandlers, releasedVersion, run as runStep, } from "./prerelease-version.mjs"; @@ -504,7 +504,7 @@ if (wants("rust")) { CARGO_TARGET_DIR: keptScratch("rust-target"), CARGO_INCREMENTAL: "0", CARGO_PROFILE_DEV_DEBUG: "0" }; delete env.CARGO_REGISTRY_TOKEN; // the crates.io token variable: never in this child - delete env.CARGO_REGISTRY_DEFAULT; delete env.CARGO_REGISTRIES_CRATES_IO_TOKEN; + delete env.CARGO_REGISTRY_DEFAULT; delete env.CARGO_REGISTRIES_CRATES_IO_TOKEN; delete env.CARGO_REGISTRIES_CRATES_IO_INDEX; // Offline: re-pin the workspace's own crates in the lockfile, fetching nothing. await run(`cd ${RUST_DIR} && cargo update --workspace --offline`, { env }); @@ -513,17 +513,24 @@ if (wants("rust")) { // GATE 8 — the crates must pack and build from their own tarballs, the siblings resolving from // the private registry. `--workspace` resolves a sibling from the tarball it just made, which is // what lets a crate that depends on an unpublished sibling verify at all. - const probe = await run(`cd ${RUST_DIR} && cargo publish --dry-run --workspace --locked --allow-dirty --registry ${CARGO_REGISTRY} 2>&1`, { env }); - // Believe only what cargo reports: it must have read the private index, and must name no - // upload to crates.io. (Reading crates.io for third-party dependencies is ordinary and expected.) - if (!probe.includes("Updating `mo-prerelease` index") || /Uploading .* to crates\.io|registry `crates-io`/.test(probe)) - die(`cargo's dry run did not target ${CARGO_REGISTRY} — aborting:\n${probe}`); + // A dry run prints no target, so the target is proven from what cargo is GIVEN (the one place + // that decides it) and checked again against what cargo REPORTS. + const cargoPublish = async (extra) => { + const args = [...extra, "--locked", "--allow-dirty", "--registry", CARGO_REGISTRY]; + try { assertCargoPublishTarget({ args, env, registry: CARGO_REGISTRY, expectedIndex: `sparse+${CARGO_URL}` }); } + catch (e) { die(`refusing to run cargo publish: ${e.message}`); } + const out = await run(`cd ${RUST_DIR} && cargo publish ${args.join(" ")} 2>&1`, { env }); + try { assertCargoPublishOutput({ output: out, registry: CARGO_REGISTRY, expectedIndex: `sparse+${CARGO_URL}`, published: !extra.includes("--dry-run") }); } + catch (e) { die(`${e.message}\n${out}`); } + return out; + }; + await cargoPublish(["--dry-run", "--workspace"]); ok(`cargo publish dry run passed against ${expectedHost}`); begin("rust"); if (!DRY) for (const name of RUST_CRATES) { // cargo waits for each crate to appear in the index before it returns, so the next can resolve it. - await run(`cd ${RUST_DIR} && cargo publish -p ${name} --locked --allow-dirty --registry ${CARGO_REGISTRY}`, { env, stdio: "inherit" }); + console.log(await cargoPublish(["-p", name])); info(`published ${name}@${V.cargo}`); } ok(DRY ? "rust: dry run, nothing published" : `rust: ${RUST_CRATES.length} crates @ ${V.cargo} → ${expectedHost}`); diff --git a/scripts/test-rust-release.mjs b/scripts/test-rust-release.mjs index 6c6fd5182..f95f768f8 100644 --- a/scripts/test-rust-release.mjs +++ b/scripts/test-rust-release.mjs @@ -10,6 +10,7 @@ import { isRustProductPath, newestRustTag, rustPublishDecision, rustPublishOrder, bumpRustManifest, candidateRustManifest, + assertCargoPublishTarget, assertCargoPublishOutput, cargoIndexVar, crateVersionTaken, EXPECTED_REGISTRY, } from "./lib/rust-release.mjs"; @@ -116,6 +117,35 @@ check(cand.includes('clap = { version = "4.5", features = ["derive"] }'), "a can check(candidateRustManifest(cand, "1.3.0-rc.6", "mo-prerelease") === cand, "the registry key is not added twice"); check(candidateRustManifest(root, "1.3.0-rc.6", "mo-prerelease").includes('version = "1.3.0-rc.6"'), "the workspace version moves"); +// The publish-target gate: a crates.io-bound invocation is refused; the private one passes. +const REG = "mo-prerelease"; +const IDX = "sparse+https://registry.example/api/packages/owner/cargo/"; +const goodEnv = { [cargoIndexVar(REG)]: IDX, PATH: "/usr/bin" }; +const goodArgs = ["-p", "metaobjects", "--locked", "--registry", REG]; +const target = (over = {}) => assertCargoPublishTarget({ args: goodArgs, env: goodEnv, registry: REG, expectedIndex: IDX, ...over }); +check(cargoIndexVar(REG) === "CARGO_REGISTRIES_MO_PRERELEASE_INDEX", "the index variable cargo reads for a hyphenated registry name"); +check(!throws(() => target()), "a publish naming the private registry and its index is allowed"); +check(throws(() => target({ args: ["-p", "metaobjects", "--locked"] })), "no --registry would publish to crates.io: refused"); +check(throws(() => target({ args: [...goodArgs, "--registry", "crates-io"] })), "a second --registry is refused"); +check(throws(() => target({ args: ["--registry", "crates-io"] })), "--registry crates-io is refused"); +check(throws(() => target({ args: [...goodArgs, "--index", "https://index.crates.io/"] })), "--index is refused"); +check(throws(() => target({ args: [...goodArgs, "--token=abc"] })), "--token is refused"); +check(throws(() => target({ env: { PATH: "/usr/bin" } })), "a registry with no index configured is refused"); +check(throws(() => target({ env: { [cargoIndexVar(REG)]: "sparse+https://index.crates.io/" } })), "an index other than the configured one is refused"); +check(throws(() => target({ env: { ...goodEnv, CARGO_REGISTRY_TOKEN: "x" } })), "a crates.io token in the environment is refused"); +check(throws(() => target({ env: { ...goodEnv, CARGO_REGISTRY_DEFAULT: "crates-io" } })), "a redirected default registry is refused"); +check(throws(() => target({ env: { [cargoIndexVar(REG)]: "sparse+https://index.crates.io/" }, expectedIndex: "sparse+https://index.crates.io/" })), + "an expected index that is crates.io is refused"); +const outOk = " Uploaded metaobjects v1.3.0-rc.6 to registry `mo-prerelease`\n Published metaobjects v1.3.0-rc.6 at registry `mo-prerelease`\n" + + `note: name of alternative registry \`${IDX}\` set to \`mo_prerelease\`\n`; +const reported = (output, published = true) => assertCargoPublishOutput({ output, registry: REG, expectedIndex: IDX, published }); +check(!throws(() => reported(outOk)), "cargo reporting the private registry throughout is accepted"); +check(throws(() => reported(" Published metaobjects v1.3.0-rc.6 at registry `crates-io`\n")), "a publish reported at crates-io is refused"); +check(throws(() => reported(outOk + " Uploaded x v1 to registry `crates-io`\n")), "one upload to another registry among good ones is refused"); +check(throws(() => reported("note: name of alternative registry `sparse+https://index.crates.io/` set to `x`\n", false)), "a different index address is refused"); +check(throws(() => reported(" Packaged 3 files\n")), "a real publish that never confirms the private registry is refused"); +check(!throws(() => reported(" Uploading metaobjects v1.3.0-rc.6 (path)\nwarning: aborting upload due to dry run\n", false)), "a dry run's output, which names no target, is accepted"); + // What crates.io answers. check(crateVersionTaken({ versions: [{ num: "1.3.0" }, { num: "1.2.0" }] }, "1.3.0"), "a published version is taken"); check(!crateVersionTaken({ versions: [{ num: "1.3.0-rc.1" }] }, "1.3.0"), "a candidate does not take the final number"); From 93e771245422ae17ec8c2c3a7de4e6380b23fadd Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 04:04:20 -0500 Subject: [PATCH 5/6] no-mistakes(test): apply changes made during test validation --- scripts/lib/rust-release.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/lib/rust-release.mjs b/scripts/lib/rust-release.mjs index 0ef30811a..a4d33e0cb 100644 --- a/scripts/lib/rust-release.mjs +++ b/scripts/lib/rust-release.mjs @@ -211,7 +211,11 @@ export function crateVersionTaken(json, version) { return (json.versions ?? []).some((v) => v.num === version); } -/** The environment variable cargo reads a named registry's index address from. */ +/** + * The environment variable cargo reads a named registry's index address from. + * @param {string} registry + * @returns {string} + */ export const cargoIndexVar = (registry) => `CARGO_REGISTRIES_${registry.toUpperCase().replaceAll("-", "_")}_INDEX`; /** Where crates.io lives, in each form cargo accepts: the sparse index and the retired git index. */ From 9ef68687c1b7c26dccfb9a77d5191d6115488527 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Tue, 1 Dec 2026 04:06:07 -0500 Subject: [PATCH 6/6] no-mistakes(document): Rust candidate docs and comments updated --- scripts/prerelease.mjs | 2 +- tools/prerelease/estate-run.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/prerelease.mjs b/scripts/prerelease.mjs index d8fe01785..12b8ef048 100644 --- a/scripts/prerelease.mjs +++ b/scripts/prerelease.mjs @@ -348,7 +348,7 @@ const restore = () => { }; // The repository's record of which commit each candidate was built from. It is written however the // run ends, because a run that stops after one registry has still burned the candidate number -// there, and a Rust consumer pins the commit this row names. Written after restore(), so the +// there, and a candidate published before the Rust crates joined names the commit to pin. Written after restore(), so the // entry is the only change the run leaves behind. let recorded = false; const recordCandidate = () => { diff --git a/tools/prerelease/estate-run.md b/tools/prerelease/estate-run.md index 5d6e27d90..5024d4870 100644 --- a/tools/prerelease/estate-run.md +++ b/tools/prerelease/estate-run.md @@ -32,8 +32,8 @@ inside the estate is refused). `--keep-linked` skips the restore and leaves the regenerated tree in place. `--no-link` skips link and unlink but still restores the estate. `--help` lists the flags. The default install, generation, verify and version-read commands for each port are in the `case` block of `estate-run.sh`; `--install-cmd`, `--gen-cmd`, `--verify-cmd` and -`--versions-cmd` override them. Rust has no estate path: a Rust consumer pins the commit -(`docs/features/prerelease.md`, "Rust"). +`--versions-cmd` override them. Rust has no estate path: a Rust consumer adds the private Cargo +registry by hand (`docs/features/prerelease.md`, "Rust"). A Java, Python or C# estate can carry TypeScript packages too: a web client, or a build step that runs `meta gen` and `meta verify` through `bun install --frozen-lockfile`. The link repins every