From 5e70ce2f145711725223934ed3a84ad8427fa64c Mon Sep 17 00:00:00 2001 From: Kamil Listopad Date: Tue, 17 Nov 2026 15:35:47 +0100 Subject: [PATCH 1/5] fix(cli): toolchain `latest` is the highest version, not the newest publish A bugfix on an older line, such as moc 1.16.2 published after 2.x, became `latest` for `mops toolchain use latest`, `mops toolchain update` and `mops toolchain info`. Pick the highest version instead, as Cargo does, and list the picker rows in the same order. Semver tags now outrank non-version tags, and wasm-opt keeps only Binaryen's `version_N` tags, so the repo's old `1.38.x` tags can't win. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/mops-cli/SKILL.md | 2 +- cli/CHANGELOG.md | 2 + cli/commands/toolchain/index.ts | 6 +- cli/commands/toolchain/release-tags.ts | 32 +++-- cli/commands/toolchain/toolchain-utils.ts | 133 ++++++++---------- cli/commands/toolchain/wasm-opt.ts | 23 ++- cli/tests/release-tags.test.ts | 32 +++-- cli/tests/toolchain-binaryen-tags.test.ts | 37 +++++ cli/tests/toolchain-release-tags.test.ts | 67 +++++++-- cli/tests/toolchain-tag-prefix.test.ts | 2 +- .../cli/5-toolchain/03-mops-toolchain-use.md | 2 +- .../cli/5-toolchain/07-mops-toolchain-info.md | 4 +- 12 files changed, 222 insertions(+), 120 deletions(-) create mode 100644 cli/tests/toolchain-binaryen-tags.test.ts diff --git a/.agents/skills/mops-cli/SKILL.md b/.agents/skills/mops-cli/SKILL.md index 62c77b7f..7992f04b 100644 --- a/.agents/skills/mops-cli/SKILL.md +++ b/.agents/skills/mops-cli/SKILL.md @@ -213,7 +213,7 @@ mops toolchain bin moc # print path to binary **`pocket-ic` versions**: pin anything from `9.0.0` up, `latest` included — mops keeps no list of blessed versions. Pins below `9.0.0` error with a migration message (they ran on the legacy client that mops 3.0.0 removed). With no pin, replica tests / `mops bench` / `--check-deploy` / `mops toolchain bin pocket-ic` error naming `mops toolchain use pocket-ic 15.0.0`. That version is a hint, not a fallback. -**Agent note**: `toolchain use ` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases; pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry. `toolchain info --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history). +**Agent note**: `toolchain use ` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases, highest version first (`latest` is the highest version, not the newest publish); pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry. `toolchain info --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history). ### Enhanced migrations diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 9dd84c03..fb714912 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,6 +1,8 @@ # Mops CLI Changelog ## Next +- **Behaviour change**: `mops toolchain use latest`, `mops toolchain update` and the `latest` line of `mops toolchain info` resolve to the release with the highest version, as Cargo does. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. +- `wasm-opt` release lists, such as `mops toolchain info wasm-opt --versions` and the picker, show only Binaryen's `version_N` releases, highest first. They also listed the repo's old `1.38.x` tags, which `mops` cannot install, and put `99` above `131`. ## 3.7.1 - Rebuilding a release now gives the same `cli.tgz` every time, so its published SHA256 can be verified. `wasm-bindgen` is updated to 0.2.130: 0.2.106 ordered the type section of the CLI's wasm differently from run to run. diff --git a/cli/commands/toolchain/index.ts b/cli/commands/toolchain/index.ts index ffc28d6c..be1e6fea 100644 --- a/cli/commands/toolchain/index.ts +++ b/cli/commands/toolchain/index.ts @@ -264,7 +264,7 @@ async function info(tool: Tool, options: ToolchainInfoOptions = {}) { } // Capped: a short history plus the `latest` line. - let { tags, truncated, publishedLatest } = await toolUtils.getReleaseTags({ + let { tags, truncated, latest } = await toolUtils.getReleaseTags({ prerelease, }); @@ -276,8 +276,8 @@ async function info(tool: Tool, options: ToolchainInfoOptions = {}) { console.log(""); console.log(chalk.green.bold(tool)); - if (publishedLatest) { - console.log(chalk.yellow(`latest: ${publishedLatest}`)); + if (latest) { + console.log(chalk.yellow(`latest: ${latest}`)); } if (pinned) { diff --git a/cli/commands/toolchain/release-tags.ts b/cli/commands/toolchain/release-tags.ts index 2fb5d2e8..f5543508 100644 --- a/cli/commands/toolchain/release-tags.ts +++ b/cli/commands/toolchain/release-tags.ts @@ -13,13 +13,28 @@ export type ReleaseFilter = { exclude?: string[]; }; +let parseSemVer = (tag: string): SemVer | undefined => { + try { + return new SemVer(tag); + } catch { + return undefined; + } +}; + +// Any version outranks a non-version tag, so a stray tag such as `dev` can +// never become `latest`. Non-version tags compare numerically, so Binaryen's +// `version_99` sorts below `version_131`. export let sortReleaseTags = (tags: string[]): string[] => { return [...tags].sort((a, b) => { - try { - return new SemVer(a).compare(new SemVer(b)); - } catch { - return a.localeCompare(b); + let va = parseSemVer(a); + let vb = parseSemVer(b); + if (va && vb) { + return va.compare(vb); + } + if (va || vb) { + return va ? 1 : -1; } + return a.localeCompare(b, "en", { numeric: true }); }); }; @@ -37,7 +52,7 @@ let filterReleases = ( ); }; -/** Tags matching what `mops toolchain update` would resolve to, newest first. */ +/** Tags matching what `mops toolchain update` would resolve to, highest first. */ export let releaseTags = ( releases: ReleaseInfo[], options?: ReleaseFilter, @@ -47,11 +62,12 @@ export let releaseTags = ( ).reverse(); }; -/** Tags in GitHub publish order, for display. */ +/** Rows in `releaseTags` order, for display with their dates. */ export let releaseRows = ( releases: ReleaseInfo[], options?: ReleaseFilter, ): ReleaseInfo[] => { - let kept = new Set(filterReleases(releases, options).map((r) => r.tag_name)); - return releases.filter((release) => kept.has(release.tag_name)); + let kept = filterReleases(releases, options); + let byTag = new Map(kept.map((release) => [release.tag_name, release])); + return releaseTags(kept, options).map((tag) => byTag.get(tag)!); }; diff --git a/cli/commands/toolchain/toolchain-utils.ts b/cli/commands/toolchain/toolchain-utils.ts index 32812cf6..f94546eb 100644 --- a/cli/commands/toolchain/toolchain-utils.ts +++ b/cli/commands/toolchain/toolchain-utils.ts @@ -242,21 +242,15 @@ export type ReleaseTagOptions = ReleaseFilter & { tagPrefix?: string; }; -let withExclusions = (tags: string[], exclude?: string[]): string[] => { - return exclude && exclude.length > 0 - ? tags.filter((tag) => !exclude.includes(tag)) - : tags; -}; - export type ReleaseTagsResult = { tags: string[]; /** True when only the first page was fetched and GitHub may have more. */ truncated: boolean; /** - * First tag in GitHub publish order, matching `getLatestReleaseTag`. Modules - * that filter `tags` further must drop it too, or the two disagree. + * Highest version in `tags`, matching `getLatestReleaseTag`. Modules that + * filter `tags` further must drop it too, or the two disagree. */ - publishedLatest?: string; + latest?: string; }; // `undefined` for a tag that belongs to another release line of the repo. @@ -267,58 +261,58 @@ let releaseVersion = (tag: string, tagPrefix?: string): string | undefined => { return tag.startsWith(tagPrefix) ? tag.slice(tagPrefix.length) : undefined; }; +let fetchReleasePage = async ( + octokit: Octokit, + repo: string, + page: number, + tagPrefix?: string, +): Promise<{ releases: ReleaseInfo[]; last: boolean }> => { + let res = await octokit.request(`GET /repos/${repo}/releases`, { + per_page: 100, + page, + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + }); + if (res.status !== 200) { + cliError("Releases fetch error"); + } + let releases: ReleaseInfo[] = []; + for (let release of res.data) { + let version = releaseVersion(release.tag_name, tagPrefix); + if (version === undefined) { + continue; + } + releases.push({ + tag_name: version, + published_at: release.published_at, + prerelease: release.prerelease, + draft: release.draft, + }); + } + return { releases, last: res.data.length < 100 }; +}; + let fetchReleasePages = async ( repo: string, { maxPages, tagPrefix }: { maxPages?: number; tagPrefix?: string } = {}, ): Promise<{ releases: ReleaseInfo[]; truncated: boolean }> => { let octokit = new Octokit({ auth: githubToken() }); let releases: ReleaseInfo[] = []; - let truncated = false; for (let page = 1; ; page++) { - if (maxPages !== undefined && page > maxPages) { - truncated = true; - break; - } - - let res = await octokit.request(`GET /repos/${repo}/releases`, { - per_page: 100, - page, - headers: { - "X-GitHub-Api-Version": "2022-11-28", - }, - }); - if (res.status !== 200) { - cliError("Releases fetch error"); - } - if (res.data.length === 0) { - break; - } - for (let release of res.data) { - let version = releaseVersion(release.tag_name, tagPrefix); - if (version === undefined) { - continue; - } - releases.push({ - tag_name: version, - published_at: release.published_at, - prerelease: release.prerelease, - draft: release.draft, - }); - } - if (res.data.length < 100) { - break; + let res = await fetchReleasePage(octokit, repo, page, tagPrefix); + releases.push(...res.releases); + if (res.last) { + return { releases, truncated: false }; } if (maxPages !== undefined && page >= maxPages) { - truncated = true; - break; + return { releases, truncated: true }; } } - - return { releases, truncated }; }; -/** Release tags, newest first. Default: first GitHub page only. */ +/** Release tags, highest version first. Default: first GitHub page only. */ export let getReleaseTags = async ( repo: string, { @@ -332,16 +326,13 @@ export let getReleaseTags = async ( maxPages: all ? undefined : 1, tagPrefix, }); - let rows = releaseRows(releases, { prerelease, exclude }); - return { - tags: withExclusions(releaseTags(releases, { prerelease }), exclude), - truncated: all ? false : truncated, - // Derived from the same filtered rows, so it can never name a tag that - // `tags` leaves out. - publishedLatest: rows[0]?.tag_name, - }; + let tags = releaseTags(releases, { prerelease, exclude }); + return { tags, truncated, latest: tags[0] }; }; +// The highest version, not the newest publish: a bugfix on an older line (moc +// 1.x after 2.0) is published last but must not become `latest`. Later pages +// are read only while no release has matched yet. export let getLatestReleaseTag = async ( repo: string, { prerelease = false, exclude, tagPrefix }: ReleaseTagOptions = {}, @@ -349,29 +340,17 @@ export let getLatestReleaseTag = async ( let octokit = new Octokit({ auth: githubToken() }); for (let page = 1; ; page++) { - let res = await octokit.request(`GET /repos/${repo}/releases`, { - per_page: 100, + let { releases, last } = await fetchReleasePage( + octokit, + repo, page, - headers: { - "X-GitHub-Api-Version": "2022-11-28", - }, - }); - if (res.status !== 200) { - cliError("Releases fetch error"); - } - if (res.data.length === 0) { - break; - } - for (let release of res.data) { - let tag = releaseVersion(release.tag_name, tagPrefix); - if (tag === undefined || exclude?.includes(tag)) { - continue; - } - if (!release.draft && (prerelease || !release.prerelease)) { - return tag; - } + tagPrefix, + ); + let [latest] = releaseTags(releases, { prerelease, exclude }); + if (latest !== undefined) { + return latest; } - if (res.data.length < 100) { + if (last) { break; } } @@ -380,7 +359,7 @@ export let getLatestReleaseTag = async ( }; /** - * Recent release rows, newest first, for prompts and the `info` preview. + * Recent release rows, highest version first, for prompts and the `info` preview. * Drafts and prereleases are excluded unless asked for explicitly. */ export let getReleases = async ( diff --git a/cli/commands/toolchain/wasm-opt.ts b/cli/commands/toolchain/wasm-opt.ts index 54f18cf5..f3a6eff6 100644 --- a/cli/commands/toolchain/wasm-opt.ts +++ b/cli/commands/toolchain/wasm-opt.ts @@ -15,19 +15,29 @@ let cacheDir = path.join(globalCacheDir, "wasm-opt"); export let repo = "WebAssembly/binaryen"; +// Also keeps out the repo's old Emscripten-era `1.38.x` tags, which mops +// cannot install and which would otherwise outrank `version_131` as semver. +let tagPrefix = "version_"; + /** Resolved wasm-opt path inside a versioned cache dir (keeps sibling `lib/` for rpath). */ export let binaryPath = (version: string) => path.join(cacheDir, version, "bin", "wasm-opt"); export let getLatestReleaseTag = async ({ prerelease = false } = {}) => { - let tag = await toolchainUtils.getLatestReleaseTag(repo, { prerelease }); + let tag = await toolchainUtils.getLatestReleaseTag(repo, { + prerelease, + tagPrefix, + }); return normalizeBinaryenVersion(tag); }; export let getReleases = async ({ prerelease = false } = {}): Promise< ReleaseInfo[] > => { - let releases = await toolchainUtils.getReleases(repo, { prerelease }); + let releases = await toolchainUtils.getReleases(repo, { + prerelease, + tagPrefix, + }); return releases.map((r) => ({ ...r, tag_name: normalizeBinaryenVersion(r.tag_name), @@ -38,13 +48,14 @@ export let getReleases = async ({ prerelease = false } = {}): Promise< export let getReleaseTags = async ( options: toolchainUtils.ReleaseTagOptions = {}, ) => { - let res = await toolchainUtils.getReleaseTags(repo, options); + let res = await toolchainUtils.getReleaseTags(repo, { + ...options, + tagPrefix, + }); return { ...res, tags: res.tags.map(normalizeBinaryenVersion), - publishedLatest: res.publishedLatest - ? normalizeBinaryenVersion(res.publishedLatest) - : undefined, + latest: res.latest ? normalizeBinaryenVersion(res.latest) : undefined, }; }; diff --git a/cli/tests/release-tags.test.ts b/cli/tests/release-tags.test.ts index bc17d4c4..0a67b4b8 100644 --- a/cli/tests/release-tags.test.ts +++ b/cli/tests/release-tags.test.ts @@ -52,7 +52,25 @@ describe("toolchain release tags", () => { ]); }); - test("releaseRows keeps GitHub publish order", () => { + // Binaryen tags are not semver, and `version_99` must not outrank `version_131`. + test("sortReleaseTags orders non-semver tags numerically", () => { + expect( + sortReleaseTags(["version_131", "version_99", "version_100"]), + ).toEqual(["version_99", "version_100", "version_131"]); + }); + + // A moc 1.x bugfix published after 2.0 must not show up as the newest. + test("releaseRows orders by version, not publish order", () => { + let releases = [release("1.16.2"), release("2.0.0"), release("1.16.1")]; + + expect(releaseRows(releases).map((r) => r.tag_name)).toEqual([ + "2.0.0", + "1.16.2", + "1.16.1", + ]); + }); + + test("releaseRows filters prereleases", () => { let releases = [ release("2.0.0-beta.0", { prerelease: true }), release("1.16.1"), @@ -69,8 +87,8 @@ describe("toolchain release tags", () => { ).toEqual([ "2.0.0-beta.0", "1.16.1", - "1.15.1-dedup-stable-types-3", "1.15.1", + "1.15.1-dedup-stable-types-3", ]); }); @@ -82,10 +100,9 @@ describe("toolchain release tags", () => { ).toEqual(["1.0.0"]); }); - // `getReleaseTags` derives `publishedLatest` from `releaseRows`, and `latest` - // falls back to it. A module that filters `tags` further must drop it too, or - // `latest` can name a tag the same command filtered out. - test("releaseTags and releaseRows agree on membership", () => { + // The picker lists `releaseRows` and `latest` resolves from `releaseTags`, so + // they must offer the same tags in the same order. + test("releaseTags and releaseRows agree", () => { let releases = [ release("49.0.0-rc.1", { prerelease: true }), release("48.0.2"), @@ -94,9 +111,8 @@ describe("toolchain release tags", () => { ]; for (let options of [undefined, { prerelease: true }]) { - let tags = new Set(releaseTags(releases, options)); expect(releaseRows(releases, options).map((r) => r.tag_name)).toEqual( - releases.map((r) => r.tag_name).filter((tag) => tags.has(tag)), + releaseTags(releases, options), ); } }); diff --git a/cli/tests/toolchain-binaryen-tags.test.ts b/cli/tests/toolchain-binaryen-tags.test.ts new file mode 100644 index 00000000..1e25be95 --- /dev/null +++ b/cli/tests/toolchain-binaryen-tags.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, jest, test } from "@jest/globals"; + +// Binaryen's first page mixes `version_N` releases with old Emscripten-era +// `1.38.x` tags, which parse as semver and mops cannot install. +let page = [ + "version_133", + "version_99", + "1.39.1", + "version_132", + "1.38.48", +].map((tag_name) => ({ + tag_name, + published_at: "2026-11-01T00:00:00Z", + prerelease: false, + draft: false, +})); + +jest.unstable_mockModule("octokit", () => ({ + Octokit: class { + request = async () => ({ status: 200, data: page }); + }, +})); + +let wasmOpt = await import("../commands/toolchain/wasm-opt.js"); + +describe("wasm-opt release tags", () => { + test("latest is the highest version_N, not a legacy semver tag", async () => { + expect(await wasmOpt.getLatestReleaseTag()).toBe("133"); + + let res = await wasmOpt.getReleaseTags(); + expect(res.latest).toBe("133"); + expect(res.tags).toEqual(["133", "132", "99"]); + + let rows = await wasmOpt.getReleases(); + expect(rows.map((r) => r.tag_name)).toEqual(["133", "132", "99"]); + }); +}); diff --git a/cli/tests/toolchain-release-tags.test.ts b/cli/tests/toolchain-release-tags.test.ts index fd488b05..3a38c59f 100644 --- a/cli/tests/toolchain-release-tags.test.ts +++ b/cli/tests/toolchain-release-tags.test.ts @@ -1,19 +1,30 @@ -import { describe, expect, jest, test } from "@jest/globals"; +import { + afterEach, + beforeEach, + describe, + expect, + jest, + test, +} from "@jest/globals"; import type { ReleaseInfo } from "../commands/toolchain/release-tags"; // Published newest-first, the order GitHub returns, with the non-version `dev` // tag at the top — the case that let `latest` name a tag the picker filtered out. -let page: ReleaseInfo[] = [ +let releases = (rows: [string, { prerelease?: boolean }][]): ReleaseInfo[] => + rows.map(([tag_name, flags]) => ({ + tag_name, + published_at: "2024-06-01T00:00:00Z", + prerelease: flags.prerelease ?? false, + draft: false, + })); + +let wasmtimePage = releases([ ["dev", { prerelease: true }], ["49.0.0-rc.1", { prerelease: true }], ["v48.0.2", {}], ["v48.0.1", {}], -].map(([tag_name, flags]: any) => ({ - tag_name, - published_at: "2024-06-01T00:00:00Z", - prerelease: flags.prerelease ?? false, - draft: flags.draft ?? false, -})); +]); +let page = wasmtimePage; jest.unstable_mockModule("octokit", () => ({ Octokit: class { @@ -24,15 +35,45 @@ jest.unstable_mockModule("octokit", () => ({ let { getReleaseTags, getLatestReleaseTag, getReleases } = await import("../commands/toolchain/toolchain-utils.js"); +// moc's shape once 2.0 ships: a 1.x bugfix is published after it. +describe("latest is the highest version", () => { + beforeEach(() => { + page = releases([ + ["1.16.2", {}], + ["2.0.1", {}], + ["2.1.0-beta.0", { prerelease: true }], + ["2.0.0", {}], + ["1.16.1", {}], + ]); + }); + afterEach(() => { + page = wasmtimePage; + }); + + test("not the newest publish", async () => { + expect(await getLatestReleaseTag("a/b")).toBe("2.0.1"); + expect(await getLatestReleaseTag("a/b", { prerelease: true })).toBe( + "2.1.0-beta.0", + ); + + let res = await getReleaseTags("a/b"); + expect(res.latest).toBe("2.0.1"); + expect(res.tags).toEqual(["2.0.1", "2.0.0", "1.16.2", "1.16.1"]); + + let rows = await getReleases("a/b"); + expect(rows.map((r) => r.tag_name)).toEqual(res.tags); + }); +}); + describe("getReleaseTags", () => { - // `publishedLatest` is what `mops toolchain info` renders as `latest`, so a + // `latest` is what `mops toolchain info` renders as `latest`, so a // tag dropped from `tags` must never survive there. - test("publishedLatest is always a member of tags", async () => { + test("latest is always a member of tags", async () => { for (let exclude of [undefined, ["dev"]]) { for (let options of [{}, { prerelease: true }, { all: true }]) { let res = await getReleaseTags("a/b", { ...options, exclude }); - if (res.publishedLatest !== undefined) { - expect(res.tags).toContain(res.publishedLatest); + if (res.latest !== undefined) { + expect(res.tags).toContain(res.latest); } } } @@ -42,7 +83,7 @@ describe("getReleaseTags", () => { let res = await getReleaseTags("a/b", { exclude: ["dev"] }); expect(res.tags).not.toContain("dev"); - expect(res.publishedLatest).toBe("48.0.2"); + expect(res.latest).toBe("48.0.2"); }); // `wasmtime` publishes `dev`, which GitHub does not flag as a prerelease but diff --git a/cli/tests/toolchain-tag-prefix.test.ts b/cli/tests/toolchain-tag-prefix.test.ts index d4164082..c475b8c9 100644 --- a/cli/tests/toolchain-tag-prefix.test.ts +++ b/cli/tests/toolchain-tag-prefix.test.ts @@ -37,7 +37,7 @@ describe("tagPrefix", () => { test("every listing keeps only prefixed tags, prefix stripped", async () => { let res = await getReleaseTags("a/b", { tagPrefix }); expect(res.tags).toEqual(["0.1.1", "0.1.0"]); - expect(res.publishedLatest).toBe("0.1.1"); + expect(res.latest).toBe("0.1.1"); let rows = await getReleases("a/b", { tagPrefix }); expect(rows.map((r) => r.tag_name)).toEqual(["0.1.1", "0.1.0"]); diff --git a/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md b/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md index 3b97cc61..2dd7c139 100644 --- a/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md +++ b/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md @@ -21,7 +21,7 @@ mops toolchain use pocket-ic 15.0.0 mops toolchain use lintoko 0.11.0 ``` -You can specify `latest` as version to install the latest available version. +You can specify `latest` as version to install the release with the highest version. A bugfix on an older line, published after a newer major release, is not `latest`. ``` mops toolchain use moc latest ``` diff --git a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md index b03886b1..19564ae3 100644 --- a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md +++ b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md @@ -56,12 +56,12 @@ mops toolchain info moc --versions --prerelease Drafts are never listed, with or without the flag. -By default, listed versions match what `mops toolchain update` and `mops toolchain use latest` resolve to (the first stable GitHub release). +By default, listed versions match what `mops toolchain update` and `mops toolchain use latest` resolve to (the stable release with the highest version, which is not always the most recently published one). ## Output Displays: -- Latest release (prerelease only with `--prerelease`) +- Latest release: the highest version, not the most recent publish (prerelease only with `--prerelease`) - Pinned version from `[toolchain]` in `mops.toml` (when run inside a project) - GitHub repository link - Recent version history (from the first releases page) From ca144e21019764c00a5d460578fff6fd7099433f Mon Sep 17 00:00:00 2001 From: Kamil Listopad Date: Tue, 17 Nov 2026 15:39:48 +0100 Subject: [PATCH 2/5] fix(cli): treat unflagged semver prereleases as prereleases, say highest version in help and docs Co-Authored-By: Claude Opus 5.5 --- .agents/skills/mops-cli/SKILL.md | 2 +- cli/CHANGELOG.md | 2 +- cli/cli.ts | 2 +- cli/commands/toolchain/release-tags.ts | 8 +++++++- cli/tests/release-tags.test.ts | 10 ++++++++++ docs/docs/cli/5-toolchain/01-toolchain-overview.md | 2 +- docs/docs/cli/5-toolchain/07-mops-toolchain-info.md | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.agents/skills/mops-cli/SKILL.md b/.agents/skills/mops-cli/SKILL.md index 7992f04b..1ae3d3dd 100644 --- a/.agents/skills/mops-cli/SKILL.md +++ b/.agents/skills/mops-cli/SKILL.md @@ -205,7 +205,7 @@ mops toolchain use mo-fmt 0.5.0 # standalone formatter used by `mops format mops toolchain update moc # update to latest (requires existing [toolchain] entry) mops toolchain update # update all tools to latest mops toolchain info # show release info (latest, pinned, history) -mops toolchain info --versions # list recent releases, newest first +mops toolchain info --versions # list recent releases, highest version first mops toolchain info --versions --all # full release history (cache warming) mops toolchain info --versions --prerelease # include prereleases mops toolchain bin moc # print path to binary diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index fb714912..9f7c3a61 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,7 +1,7 @@ # Mops CLI Changelog ## Next -- **Behaviour change**: `mops toolchain use latest`, `mops toolchain update` and the `latest` line of `mops toolchain info` resolve to the release with the highest version, as Cargo does. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. +- **Behaviour change**: `mops toolchain use latest`, `mops toolchain update` and the `latest` line of `mops toolchain info` resolve to the stable release with the highest version, as Cargo does. A tag with a semver prerelease suffix, such as `2.3.0-rc.1`, counts as a prerelease even when GitHub does not flag it. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. - `wasm-opt` release lists, such as `mops toolchain info wasm-opt --versions` and the picker, show only Binaryen's `version_N` releases, highest first. They also listed the repo's old `1.38.x` tags, which `mops` cannot install, and put `99` above `131`. ## 3.7.1 diff --git a/cli/cli.ts b/cli/cli.ts index b389a541..0fdc9ade 100755 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -1052,7 +1052,7 @@ toolchainCommand ) .option( "--versions", - "List release versions, one per line (newest first; first GitHub page by default)", + "List release versions, one per line (highest version first; first GitHub page by default)", ) .option( "--all", diff --git a/cli/commands/toolchain/release-tags.ts b/cli/commands/toolchain/release-tags.ts index f5543508..92d7059b 100644 --- a/cli/commands/toolchain/release-tags.ts +++ b/cli/commands/toolchain/release-tags.ts @@ -38,6 +38,12 @@ export let sortReleaseTags = (tags: string[]): string[] => { }); }; +// A semver prerelease such as `2.3.0-rc.1` counts even when GitHub does not +// flag it, or it would outrank the stable `2.2.x` line as `latest`. +let isPrerelease = (release: ReleaseInfo): boolean => + release.prerelease || + (parseSemVer(release.tag_name)?.prerelease.length ?? 0) > 0; + // Drafts are excluded unconditionally: GitHub never exposes them to anyone but // the repo's own maintainers. Callers only choose whether prereleases show. let filterReleases = ( @@ -47,7 +53,7 @@ let filterReleases = ( return releases.filter( (release) => !release.draft && - (prerelease || !release.prerelease) && + (prerelease || !isPrerelease(release)) && !exclude?.includes(release.tag_name), ); }; diff --git a/cli/tests/release-tags.test.ts b/cli/tests/release-tags.test.ts index 0a67b4b8..f524cb3c 100644 --- a/cli/tests/release-tags.test.ts +++ b/cli/tests/release-tags.test.ts @@ -92,6 +92,16 @@ describe("toolchain release tags", () => { ]); }); + test("an unflagged semver prerelease is still a prerelease", () => { + let releases = [release("2.2.3"), release("2.3.0-rc.1")]; + + expect(releaseTags(releases)).toEqual(["2.2.3"]); + expect(releaseTags(releases, { prerelease: true })).toEqual([ + "2.3.0-rc.1", + "2.2.3", + ]); + }); + test("releaseRows drops drafts unconditionally", () => { let releases = [release("1.0.0"), release("2.0.0", { draft: true })]; diff --git a/docs/docs/cli/5-toolchain/01-toolchain-overview.md b/docs/docs/cli/5-toolchain/01-toolchain-overview.md index 835540a4..c6e6b20c 100644 --- a/docs/docs/cli/5-toolchain/01-toolchain-overview.md +++ b/docs/docs/cli/5-toolchain/01-toolchain-overview.md @@ -55,7 +55,7 @@ You need to run `mops install` command when you edit `mops.toml` file manually. Replica tests, benchmarks, `--check-deploy`, and `mops toolchain bin pocket-ic` all require an explicit `[toolchain] pocket-ic` pin — there is no default. Unpinned, they error naming `mops toolchain use pocket-ic 15.0.0`. The version in that hint is not a runtime fallback; it can move when a newer server is the one to recommend. The one exception is [`MOPS_POCKET_IC_URL`](../7-misc/06-environment-variables.md#mops_pocket_ic_url): when it points at an already-running PocketIC server, no pin is needed, an existing pin is ignored with a warning, and no binary is downloaded. -Any version from `9.0.0` up can be pinned (`mops toolchain use pocket-ic latest` resolves and pins the newest release). Mops keeps no list of blessed versions — as with `moc`, `wasmtime` and `lintoko`, the version you pin is the version you get. A literal `pocket-ic = "latest"` written into `mops.toml` by hand does not work — the field takes a concrete version or a file path. +Any version from `9.0.0` up can be pinned (`mops toolchain use pocket-ic latest` resolves and pins the highest version). Mops keeps no list of blessed versions — as with `moc`, `wasmtime` and `lintoko`, the version you pin is the version you get. A literal `pocket-ic = "latest"` written into `mops.toml` by hand does not work — the field takes a concrete version or a file path. Pins **below `9.0.0`** are rejected with a migration message. They worked in Mops 2.x through a second, legacy PocketIC client, which 3.0.0 removed; without the check, upgrading with an old pin would fail with an opaque timeout from the client instead. Run `mops toolchain use pocket-ic 15.0.0`. diff --git a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md index 19564ae3..b3dc7b68 100644 --- a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md +++ b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md @@ -31,7 +31,7 @@ mops toolchain info lintoko ### `--versions` -Print release versions, one per line (newest first). By default fetches only the first GitHub releases page (up to 100 releases). Useful for scripting. +Print release versions, one per line (highest version first). By default fetches only the first GitHub releases page (up to 100 releases). Useful for scripting. ``` mops toolchain info moc --versions From 5d891183f28068d6551fc8ecc4594676adbf9c96 Mon Sep 17 00:00:00 2001 From: Kamil Listopad Date: Tue, 17 Nov 2026 15:59:31 +0100 Subject: [PATCH 3/5] feat(cli): `mops toolchain update` stays within the pin's caret range Like `mops update` for packages, `mops toolchain update` now moves a pin only within its caret range: same major, or same minor for 0.x. A project on moc 1.16.1 gets the 1.x bugfix instead of 2.x. `--major` crosses the bound, and the command names a newer out-of-range release when there is one. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/mops-cli/SKILL.md | 7 +- cli/CHANGELOG.md | 1 + cli/cli.ts | 10 ++- cli/commands/toolchain/index.ts | 71 +++++++++++++++---- cli/commands/toolchain/release-tags.ts | 17 ++++- cli/tests/release-tags.test.ts | 25 +++++++ .../5-toolchain/04-mops-toolchain-update.md | 22 ++++-- 7 files changed, 127 insertions(+), 26 deletions(-) diff --git a/.agents/skills/mops-cli/SKILL.md b/.agents/skills/mops-cli/SKILL.md index 1ae3d3dd..39f117fc 100644 --- a/.agents/skills/mops-cli/SKILL.md +++ b/.agents/skills/mops-cli/SKILL.md @@ -202,8 +202,9 @@ mops toolchain use lintoko 0.11.0 # pin specific version mops toolchain use pocket-ic 15.0.0 # pin for replica tests / benchmarks / --check-deploy mops toolchain use wasm-opt 131 # Binaryen for [optimize] (or `latest`) mops toolchain use mo-fmt 0.5.0 # standalone formatter used by `mops format` -mops toolchain update moc # update to latest (requires existing [toolchain] entry) -mops toolchain update # update all tools to latest +mops toolchain update moc # newest compatible version, same major (requires existing [toolchain] entry) +mops toolchain update # update all tools within their caret range +mops toolchain update moc --major # cross the major version (same as `use moc latest`) mops toolchain info # show release info (latest, pinned, history) mops toolchain info --versions # list recent releases, highest version first mops toolchain info --versions --all # full release history (cache warming) @@ -213,7 +214,7 @@ mops toolchain bin moc # print path to binary **`pocket-ic` versions**: pin anything from `9.0.0` up, `latest` included — mops keeps no list of blessed versions. Pins below `9.0.0` error with a migration message (they ran on the legacy client that mops 3.0.0 removed). With no pin, replica tests / `mops bench` / `--check-deploy` / `mops toolchain bin pocket-ic` error naming `mops toolchain use pocket-ic 15.0.0`. That version is a hint, not a fallback. -**Agent note**: `toolchain use ` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases, highest version first (`latest` is the highest version, not the newest publish); pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry. `toolchain info --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history). +**Agent note**: `toolchain use ` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases, highest version first (`latest` is the highest version, not the newest publish); pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry, and stays within the caret range of the pin unless you pass `--major`. `toolchain info --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history). ### Enhanced migrations diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 9f7c3a61..81eb79ef 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,6 +1,7 @@ # Mops CLI Changelog ## Next +- **Behaviour change**: `mops toolchain update` stays within the caret range of each pin, as `mops update` does for packages: the same major version, or the same minor version for `0.x.y`. A project pinned to `moc` 1.16.1 now gets the newest 1.x release instead of jumping to 2.x. When a newer release is out of range, the command names it. To cross the bound, pass the new `--major` flag. A pin that is not a semantic version, such as `wasm-opt` `133`, changes only with `--major`, and a pin to a local file is skipped without it. - **Behaviour change**: `mops toolchain use latest`, `mops toolchain update` and the `latest` line of `mops toolchain info` resolve to the stable release with the highest version, as Cargo does. A tag with a semver prerelease suffix, such as `2.3.0-rc.1`, counts as a prerelease even when GitHub does not flag it. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. - `wasm-opt` release lists, such as `mops toolchain info wasm-opt --versions` and the picker, show only Binaryen's `version_N` releases, highest first. They also listed the repo's old `1.38.x` tags, which `mops` cannot install, and put `99` above `131`. diff --git a/cli/cli.ts b/cli/cli.ts index 0fdc9ade..54385d01 100755 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -1031,7 +1031,7 @@ toolchainCommand toolchainCommand .command("update") .description( - "Update specified tool or all tools to the latest version and update mops.toml", + "Update specified tool or all tools to the newest compatible version and update mops.toml", ) .addArgument( new Argument( @@ -1039,9 +1039,13 @@ toolchainCommand "tool to update (defaults to all configured tools)", ).choices(TOOLCHAINS), ) - .action(async (tool?: Tool) => { + .option( + "--major", + "Allow updates that cross the caret bound (major versions, or for 0.x.y tools, minor versions)", + ) + .action(async (tool: Tool | undefined, options: { major?: boolean }) => { checkConfigFile(); - await toolchain.update(tool); + await toolchain.update(tool, options); }); toolchainCommand diff --git a/cli/commands/toolchain/index.ts b/cli/commands/toolchain/index.ts index be1e6fea..dc578af8 100644 --- a/cli/commands/toolchain/index.ts +++ b/cli/commands/toolchain/index.ts @@ -22,7 +22,12 @@ import { FILE_PATH_REGEX } from "../../constants.js"; import { cliError } from "../../error.js"; import { getPocketIcUrl } from "../../helpers/pocket-ic-startup.js"; import { RECOMMENDED_POCKET_IC_VERSION } from "./pocket-ic-versions.js"; -import type { ReleaseInfo } from "./release-tags.js"; +import semver from "semver"; +import { + latestCompatible, + sortReleaseTags, + type ReleaseInfo, +} from "./release-tags.js"; function label(text: string): string { return chalk.bold(text.padEnd(16)); @@ -208,35 +213,71 @@ async function use(tool: Tool, version?: string, { prerelease = false } = {}) { } } -// download latest binary and set version in mops.toml -async function update(tool?: Tool) { +// The newest version `update` may move a pin to, and the overall latest when +// that is out of range. Mirrors `mops update`: stays within the caret range of +// the pin unless `major` is set. +async function resolveUpdate( + tool: Tool, + pinned: string, + major: boolean, +): Promise<{ version: string; latest: string }> { + let toolUtils = getToolUtils(tool); + let latest = await toolUtils.getLatestReleaseTag(); + if (major) { + return { version: latest, latest }; + } + let { tags, truncated } = await toolUtils.getReleaseTags(); + let version = latestCompatible(pinned, tags); + // A newer release on the pinned line is almost always on page 1. Only an + // old pin with nothing there needs the full history. + if (version === undefined && truncated && semver.valid(pinned)) { + ({ tags } = await toolUtils.getReleaseTags({ all: true })); + version = latestCompatible(pinned, tags); + } + return { version: version ?? pinned, latest }; +} + +// download the newest compatible binary and set version in mops.toml +async function update(tool?: Tool, { major = false } = {}) { let config = readConfig(); config.toolchain = config.toolchain || {}; let tools = tool ? [tool] : (Object.keys(config.toolchain) as Tool[]); for (let tool of tools) { - if (!config.toolchain[tool]) { + let pinned = config.toolchain[tool]; + if (!pinned) { cliError( `Tool '${tool}' is not defined in [toolchain] section in mops.toml`, ); } - let toolUtils = getToolUtils(tool); - let version = await toolUtils.getLatestReleaseTag(); - - await download(tool, version); + if (!major && pinned.match(FILE_PATH_REGEX)) { + console.log(`${tool} is pinned to a local file, skipping`); + continue; + } - let oldVersion = config.toolchain[tool]; - config.toolchain[tool] = version; - writeConfig(config); + let { version, latest } = await resolveUpdate(tool, pinned, major); - await checkRequirements(); + await download(tool, version); - if (oldVersion === version) { - console.log(`Latest ${tool} ${version} is already installed`); - } else { + if (version !== pinned) { + config.toolchain[tool] = version; + writeConfig(config); + await checkRequirements(); console.log(chalk.green(`Installed ${tool} ${version}`)); + } else { + console.log(`${tool} ${pinned} is already the latest compatible version`); + } + + let outOfRange = + latest !== version && sortReleaseTags([version, latest])[1] === latest; + if (outOfRange) { + console.log( + chalk.gray( + `${tool} ${latest} is available. To update to it, run ${chalk.green(`mops toolchain update ${tool} --major`)}`, + ), + ); } } } diff --git a/cli/commands/toolchain/release-tags.ts b/cli/commands/toolchain/release-tags.ts index 92d7059b..33bb2e74 100644 --- a/cli/commands/toolchain/release-tags.ts +++ b/cli/commands/toolchain/release-tags.ts @@ -1,4 +1,4 @@ -import { SemVer } from "semver"; +import semver, { SemVer } from "semver"; export type ReleaseInfo = { tag_name: string; @@ -77,3 +77,18 @@ export let releaseRows = ( let byTag = new Map(kept.map((release) => [release.tag_name, release])); return releaseTags(kept, options).map((tag) => byTag.get(tag)!); }; + +/** + * Highest of `tags` within the caret range of `pinned`, as `mops update` picks + * for packages: same major, or same minor for `0.x`. `undefined` when `pinned` + * is not a version (a Binaryen `133`, a local file) or no tag fits the range. + */ +export let latestCompatible = ( + pinned: string, + tags: string[], +): string | undefined => { + if (!semver.valid(pinned)) { + return undefined; + } + return semver.maxSatisfying(tags, `^${pinned}`) ?? undefined; +}; diff --git a/cli/tests/release-tags.test.ts b/cli/tests/release-tags.test.ts index f524cb3c..71688946 100644 --- a/cli/tests/release-tags.test.ts +++ b/cli/tests/release-tags.test.ts @@ -1,5 +1,6 @@ import { describe, expect, test } from "@jest/globals"; import { + latestCompatible, releaseRows, releaseTags, sortReleaseTags, @@ -126,4 +127,28 @@ describe("toolchain release tags", () => { ); } }); + + describe("latestCompatible", () => { + let tags = ["2.2.2", "2.0.0", "1.16.2", "1.16.1", "0.14.1", "0.14.0"]; + + // A project on moc 1.x gets the 1.x bugfix from `update`, not 2.x. + test("stays on the pinned major", () => { + expect(latestCompatible("1.16.1", tags)).toBe("1.16.2"); + expect(latestCompatible("2.0.0", tags)).toBe("2.2.2"); + }); + + test("stays on the pinned minor for 0.x", () => { + expect(latestCompatible("0.14.0", ["0.15.0", ...tags])).toBe("0.14.1"); + }); + + test("never moves below the pin", () => { + expect(latestCompatible("2.3.0-beta.1", tags)).toBeUndefined(); + expect(latestCompatible("1.17.0", tags)).toBeUndefined(); + }); + + test("a pin that is not a version has no compatible range", () => { + expect(latestCompatible("133", ["134", "133"])).toBeUndefined(); + expect(latestCompatible("./moc", tags)).toBeUndefined(); + }); + }); }); diff --git a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md index 966c900b..f0efc3c0 100644 --- a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md +++ b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md @@ -5,22 +5,36 @@ sidebar_label: mops toolchain update # `mops toolchain update` -Update tools already pinned in `[toolchain]` to the latest version and update `mops.toml` +Update tools already pinned in `[toolchain]` to the newest compatible version and update `mops.toml` ``` -mops toolchain update [tool] +mops toolchain update [tool] [--major] ``` Only tools present in the `[toolchain]` section of `mops.toml` are updated. Without an argument, every pinned tool is updated; with an argument, the command fails if that tool is not pinned yet — use [`mops toolchain use`](./03-mops-toolchain-use.md) for a first pin. +Like [`mops update`](../1-deps/04-mops-update.md) for packages, the update stays within the caret range of the pinned version: the same major version, or for a `0.x.y` pin, the same minor version. A project pinned to `moc` 1.16.1 gets the newest 1.x release, not 2.x. When a newer release is out of range, the command names it and the flag that installs it. + +A pin that is not a semantic version, such as `wasm-opt` `133`, has no compatible range, so it changes only with `--major`. A pin to a local file is skipped unless you pass `--major`. + +## Options + +### `--major` + +Allow updates that cross the caret bound, to the stable release with the highest version. This is what [`mops toolchain use latest`](./03-mops-toolchain-use.md) installs. + +``` +mops toolchain update moc --major +``` + ## Examples -Update all pinned tools to the latest version +Update all pinned tools to the newest compatible version ``` mops toolchain update ``` -Update specific tool to the latest version +Update specific tool to the newest compatible version ``` mops toolchain update moc mops toolchain update wasmtime From 421f884e66328360ba9ebdc31440473f8ca8a80e Mon Sep 17 00:00:00 2001 From: Kamil Listopad Date: Tue, 17 Nov 2026 16:04:05 +0100 Subject: [PATCH 4/5] fix(cli): `toolchain update` always skips local-file pins, one release fetch per tool `--major` replaced a local-file pin with the latest release, which `mops update --major` never does to path dependencies. `update` also fetched the first releases page twice per tool. Fix docs and changelog that still said `update` goes to the highest version. Co-Authored-By: Claude Opus 5.5 --- cli/CHANGELOG.md | 4 ++-- cli/commands/toolchain/index.ts | 10 +++++++--- cli/commands/toolchain/release-tags.ts | 6 +++--- docs/docs/cli/5-toolchain/04-mops-toolchain-update.md | 2 +- docs/docs/cli/5-toolchain/07-mops-toolchain-info.md | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 81eb79ef..13b5702b 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,8 +1,8 @@ # Mops CLI Changelog ## Next -- **Behaviour change**: `mops toolchain update` stays within the caret range of each pin, as `mops update` does for packages: the same major version, or the same minor version for `0.x.y`. A project pinned to `moc` 1.16.1 now gets the newest 1.x release instead of jumping to 2.x. When a newer release is out of range, the command names it. To cross the bound, pass the new `--major` flag. A pin that is not a semantic version, such as `wasm-opt` `133`, changes only with `--major`, and a pin to a local file is skipped without it. -- **Behaviour change**: `mops toolchain use latest`, `mops toolchain update` and the `latest` line of `mops toolchain info` resolve to the stable release with the highest version, as Cargo does. A tag with a semver prerelease suffix, such as `2.3.0-rc.1`, counts as a prerelease even when GitHub does not flag it. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. +- **Behaviour change**: `mops toolchain update` stays within the caret range of each pin, as `mops update` does for packages: the same major version, or the same minor version for `0.x.y`. A project pinned to `moc` 1.16.1 now gets the newest 1.x release instead of jumping to 2.x. When a newer release is out of range, the command names it. To cross the bound, pass the new `--major` flag. A pin that is not a semantic version, such as `wasm-opt` `133`, changes only with `--major`. A pin to a local file is always skipped, as `mops update` skips path dependencies; before, `update` replaced it with the latest release. +- **Behaviour change**: `mops toolchain use latest`, `mops toolchain update --major` and the `latest` line of `mops toolchain info` resolve to the stable release with the highest version, as Cargo does. A tag with a semver prerelease suffix, such as `2.3.0-rc.1`, counts as a prerelease even when GitHub does not flag it. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use ` picker also lists releases highest version first, so it no longer preselects that bugfix. - `wasm-opt` release lists, such as `mops toolchain info wasm-opt --versions` and the picker, show only Binaryen's `version_N` releases, highest first. They also listed the repo's old `1.38.x` tags, which `mops` cannot install, and put `99` above `131`. ## 3.7.1 diff --git a/cli/commands/toolchain/index.ts b/cli/commands/toolchain/index.ts index dc578af8..8aa674de 100644 --- a/cli/commands/toolchain/index.ts +++ b/cli/commands/toolchain/index.ts @@ -222,11 +222,14 @@ async function resolveUpdate( major: boolean, ): Promise<{ version: string; latest: string }> { let toolUtils = getToolUtils(tool); - let latest = await toolUtils.getLatestReleaseTag(); + let res = await toolUtils.getReleaseTags(); + let { tags, truncated } = res; + // Page 1 nearly always has a stable release. Only when it does not is + // another request worth it. + let latest = res.latest ?? (await toolUtils.getLatestReleaseTag()); if (major) { return { version: latest, latest }; } - let { tags, truncated } = await toolUtils.getReleaseTags(); let version = latestCompatible(pinned, tags); // A newer release on the pinned line is almost always on page 1. Only an // old pin with nothing there needs the full history. @@ -252,7 +255,8 @@ async function update(tool?: Tool, { major = false } = {}) { ); } - if (!major && pinned.match(FILE_PATH_REGEX)) { + // As `mops update` never touches path dependencies, `--major` included. + if (pinned.match(FILE_PATH_REGEX)) { console.log(`${tool} is pinned to a local file, skipping`); continue; } diff --git a/cli/commands/toolchain/release-tags.ts b/cli/commands/toolchain/release-tags.ts index 33bb2e74..186a1c54 100644 --- a/cli/commands/toolchain/release-tags.ts +++ b/cli/commands/toolchain/release-tags.ts @@ -58,7 +58,7 @@ let filterReleases = ( ); }; -/** Tags matching what `mops toolchain update` would resolve to, highest first. */ +/** Tags matching what `mops toolchain use latest` resolves to, highest first. */ export let releaseTags = ( releases: ReleaseInfo[], options?: ReleaseFilter, @@ -79,8 +79,8 @@ export let releaseRows = ( }; /** - * Highest of `tags` within the caret range of `pinned`, as `mops update` picks - * for packages: same major, or same minor for `0.x`. `undefined` when `pinned` + * Highest of `tags` within Cargo's caret range of `pinned`: same major, or + * same minor for `0.x`, as `mops update` picks for packages. `undefined` when `pinned` * is not a version (a Binaryen `133`, a local file) or no tag fits the range. */ export let latestCompatible = ( diff --git a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md index f0efc3c0..101d989a 100644 --- a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md +++ b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md @@ -15,7 +15,7 @@ Only tools present in the `[toolchain]` section of `mops.toml` are updated. With Like [`mops update`](../1-deps/04-mops-update.md) for packages, the update stays within the caret range of the pinned version: the same major version, or for a `0.x.y` pin, the same minor version. A project pinned to `moc` 1.16.1 gets the newest 1.x release, not 2.x. When a newer release is out of range, the command names it and the flag that installs it. -A pin that is not a semantic version, such as `wasm-opt` `133`, has no compatible range, so it changes only with `--major`. A pin to a local file is skipped unless you pass `--major`. +A pin that is not a semantic version, such as `wasm-opt` `133`, has no compatible range, so it changes only with `--major`. A pin to a local file is always skipped. To replace it, run [`mops toolchain use `](./03-mops-toolchain-use.md). ## Options diff --git a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md index b3dc7b68..403a4250 100644 --- a/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md +++ b/docs/docs/cli/5-toolchain/07-mops-toolchain-info.md @@ -56,7 +56,7 @@ mops toolchain info moc --versions --prerelease Drafts are never listed, with or without the flag. -By default, listed versions match what `mops toolchain update` and `mops toolchain use latest` resolve to (the stable release with the highest version, which is not always the most recently published one). +By default, listed versions match what `mops toolchain update --major` and `mops toolchain use latest` resolve to (the stable release with the highest version, which is not always the most recently published one). ## Output From f77bd17978345220d318c88d98ba9d24b0236ee1 Mon Sep 17 00:00:00 2001 From: Kamil Listopad Date: Tue, 17 Nov 2026 16:06:42 +0100 Subject: [PATCH 5/5] fix(cli): `toolchain update --major` keeps a prerelease pin newer than every stable release Also fix two doc spots that still tied `update` to the highest version. Co-Authored-By: Claude Opus 5.5 --- cli/commands/toolchain/index.ts | 5 ++++- docs/docs/cli/5-toolchain/03-mops-toolchain-use.md | 2 +- docs/docs/cli/5-toolchain/04-mops-toolchain-update.md | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/commands/toolchain/index.ts b/cli/commands/toolchain/index.ts index 8aa674de..9a7206fe 100644 --- a/cli/commands/toolchain/index.ts +++ b/cli/commands/toolchain/index.ts @@ -227,8 +227,11 @@ async function resolveUpdate( // Page 1 nearly always has a stable release. Only when it does not is // another request worth it. let latest = res.latest ?? (await toolUtils.getLatestReleaseTag()); + // `--major` never moves a prerelease pin back to an older stable line. + let pinnedIsNewer = + pinned !== latest && sortReleaseTags([pinned, latest])[1] === pinned; if (major) { - return { version: latest, latest }; + return { version: pinnedIsNewer ? pinned : latest, latest }; } let version = latestCompatible(pinned, tags); // A newer release on the pinned line is almost always on page 1. Only an diff --git a/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md b/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md index 2dd7c139..d8188fa2 100644 --- a/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md +++ b/docs/docs/cli/5-toolchain/03-mops-toolchain-use.md @@ -35,7 +35,7 @@ mops toolchain use moc ![user prompt image](mops-toolchain-use-moc.png) -The picker lists stable releases only, matching what `mops toolchain update` resolves to. Pass `--prerelease` to include prereleases (and let `latest` resolve to one): +The picker lists stable releases only, highest version first, matching what `mops toolchain use latest` resolves to. Pass `--prerelease` to include prereleases (and let `latest` resolve to one): ``` mops toolchain use moc --prerelease ``` diff --git a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md index 101d989a..74614dfb 100644 --- a/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md +++ b/docs/docs/cli/5-toolchain/04-mops-toolchain-update.md @@ -40,5 +40,9 @@ mops toolchain update moc mops toolchain update wasmtime mops toolchain update pocket-ic mops toolchain update lintoko -mops toolchain update wasm-opt +``` + +Update a tool past its compatible range, for example `wasm-opt`, whose pins are not semantic versions +``` +mops toolchain update wasm-opt --major ```