deploy the closure the swarm declares, read no forge head, drop the update badge
This commit is contained in:
parent
279428a66f
commit
47c2acb640
1 changed files with 647 additions and 2001 deletions
|
|
@ -2,8 +2,8 @@
|
|||
//! from hyperhive's `agent-base` and the agent's config input or archetype.
|
||||
//!
|
||||
//! Pure: the output is a function of the arguments only. swarm-controller
|
||||
//! renders through [`render_flake`]; hive-c0re reads the pins of the result
|
||||
//! ([`pinned_rev`], [`builds_agent_at`]).
|
||||
//! renders through [`render_flake`] and reads the pins of the result
|
||||
//! ([`pinned_rev`]).
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use swarm_wire::agent_archetype::ArchetypeRef;
|
||||
|
|
@ -511,27 +511,6 @@ pub fn pinned_rev<'a>(flake_nix: &'a str, input: &str) -> Option<&'a str> {
|
|||
is_rev(rev).then_some(rev)
|
||||
}
|
||||
|
||||
/// Whether a flake [`render_flake`] rendered builds agent `name` the way the
|
||||
/// caller wants it built: from `archetype` when that is set, otherwise from
|
||||
/// its own config repo at the commit `config_head`. A flake that lists the
|
||||
/// agent under another archetype, or as custom where `archetype` is set (or
|
||||
/// the reverse), does not; nor does a custom agent with no `config_head`.
|
||||
#[must_use]
|
||||
pub fn builds_agent_at(
|
||||
flake_nix: &str,
|
||||
name: &str,
|
||||
archetype: Option<&ArchetypeRef>,
|
||||
config_head: Option<&str>,
|
||||
) -> bool {
|
||||
let entry = format!("\n{}\n", agent_entry(name, agent_web_port(name), archetype));
|
||||
if !flake_nix.contains(&entry) {
|
||||
return false;
|
||||
}
|
||||
archetype.is_some()
|
||||
|| config_head
|
||||
.is_some_and(|head| pinned_rev(flake_nix, &format!("agent-{name}")) == Some(head))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -627,54 +606,6 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
fn reviewer() -> ArchetypeRef {
|
||||
ArchetypeRef {
|
||||
source: "hyperhive".to_owned(),
|
||||
name: "reviewer".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_custom_agent_is_built_only_at_the_config_head_the_flake_pins() {
|
||||
let flake = rendered();
|
||||
assert!(builds_agent_at(&flake, "argus", None, Some(ARGUS)));
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "argus", None, Some(HYPERHIVE)),
|
||||
"a stale pin"
|
||||
);
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "argus", None, None),
|
||||
"a custom agent with no config commit"
|
||||
);
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "ghost", None, Some(ARGUS)),
|
||||
"an agent the flake lacks"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_archetype_agent_is_built_only_from_the_archetype_the_flake_lists() {
|
||||
let flake = rendered();
|
||||
assert!(builds_agent_at(&flake, "rev", Some(&reviewer()), None));
|
||||
let other = ArchetypeRef {
|
||||
name: "planner".to_owned(),
|
||||
..reviewer()
|
||||
};
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "rev", Some(&other), None),
|
||||
"another archetype of the same source"
|
||||
);
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "rev", None, Some(ARGUS)),
|
||||
"listed as an archetype agent, wanted as a custom one"
|
||||
);
|
||||
assert!(
|
||||
!builds_agent_at(&flake, "argus", Some(&reviewer()), None),
|
||||
"listed as a custom agent, wanted as an archetype one"
|
||||
);
|
||||
assert!(!builds_agent_at(&flake, "ghost", Some(&reviewer()), None));
|
||||
}
|
||||
|
||||
/// The text of `mkAgent`'s `let` binding `name`: from `name =` to the
|
||||
/// next binding at the same indent (`;` ends it at line end).
|
||||
fn binding<'a>(flake: &'a str, name: &str) -> &'a str {
|
||||
|
|
@ -724,12 +655,6 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_agent_whose_name_ends_another_s_is_not_that_agent() {
|
||||
let flake = rendered();
|
||||
assert!(!builds_agent_at(&flake, "gus", None, Some(ARGUS)));
|
||||
assert!(!builds_agent_at(&flake, "v", Some(&reviewer()), None));
|
||||
}
|
||||
/// An agent that declares `hyperhive` follows meta's own pin, so the
|
||||
/// lock holds one hyperhive; one that declares nothing gets no line (the
|
||||
/// control that the line is the declared input's, not every agent's).
|
||||
|
|
|
|||
Loading…
Reference in a new issue