Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/gunnar-ui

crates/gunnar-ui-recipe/tests/toolchain_pin.rs

//! **`rust-toolchain.toml` names the build image's compiler.**
//!
//! Every cargo row builds in `[build.toolchain]`'s image with `--network none`,
//! and rustup inside it honours `rust-toolchain.toml`. A channel the image does
//! not carry sends rustup to the network, and the row dies before cargo runs
//! (ODEN-CI round 1, 2026-10-25: the pin said 1.96.0, the ci3 image carries only
//! 1.97.1, so test, public-site, wasm and rows died at rustup).

use gunnar_ui_recipe::{declared, repo_root};

/// The `channel = "…"` value of `rust-toolchain.toml`.
fn pinned_channel(text: &str) -> Option<String> {
    text.lines().find_map(|line| {
        let rest = line.trim().strip_prefix("channel")?.trim_start();
        let value = rest.strip_prefix('=')?.trim();
        Some(value.trim_matches('"').to_string())
    })
}

#[test]
fn the_pinned_channel_is_the_build_images_compiler() {
    let path = repo_root().join("rust-toolchain.toml");
    let text =
        std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()));
    let channel = pinned_channel(&text).expect("rust-toolchain.toml has a channel line");
    let image = declared()
        .toolchain
        .expect("the recipe declares [build.toolchain]")
        .rust_version;
    assert_eq!(
        channel, image,
        "rust-toolchain.toml pins {channel}, but [build.toolchain] builds with {image}: \
         rustup in the image would go to the network for {channel}"
    );
}

#[test]
fn the_channel_reader_reads_the_value_and_only_the_value() {
    assert_eq!(
        pinned_channel("[toolchain]\nchannel = \"1.97.1\"\n").as_deref(),
        Some("1.97.1")
    );
    assert_eq!(pinned_channel("[toolchain]\ncomponents = []\n"), None);
    assert_ne!(
        pinned_channel("channel = \"1.96.0\"").as_deref(),
        Some("1.97.1"),
        "a different pin must compare unequal"
    );
}