if you let AI add Deserialize for everything Serialize you will have to fight this

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
lda
2026-05-03 03:58:04 +07:00
co-authored by Copilot
Verified
parent f5ed1ab8f6
commit 64cf5f9e69
7 changed files with 39 additions and 4 deletions
Generated
+1
View File
@@ -3779,6 +3779,7 @@ version = "0.3.0"
dependencies = [
"macaddr",
"serde",
"serde_json",
"serde_with",
"strum",
"thiserror 2.0.18",
+2
View File
@@ -16,6 +16,8 @@ pub async fn get_leases_with_neighbor_state() -> Result<Vec<DhcpLeaseWithState>>
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
.await
.context("failed to read DHCP leases")?;
// this is only used in the wakey CLI
#[allow(deprecated)]
Ok(wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await)
}
+2
View File
@@ -29,6 +29,8 @@ async fn dispatch_leases(req: LeasesRequest, config: &AgentConfig) -> Result<Com
)
.await?;
let leases = if req.include_state {
// only runs when requested explicitly to the endpoint
#[allow(deprecated)]
wakey::wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await
} else {
wakey::leases_without_state(leases)
+3
View File
@@ -10,3 +10,6 @@ serde = { workspace = true }
serde_with = { version = "3", features = ["json"] }
strum = { version = "0", features = ["derive", "strum_macros"] }
thiserror = "2"
[dev-dependencies]
serde_json.workspace = true
+25 -1
View File
@@ -12,7 +12,7 @@ use crate::parse::mac;
pub struct NeighborEntry {
pub ip: IpAddr,
pub dev: Option<String>,
#[serde(with = "mac::option_mac")]
#[serde(with = "mac::option_mac", default)]
pub mac: Option<MacAddr>,
pub state: NeighborState,
}
@@ -132,3 +132,27 @@ impl FromStr for NeighborEntry {
parse_neighbor_line(s)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn deserialize_online_neighbor() {
NeighborEntry::deserialize(serde_json::json!({
"ip" : "192.168.100.94",
"dev" : "br-lan",
"mac" : "04:7C:16:79:6D:EE",
"state" : "REACHABLE"
}))
.expect("all fields must pass");
}
#[test]
fn deserialize_failed_neighbor() {
NeighborEntry::deserialize(serde_json::json!({
"ip" : "192.168.100.94",
"dev" : "br-lan",
"state" : "FAILED"
}))
.expect("default");
}
}
+5 -3
View File
@@ -2,10 +2,12 @@ use std::path::PathBuf;
mod leases;
#[allow(deprecated)]
pub use leases::enrich_leases_with_nud_state;
pub use leases::{
enrich_leases_with_nud_state, parse_dhcp_lease_line, read_dhcp_leases,
read_dhcp_leases_from_path, read_dhcp_leases_with_names,
read_dhcp_leases_with_names_from_paths,
parse_dhcp_lease_line, read_dhcp_leases, read_dhcp_leases_from_path,
read_dhcp_leases_with_names, read_dhcp_leases_with_names_from_paths,
};
const DEFAULT_DHCP_LEASES: &str = "/tmp/dhcp.leases";
+1
View File
@@ -89,6 +89,7 @@ pub async fn read_dhcp_leases_with_names_from_paths(
}
/// Enrich DHCP leases with the best currently known neighbor state per IP.
#[deprecated(note = "use inventory")]
pub async fn enrich_leases_with_nud_state(leases: Vec<DhcpLease>) -> Vec<DhcpLeaseWithState> {
let ips: Vec<IpAddr> = leases.iter().map(|l| l.ip).collect();
let mut map: std::collections::HashMap<IpAddr, wakey_core::NeighborState> =