mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
fix(release): recover verified versions after npm advances (#15234)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
490461938b
commit
4886a406f9
8 files changed
+90
-15
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export function readNpmRelease(
|
||||
export function stableUpdateVersion(
|
||||
version: string,
|
||||
published: NpmReleaseState,
|
||||
options?: { allowSuperseded?: boolean },
|
||||
): string;
|
||||
export function waitForNpmRelease(
|
||||
version: string,
|
||||
|
||||
@@ -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" ||
|
||||
|
||||
@@ -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 <version>");
|
||||
throw new Error(
|
||||
"Usage: node scripts/verify-published-package.mjs <version> [--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");
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user