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

nordisk/dwarves

dwarves-gui/tests/robot_release_runs.rs

//! **A release run on the Pipeline tab's runs** (lane RELBUILD-RUNA). A release build is
//! a Runa pipeline (`release-build`), so its runs are drawn by the same runs leg as any
//! other: the "Request release" form sends the CLI's inputs to the forge
//! (`Dwarf.Trigger`), the queued run shows with its release state, and the signed-bundle
//! upload goes to `Dwarf.ReleaseBundle`, which refuses a run that waits for no signature.
//! The UI only sends and draws; a real forge (with a release runner's inbox and runs)
//! answers.

use dwarves_gui::pipeline_runs::{RunsLeg, RELEASE_PIPELINE};

#[test]
fn the_runs_leg_requests_a_release_shows_its_state_and_uploads_a_bundle_through_the_forge() {
    let d = tempfile::tempdir().unwrap();
    let dirs = dwarves::release_runa::ReleaseDirs { inbox: d.path().join("inbox"), runs: d.path().join("runs") };
    std::fs::create_dir_all(&dirs.inbox).unwrap();
    std::fs::create_dir_all(dirs.runs.join("requests")).unwrap();
    let forge = dwarves::server::spawn_dwarf_release(d.path().join("warehouse"), dirs.clone());
    let steps = d.path().join("steps");
    std::fs::write(&steps, "1  demo  0.1.0  demo  crates/demo  all\n").unwrap();
    let pins = d.path().join("pins");
    std::fs::write(&pins, format!("demo {}\n", "a".repeat(40))).unwrap();

    let mut leg = RunsLeg::new(forge.endpoint.clone(), "");
    leg.set_pipeline(RELEASE_PIPELINE);
    {
        let f = leg.form_mut();
        f.name = "demo-0.1.0".into();
        f.steps_path = steps.display().to_string();
        f.pins_path = pins.display().to_string();
        f.locks = "demo/Cargo.toml".into();
    }
    leg.request_release();
    leg.wait_actions();
    let s = leg.state_json();
    let note = s["request_note"].as_str().unwrap_or_default().to_string();
    assert!(note.starts_with("queued: run demo-0.1.0-"), "{note}");
    assert_eq!(std::fs::read_dir(&dirs.inbox).unwrap().count(), 1, "the forge wrote the request");

    leg.wait();
    let s = leg.state_json();
    assert_eq!(s["runs"][0]["status"], "queued", "{s}");
    assert_eq!(s["release"]["state"], "queued", "{s}");
    assert_eq!(s["release"]["release"], "demo-0.1.0");

    let junk = d.path().join("release.intoto.jsonl");
    std::fs::write(&junk, "{}\n").unwrap();
    leg.set_bundle_path(&junk.display().to_string());
    leg.attach_bundle();
    leg.wait_actions();
    let note = leg.state_json()["attach_note"].as_str().unwrap_or_default().to_string();
    assert!(note.starts_with("not stored") && note.contains("not waiting"), "{note}");
}