pi-setup-system 0.0.60

Install, update, back up, restore and remove complete Pi Coding Agent configurations. Built by NDDev.
//! Pi Coding Agent's own program, as measured rather than as described.
//!
//! Generated by `tools/transcribe_software.py` from the `software_artifacts`
//! block of `references/pi-baseline.json`, which
//! `tools/refresh_software_pins.py` writes from bytes it actually fetched.
//! Every member path below was read out of the archive it names, not assumed:
//! codex's carries the target triple and so genuinely differs per platform.
//!
//! Where a `previous_software_artifacts` block is present, it is transcribed
//! too. It is not a second choice: `refresh_software_pins.py` puts the outgoing
//! current pin there on a bump, so the pair is always two consecutive real
//! releases and there is still exactly one value to keep fresh.
//!
//! Do not edit. The test at the bottom re-reads that baseline and compares it
//! field by field, so an edit here fails rather than silently installing bytes
//! nobody measured.

use crate::harness_runtime::{Artifact, Delivery, Previous, Shape, Software};

/// The artifacts pi is published as.
pub(crate) const ARTIFACTS: &[Artifact] = &[
    Artifact {
        platform: "linux/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-linux-arm64.tar.gz",
        bytes: 42_529_658,
        sha256: "sha256:135580f6b942151646e67b8b866d987d28ce3cff5a497030775ddd29659f943d",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "linux/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-linux-x64.tar.gz",
        bytes: 42_464_648,
        sha256: "sha256:c2f3c3e6a1850bd87654cc3ca8811013272397c3d042a4e2a64c43ee1b423972",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "macos/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-darwin-arm64.tar.gz",
        bytes: 30_928_407,
        sha256: "sha256:c68e3ac4d05b4e282aaab2e6c76f161d3e9e68f19a22e38913cbfaadb6c800f0",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "macos/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-darwin-x64.tar.gz",
        bytes: 33_440_191,
        sha256: "sha256:7a042d6413065421387001a4986190a1a03186c95a695f4dee0bdc76e60de8f7",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "windows/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-windows-arm64.zip",
        bytes: 43_455_125,
        sha256: "sha256:6b2726efc34a9158ab06bf7b981f7bcccf15de9ea236a3f4ef7a894a78aa386e",
        shape: Shape::Zip,
        member: "pi.exe",
    },
    Artifact {
        platform: "windows/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.4/pi-windows-x64.zip",
        bytes: 44_907_374,
        sha256: "sha256:03b2318774f18721e959d9f8f3340a9f942e7aa516fb7030d3007a12a40a4a97",
        shape: Shape::Zip,
        member: "pi.exe",
    },
];

/// The artifacts 0.84.3 was published as, kept so
/// `software_update` has a version to move from and `rollback` a tree to
/// return to. Measured from bytes when it was the current pin.
pub(crate) const PREVIOUS_ARTIFACTS: &[Artifact] = &[
    Artifact {
        platform: "linux/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-linux-arm64.tar.gz",
        bytes: 42_521_548,
        sha256: "sha256:e7cd48cd6f64b708e8459a890882b1007332f6e6b876fe1fd5c5203abd0addb7",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "linux/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-linux-x64.tar.gz",
        bytes: 42_458_773,
        sha256: "sha256:6f8bb67c21bc6b8a8a106d354f56d7fd4a190a3cd8ad3a32db45f6d281a5d008",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "macos/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-darwin-arm64.tar.gz",
        bytes: 30_919_980,
        sha256: "sha256:0120c9f99ea05fe801e6e7c2c9d91dd65636563ca0803711b37b9f32920d4b63",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "macos/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-darwin-x64.tar.gz",
        bytes: 33_434_213,
        sha256: "sha256:b99706b3254faaf3695395ecb69cb7e1f4d4822bd3f832e6d1f2636d896b6bde",
        shape: Shape::GzipTar,
        member: "pi/pi",
    },
    Artifact {
        platform: "windows/arm64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-windows-arm64.zip",
        bytes: 43_448_675,
        sha256: "sha256:d0f28a5bbeddcaee25fb7f4d8c70917d2c287d02b815614382aac9ac55a8fe39",
        shape: Shape::Zip,
        member: "pi.exe",
    },
    Artifact {
        platform: "windows/x86_64",
        url: "https://github.com/earendil-works/pi/releases/download/v0.84.3/pi-windows-x64.zip",
        bytes: 44_900_235,
        sha256: "sha256:636a56f546c8bb1f2cb327964b7afbd9302efcd45c1704922a097cd8bd935fb9",
        shape: Shape::Zip,
        member: "pi.exe",
    },
];

/// Pi Coding Agent's program, and where its bytes come from.
pub(crate) const SOFTWARE: Software = Software {
    version: "0.84.4",
    command: "pi",
    delivery: Delivery::Artifacts(ARTIFACTS),
    unsupported: &[],
    previous: Some(Previous {
        version: "0.84.3",
        artifacts: PREVIOUS_ARTIFACTS,
    }),
};

#[cfg(test)]
mod tests {
    #![allow(clippy::unwrap_used, clippy::panic)]

    // Named rather than glob-imported: a product delivered by a package manager
    // has no `Artifact` in scope, and the test is the same text for all seven.
    use crate::harness_runtime::{Delivery, Shape};

    use super::SOFTWARE;

    fn measured() -> serde_json::Value {
        let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
            .join("../../references/pi-baseline.json");
        serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap()
    }

    #[test]
    fn every_artifact_compiled_in_is_the_one_the_baseline_measured() {
        let block = &measured()["software_artifacts"];
        assert_eq!(block["version"], SOFTWARE.version);
        assert_eq!(block["command"], SOFTWARE.command);

        let Delivery::Artifacts(compiled) = SOFTWARE.delivery else {
            // A product delivered by a package manager has no artifacts, and
            // the baseline must agree that it has none.
            assert_eq!(block["shape"], "manager");
            assert!(block["platforms"].as_object().unwrap().is_empty());
            return;
        };
        let published = block["platforms"].as_object().unwrap();
        assert_eq!(
            compiled.len(),
            published.len(),
            "the table and the baseline disagree on how many platforms exist"
        );
        for artifact in compiled {
            let entry = &published[artifact.platform];
            assert_eq!(entry["url"], artifact.url, "{}", artifact.platform);
            assert_eq!(entry["bytes"], artifact.bytes, "{}", artifact.platform);
            assert_eq!(entry["sha256"], artifact.sha256, "{}", artifact.platform);
            let member = entry.get("member").and_then(serde_json::Value::as_str);
            assert_eq!(
                member.unwrap_or(""),
                artifact.member,
                "{} names a different member",
                artifact.platform
            );
            assert_eq!(
                artifact.shape == Shape::Raw,
                member.is_none(),
                "{} disagrees about whether the bytes are the program",
                artifact.platform
            );
        }
    }

    /// The second pin is the baseline's, or it is absent in both places.
    ///
    /// Asserted from either side rather than only where it exists: a harness
    /// that has never been bumped must compile in `None`, and a build that
    /// dropped the block while the baseline still carried it would otherwise
    /// pass by having nothing to compare.
    #[test]
    fn the_version_this_build_can_move_between_is_the_one_measured_before_it() {
        let baseline = measured();
        let recorded = baseline.get("previous_software_artifacts");
        let Some(earlier) = SOFTWARE.previous else {
            assert!(
                recorded.is_none(),
                "the baseline records a previous release and this build names none"
            );
            return;
        };
        let block = recorded.unwrap_or_else(|| {
            panic!("this build names a previous release the baseline does not record")
        });
        assert_eq!(block["version"], earlier.version);
        assert_ne!(
            earlier.version, SOFTWARE.version,
            "a second pin equal to the first is one version wearing two names"
        );
        let published = block["platforms"].as_object().unwrap();
        assert_eq!(
            earlier.artifacts.len(),
            published.len(),
            "the previous table and the baseline disagree on how many platforms exist"
        );
        for artifact in earlier.artifacts {
            let entry = &published[artifact.platform];
            assert_eq!(entry["url"], artifact.url, "{}", artifact.platform);
            assert_eq!(entry["bytes"], artifact.bytes, "{}", artifact.platform);
            assert_eq!(entry["sha256"], artifact.sha256, "{}", artifact.platform);
        }
    }

    #[test]
    fn a_platform_the_vendor_does_not_publish_is_listed_rather_than_missing() {
        let block = &measured()["software_artifacts"];
        let unpublished: Vec<&str> = block
            .get("unpublished")
            .and_then(serde_json::Value::as_array)
            .map(|entries| {
                entries
                    .iter()
                    .filter_map(serde_json::Value::as_str)
                    .collect()
            })
            .unwrap_or_default();
        assert_eq!(unpublished, SOFTWARE.unsupported);
    }

    #[test]
    fn no_release_calls_a_platform_both_published_and_unpublished() {
        let baseline = measured();
        for name in ["software_artifacts", "previous_software_artifacts"] {
            let Some(block) = baseline.get(name) else {
                continue;
            };
            let published = block["platforms"].as_object().unwrap();
            let unpublished = block
                .get("unpublished")
                .and_then(serde_json::Value::as_array)
                .into_iter()
                .flatten()
                .filter_map(serde_json::Value::as_str);
            for platform in unpublished {
                assert!(
                    !published.contains_key(platform),
                    "{name}: {platform} is both published and unpublished"
                );
            }
        }
    }
}