From 4886a406f9c86f7a286ea20cc1a9b46c2bfd3913 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Mon, 30 Nov 2026 22:39:39 +0800 Subject: [PATCH] fix(release): recover verified versions after npm advances (#15234) Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> --- .github/workflows/release-recovery.yml | 2 +- docs/development/releasing.md | 3 ++ scripts/ci/npm-release.d.mts | 1 + scripts/ci/npm-release.mjs | 26 ++++++++++++--- scripts/verify-published-package.mjs | 12 +++++-- tests/boundary/filesystem/npmRelease.test.ts | 33 +++++++++++++++++++ .../filesystem/releaseRecovery.test.ts | 3 ++ .../publishedPackageNpmSelection.test.ts | 25 ++++++++++---- 8 files changed, 90 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release-recovery.yml b/.github/workflows/release-recovery.yml index 2848112b15f..f74c35ef20e 100644 --- a/.github/workflows/release-recovery.yml +++ b/.github/workflows/release-recovery.yml @@ -88,7 +88,7 @@ jobs: - name: Verify published CLI, MCP and update env: RECOVERY_VERSION: ${{ steps.release.outputs.version }} - run: node scripts/verify-published-package.mjs "$RECOVERY_VERSION" + run: node scripts/verify-published-package.mjs "$RECOVERY_VERSION" --recovery - name: Validate released registry metadata working-directory: .cache/release-source run: npm run mcp-registry:check diff --git a/docs/development/releasing.md b/docs/development/releasing.md index a10b778438a..63b09275a18 100644 --- a/docs/development/releasing.md +++ b/docs/development/releasing.md @@ -163,6 +163,9 @@ and verifier runtime. Expired or missing artifacts stop recovery. The archive's original run/attempt and Node version must match, and its SHA-512 must equal npm's published integrity. The corrected controller runs the public CLI, MCP catalog/session and previous-version update canary against that released runtime. +If the release channel has advanced to a newer version, recovery still verifies +the requested version's package and exercises its updater against the current +stable `latest`. The installation completes before MCP's handshake begins; dependency lifecycle scripts are disabled as in the installed-package verifier. diff --git a/scripts/ci/npm-release.d.mts b/scripts/ci/npm-release.d.mts index 4ad6b47d661..f8ad24c8479 100644 --- a/scripts/ci/npm-release.d.mts +++ b/scripts/ci/npm-release.d.mts @@ -7,6 +7,7 @@ export function readNpmRelease( export function stableUpdateVersion( version: string, published: NpmReleaseState, + options?: { allowSuperseded?: boolean }, ): string; export function waitForNpmRelease( version: string, diff --git a/scripts/ci/npm-release.mjs b/scripts/ci/npm-release.mjs index 5de9670a86c..26a8bbedd74 100644 --- a/scripts/ci/npm-release.mjs +++ b/scripts/ci/npm-release.mjs @@ -2,7 +2,7 @@ import { appendFile } from "node:fs/promises"; import { resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { setTimeout } from "node:timers/promises"; -import { prerelease, valid } from "semver"; +import { gt, prerelease, valid } from "semver"; import { releaseNpmTag } from "../release-npm-tag.mjs"; import { readQualifiedNpmRelease, @@ -19,9 +19,27 @@ export async function readNpmRelease(version, request = fetch) { } /** REA update follows stable latest even when the candidate is published on next. */ -export function stableUpdateVersion(version, published) { - if (published.status !== "published" || published.taggedVersion !== version) - throw new Error(`npm does not select ${version} on its release channel`); +export function stableUpdateVersion( + version, + published, + { allowSuperseded = false } = {}, +) { + const mismatch = () => + new Error(`npm does not select ${version} on its release channel`); + if (published.status !== "published") throw mismatch(); + const tagged = published.taggedVersion; + if ( + tagged !== version && + !( + allowSuperseded && + typeof tagged === "string" && + valid(tagged) === tagged && + valid(version) === version && + releaseNpmTag(tagged) === published.tag && + gt(tagged, version) + ) + ) + throw mismatch(); const stable = published.stableVersion; if ( typeof stable !== "string" || diff --git a/scripts/verify-published-package.mjs b/scripts/verify-published-package.mjs index 298d28ea4b6..e2eac121eef 100644 --- a/scripts/verify-published-package.mjs +++ b/scripts/verify-published-package.mjs @@ -17,13 +17,16 @@ import { VerifierFixture } from "./lib/verifier-fixture.mjs"; const verifierRun = createVerifierRun(); -const version = process.argv[2]; +const [version, mode, ...extra] = process.argv.slice(2); if ( typeof version !== "string" || valid(version) !== version || - process.argv.length !== 3 + (mode !== undefined && mode !== "--recovery") || + extra.length > 0 ) - throw new Error("Usage: node scripts/verify-published-package.mjs "); + throw new Error( + "Usage: node scripts/verify-published-package.mjs [--recovery]", + ); // npm and the package's children write beneath the root, as under the former mkdtemp. const fixture = await VerifierFixture.open({ @@ -58,6 +61,7 @@ await withVerifierCleanup(async () => { version, canaryRoot, updaterRoot: publishedRoot, + allowSuperseded: mode === "--recovery", }); }, [() => commands.close()]); process.stdout.write( @@ -68,10 +72,12 @@ async function verifyPublishedUpdate({ version: targetVersion, canaryRoot, updaterRoot, + allowSuperseded, }) { const updateVersion = stableUpdateVersion( targetVersion, await readNpmRelease(targetVersion), + { allowSuperseded }, ); const prefix = join(canaryRoot, "update-prefix"); const home = join(canaryRoot, "update-home"); diff --git a/tests/boundary/filesystem/npmRelease.test.ts b/tests/boundary/filesystem/npmRelease.test.ts index dd62b22c0b1..8f3aad34d0e 100644 --- a/tests/boundary/filesystem/npmRelease.test.ts +++ b/tests/boundary/filesystem/npmRelease.test.ts @@ -172,6 +172,39 @@ it("keeps prerelease verification on next and the updater on stable latest", asy ).toThrow("stable release"); }); +it.each([ + ["6.9.0", "6.10.1", "6.10.1"], + ["6.9.0-rc.1", "6.10.1-rc.1", "6.10.0"], +])( + "recovers %s after its tag advances to %s", + async (version, replacement, latest) => { + const tag = version.includes("-") ? "next" : "latest"; + const published = await readNpmRelease(version, async () => + Response.json( + metadata(version, "sha512-original", { latest, [tag]: replacement }), + ), + ); + expect(() => stableUpdateVersion(version, published)).toThrow( + "release channel", + ); + expect( + stableUpdateVersion(version, published, { allowSuperseded: true }), + ).toBe(latest); + if (published.status !== "published") + throw new Error("Fixture release is absent"); + const wrongChannel = tag === "latest" ? "6.11.0-rc.1" : "6.11.0"; + for (const taggedVersion of [null, "6.0.0", "invalid", wrongChannel]) { + expect(() => + stableUpdateVersion( + version, + { ...published, taggedVersion }, + { allowSuperseded: true }, + ), + ).toThrow("release channel"); + } + }, +); + it("distinguishes absence from failed or malformed registry responses", async () => { await expect( readNpmRelease( diff --git a/tests/boundary/filesystem/releaseRecovery.test.ts b/tests/boundary/filesystem/releaseRecovery.test.ts index 03c95c173cf..09426297877 100644 --- a/tests/boundary/filesystem/releaseRecovery.test.ts +++ b/tests/boundary/filesystem/releaseRecovery.test.ts @@ -302,6 +302,9 @@ it("limits recovery to verification and dependent MCP publication from the relea expect(digest).toBeGreaterThanOrEqual(0); expect(rehearsal).toBeGreaterThan(digest); expect(canary).toBeGreaterThan(rehearsal); + expect(steps[canary]?.run).toBe( + 'node scripts/verify-published-package.mjs "$RECOVERY_VERSION" --recovery', + ); const publisher = workflow.jobs["publish-mcp"]; const tag = workflow.jobs["tag-release"]; expect(tag.needs).toBe("verify"); diff --git a/tests/boundary/process/publishedPackageNpmSelection.test.ts b/tests/boundary/process/publishedPackageNpmSelection.test.ts index 2ad4af701fa..4fdc196d176 100644 --- a/tests/boundary/process/publishedPackageNpmSelection.test.ts +++ b/tests/boundary/process/publishedPackageNpmSelection.test.ts @@ -27,8 +27,8 @@ export async function runUpdate(previousVersion, host) { const prerequisiteProgram = ` import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; -export const readNpmRelease = async () => ({ status: "published", taggedVersion: "6.9.0", stableVersion: "6.9.0" }); -export const stableUpdateVersion = () => "6.9.0"; +export { stableUpdateVersion } from ${JSON.stringify(pathToFileURL(resolve("scripts/ci/npm-release.mjs")).href)}; +export const readNpmRelease = async () => ({ status: "published", tag: "latest", taggedVersion: "6.9.0", stableVersion: "6.9.0" }); export const verifyInstalledCanaryPackage = async () => ({ controlled_protocol_prerequisite: true }); export async function installCanaryPackage(specifier, workspace) { const root = join(workspace, "controlled-updater"); @@ -101,9 +101,14 @@ registerHooks({ resolve(specifier, context, next) { return { root, controller, hook, selectedNpm, bin }; }; -processTest.skipIf(process.platform === "win32").for([true, false])( - "preserves npm selection for all published-update operations (explicit selection: %s)", - async (selected, { processes }) => { +processTest.skipIf(process.platform === "win32").for([ + { selected: true, recovery: false }, + { selected: false, recovery: false }, + { selected: true, recovery: true }, +])( + "preserves npm selection for published-update operations (explicit: $selected, recovery: $recovery)", + async ({ selected, recovery }, { processes }) => { + const version = recovery ? "6.8.5" : "6.9.0"; const { root, controller, hook, selectedNpm, bin } = await prepare(); const log = join(root, "npm-operations.jsonl"); const env = { @@ -115,7 +120,13 @@ processTest.skipIf(process.platform === "win32").for([true, false])( }; const result = await processes.run( process.execPath, - ["--import", hook, "scripts/verify-published-package.mjs", "6.9.0"], + [ + "--import", + hook, + "scripts/verify-published-package.mjs", + version, + ...(recovery ? ["--recovery"] : []), + ], { cwd: controller, env }, ); expect(result.exitCode, result.stderr).toBe(0); @@ -160,7 +171,7 @@ processTest.skipIf(process.platform === "win32").for([true, false])( ["root", "--global"], ]); expect(JSON.parse(result.stdout)).toMatchObject({ - version: "6.9.0", + version, update: { status: "updated", previousVersion: "6.8.0",