Wire preserved update control, health evidence and record publication
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -1777,6 +1777,23 @@ fn update_inflight_negative_control_keeps_every_start_closed_and_owner_loss_is_t
|
||||
.apply(&mut f.db, &guard, &signed, &raw, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
assert!(!applied.ready && applied.unlocked_grants.is_empty());
|
||||
let local_apply = rmm_agent_core::update_handoff::read_applied_sync(
|
||||
&f.db,
|
||||
&guard,
|
||||
handoff.attempt.grant_id,
|
||||
decision.decision_id,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(local_apply.applied_at, f.clock.now);
|
||||
assert_eq!(local_apply.request_sha256, hash(&raw));
|
||||
let proto = rmm_protocol::SyncResponse {
|
||||
decision_bytes: signed.decision_bytes.clone(),
|
||||
signature: signed.signature.clone(),
|
||||
};
|
||||
assert_eq!(
|
||||
local_apply.response_protobuf_sha256,
|
||||
hash(&prost::Message::encode_to_vec(&proto))
|
||||
);
|
||||
assert!(!fresh.can_start(&f.db, &guard, 8, &f.clock, &f.boot));
|
||||
assert_eq!(
|
||||
f.db.query_row::<u32, _, _>(
|
||||
@@ -1974,3 +1991,63 @@ fn native_stop_intent_is_original_head_bound_create_once_and_transactional() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restarted_update_can_only_schedule_control_from_its_verified_original_not_unknown() {
|
||||
use rmm_agent_core::{jobs, ledger};
|
||||
let (f, _, request, _, _) = update_case();
|
||||
let app = Connection::open_in_memory().unwrap();
|
||||
app.execute_batch("CREATE TABLE job_attempts(job TEXT,attempt TEXT,offer BLOB,state TEXT,revision INTEGER DEFAULT 0,grant_id TEXT DEFAULT '',cancel_requested INTEGER DEFAULT 0,PRIMARY KEY(job,attempt));").unwrap();
|
||||
let mut own = Connection::open_in_memory().unwrap();
|
||||
ledger::initialize_ledger(&own).unwrap();
|
||||
let payload: rmm_domain::jobs::JobPayload = serde_json::from_slice(&request.job_bytes).unwrap();
|
||||
let permit: ExecutionPermitPayload = serde_json::from_slice(&request.permit_bytes).unwrap();
|
||||
let offer = rmm_protocol::JobOffer {
|
||||
job_id: payload.job_id.to_string(),
|
||||
attempt_id: payload.attempt_id.to_string(),
|
||||
authorization_id: request.authorization_id.to_string(),
|
||||
plan_hash: request.plan_hash.clone(),
|
||||
job_payload_hash: hash(&request.job_bytes),
|
||||
payload_bytes: request.job_bytes.clone(),
|
||||
};
|
||||
jobs::accept(&app, &f.binding, &offer, |job| {
|
||||
matches!(job.action, Action::UpdateAgent { .. })
|
||||
})
|
||||
.unwrap();
|
||||
assert!(!jobs::needs_update_control(&app, &own, &f.binding).unwrap());
|
||||
ledger::begin_execution(&mut own, &permit, &request, f.boot.0, f.clock.now).unwrap();
|
||||
jobs::transition(&app, &offer, "running", &permit.grant_id.to_string()).unwrap();
|
||||
let original: Vec<u8> = own
|
||||
.query_row("SELECT start FROM execution_evidence", [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert!(jobs::needs_update_control(&app, &own, &f.binding).unwrap());
|
||||
assert_eq!(
|
||||
app.query_row::<String, _, _>("SELECT state FROM job_attempts", [], |r| r.get(0))
|
||||
.unwrap(),
|
||||
"running"
|
||||
);
|
||||
assert_eq!(
|
||||
own.query_row::<u32, _, _>(
|
||||
"SELECT count(*) FROM execution_evidence WHERE outcome IS NOT NULL",
|
||||
[],
|
||||
|r| r.get(0)
|
||||
)
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
own.execute("UPDATE consumed SET agent=?1", [Uuid::new_v4().to_string()])
|
||||
.unwrap();
|
||||
assert!(jobs::needs_update_control(&app, &own, &f.binding).is_err());
|
||||
own.execute(
|
||||
"UPDATE consumed SET agent=?1",
|
||||
[f.binding.agent_id.to_string()],
|
||||
)
|
||||
.unwrap();
|
||||
jobs::transition(&app, &offer, "unknown", &permit.grant_id.to_string()).unwrap();
|
||||
assert!(!jobs::needs_update_control(&app, &own, &f.binding).unwrap());
|
||||
assert_eq!(
|
||||
own.query_row::<Vec<u8>, _, _>("SELECT start FROM execution_evidence", [], |r| r.get(0))
|
||||
.unwrap(),
|
||||
original
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user