drop the applied repo: the hive keeps no copy of an agent's config, only the deploy markers. Refs #5913
This commit is contained in:
parent
deeb5ecd86
commit
862495530c
1 changed files with 190 additions and 1634 deletions
|
|
@ -3,48 +3,6 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
/// Regression test: `setup_applied` must seed both agent.nix and flake.nix
|
||||
/// in the initial commit, and tag it `deployed/0`. Before commit 5b5a93e
|
||||
/// flake.nix was missing from the scaffold, requiring manual creation (seen
|
||||
/// with the damocles agent).
|
||||
///
|
||||
/// Exercises the template arm: there is no forge to take a config from in a
|
||||
/// test (no reader token), so `setup_applied` falls through to
|
||||
/// `seed_template` — which is the arm this asserts about.
|
||||
#[tokio::test]
|
||||
async fn setup_applied_seeds_flake_nix() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let applied = dir.path().join("applied");
|
||||
setup_applied(&applied, "test-agent")
|
||||
.await
|
||||
.expect("setup_applied");
|
||||
git_rev_parse(&applied, "refs/tags/deployed/0")
|
||||
.await
|
||||
.expect("the seed commit is tagged deployed/0");
|
||||
|
||||
// Both files must exist on disk.
|
||||
assert!(applied.join("agent.nix").exists(), "agent.nix missing");
|
||||
assert!(applied.join("flake.nix").exists(), "flake.nix missing");
|
||||
|
||||
// flake.nix must export nixosModules.default (the meta-flake contract).
|
||||
let flake = std::fs::read_to_string(applied.join("flake.nix")).unwrap();
|
||||
assert!(
|
||||
flake.contains("nixosModules.default"),
|
||||
"flake.nix does not export nixosModules.default"
|
||||
);
|
||||
|
||||
// Both files must be tracked in the initial git commit.
|
||||
let out = git_command()
|
||||
.current_dir(&applied)
|
||||
.args(["show", "--name-only", "--format=", "HEAD"])
|
||||
.output()
|
||||
.await
|
||||
.expect("git show");
|
||||
let tracked = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(tracked.contains("agent.nix"), "agent.nix not committed");
|
||||
assert!(tracked.contains("flake.nix"), "flake.nix not committed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_gateway_ip_extracts_verbatim_address() {
|
||||
// HIVE_NETWORK_SUBNET carries the bridge IP verbatim, not the
|
||||
|
|
@ -132,122 +90,6 @@ fn network_isolation_errors_name_the_offending_variable() {
|
|||
);
|
||||
}
|
||||
|
||||
/// `setup_applied` is idempotent: calling it on an already seeded repo is a
|
||||
/// no-op (the shape check passes and nothing is written).
|
||||
#[tokio::test]
|
||||
async fn setup_applied_idempotent() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let applied = dir.path().join("applied");
|
||||
setup_applied(&applied, "test-agent")
|
||||
.await
|
||||
.expect("first call");
|
||||
// Second call must not error even though .git already exists.
|
||||
setup_applied(&applied, "test-agent")
|
||||
.await
|
||||
.expect("second call");
|
||||
// Still one commit.
|
||||
let out = git_command()
|
||||
.current_dir(&applied)
|
||||
.args(["rev-list", "--count", "HEAD"])
|
||||
.output()
|
||||
.await
|
||||
.expect("git rev-list");
|
||||
let count = String::from_utf8_lossy(&out.stdout).trim().to_owned();
|
||||
assert_eq!(
|
||||
count, "1",
|
||||
"expected exactly one commit after idempotent call"
|
||||
);
|
||||
}
|
||||
|
||||
/// Build a two-commit repo and return `(dir, repo_path, first, second)`.
|
||||
async fn two_commit_repo() -> (tempfile::TempDir, std::path::PathBuf, String, String) {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let repo = dir.path().join("applied");
|
||||
setup_applied(&repo, "test-agent")
|
||||
.await
|
||||
.expect("setup_applied");
|
||||
let first = git_rev_parse(&repo, "HEAD").await.expect("rev-parse first");
|
||||
|
||||
std::fs::write(repo.join("second.txt"), "second").expect("write second.txt");
|
||||
git(&repo, &["add", "second.txt"]).await.expect("git add");
|
||||
git(
|
||||
&repo,
|
||||
&[
|
||||
"-c",
|
||||
"user.name=test",
|
||||
"-c",
|
||||
"user.email=test@example.com",
|
||||
"commit",
|
||||
"-m",
|
||||
"second",
|
||||
],
|
||||
)
|
||||
.await
|
||||
.expect("git commit");
|
||||
let second = git_rev_parse(&repo, "HEAD")
|
||||
.await
|
||||
.expect("rev-parse second");
|
||||
|
||||
assert_ne!(first, second, "second commit did not advance HEAD");
|
||||
(dir, repo, first, second)
|
||||
}
|
||||
|
||||
/// `git_is_ancestor` answers reachability in both directions. This is the
|
||||
/// check that decides whether moving a branch is a real fast-forward or a
|
||||
/// rewind that discards commits.
|
||||
#[tokio::test]
|
||||
async fn is_ancestor_distinguishes_direction() {
|
||||
let (_dir, repo, first, second) = two_commit_repo().await;
|
||||
|
||||
assert!(
|
||||
git_is_ancestor(&repo, &first, &second)
|
||||
.await
|
||||
.expect("ancestor check forward"),
|
||||
"first must be an ancestor of second"
|
||||
);
|
||||
assert!(
|
||||
!git_is_ancestor(&repo, &second, &first)
|
||||
.await
|
||||
.expect("ancestor check reverse"),
|
||||
"second must NOT be an ancestor of first"
|
||||
);
|
||||
}
|
||||
|
||||
/// Regression test for the deploy path that ate a committed agent config:
|
||||
/// `git_update_ref_cas` must refuse to move a ref whose current value is not
|
||||
/// the expected one, and must leave the ref untouched when it refuses. A bare
|
||||
/// `update-ref` accepts that move and silently drops everything in between.
|
||||
#[tokio::test]
|
||||
async fn update_ref_cas_refuses_stale_expectation() {
|
||||
let (_dir, repo, first, second) = two_commit_repo().await;
|
||||
|
||||
// Park a ref at `first`, then CAS it forward with the correct old value.
|
||||
git_update_ref(&repo, "refs/heads/cas", &first)
|
||||
.await
|
||||
.expect("plant ref");
|
||||
git_update_ref_cas(&repo, "refs/heads/cas", &second, &first)
|
||||
.await
|
||||
.expect("CAS with the correct old value must succeed");
|
||||
assert_eq!(
|
||||
git_rev_parse(&repo, "refs/heads/cas").await.unwrap(),
|
||||
second
|
||||
);
|
||||
|
||||
// Now retry with the SAME (now stale) expectation, as a racing deploy
|
||||
// holding a pre-merge sha would: it must fail rather than rewind.
|
||||
assert!(
|
||||
git_update_ref_cas(&repo, "refs/heads/cas", &first, &first)
|
||||
.await
|
||||
.is_err(),
|
||||
"CAS accepted a stale old value"
|
||||
);
|
||||
assert_eq!(
|
||||
git_rev_parse(&repo, "refs/heads/cas").await.unwrap(),
|
||||
second,
|
||||
"ref moved even though the CAS failed"
|
||||
);
|
||||
}
|
||||
|
||||
/// `systemctl is-active` prints the state with a trailing newline, which is
|
||||
/// the whole reason this parser trims rather than comparing raw.
|
||||
#[test]
|
||||
|
|
@ -416,60 +258,6 @@ async fn a_systemctl_answer_inside_the_bound_passes_through() {
|
|||
assert_eq!(got, Some(7));
|
||||
}
|
||||
|
||||
/// A child that outlives the deadline yields an error naming the command and
|
||||
/// the deadline, and the child and its grandchild are both killed rather than
|
||||
/// orphaned.
|
||||
#[tokio::test]
|
||||
async fn run_with_deadline_times_out_and_kills_the_process_group() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let (shpid, sleeppid) = (dir.path().join("sh.pid"), dir.path().join("sleep.pid"));
|
||||
let mut cmd = tokio::process::Command::new("sh");
|
||||
cmd.arg("-c").arg(format!(
|
||||
"echo $$ > {}; sleep 300 & echo $! > {}; wait",
|
||||
shpid.display(),
|
||||
sleeppid.display()
|
||||
));
|
||||
let err = run_with_deadline(
|
||||
&mut cmd,
|
||||
std::time::Duration::from_millis(500),
|
||||
"fake fetch",
|
||||
)
|
||||
.await
|
||||
.expect_err("a sleeping child must hit the deadline");
|
||||
let msg = format!("{err:#}");
|
||||
assert!(msg.contains("fake fetch timed out after 0.5s"), "{msg}");
|
||||
|
||||
for file in [&shpid, &sleeppid] {
|
||||
// The pid file proves the process existed before the kill.
|
||||
let pid = std::fs::read_to_string(file)
|
||||
.expect("process wrote its pid before the deadline")
|
||||
.trim()
|
||||
.to_owned();
|
||||
let proc = std::path::PathBuf::from("/proc").join(&pid);
|
||||
let mut gone = false;
|
||||
for _ in 0..100 {
|
||||
if !proc.exists() {
|
||||
gone = true;
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||
}
|
||||
assert!(gone, "pid {pid} ({}) still running", file.display());
|
||||
}
|
||||
}
|
||||
|
||||
/// Presence control for the timeout test: a child that finishes in time
|
||||
/// returns its output.
|
||||
#[tokio::test]
|
||||
async fn run_with_deadline_returns_output_of_a_fast_child() {
|
||||
let mut cmd = tokio::process::Command::new("echo");
|
||||
cmd.arg("hi");
|
||||
let out = run_with_deadline(&mut cmd, std::time::Duration::from_secs(30), "echo")
|
||||
.await
|
||||
.expect("echo finishes");
|
||||
assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "hi");
|
||||
}
|
||||
|
||||
/// The per-host values reach the container as facts: the dashboard port and
|
||||
/// pinned claude from the hive's config, the OTEL labels and the queue
|
||||
/// address from the daemon's environment.
|
||||
|
|
|
|||
Loading…
Reference in a new issue