Watch
0
0
Fork
You've already forked hyperhive
0

the builder reads an agent's icon from its config and the controller writes the swarm's copy

This commit is contained in:
iris 2026-11-16 22:21:21 +01:00 • committed by mara
commit 181ef5f421

View file

@ -136,6 +136,18 @@ pub struct BuildFromMeta {
pub meta_rev: String,
}
/// What an agent's `services.hyperhive.agent.icon` came to in its evaluated
/// config.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "state", rename_all = "kebab-case")]
pub enum IconRead {
/// The option names an SVG file; `svg` is its text.
Set { svg: String },
/// The option is not set: the agent has no icon, and an icon it had is
/// removed.
Unset,
}
/// The builder's answer to one [`BuildFromMeta`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "state", rename_all = "kebab-case")]
@ -160,6 +172,11 @@ pub enum FromMetaReply {
/// when the builder could not read it, as for `private_users`.
#[serde(default, skip_serializing_if = "Option::is_none")]
nix_builds: Option<NixBuilds>,
/// The agent's `services.hyperhive.agent.icon`. Absent (`None`) when
/// the builder could not read it, as for `private_users`: the
/// controller then leaves the agent's icon as it is.
#[serde(default, skip_serializing_if = "Option::is_none")]
icon: Option<IconRead>,
},
/// The build did not succeed: the last lines `nix` printed, or why it
/// stopped (it timed out, or could not start). The controller holds the
@ -275,6 +292,9 @@ mod tests {
cached: true,
private_users: Some(true),
nix_builds: Some(NixBuilds::Disabled),
icon: Some(IconRead::Set {
svg: "<svg/>".to_owned(),
}),
},
json!({
"state": "built",
@ -283,6 +303,24 @@ mod tests {
"cached": true,
"private_users": true,
"nix_builds": "none",
"icon": {"state": "set", "svg": "<svg/>"},
}),
),
(
FromMetaReply::Built {
out_path: "/nix/store/x".to_owned(),
system: "x86_64-linux".to_owned(),
cached: false,
private_users: None,
nix_builds: None,
icon: Some(IconRead::Unset),
},
json!({
"state": "built",
"out_path": "/nix/store/x",
"system": "x86_64-linux",
"cached": false,
"icon": {"state": "unset"},
}),
),
(
@ -317,6 +355,7 @@ mod tests {
cached: false,
private_users: None,
nix_builds: None,
icon: None,
}
);
}
@ -337,11 +376,13 @@ mod tests {
cached: false,
private_users: None,
nix_builds: Some(NixBuilds::Host),
icon: None,
};
let wire = serde_json::to_value(&reply).expect("encodes");
let fields = wire.as_object().expect("an object");
assert!(!fields.contains_key("private_users"), "{wire}");
assert_eq!(fields["nix_builds"], "host");
assert!(!fields.contains_key("icon"), "{wire}");
assert!(
!serde_json::from_value::<Before>(wire.clone())
.expect("decodes")