diff --git a/.github/scripts/vale-upgrade-wait.cjs b/.github/scripts/vale-upgrade-wait.cjs index 1e38fa8a..5d304884 100644 --- a/.github/scripts/vale-upgrade-wait.cjs +++ b/.github/scripts/vale-upgrade-wait.cjs @@ -30,19 +30,37 @@ * in seconds, occasionally longer. Ask the registry the exact question * the detect step is about to ask, with the same script and no side * effects (`--json` alone, which the script refuses to combine with - * `--write`), up to five times a minute apart. + * `--write`), up to five times a minute apart, and hold until the + * published set is AT (OR PAST) THE VALE VERSION THIS COMMIT'S MANIFEST + * RECORDS. + * + * WHY "AT THE MANIFEST'S VERSION" AND NOT "NEWER THAN THE PINS". The pins can + * lag more than one release behind, because the previous upgrade pull request + * may still be open. Measured on 3.29.0 (2026-12-02): the pins were at 3.27.0 + * with the 3.28.1 upgrade unmerged, the Release Vale run for the 3.29.0 + * manifest succeeded at 07:10:47Z, and the registry still served 3.28.1 as + * latest until 07:12:28Z. "Newer than the pins" was already true of 3.28.1, + * so the first probe returned at once and the run rebuilt the upgrade branch + * at 3.28.1, an older Vale than the release that triggered it. The manifest + * at GITHUB_SHA names the release this run exists for, so the wait holds + * until the base version inside the published stamp (3.29.0 of + * 3.29.0-20261202071030) is at least it. "At least" rather than "equal": if a + * later manifest bump has already published by the time this run probes, the + * registry is past this run's release, and upgrading to it is still never + * older than what triggered the run. * * EVERY EXIT IS 0. A publish that concludes anything but success, one that - * never appears inside the bound, a registry that still says "current" at the - * end: each is a `::warning::` and a clean exit, never a failed check. This + * never appears inside the bound, a registry that has not reached the + * manifest's version at the end: each is a `::warning::` and a clean exit, never a failed check. This * workflow must not go red over a race it did not cause, and a red here would * say "the upgrade is broken" when the truth is "the publish is". The daily * schedule in vale-upgrade.yml retries once the packages are actually there, * which is what a backstop is for. * * What the workflow learns is the `ready` output: whether the detect step - * should run at all. It is "true" when the registry serves a newer set, and - * "false" when waiting established there is nothing to upgrade to yet. + * should run at all. It is "true" when the registry serves a newer set at the + * manifest's version, and "false" when waiting established there is nothing + * to upgrade to yet. * * TWO CASES ARE "true" WITHOUT A NEWER SET, on purpose: * @@ -65,8 +83,9 @@ * [--workflow ] [--timeout-minutes ] [--poll-seconds ] * [--attempts ] [--interval-seconds ] [--call-timeout-seconds ] * - * Reads GITHUB_EVENT_NAME and GITHUB_SHA. `gh` needs GH_TOKEN with - * `actions: read`. + * Reads GITHUB_EVENT_NAME and GITHUB_SHA, and on a push the `valeVersion` of + * vale-manifest.json as checked out, which is the manifest at GITHUB_SHA. `gh` + * needs GH_TOKEN with `actions: read`. * * Outputs (appended to $GITHUB_OUTPUT when set): * ready "true" when the detect step should run @@ -75,11 +94,14 @@ */ const { execFileSync } = require("node:child_process"); -const { appendFileSync } = require("node:fs"); +const { appendFileSync, readFileSync } = require("node:fs"); const { join } = require("node:path"); +const { compareValeVersions } = require("./vale-release.cjs"); + const RELEASE_WORKFLOW = "release-vale.yml"; const DETECT_SCRIPT = join(__dirname, "vale-upgrade-detect.cjs"); +const MANIFEST_PATH = join(__dirname, "vale-manifest.json"); const MINUTE = 60 * 1000; const SECOND = 1000; @@ -212,6 +234,21 @@ function probeRegistry({ } } +/** + * The Vale release the checked-out manifest records. On a push the checkout + * is GITHUB_SHA, so this is the release whose publish this run waited for. + */ +function readManifestVersion(path = MANIFEST_PATH) { + const { valeVersion } = JSON.parse(readFileSync(path, "utf8")); + if (typeof valeVersion !== "string" || valeVersion === "") { + throw new TypeError(`${path} records no valeVersion`); + } + return valeVersion; +} + +/** `3.29.0-20261202071030` -> `3.29.0`: the upstream release inside a stamp. */ +const stampBase = (stamped) => String(stamped).split("-")[0]; + const sleepFor = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); /** `gh run list --json status,conclusion` as a list of {status, conclusion}. */ @@ -311,14 +348,20 @@ async function waitForReleaseRun({ } /** - * Hold until the registry serves a newer set than the pins. + * Hold until the registry serves a newer set than the pins, and, when + * `expectedVersion` is given, one whose base version is that release or later. + * A newer set at an EARLIER version (an intermediate release published before + * this one, while the pins were further behind) is not what this run is for, + * and counts as "not yet" like an answer of "current". A set already past it + * (a later manifest bump that published first) counts as reached. * * Resolves to `{ outcome: "ahead" | "stale" | "probe-errored", ... }`. "stale" - * means at least one probe answered and the answer was "current" every time it - * did; "probe-errored" means no probe answered at all, which is a different - * fact and is reported as one. + * means at least one probe answered and no answer was the set waited for; + * "probe-errored" means no probe answered at all, which is a different fact + * and is reported as one. */ async function waitForRegistry({ + expectedVersion, attempts = DEFAULTS.attempts, intervalMs = DEFAULTS.intervalMs, probe = probeRegistry, @@ -330,14 +373,20 @@ async function waitForRegistry({ try { const comparison = await probe(); answered += 1; - if (comparison.ahead === true) { + const reached = + expectedVersion === undefined || + compareValeVersions(stampBase(comparison.upstream), expectedVersion) >= + 0; + if (comparison.ahead === true && reached) { log( - `The registry serves a newer set than the pins: ${JSON.stringify(comparison)}` + `The registry serves a newer set than the pins${expectedVersion === undefined ? "" : `, at Vale ${expectedVersion}`}: ${JSON.stringify(comparison)}` ); return { outcome: "ahead", comparison, attempt }; } log( - `The registry still serves the pinned version (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` + comparison.ahead === true + ? `The registry serves a newer set than the pins, but not yet Vale ${expectedVersion} (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` + : `The registry still serves the pinned version (attempt ${attempt} of ${attempts}): ${JSON.stringify(comparison)}` ); } catch (error) { log( @@ -364,6 +413,7 @@ async function main({ sleep = sleepFor, log = (line) => console.log(line), now = Date.now, + manifestVersion = readManifestVersion, } = {}) { const options = parseArgs(argv); const finish = (ready, outcome) => { @@ -384,6 +434,7 @@ async function main({ if (!sha) { throw new Error("GITHUB_SHA must be set on a push"); } + const expectedVersion = manifestVersion(); // The per-call bound reaches the real runners through a second argument an // injected fake is free to ignore. @@ -413,6 +464,7 @@ async function main({ log(`Release Vale succeeded for ${sha}.`); const registry = await waitForRegistry({ + expectedVersion, attempts: options.attempts, intervalMs: options.intervalMs, probe: () => probe(call), @@ -424,7 +476,7 @@ async function main({ } if (registry.outcome === "stale") { log( - `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins; each attempt is logged above with its result. The daily schedule will retry.` + `::warning::no probe in ${registry.attempts} attempts after the publish succeeded reported a newer set than the pins at or past Vale ${expectedVersion}, the version this commit's manifest records; each attempt is logged above with its result. The daily schedule will retry.` ); return finish(false, "registry-stale"); } @@ -464,6 +516,7 @@ module.exports = { parseArgs, parseRuns, probeRegistry, + readManifestVersion, recover, runGh, waitForRegistry, diff --git a/.github/scripts/vale-upgrade-wait.test.cjs b/.github/scripts/vale-upgrade-wait.test.cjs index ed10101a..c394d670 100644 --- a/.github/scripts/vale-upgrade-wait.test.cjs +++ b/.github/scripts/vale-upgrade-wait.test.cjs @@ -26,6 +26,7 @@ const { parseArgs, parseRuns, probeRegistry, + readManifestVersion, recover, runGh, waitForRegistry, @@ -90,6 +91,26 @@ const failed = { status: "completed", conclusion: "failure" }; const stale = { pinned: "3.21.0-1", upstream: "3.21.0-1", ahead: false }; const ahead = { pinned: "3.21.0-1", upstream: "3.22.0-2", ahead: true }; +/** The manifest version `ahead` is at, which main() is told it waits for. */ +const MANIFEST_VERSION = "3.22.0"; + +/* + * The 3.29.0 incident (2026-12-02), in stamps: pins at 3.27.0 because the + * 3.28.1 upgrade was still open, the registry still serving 3.28.1 when the + * 3.29.0 publish run succeeded, and 3.29.0 visible a minute and a half later. + */ +const pinsBehind = "3.27.0-20261101000000"; +const intermediate = { + pinned: pinsBehind, + upstream: "3.28.1-20261120000000", + ahead: true, +}; +const atManifest = { + pinned: pinsBehind, + upstream: "3.29.0-20261202071030", + ahead: true, +}; + test("parseRuns reads gh's JSON and tolerates a null conclusion", () => { assert.deepEqual(parseRuns("[]"), []); assert.deepEqual(parseRuns("\n"), []); @@ -342,8 +363,99 @@ test("registry: one answer among errors is still 'stale'", async () => { assert.equal(result.answered, 1); }); +test("registry: an intermediate newer set is not the manifest's version, so it waits", async () => { + const time = clock(); + const logged = []; + const { probe, count } = probeScript([ + intermediate, + intermediate, + atManifest, + ]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: (line) => logged.push(line), + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 3); + assert.deepEqual(result.comparison, atManifest); + assert.equal(count(), 3); + assert.equal( + logged.filter((line) => + /newer set than the pins, but not yet Vale 3\.29\.0/.test(line) + ).length, + 2 + ); +}); + +test("registry: a newer set that never reaches the manifest's version is 'stale'", async () => { + const time = clock(); + const { probe } = probeScript([intermediate]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "stale"); + assert.equal(result.answered, DEFAULTS.attempts); +}); + +test("registry: a set already past the manifest's version counts as reached", async () => { + const time = clock(); + const later = { + pinned: pinsBehind, + upstream: "3.30.0-20261203000000", + ahead: true, + }; + const { probe } = probeScript([later]); + const result = await waitForRegistry({ + expectedVersion: "3.29.0", + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 1); + assert.deepEqual(result.comparison, later); +}); + +test("registry: without an expected version, any newer set is ahead", async () => { + const time = clock(); + const { probe } = probeScript([intermediate]); + const result = await waitForRegistry({ + probe, + sleep: time.sleep, + log: () => {}, + }); + assert.equal(result.outcome, "ahead"); + assert.equal(result.attempt, 1); +}); + +test("readManifestVersion reads valeVersion and refuses a manifest without one", () => { + const directory = mkdtempSync(join(tmpdir(), "vale-upgrade-wait-test-")); + try { + const path = join(directory, "vale-manifest.json"); + writeFileSync(path, JSON.stringify({ valeVersion: "3.29.0" })); + assert.equal(readManifestVersion(path), "3.29.0"); + writeFileSync(path, JSON.stringify({})); + assert.throws(() => readManifestVersion(path), /records no valeVersion/); + } finally { + rmSync(directory, { recursive: true, force: true }); + } + // The real manifest parses, so a push run never falls back to wait-errored. + assert.match(readManifestVersion(), /^\d+\.\d+\.\d+$/); +}); + /** Drive main() with everything injected and read back $GITHUB_OUTPUT. */ -async function run({ event = "push", gh, probe, argv = [] }) { +async function run({ + event = "push", + gh, + probe, + argv = [], + manifestVersion = MANIFEST_VERSION, +}) { const directory = mkdtempSync(join(tmpdir(), "vale-upgrade-wait-test-")); const outputPath = join(directory, "github-output"); const time = clock(); @@ -361,6 +473,10 @@ async function run({ event = "push", gh, probe, argv = [] }) { sleep: time.sleep, now: time.now, log: (line) => logged.push(line), + manifestVersion: + typeof manifestVersion === "function" + ? manifestVersion + : () => manifestVersion, }); let outputs = {}; try { @@ -467,6 +583,46 @@ test("main: probe never ahead -> warning, ready=false", async () => { assert.deepEqual(outputs, { ready: "false", outcome: "registry-stale" }); assert.equal(warnings.length, 1); assert.match(warnings[0], /no probe in 5 attempts .* reported a newer set/); + assert.match( + warnings[0], + /at or past Vale 3\.22\.0, the version this commit's manifest records/ + ); +}); + +test("main: pins behind, registry at an intermediate release, then at the manifest's -> waits for the manifest's", async () => { + const probed = probeScript([intermediate, atManifest]); + const { outputs, warnings, slept } = await run({ + probe: probed.probe, + manifestVersion: "3.29.0", + }); + assert.deepEqual(outputs, { ready: "true", outcome: "ahead" }); + assert.deepEqual(warnings, []); + assert.equal(probed.count(), 2); + assert.deepEqual(slept, [DEFAULTS.intervalMs]); +}); + +test("main: registry stuck at an intermediate release -> registry-stale, detect never runs", async () => { + const { outputs, warnings } = await run({ + probe: probeScript([intermediate]).probe, + manifestVersion: "3.29.0", + }); + assert.deepEqual(outputs, { ready: "false", outcome: "registry-stale" }); + assert.equal(warnings.length, 1); + assert.match( + warnings[0], + /at or past Vale 3\.29\.0, the version this commit's manifest records/ + ); + assert.match(warnings[0], /daily schedule will retry/); +}); + +test("main: a non-push event never reads the manifest", async () => { + const { outputs } = await run({ + event: "schedule", + manifestVersion: () => { + throw new Error("a non-push run read the manifest"); + }, + }); + assert.deepEqual(outputs, { ready: "true", outcome: "skipped" }); }); test("main: a non-push event skips both waits with ready=true", async () => { @@ -659,6 +815,7 @@ test("main: the call timeout reaches gh and the probe as a second argument", asy }, sleep: async () => {}, log: () => {}, + manifestVersion: () => MANIFEST_VERSION, }); } finally { rmSync(directory, { recursive: true, force: true }); diff --git a/.github/workflows/vale-upgrade.yml b/.github/workflows/vale-upgrade.yml index 551c252e..5d8d7d62 100644 --- a/.github/workflows/vale-upgrade.yml +++ b/.github/workflows/vale-upgrade.yml @@ -81,7 +81,10 @@ on: # OLD latest, found nothing to do, and exited clean. The wait step before # detect exists for that: vale-upgrade-wait.cjs holds until the `Release # Vale` run for this same commit has concluded, then until the registry - # actually serves a newer set. It cannot fail the run; see below. + # actually serves the set at (or past) the Vale version this commit's manifest records + # (not merely one newer than the pins: on 3.29.0 the pins were two releases + # behind and the registry still served 3.28.1, which an earlier wait took for + # the new release). It cannot fail the run; see below. push: branches: [main] paths: @@ -129,12 +132,16 @@ jobs: # minutes; on 3.22.0 the run had stamped the packages 14 s after it # started, so the bound is for a queued runner, not for the work), then # until the registry answers the exact question the detect step is about - # to ask with "a newer set" (five probes a minute apart, using the same - # script with `--json` alone, a read that changes nothing). + # to ask with "a newer set, at or past the manifest's Vale version" (five probes a + # minute apart, using the same script with `--json` alone, a read that + # changes nothing). A newer set at an intermediate release, published + # while an earlier upgrade pull request was still open, counts as "not + # yet": proposing it would rebuild the upgrade branch at an older Vale + # than the release this push is for. # # EVERY EXIT HERE IS 0. A publish that concludes anything but success, - # one that never appears inside the bound, or a registry that still says - # "current" at the end is a `::warning::` and `ready=false`, never a + # one that never appears inside the bound, or a registry that has not + # reached the manifest's version at the end is a `::warning::` and `ready=false`, never a # failed check: this workflow must not go red over a race it did not # cause, and a red here would say "the upgrade is broken" when the truth # is "the publish is". The daily schedule above retries once the packages