mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 19:09:21 +00:00
fix(ci): preserve the 75-minute npm visibility deadline (#14761)
* fix(ci): preserve the 75-minute npm visibility deadline * test(ci): use ES2023-compatible registry deadline fixture * refactor(ci): keep the npm visibility deadline at the polling boundary --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> Co-authored-by: Kei Ito <angila-antonia-casey@dr.com>
This commit is contained in:
4 files changed
+100
-13
No files matched your search
@@ -40,7 +40,9 @@ Before publishing, npm lookup failures and malformed metadata stop the job.
|
||||
An existing version must match the qualified tarball's SHA-512 and intended
|
||||
`latest`/`next` dist-tag before it can be reused. Publication never overwrites
|
||||
an existing version or silently changes a dist-tag. After publication, confirmed
|
||||
registry absence is polled every 30 seconds for a 75-minute retry window. Lookup errors and content or tag mismatches fail immediately. If
|
||||
registry absence is polled every 30 seconds. A single 75-minute deadline covers
|
||||
both requests and polling delays, and each request keeps its 30-second cap.
|
||||
Lookup errors and content or tag mismatches fail immediately. If
|
||||
visibility takes longer, rerun the failed jobs in the original workflow once the
|
||||
package appears. A separate post-publication job with read-only
|
||||
repository/actions permissions verifies registry bytes and tags, then installs
|
||||
|
||||
@@ -10,6 +10,7 @@ export function stableUpdateVersion(
|
||||
): string;
|
||||
export function waitForNpmRelease(
|
||||
version: string,
|
||||
lookup?: (version: string) => Promise<NpmReleaseState>,
|
||||
pause?: (milliseconds: number) => Promise<unknown>,
|
||||
lookup?: (version: string, signal: AbortSignal) => Promise<NpmReleaseState>,
|
||||
pause?: (milliseconds: number, signal: AbortSignal) => Promise<unknown>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Extract<NpmReleaseState, { status: "published" }>>;
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
requireMatchingNpmRelease,
|
||||
} from "./npm-release-state.mjs";
|
||||
|
||||
const windowMinutes = 75;
|
||||
const windowMs = windowMinutes * 60_000;
|
||||
const intervalMs = 30_000;
|
||||
|
||||
/** Read-only callers derive the channel through the canonical SemVer owner. */
|
||||
export async function readNpmRelease(version, request = fetch) {
|
||||
return readQualifiedNpmRelease(version, releaseNpmTag(version), request);
|
||||
@@ -33,16 +37,29 @@ export function stableUpdateVersion(version, published) {
|
||||
/** Retry only confirmed absence during the existing registry propagation window. */
|
||||
export async function waitForNpmRelease(
|
||||
version,
|
||||
lookup = readNpmRelease,
|
||||
pause = setTimeout,
|
||||
lookup = (candidate, signal) =>
|
||||
readNpmRelease(candidate, (url, init) =>
|
||||
fetch(url, { ...init, signal: AbortSignal.any([init.signal, signal]) }),
|
||||
),
|
||||
pause = (milliseconds, signal) =>
|
||||
setTimeout(milliseconds, undefined, { signal }),
|
||||
signal = AbortSignal.timeout(windowMs),
|
||||
) {
|
||||
const windowMinutes = 75;
|
||||
const intervalMs = 30_000;
|
||||
const attempts = (windowMinutes * 60_000) / intervalMs + 1;
|
||||
for (let attempt = 1; attempt <= attempts; attempt++) {
|
||||
const published = await lookup(version);
|
||||
if (published.status === "published") return published;
|
||||
if (attempt < attempts) await pause(intervalMs);
|
||||
const attempts = windowMs / intervalMs + 1;
|
||||
try {
|
||||
for (let attempt = 1; attempt <= attempts; attempt++) {
|
||||
signal.throwIfAborted();
|
||||
const published = await lookup(version, signal);
|
||||
signal.throwIfAborted();
|
||||
if (published.status === "published") return published;
|
||||
if (attempt < attempts) await pause(intervalMs, signal);
|
||||
}
|
||||
} catch (cause) {
|
||||
if (!signal.aborted) throw cause;
|
||||
throw new Error(
|
||||
`npm registry visibility deadline reached for rea-agents@${version} after ${windowMinutes} minutes. Re-run the failed verification after the version becomes visible.`,
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`rea-agents@${version} was not visible on npm after ${attempts} attempts over ${windowMinutes} minutes. Re-run the failed verification after the version becomes visible.`,
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import {
|
||||
readNpmRelease,
|
||||
stableUpdateVersion,
|
||||
waitForNpmRelease,
|
||||
} from "../../../scripts/ci/npm-release.mjs";
|
||||
import { requireMatchingNpmRelease } from "../../../scripts/ci/npm-release-state.mjs";
|
||||
import { createDeferred } from "../../fixtures/binarySession.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const metadata = (
|
||||
@@ -174,3 +175,69 @@ it.each([
|
||||
readNpmRelease("6.5.0", async () => Response.json(value)),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("keeps the 75-minute visibility budget and the per-request cap", async () => {
|
||||
const timeout = vi.spyOn(AbortSignal, "timeout");
|
||||
const request = vi.fn(async () =>
|
||||
Response.json(metadata("6.5.0", "sha512-target", { latest: "6.5.0" })),
|
||||
);
|
||||
vi.stubGlobal("fetch", request);
|
||||
try {
|
||||
await expect(waitForNpmRelease("6.5.0")).resolves.toMatchObject({
|
||||
status: "published",
|
||||
});
|
||||
expect(timeout.mock.calls).toEqual([[75 * 60_000], [30_000]]);
|
||||
expect(request).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
timeout.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("interrupts an in-flight registry request at the shared deadline", async () => {
|
||||
const deadline = new AbortController();
|
||||
const reason = new Error("test deadline");
|
||||
const { promise: started, resolve: markStarted } = createDeferred<void>();
|
||||
vi.stubGlobal("fetch", (_url: string, init: RequestInit) => {
|
||||
markStarted();
|
||||
const requestSignal = init.signal;
|
||||
if (!requestSignal) throw new Error("missing request signal");
|
||||
return new Promise<Response>((_resolve, reject) => {
|
||||
requestSignal.addEventListener(
|
||||
"abort",
|
||||
() => reject(requestSignal.reason),
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
try {
|
||||
const waiting = waitForNpmRelease(
|
||||
"6.5.0",
|
||||
undefined,
|
||||
undefined,
|
||||
deadline.signal,
|
||||
);
|
||||
await Promise.race([started, waiting]);
|
||||
deadline.abort(reason);
|
||||
await expect(waiting).rejects.toMatchObject({
|
||||
message: expect.stringContaining("after 75 minutes"),
|
||||
cause: reason,
|
||||
});
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
|
||||
it("interrupts the polling delay without starting another lookup", async () => {
|
||||
const deadline = new AbortController();
|
||||
const lookup = vi.fn(async () => {
|
||||
setImmediate(() => deadline.abort());
|
||||
return { status: "absent" } as const;
|
||||
});
|
||||
await expect(
|
||||
waitForNpmRelease("6.5.0", lookup, undefined, deadline.signal),
|
||||
).rejects.toThrow("visibility deadline reached");
|
||||
expect(lookup).toHaveBeenCalledExactlyOnceWith("6.5.0", deadline.signal);
|
||||
});
|
||||
Reference in new issue
Block a user