diff --git a/Cargo.lock b/Cargo.lock index 67cd0e6..728ff27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -927,6 +927,27 @@ dependencies = [ "serde_core", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + [[package]] name = "dialoguer" version = "0.11.0" @@ -1692,6 +1713,7 @@ name = "hm-plugin-protocol" version = "0.0.0-dev" dependencies = [ "chrono", + "derive_more", "insta", "schemars 0.8.22", "semver", diff --git a/Cargo.toml b/Cargo.toml index 5da02aa..7244bb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ semver = { version = "1", features = ["serde"] } uuid = { version = "1", features = ["serde", "v4"] } chrono = { version = "0.4", features = ["serde"] } thiserror = "2" +derive_more = { version = "1", default-features = false, features = ["deref", "from", "display"] } tokio = { version = "1", features = ["full"] } tokio-util = { version = "0.7", features = ["rt"] } extism = "1" diff --git a/crates/hm-plugin-docker/src/lib.rs b/crates/hm-plugin-docker/src/lib.rs index d50a574..4bc4dbe 100644 --- a/crates/hm-plugin-docker/src/lib.rs +++ b/crates/hm-plugin-docker/src/lib.rs @@ -127,7 +127,7 @@ fn run_step(input: ExecutorInput) -> Result { } }) .collect(); - hm_plugin_protocol::SnapshotRef(format!( + hm_plugin_protocol::SnapshotRef::from(format!( "harmont-local-ephemeral/{safe}:run-{}", input.step_id.simple() )) diff --git a/crates/hm-plugin-protocol/Cargo.toml b/crates/hm-plugin-protocol/Cargo.toml index ec74a4e..ea55430 100644 --- a/crates/hm-plugin-protocol/Cargo.toml +++ b/crates/hm-plugin-protocol/Cargo.toml @@ -14,6 +14,7 @@ semver = { workspace = true } uuid = { workspace = true } chrono = { workspace = true } thiserror = { workspace = true } +derive_more = { workspace = true } [dev-dependencies] insta = { version = "1", features = ["json"] } diff --git a/crates/hm-plugin-protocol/src/executor.rs b/crates/hm-plugin-protocol/src/executor.rs index bb0f9b5..bc86727 100644 --- a/crates/hm-plugin-protocol/src/executor.rs +++ b/crates/hm-plugin-protocol/src/executor.rs @@ -10,14 +10,20 @@ use crate::ir::CommandStep; /// Opaque archive handle. The plugin streams bytes via /// `hm_archive_read(id, offset, max)`. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema, + derive_more::From, derive_more::Deref, derive_more::Display, +)] #[serde(transparent)] pub struct ArchiveId(pub Uuid); /// Opaque snapshot reference. For the docker plugin this is an image /// tag; other plugins are free to encode their own format. The host /// never inspects the contents. -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)] +#[derive( + Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema, + derive_more::From, derive_more::Deref, derive_more::Display, +)] #[serde(transparent)] pub struct SnapshotRef(pub String); diff --git a/crates/hm-plugin-protocol/src/host_abi.rs b/crates/hm-plugin-protocol/src/host_abi.rs index aa016a6..f69c333 100644 --- a/crates/hm-plugin-protocol/src/host_abi.rs +++ b/crates/hm-plugin-protocol/src/host_abi.rs @@ -33,13 +33,19 @@ pub enum KvScope { /// Opaque socket handle returned by `hm_unix_socket_connect`. Bound /// to the plugin instance that opened it. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema, + derive_more::From, derive_more::Deref, derive_more::Display, +)] #[serde(transparent)] pub struct SocketHandle(pub u64); /// Opaque handle returned by `hm_spawn_loopback`. Bound to the plugin /// instance. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema, + derive_more::From, derive_more::Deref, derive_more::Display, +)] #[serde(transparent)] pub struct LoopbackHandle(pub u64); diff --git a/crates/hm/src/orchestrator/archive.rs b/crates/hm/src/orchestrator/archive.rs index c40d835..c6cd64c 100644 --- a/crates/hm/src/orchestrator/archive.rs +++ b/crates/hm/src/orchestrator/archive.rs @@ -26,7 +26,7 @@ impl ArchiveStore { /// Register a new archive. Returns the freshly-minted ID. pub fn register(&self, bytes: Vec) -> ArchiveId { - let id = ArchiveId(Uuid::new_v4()); + let id = ArchiveId::from(Uuid::new_v4()); let _ = self.archives.lock().map(|mut m| m.insert(id, bytes)); id } diff --git a/crates/hm/src/orchestrator/cache.rs b/crates/hm/src/orchestrator/cache.rs index 2f1bdf2..d7f8e38 100644 --- a/crates/hm/src/orchestrator/cache.rs +++ b/crates/hm/src/orchestrator/cache.rs @@ -60,11 +60,11 @@ pub async fn decide(docker: &DockerClient, step: &CommandStep) -> Result Result<() let s = current().context("no orchestrator state")?; let archive = s.archives.read(args.archive_id, 0, u64::MAX); if archive.is_empty() { - anyhow::bail!("archive {} is empty or unknown", args.archive_id.0); + anyhow::bail!("archive {} is empty or unknown", args.archive_id); } let cancel = s.cancel.clone(); let docker = s.docker.clone();