Skip to main content

stackql_mcp/
pins.rs

1//! Per-platform sha256 pins for the packaged stackql release.
2//!
3//! Rendered from the .sha256 assets on the stackql/stackql release that the
4//! packaging repo (stackql/stackql-mcpb-packaging) targets. Update this table
5//! when bumping STACKQL_VERSION. Once the packaging repo publishes a
6//! consolidated platforms.json release asset, prefer rendering from that.
7
8use crate::error::{Error, Result};
9use crate::platform::Platform;
10
11/// The stackql release this crate version pins (release.yaml in the
12/// packaging repo, leading v stripped).
13pub const STACKQL_VERSION: &str = "0.10.500";
14
15/// A pinned bundle: name and sha256 as published on the GitHub release.
16#[derive(Clone, Copy, Debug)]
17pub struct Pin {
18    pub platform_key: &'static str,
19    pub bundle_name: &'static str,
20    pub sha256: &'static str,
21}
22
23pub const PINS: &[Pin] = &[
24    Pin {
25        platform_key: "linux-x64",
26        bundle_name: "stackql-mcp-linux-x64.mcpb",
27        sha256: "6615737747156b1a8413a976afb23af2e7eec29ebc98a6f0a0f65d1b153c44be",
28    },
29    Pin {
30        platform_key: "linux-arm64",
31        bundle_name: "stackql-mcp-linux-arm64.mcpb",
32        sha256: "594bedbabc3096dc3563c907724e845ce0b61a67de4b3fed4158b40c0363786c",
33    },
34    Pin {
35        platform_key: "windows-x64",
36        bundle_name: "stackql-mcp-windows-x64.mcpb",
37        sha256: "d2ce895e88f9c6b557df07073158629808f56d75598f3a701164d65506b791b0",
38    },
39    Pin {
40        platform_key: "darwin-universal",
41        bundle_name: "stackql-mcp-darwin-universal.mcpb",
42        sha256: "4eed70af5cfa67295ae0b42fa3a6dca71ac9acabd0d67914fd96ad1247a9b4cc",
43    },
44];
45
46/// Look up the pin for a platform. Every `Platform` variant has a pin; a miss
47/// here is a crate bug, so it surfaces as `UnsupportedPlatform`.
48pub fn pin_for(platform: Platform) -> Result<&'static Pin> {
49    PINS.iter()
50        .find(|p| p.platform_key == platform.key())
51        .ok_or(Error::UnsupportedPlatform {
52            os: std::env::consts::OS,
53            arch: std::env::consts::ARCH,
54        })
55}
56
57/// Download URL for a pinned bundle. Bundles are attached to the matching
58/// stackql/stackql release.
59pub fn bundle_url(pin: &Pin) -> String {
60    format!(
61        "https://github.com/stackql/stackql/releases/download/v{STACKQL_VERSION}/{}",
62        pin.bundle_name
63    )
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn every_platform_has_a_pin() {
72        for platform in [
73            Platform::LinuxX64,
74            Platform::LinuxArm64,
75            Platform::WindowsX64,
76            Platform::DarwinUniversal,
77        ] {
78            let pin = pin_for(platform).unwrap();
79            assert_eq!(pin.platform_key, platform.key());
80            assert_eq!(
81                pin.bundle_name,
82                format!("stackql-mcp-{}.mcpb", platform.key())
83            );
84        }
85    }
86
87    #[test]
88    fn pins_are_well_formed_sha256_hex() {
89        for pin in PINS {
90            assert_eq!(pin.sha256.len(), 64, "{}", pin.bundle_name);
91            assert!(
92                pin.sha256.chars().all(|c| c.is_ascii_hexdigit()),
93                "{}",
94                pin.bundle_name
95            );
96            assert_eq!(pin.sha256, pin.sha256.to_lowercase());
97        }
98    }
99
100    #[test]
101    fn bundle_url_points_at_the_pinned_release() {
102        let pin = pin_for(Platform::LinuxX64).unwrap();
103        assert_eq!(
104            bundle_url(pin),
105            "https://github.com/stackql/stackql/releases/download/v0.10.500/stackql-mcp-linux-x64.mcpb"
106        );
107    }
108}