Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/rocm/src/therock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6123,6 +6123,45 @@ 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());
// 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]
fn host_version_notes_and_warning_render_the_expected_text() {
// Wheel path: the note names both versions and offers the --version override.
Expand Down
16 changes: 12 additions & 4 deletions apps/rocm/src/therock/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(super) fn version_relation(left: &str, right: &str) -> Option<Ordering> {
/// 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
Expand Down Expand Up @@ -351,21 +351,29 @@ pub(super) fn parse_version(value: &str) -> Option<ParsedVersion> {
/// 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<VersionOrderKey> {
// `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)
Expand Down
36 changes: 36 additions & 0 deletions tests/e2e-cucumber/features/runtime_setup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion tests/e2e-cucumber/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
98 changes: 98 additions & 0 deletions tests/e2e-cucumber/tests/e2e/therock_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
);
}
Loading