#![deny(clippy::unwrap_used, clippy::panic)]
#![allow(
clippy::expect_used,
reason = "tests use expect for readable assertions"
)]
use anyhow::{Context, Result};
#[test]
fn test_version_sync() -> Result<()> {
let cargo_toml = std::fs::read_to_string("Cargo.toml").context("Failed to read Cargo.toml")?;
let cargo_table: toml::Table = cargo_toml.parse().context("Failed to parse Cargo.toml")?;
let cargo_version = cargo_table["package"]["version"]
.as_str()
.context("Failed to get version from Cargo.toml")?;
let plugin_json = std::fs::read_to_string(".claude-plugin/marketplace.json")
.context("Failed to read marketplace.json")?;
let plugin_data: serde_json::Value =
serde_json::from_str(&plugin_json).context("Failed to parse marketplace.json")?;
let plugin_version = plugin_data["plugins"][0]["version"]
.as_str()
.context("Failed to get version from marketplace.json")?;
let gemini_json = std::fs::read_to_string("gemini-extension.json")
.context("Failed to read gemini-extension.json")?;
let gemini_data: serde_json::Value =
serde_json::from_str(&gemini_json).context("Failed to parse gemini-extension.json")?;
let gemini_version = gemini_data["version"]
.as_str()
.context("Failed to get version from gemini-extension.json")?;
assert_eq!(
cargo_version, plugin_version,
"Version mismatch! Cargo.toml: {cargo_version}, marketplace.json: {plugin_version}"
);
assert_eq!(
cargo_version, gemini_version,
"Version mismatch! Cargo.toml: {cargo_version}, gemini-extension.json: {gemini_version}"
);
Ok(())
}
#[test]
fn test_cargo_lock_freshness() -> Result<()> {
let status = std::process::Command::new("cargo")
.args(["check", "--locked"])
.status()
.context("Failed to execute cargo check")?;
assert!(
status.success(),
"Cargo.lock is out of sync with Cargo.toml! Please run 'cargo check' and stage the changes."
);
Ok(())
}