feat: restore inside the Vault; the Refresh page and file export UI are gone
- POST /refresh-runs accepts snapshot_id: restore a snapshot somebody picked (a restorable capture of the relation's own source, never a safety copy or another orbit's) through the same run engine - refresh-relations carries source_orbit_id; snapshots carry kind (capture|safety), and the UI hides safety copies - snapshot detail: Restore replaces Export file on hub (disabled with No restore point without a relation); modal with a restore point selector, a ten second countdown with Abort, and a four step progress view - administrators keep Other registered target; the Refresh menu and refresh-only screen are removed - proven with a real agent and PostgreSQL in the browser: capture, restore to Development, abort, no relation Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1987,3 +1987,204 @@ async fn an_orbit_name_is_validated_unique_and_only_administrators_change_it() {
|
||||
"{status}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---- restoring a snapshot that already exists (the Restore button on a snapshot) ----
|
||||
|
||||
impl Lab {
|
||||
async fn start_snapshot(
|
||||
&self,
|
||||
caller: &Caller,
|
||||
key: &str,
|
||||
snapshot: Uuid,
|
||||
) -> (StatusCode, Value) {
|
||||
self.send(
|
||||
caller,
|
||||
"POST",
|
||||
"/api/v1/refresh-runs",
|
||||
Some(json!({"relation_id": self.relation, "confirmation": self.confirmation(), "idempotency_key": key, "snapshot_id": snapshot})),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// A snapshot written straight into the vault, to stand in for one of another orbit or a safety copy.
|
||||
async fn plant_snapshot(&self, orbit: Uuid, labels: &[&str], hints: Value) -> Uuid {
|
||||
let id = Uuid::new_v4();
|
||||
let manifest = tessera_core::manifest::SnapshotManifest {
|
||||
snapshot_id: id,
|
||||
orbit_id: orbit,
|
||||
orbit_name: "planted".into(),
|
||||
labels: labels.iter().map(|s| s.to_string()).collect(),
|
||||
provider: "postgres".into(),
|
||||
paths: vec![],
|
||||
restore_hints: hints,
|
||||
};
|
||||
self.state
|
||||
.vault
|
||||
.write()
|
||||
.await
|
||||
.snapshot(manifest, b"PGDMP planted", false)
|
||||
.unwrap();
|
||||
id
|
||||
}
|
||||
|
||||
/// Walk a restore job through to the end the way the agent does.
|
||||
async fn finish_restore(&self) -> String {
|
||||
let (job, token) = self
|
||||
.restore_until_ready()
|
||||
.await
|
||||
.expect("a restore job is waiting");
|
||||
assert_eq!(self.apply(&job, &token).await, StatusCode::NO_CONTENT);
|
||||
self.report_applied(&job, &token).await;
|
||||
self.tick().await;
|
||||
job
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_existing_snapshot_is_restored_without_a_new_capture_and_can_be_restored_again() {
|
||||
let lab = fresh().await;
|
||||
let (qa, _) = lab.refresher("qa");
|
||||
// a snapshot exists from an earlier refresh
|
||||
lab.start(&lab.admin(), "seed").await;
|
||||
let snapshot = lab
|
||||
.capture(&Lab::production_identity(), false)
|
||||
.await
|
||||
.unwrap();
|
||||
lab.tick().await;
|
||||
lab.finish_restore().await;
|
||||
let captures = lab.capture_jobs();
|
||||
|
||||
let (status, run) = lab.start_snapshot(&qa, "again", snapshot).await;
|
||||
assert_eq!(status, StatusCode::ACCEPTED, "{run}");
|
||||
let run_id = run["id"].as_str().unwrap().to_string();
|
||||
lab.tick().await;
|
||||
assert_eq!(lab.run(&run_id).status, "restoring");
|
||||
assert_eq!(
|
||||
lab.run(&run_id).snapshot_id.as_deref(),
|
||||
Some(snapshot.to_string().as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
lab.capture_jobs(),
|
||||
captures,
|
||||
"no new capture: the person picked a backup"
|
||||
);
|
||||
lab.finish_restore().await;
|
||||
assert_eq!(lab.run(&run_id).status, "completed");
|
||||
|
||||
// and the same snapshot can go to the target again
|
||||
let (status, again) = lab.start_snapshot(&qa, "third", snapshot).await;
|
||||
assert_eq!(status, StatusCode::ACCEPTED, "{again}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn only_a_restorable_snapshot_of_the_relations_own_source_is_accepted() {
|
||||
let lab = fresh().await;
|
||||
let admin = lab.admin();
|
||||
// a real capture, so the planted copies below are as restorable as it is
|
||||
lab.start(&admin, "seed").await;
|
||||
let real = lab
|
||||
.capture(&Lab::production_identity(), false)
|
||||
.await
|
||||
.unwrap();
|
||||
let hints = lab
|
||||
.state
|
||||
.vault
|
||||
.read()
|
||||
.await
|
||||
.get_snapshot(real)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.manifest
|
||||
.restore_hints;
|
||||
let other_orbit = lab.plant_snapshot(Uuid::new_v4(), &[], hints.clone()).await;
|
||||
let safety = lab
|
||||
.plant_snapshot(lab.orbit, &["restore-safety"], hints)
|
||||
.await;
|
||||
lab.tick().await;
|
||||
lab.finish_restore().await;
|
||||
let runs = lab.scalar::<i64>("SELECT COUNT(*) FROM refresh_runs");
|
||||
let jobs = lab.restore_jobs();
|
||||
// the real one is accepted, so the refusals below are about the snapshot and nothing else
|
||||
assert_eq!(
|
||||
lab.start_snapshot(&admin, "good", real).await.0,
|
||||
StatusCode::ACCEPTED
|
||||
);
|
||||
lab.tick().await;
|
||||
lab.finish_restore().await;
|
||||
let runs = runs + 1;
|
||||
let jobs = jobs + 1;
|
||||
for (n, (what, snapshot)) in [
|
||||
("another orbit's", other_orbit),
|
||||
("a safety copy", safety),
|
||||
("an unknown one", Uuid::new_v4()),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let (status, body) = lab
|
||||
.start_snapshot(&admin, &format!("bad-{n}"), snapshot)
|
||||
.await;
|
||||
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY, "{what}: {body}");
|
||||
assert_eq!(body["reason"], "snapshot_unusable", "{what}");
|
||||
}
|
||||
assert_eq!(lab.restore_jobs(), jobs);
|
||||
assert_eq!(
|
||||
lab.scalar::<i64>("SELECT COUNT(*) FROM refresh_runs"),
|
||||
runs,
|
||||
"nothing was started"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_restore_of_an_existing_snapshot_is_stopped_when_the_grant_goes_before_it_is_queued() {
|
||||
let lab = fresh().await;
|
||||
let (qa, grant) = lab.refresher("qa");
|
||||
lab.start(&lab.admin(), "seed").await;
|
||||
let snapshot = lab
|
||||
.capture(&Lab::production_identity(), false)
|
||||
.await
|
||||
.unwrap();
|
||||
lab.tick().await;
|
||||
lab.finish_restore().await;
|
||||
let jobs = lab.restore_jobs();
|
||||
let (_, run) = lab.start_snapshot(&qa, "revoked", snapshot).await;
|
||||
let run_id = run["id"].as_str().unwrap().to_string();
|
||||
lab.revoke(Revoke::GrantDeleted, &qa, &grant).await;
|
||||
lab.tick().await;
|
||||
assert_eq!(lab.run(&run_id).status, "blocked");
|
||||
assert_eq!(
|
||||
lab.run(&run_id).blocked_reason.as_deref(),
|
||||
Some("access_revoked")
|
||||
);
|
||||
assert_eq!(lab.restore_jobs(), jobs, "no restore job was ever queued");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_screens_get_what_they_need_to_offer_restore_for_an_orbit() {
|
||||
let lab = fresh().await;
|
||||
let (qa, _) = lab.refresher("qa");
|
||||
let (_, mine) = lab
|
||||
.send(&qa, "GET", "/api/v1/refresh-relations", None)
|
||||
.await;
|
||||
assert_eq!(mine[0]["source_orbit_id"], lab.orbit.to_string(), "{mine}");
|
||||
// a snapshot knows whether it is a capture or a safety copy, so pickers can leave the latter out
|
||||
lab.start(&lab.admin(), "kind").await;
|
||||
lab.capture(&Lab::production_identity(), false)
|
||||
.await
|
||||
.unwrap();
|
||||
lab.tick().await;
|
||||
lab.restore_until_ready().await.unwrap();
|
||||
let (_, listed) = lab
|
||||
.send(&lab.admin(), "GET", "/api/v1/snapshots", None)
|
||||
.await;
|
||||
let kinds: Vec<_> = listed
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|s| s["kind"].as_str().unwrap().to_string())
|
||||
.collect();
|
||||
assert!(
|
||||
kinds.contains(&"capture".to_string()) && kinds.contains(&"safety".to_string()),
|
||||
"{kinds:?}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user