Watch
0
0
Fork
You've already forked hyperhive
0

bind a container apply to the closure realised for the agent, and record the deployed pins on drift

hive-priv applies only the path its last RealiseClosure returned for that agent. On drift the swap and create record the pins of the commit the closure was built from.
This commit is contained in:
atlas 2026-10-29 22:36:58 +01:00
commit 6b800600e2

View file

@ -130,7 +130,58 @@ pub(crate) async fn resolve(agent: &str) -> Result<MetaBuild> {
Ok(build)
}
/// Record `build` as what `agent`'s rebuild builds from. The record is in
/// The pins `internal/meta` at `rev` holds for `agent`: the hyperhive commit and,
/// for a custom agent (`archetype` false), its config commit. This is what a
/// deploy of the swarm's closure for `rev` applies, which can differ from the
/// head [`choose`] took.
///
/// # Errors
/// `rev` is not a commit id, the forge read failed, or the flake pins no
/// hyperhive commit or, for a custom agent, no config commit.
pub(crate) async fn pins_at(
source: &impl MetaSource,
agent: &str,
archetype: bool,
rev: &str,
) -> Result<MetaBuild> {
if !valid_meta_rev(rev) {
bail!("{agent}: {rev:?} is not an internal/meta commit id");
}
let flake = source.flake_at(rev).await?;
let Some(hyperhive) = hive_meta_flake::pinned_rev(&flake, "hyperhive") else {
bail!("{agent}: internal/meta at {rev} pins no hyperhive commit");
};
let config = if archetype {
None
} else {
let Some(config) = hive_meta_flake::pinned_rev(&flake, &format!("agent-{agent}")) else {
bail!("{agent}: internal/meta at {rev} pins no config commit for it");
};
Some(config.to_owned())
};
Ok(MetaBuild {
rev: rev.to_owned(),
hyperhive: hyperhive.to_owned(),
config,
})
}
/// [`pins_at`] against the forge this hive reads.
///
/// # Errors
/// As [`pins_at`], or this hive holds no forge token or cannot read the
/// agent's archetype.
pub(crate) async fn resolve_at(agent: &str, rev: &str) -> Result<MetaBuild> {
let archetype = crate::archetypes::of(agent)
.with_context(|| format!("{agent}: cannot read the agent's archetype"))?;
let Some(source) = crate::forge::internal_meta_source().await else {
bail!("{agent}: this hive holds no forge token to read internal/meta with");
};
pins_at(&source, agent, archetype.is_some(), rev).await
}
/// Record `build` as the commit `agent`'s rebuild expects the swarm's closure
/// from, and the pins it deploys. The record is in
/// hive-c0re's own state ([`crate::paths::meta_rev_dir`]), where the agent
/// cannot write.
///
@ -397,6 +448,28 @@ mod tests {
assert_unpinned(&choose(&source, "rev", None).await.unwrap_err(), "rev");
}
#[tokio::test]
async fn the_pins_at_a_commit_are_what_its_flake_holds() {
let source = forge(Some(ARGUS_HEAD));
let argus = pins_at(&source, "argus", false, META).await.unwrap();
assert_eq!(
argus,
MetaBuild {
rev: META.to_owned(),
hyperhive: HYPERHIVE.to_owned(),
config: Some(ARGUS_HEAD.to_owned()),
}
);
// An archetype agent has no config pin of its own.
let rev = pins_at(&source, "rev", true, META).await.unwrap();
assert_eq!((rev.hyperhive.as_str(), rev.config), (HYPERHIVE, None));
// A custom agent the flake doesn't list, and a rev that is no commit id.
let err = pins_at(&source, "nobody", false, META).await.unwrap_err();
assert!(format!("{err:#}").contains("no config commit"), "{err:#}");
let err = pins_at(&source, "argus", false, "main").await.unwrap_err();
assert!(format!("{err:#}").contains("not an internal/meta commit"));
}
#[tokio::test]
async fn no_repo_or_no_commit_is_an_error_naming_the_agent() {
let mut source = forge(Some(ARGUS_HEAD));