[control] Store and recovery fixes: cross-process token lock, revert keeps its journal until done, epoch and deny list never roll back, journal errors propagate, lost confirm reloads edge, trial hash checked

This commit is contained in:
2026-11-07 18:51:58 +01:00
parent b9e14c6aee
commit 4448527b16
10 changed files with 305 additions and 66 deletions
+28 -7
View File
@@ -523,7 +523,6 @@ mod unix {
let lock = env.repo().join("refs/heads/main.lock");
std::fs::write(&lock, "").unwrap();
let rec = env.wait_apply(&id).await;
std::fs::remove_file(&lock).unwrap();
assert_eq!(rec["state"], "needs_attention", "{rec}");
// Edge was still told to drop the trial: visitors get the last good config.
let st = env.edge_status().await;
@@ -540,10 +539,14 @@ mod unix {
)
.await;
assert_eq!(r.status, 409);
// A control restart does not push the unverified head to edge.
// A control restart (the branch still locked) retries the revert, fails again, and
// does not push the unverified head to edge.
env.kill_control();
env.start_control(None);
assert_eq!(env.edge_status().await["config_sha256"], sha256(&good_edge));
let o = env.call("GET", "/api/v1/overview", None).await;
assert_eq!(o.json["paused"]["code"], "control.paused", "{}", o.text);
std::fs::remove_file(&lock).unwrap();
// Restore the last kept version: the way out.
let r = env
.apply(
@@ -563,16 +566,31 @@ mod unix {
let good = Echo::start("good").await;
let sick = Echo::start("sick").await;
sick.health.store(500, std::sync::atomic::Ordering::SeqCst);
let mut env = Env::new(EnvSpec { watch_secs: 3, ..Default::default() }).await;
let mut env = Env::new(EnvSpec {
watch_secs: 3,
..Default::default()
})
.await;
// A full disk, as far as paused.json is concerned.
env.start_control_env(None, &[("IANITOR_TEST_FAIL_WRITE", "paused.json")]);
let kept = env.add_host(host("a.test", &good.url(), true)).await;
let good_edge = env.file("edge/edge.json");
let good_tree = env.git(&["rev-parse", "refs/heads/main^{tree}"]);
let r = env.call("POST", "/api/v1/hosts", Some(json!({ "host": host("b.test", &sick.url(), true) }))).await;
let r = env
.call(
"POST",
"/api/v1/hosts",
Some(json!({ "host": host("b.test", &sick.url(), true) })),
)
.await;
let id = r.json["apply"]["id"].as_str().unwrap().to_owned();
let deadline = std::time::Instant::now() + Duration::from_secs(10);
while env.call("GET", &format!("/api/v1/applies/{id}"), None).await.json["commit"].is_null() {
while env
.call("GET", &format!("/api/v1/applies/{id}"), None)
.await
.json["commit"]
.is_null()
{
assert!(std::time::Instant::now() < deadline);
tokio::time::sleep(Duration::from_millis(20)).await;
}
@@ -582,7 +600,8 @@ mod unix {
assert_eq!(rec["state"], "needs_attention", "{rec}");
// The pause is not on disk, so the journal must stay, at `reverting`.
assert!(!env.dir.join("state/paused.json").exists());
let j: serde_json::Value = serde_json::from_str(&env.file("state/journal.json")).expect("journal kept");
let j: serde_json::Value =
serde_json::from_str(&env.file("state/journal.json")).expect("journal kept");
assert_eq!(j["stage"], "reverting", "{j}");
// Restart while the branch is still locked: still no unverified config for edge.
@@ -597,7 +616,9 @@ mod unix {
env.kill_control();
std::fs::remove_file(&lock).unwrap();
env.start_control(None);
let rec = env.call("GET", &format!("/api/v1/applies/{id}"), None).await;
let rec = env
.call("GET", &format!("/api/v1/applies/{id}"), None)
.await;
assert_eq!(rec.json["state"], "reverted", "{}", rec.text);
assert_eq!(env.git(&["rev-parse", "refs/heads/main^{tree}"]), good_tree);
let o = env.call("GET", "/api/v1/overview", None).await;