From 0f3cc3a91f370ee38923c9db6049e433edf90488 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 26 Oct 2026 09:31:11 +0000 Subject: [PATCH 1/2] fix(therock): drop a host version's - suffix only when it is all digits parse_host_version's doc says only a numeric - suffix (a packaging build number such as 7.2.4-98) is dropped, but the check only looked at the first character of the suffix. A host string like 7.2.4-98rc1 therefore had -98rc1 silently dropped and was read as plain 7.2.4. Require the whole suffix to be digits. Any other suffix now stays on the string for the PEP 440 ordering parser, which reads 7.0.0-rc1 as a release candidate and cannot read 7.2.4-98rc1, so that host version is "can't tell" and produces no host-newer note at install time. Signed-off-by: Roman Inflianskas --- apps/rocm/src/therock.rs | 29 +++++++++++++++++++++++++++++ apps/rocm/src/therock/version.rs | 16 ++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/apps/rocm/src/therock.rs b/apps/rocm/src/therock.rs index 36bd519cc0..0c565c8237 100644 --- a/apps/rocm/src/therock.rs +++ b/apps/rocm/src/therock.rs @@ -6123,6 +6123,35 @@ mod tests { assert!(host_version_newer_than(Some("unknown".to_owned()), "7.13.0").is_none()); } + #[test] + fn parse_host_version_drops_only_an_all_digit_build_suffix() { + // An all-digit tail is a packaging build number and is dropped. + assert_eq!( + parse_host_version("7.2.4-98"), + parse_version_for_ordering("7.2.4") + ); + assert!(parse_host_version("7.2.4-98").is_some()); + // A PEP 440 pre-release spelled with `-` is kept and read as one. + assert_eq!( + parse_host_version("7.0.0-rc1"), + parse_version_for_ordering("7.0.0rc1") + ); + // A tail that starts with a digit but is not all digits is neither a + // build number nor a PEP 440 stage. The whole string goes to the + // ordering parser, which cannot read it, so the host version is + // unreadable rather than silently read as `7.2.4`. + assert_eq!(parse_host_version("7.2.4-98rc1"), None); + assert_eq!(parse_version_for_ordering("7.2.4-98rc1"), None); + // What the user sees: an unreadable host version is "can't tell", so + // no host-newer note, even where the dropped-suffix reading (`7.20.1`) + // would have been newer than the version being installed. + assert!(host_version_newer_than(Some("7.20.1-33rc1".to_owned()), "7.13.0").is_none()); + assert_eq!( + host_version_newer_than(Some("7.20.1-33".to_owned()), "7.13.0").as_deref(), + Some("7.20.1-33") + ); + } + #[test] fn host_version_notes_and_warning_render_the_expected_text() { // Wheel path: the note names both versions and offers the --version override. diff --git a/apps/rocm/src/therock/version.rs b/apps/rocm/src/therock/version.rs index 9ad06419a8..cefbef9b99 100644 --- a/apps/rocm/src/therock/version.rs +++ b/apps/rocm/src/therock/version.rs @@ -187,7 +187,7 @@ pub(super) fn version_relation(left: &str, right: &str) -> Option { /// only a defined position. /// /// What makes the two sides agree is that [`parse_host_version`] strips a -/// `-` suffix only when it is *numeric*. A host `7.2.4-98` is reduced to +/// `-` suffix only when it is all digits. A host `7.2.4-98` is reduced to /// `7.2.4` before it reaches here, so this function never sees that shape /// from the host; and `7.0.0-rc1` is left intact, so both sides read it as a /// release candidate. Widening either side of that rule re-opens the @@ -351,21 +351,29 @@ pub(super) fn parse_version(value: &str) -> Option { /// one: a legacy/system ROCm reports a packaging build number as `7.2.4-98`, /// which is not a PEP 440 spelling of anything. /// -/// Only a *numeric* `-` suffix is dropped. `-` is also a PEP 440 pre-release +/// Only an all-digit `-` suffix is dropped. `-` is also a PEP 440 pre-release /// separator, so stripping it unconditionally would read `7.0.0-rc1` as the /// final `7.0.0` — and then this function and the comparator would disagree /// about that string, which is exactly the self-contradiction the shared parser /// exists to remove. /// +/// Any other suffix stays on the string, and the whole string goes to +/// [`parse_version_for_ordering`]: `7.0.0-rc1` is read as a release candidate, +/// and a shape that is neither a build number nor a PEP 440 stage +/// (`7.2.4-98rc1`) is unreadable, so this returns `None`. Checking only that the +/// suffix *starts* with a digit would drop `-98rc1` and read that string as the +/// plain `7.2.4`. +/// /// Sharing the parser is the point: a host version and an index version are /// compared against each other, and the two must not disagree about which is /// newer. Returns `None` when the string still cannot be read, so an /// unparseable host string is "can't tell" rather than a lexicographic guess. pub(super) fn parse_host_version(value: &str) -> Option { - // `7.2.4-98` -> `7.2.4`, but `7.0.0-rc1` is left for the PEP 440 parser. + // `7.2.4-98` -> `7.2.4`. `7.0.0-rc1` and `7.2.4-98rc1` are left whole for + // the PEP 440 parser, which reads the first and rejects the second. let trimmed = value.trim(); let candidate = match trimmed.split_once('-') { - Some((head, tail)) if tail.starts_with(|ch: char| ch.is_ascii_digit()) => head, + Some((head, tail)) if !tail.is_empty() && tail.chars().all(|c| c.is_ascii_digit()) => head, _ => trimmed, }; parse_version_for_ordering(candidate) From cb98413491dfe05327a77d770cacfb5a6ace6d84 Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Tue, 3 Nov 2026 10:28:50 +0200 Subject: [PATCH 2/2] test(therock): cover the empty build suffix and the host-newer install note Address review on the all-digit host-version rule: - assert that `7.2.4-` is unreadable, which is what the emptiness guard protects (`.all()` holds vacuously on an empty tail); it replaces an assertion duplicated from the neighbouring test - pin that distro-style packaging tails (`-98.el9`, `-120~22.04`, `-98-1`, `-98+local`) are unreadable under the strict rule - add runtime-20 and runtime-21: a tarball install preview on a host whose own ROCm reports a newer version names it in a version_note, and a host version with an unreadable suffix produces no newer-host claim Signed-off-by: Roman Inflianskas --- apps/rocm/src/therock.rs | 18 +++- .../features/runtime_setup.feature | 36 +++++++ tests/e2e-cucumber/tests/e2e.rs | 9 +- tests/e2e-cucumber/tests/e2e/therock_steps.rs | 98 +++++++++++++++++++ 4 files changed, 156 insertions(+), 5 deletions(-) diff --git a/apps/rocm/src/therock.rs b/apps/rocm/src/therock.rs index 0c565c8237..b4cf30019d 100644 --- a/apps/rocm/src/therock.rs +++ b/apps/rocm/src/therock.rs @@ -6146,10 +6146,20 @@ mod tests { // no host-newer note, even where the dropped-suffix reading (`7.20.1`) // would have been newer than the version being installed. assert!(host_version_newer_than(Some("7.20.1-33rc1".to_owned()), "7.13.0").is_none()); - assert_eq!( - host_version_newer_than(Some("7.20.1-33".to_owned()), "7.13.0").as_deref(), - Some("7.20.1-33") - ); + // An empty tail is not a build number: `.all()` holds vacuously on it, + // so without the emptiness guard `7.2.4-` would be read as `7.2.4`. + assert_eq!(parse_host_version("7.2.4-"), None); + // The rule is deliberately strict: only an all-digit tail is a build + // number, so distro-style packaging tails are unreadable too. The cost + // is a missing host-newer note for such a host, never a false one. + for distro_tail in [ + "7.2.4-98.el9", + "6.4.1-120~22.04", + "7.2.4-98-1", + "7.2.4-98+local", + ] { + assert_eq!(parse_host_version(distro_tail), None, "{distro_tail}"); + } } #[test] diff --git a/tests/e2e-cucumber/features/runtime_setup.feature b/tests/e2e-cucumber/features/runtime_setup.feature index 2ebd4fe962..6e9e51e819 100644 --- a/tests/e2e-cucumber/features/runtime_setup.feature +++ b/tests/e2e-cucumber/features/runtime_setup.feature @@ -415,3 +415,39 @@ Feature: Runtime configuration When the user dry-runs an SDK install for the gfx90c Vega iGPU Then the install is refused as having no ROCm build for that GPU And the refusal offers no package family to install instead + + # When the machine already has its own (unmanaged) ROCm and that ROCm is newer + # than the SDK the install picks, the preview says why the older SDK is + # selected. Such a host often reports its version with a packaging build + # number on the end, which must not stop the CLI from reading it. + # + # Linux-only: `--format tarball` is rejected outright on Windows. Hermetic: + # the catalog is a loopback fixture and `--family` is named, so no GPU and no + # network are needed and this runs on the ordinary E2E lane. + # + # Technical details: the host install is planted under the scenario's root + # and exported as ROCM_PATH; its `.info/version` reads `7.20.1-33`. The + # catalog serves one release tarball, ROCm 7.10.0, for `gfx120X-all`. + @id:runtime-install-preview-notes-newer-host-rocm @requires-os:linux + Scenario: runtime-20 - Previewing an install on a host with newer ROCm explains why the older SDK is selected + Given a release tarball catalog whose newest ROCm is older than the host's + And a machine whose own ROCm install reports a newer version with a packaging build number + When the user previews a tarball SDK install + Then the preview explains that the host's newer ROCm is passed over for the selected SDK + + # A host version the CLI cannot read is "can't tell", and "can't tell" is + # never "newer". The regression this pins: a suffix that merely starts with a + # digit was dropped whole, so the host was read as a plain, newer release and + # the preview claimed so. runtime-20 is what makes the absence below + # evidence: it shows the same preview printing the note when the host + # version is readable and newer. + # + # Technical details: `.info/version` reads `7.20.1-33rc1`, which with its + # suffix dropped would be `7.20.1`, newer than the catalog's 7.10.0. + @id:runtime-install-preview-ignores-unreadable-host-rocm @requires-os:linux + Scenario: runtime-21 - Previewing an install on a host whose ROCm version cannot be read makes no newer-host claim + Given a release tarball catalog whose newest ROCm is older than the host's + And a machine whose own ROCm install reports a version with an unreadable build suffix + When the user previews a tarball SDK install + Then the preview selects the newest SDK in the catalog + And the preview does not claim the host's ROCm is newer diff --git a/tests/e2e-cucumber/tests/e2e.rs b/tests/e2e-cucumber/tests/e2e.rs index 2d56ac2835..d1eac8d675 100644 --- a/tests/e2e-cucumber/tests/e2e.rs +++ b/tests/e2e-cucumber/tests/e2e.rs @@ -602,10 +602,17 @@ impl E2eWorld { /// on every platform, instead of depending on an ambient system `/opt/rocm` /// that exists on the MI300X box but not on the Strix Windows runner. pub fn plant_unmanaged_rocm(&mut self) { + self.plant_unmanaged_rocm_reporting("6.0.0"); + } + + /// [`Self::plant_unmanaged_rocm`], with the version its `.info/version` + /// reports chosen by the scenario — for the install preview's note about a + /// host ROCm newer than the SDK it selects. + pub fn plant_unmanaged_rocm_reporting(&mut self, version: &str) { let root = self.isolated_root.as_ref().expect("no isolated root"); let rocm = root.path().join("legacy-rocm"); std::fs::create_dir_all(rocm.join(".info")).expect("failed to create legacy rocm dir"); - std::fs::write(rocm.join(".info").join("version"), "6.0.0\n") + std::fs::write(rocm.join(".info").join("version"), format!("{version}\n")) .expect("failed to write legacy rocm marker"); self.legacy_rocm_path = Some(rocm); } diff --git a/tests/e2e-cucumber/tests/e2e/therock_steps.rs b/tests/e2e-cucumber/tests/e2e/therock_steps.rs index 6c7e18b8ed..9104b50b09 100644 --- a/tests/e2e-cucumber/tests/e2e/therock_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/therock_steps.rs @@ -87,6 +87,16 @@ const NEXT_REAL_TARBALL: &str = "therock-dist-linux-gfx120X-all-10.0.0.tar.gz"; /// The non-release sibling the live catalog publishes beside the real archive. const NEXT_TESTS_TARBALL: &str = "therock-dist-linux-gfx120X-all-tests-10.0.0.tar.gz"; const CURRENT_TARBALL: &str = "therock-dist-linux-gfx120X-all-7.10.0.tar.gz"; +/// The ROCm version `CURRENT_TARBALL` carries, as the preview reports it. +const CURRENT_TARBALL_VERSION: &str = "7.10.0"; + +/// A host ROCm newer than `CURRENT_TARBALL_VERSION`, reported with a packaging +/// build number the way a system install's `.info/version` reports one. +const HOST_ROCM_NEWER_WITH_BUILD_NUMBER: &str = "7.20.1-33"; +/// The same host version with a suffix that is neither a build number nor a +/// PEP 440 stage. Dropping the whole suffix would read it as `7.20.1`, newer +/// than `CURRENT_TARBALL_VERSION`; it must be read as "can't tell" instead. +const HOST_ROCM_WITH_UNREADABLE_SUFFIX: &str = "7.20.1-33rc1"; /// How many leading bytes of `"Downloading {CURRENT_TARBALL}"` to check for in /// [`assert_spinner_lines_cleared`] below. Comfortably under the ~48-column @@ -1496,3 +1506,91 @@ async fn assert_vllm_rocm10_discovery_pins(world: &mut E2eWorld) { "vLLM install against a live ROCm 10.x runtime did not report discovery pins:\n{install_output}" ); } + +#[given("a release tarball catalog whose newest ROCm is older than the host's")] +async fn release_tarball_catalog_only(world: &mut E2eWorld) { + let served = root(world).join("therock-release-tarball-fixture"); + write_fixture( + &served.join("tarball").join("current").join("index.html"), + &tarball_index_html(&[(CURRENT_TARBALL, 1_787_000_000.0)]), + ); + world.artifact_server = Some(LoopbackServer::start(&served)); + allow_base_overrides(world); + let base = server_base(world); + world.command_env.push(( + "ROCM_CLI_THEROCK_RELEASE_TARBALL_BASE", + format!("{base}/tarball/current/").into(), + )); +} + +#[given("a machine whose own ROCm install reports a newer version with a packaging build number")] +async fn host_rocm_newer_with_build_number(world: &mut E2eWorld) { + world.plant_unmanaged_rocm_reporting(HOST_ROCM_NEWER_WITH_BUILD_NUMBER); +} + +#[given("a machine whose own ROCm install reports a version with an unreadable build suffix")] +async fn host_rocm_with_unreadable_suffix(world: &mut E2eWorld) { + world.plant_unmanaged_rocm_reporting(HOST_ROCM_WITH_UNREADABLE_SUFFIX); +} + +#[when("the user previews a tarball SDK install")] +async fn preview_unpinned_tarball_install(world: &mut E2eWorld) { + // No `--version`: an unpinned release install reaches the canonical + // catalog, which the given-step populated with `CURRENT_TARBALL` alone. + // `--family` keeps the preview off host GPU detection. + preview_ok( + world, + &[ + "install", + "sdk", + "--channel", + "release", + "--format", + "tarball", + "--family", + GROUP_FAMILY, + "--dry-run", + ], + ); +} + +#[then("the preview selects the newest SDK in the catalog")] +async fn preview_selects_catalog_newest(world: &mut E2eWorld) { + assert_contains( + world, + &format!("tarball: {CURRENT_TARBALL}"), + "selected artifact", + ); + assert_contains( + world, + &format!("latest_version: {CURRENT_TARBALL_VERSION}"), + "selected artifact version", + ); +} + +#[then("the preview explains that the host's newer ROCm is passed over for the selected SDK")] +async fn preview_explains_host_newer(world: &mut E2eWorld) { + // The note claims the catalog's version "is selected", so assert the + // selection beside it: the claim and the state it describes, together. + preview_selects_catalog_newest(world).await; + assert_contains( + world, + &format!( + "version_note: this host reports ROCm {HOST_ROCM_NEWER_WITH_BUILD_NUMBER}, but \ + {CURRENT_TARBALL_VERSION} is the newest TheRock ROCm tarball for this GPU family, \ + so it is selected" + ), + "host-newer version note", + ); +} + +#[then("the preview does not claim the host's ROCm is newer")] +async fn preview_does_not_claim_host_newer(world: &mut E2eWorld) { + // Absence is only evidence because the sibling scenario shows the same + // preview printing the note when the host version is readable and newer. + let preview = stdout(world); + assert!( + !preview.contains("version_note:") && !preview.contains("this host reports ROCm"), + "the preview claimed an unreadable host ROCm version is newer:\n{preview}" + ); +}