|
3 | 3 | // |
4 | 4 | // node scripts/test-release-branch.mjs |
5 | 5 |
|
6 | | -import { releaseBranchRefusal } from "./lib/release-branch.mjs"; |
| 6 | +import { releaseBranchRefusal, latestRegressionRefusal, newestNpmReleaseTag } from "./lib/release-branch.mjs"; |
7 | 7 |
|
8 | 8 | let fails = 0; |
9 | 9 | const check = (cond, label) => (cond ? console.log(`ok: ${label}`) : (console.error(`FAIL: ${label}`), fails++)); |
@@ -35,6 +35,35 @@ check(refused("HEAD", "1.2.2"), "a detached HEAD is refused"); |
35 | 35 | check(releaseBranchRefusal("release-prep", "1.2.2")?.includes("not on main") === true, |
36 | 36 | "the refusal for an ordinary branch still says it is not on main"); |
37 | 37 |
|
| 38 | +// `latest` never moves backwards: `bun publish` tags `latest`, so a version older than the |
| 39 | +// newest release must be refused. The oracle is npm's own dist-tag semantics: `latest` |
| 40 | +// resolves to whichever version was published last, so publishing an older one regresses it. |
| 41 | +check(latestRegressionRefusal("1.2.4", "v1.3.0") !== null, |
| 42 | + "a version older than the newest release is refused"); |
| 43 | +check(latestRegressionRefusal("1.2.4-rc.1", "v1.3.0") !== null, |
| 44 | + "an RC on a line a newer release passed is refused too"); |
| 45 | +check(latestRegressionRefusal("1.3.1", "v1.3.0") === null, |
| 46 | + "a version newer than the newest release passes"); |
| 47 | +check(latestRegressionRefusal("1.2.4", "v1.2.3") === null, |
| 48 | + "a patch on the newest release line passes"); |
| 49 | +check(latestRegressionRefusal("1.2.4", "") === null, |
| 50 | + "no released tag yet passes"); |
| 51 | +check(latestRegressionRefusal("1.2.4", "v1.3.0")?.includes("`latest` backwards") === true, |
| 52 | + "the refusal names the `latest` constraint"); |
| 53 | + |
| 54 | +// The newest release is resolved by the property that defines the npm line (deploy.yml's |
| 55 | +// selector): the newest `vN.N.N` whose cli/package.json is versioned as the tag. A version |
| 56 | +// prefix would wrongly pick `v8.2.2` (no cli tree) or the JVM `v7.20.12` (cli 0.20.11). |
| 57 | +const cliOf = new Map([["v1.3.0", "1.3.0"], ["v1.2.2", "1.2.2"], ["v7.20.12", "0.20.11"]]); |
| 58 | +const fakeOut = (cmd) => { |
| 59 | + if (cmd.startsWith("git tag -l")) return "v8.2.2\nv1.3.0\nv1.2.2\nv7.20.12"; |
| 60 | + const t = /^git show (v[\d.]+):/.exec(cmd)?.[1]; |
| 61 | + const v = t === undefined ? undefined : cliOf.get(t); |
| 62 | + return v === undefined ? "" : `{"name":"@metaobjectsdev/cli","version":"${v}"}`; |
| 63 | +}; |
| 64 | +check(newestNpmReleaseTag(fakeOut) === "v1.3.0", |
| 65 | + "the newest npm-line tag wins; a treeless tag and the JVM line are skipped"); |
| 66 | + |
38 | 67 | if (fails > 0) { |
39 | 68 | console.error(`\n${fails} check(s) failed`); |
40 | 69 | process.exit(1); |
|
0 commit comments