Implement and natively verify the human-reviewed Windows recovery tool
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-15 23:27:14 +01:00
parent a537517428
commit fd17b6c662
12 changed files with 1109 additions and 243 deletions
@@ -0,0 +1,125 @@
// Isolated synthetic test data shared by the two Windows operator CLI test harnesses.
use anyhow::Result;
use chrono::{Duration, Utc};
use ed25519_dalek::{Signer, SigningKey};
use prost::Message;
use rmm_agent_core::{
auth::Binding,
helper_reconcile::SignedResponse,
windows_sync_history::{AGENT, BOOT, CASES, FAULT, FIRST, LAST},
};
use rmm_domain::{jobs::hash, reconciliation::ReconcileDecisionPayload};
use rmm_protocol::{Envelope, Payload, SyncRequest, SyncResponse};
use rusqlite::{Connection, params};
use uuid::Uuid;
pub fn verified_pair() -> Result<(Connection, Connection, Connection, Binding, SigningKey)> {
let a = Connection::open_in_memory()?;
let l = Connection::open_in_memory()?;
let h = Connection::open_in_memory()?;
rmm_agent_core::reconcile::initialize(&a)?;
a.execute_batch("CREATE TABLE job_attempts(job); CREATE TABLE job_events(id,payload); CREATE TABLE events(id,payload);")?;
for db in [&l, &h] {
db.execute_batch(
"CREATE TABLE consumed(grant_id); CREATE TABLE execution_evidence(grant_id);",
)?;
}
l.execute_batch("CREATE TABLE reconcile_consumption(decision_id,response);")?;
h.execute_batch("CREATE TABLE helper_sync_rows(grant_id); CREATE TABLE helper_sync_decisions(decision_id,checkpoint,response,request); CREATE TABLE helper_sync_meta(id,journal_id,checkpoint,generation,last_decision,agent_journal_id,agent_checkpoint,fault);")?;
let id = Uuid::new_v4();
let peer = Uuid::new_v4();
let key = SigningKey::from_bytes(&[13; 32]); // Public deterministic fixture only.
let binding = Binding {
tenant_id: Uuid::new_v4(),
agent_id: Uuid::parse_str(AGENT)?,
asset_id: Uuid::new_v4(),
assignment_version: 1,
enrollment_generation: 1,
public_key_hex: key
.verifying_key()
.to_bytes()
.iter()
.map(|b| format!("{b:02x}"))
.collect(),
};
for (req, dec, cp) in CASES {
let first = dec == FIRST;
let r = SyncRequest {
request_id: req.into(),
journal_id: id.to_string(),
checkpoint: cp,
assignment_version: 1,
journal_complete: true,
helper_journal_id: peer.to_string(),
helper_checkpoint: 1,
previous_decision_id: if first { "" } else { FIRST }.into(),
..Default::default()
};
let raw = r.encode_to_vec();
let e = Envelope {
protocol_major: 1,
agent_id: AGENT.into(),
enrollment_generation: 1,
connection_generation: 150,
boot_id: BOOT.into(),
sequence: cp,
payload: Some(Payload::SyncRequest(r)),
..Default::default()
};
let now = Utc::now() - Duration::hours(1);
let d = ReconcileDecisionPayload {
domain: "rmm.reconciliation-decision".into(),
schema_version: 1,
decision_id: Uuid::parse_str(dec)?,
request_id: Uuid::parse_str(req)?,
request_hash: hash(&raw),
tenant_id: binding.tenant_id,
asset_id: binding.asset_id,
agent_id: binding.agent_id,
enrollment_generation: 1,
assignment_version: 1,
connection_generation: 150,
boot_id: Uuid::parse_str(BOOT)?,
journal_id: id,
checkpoint: cp,
helper_journal_id: Some(peer),
helper_checkpoint: 1,
issued_at: now,
valid_until: now + Duration::seconds(60),
ready: first,
helper_ready: first,
reason: if first { "CONSISTENT" } else { FAULT }.into(),
attempts: vec![],
acknowledged_message_ids: vec![],
key_id: hash(&key.verifying_key().to_bytes()),
};
let bytes = serde_json::to_vec(&d)?;
let signed = SyncResponse {
signature: key.sign(&bytes).to_bytes().into(),
decision_bytes: bytes,
};
a.execute("INSERT INTO reconcile_requests(id,request,envelope,generation,response) VALUES(?,?,?,150,?)",params![req,raw,e.encode_to_vec(),signed.encode_to_vec()])?;
l.execute(
"INSERT INTO reconcile_consumption VALUES(?,?)",
params![dec, signed.encode_to_vec()],
)?;
if !first {
h.execute(
"INSERT INTO helper_sync_decisions VALUES(?,1,?,?)",
params![
dec,
serde_json::to_vec(&SignedResponse {
signature: signed.signature,
decision_bytes: signed.decision_bytes
})?,
raw
],
)?;
}
}
a.execute("UPDATE reconcile_meta SET journal_id=?,checkpoint=6756,generation=150,last_decision=?,helper_id=?,helper_checkpoint=1,fault=?",params![id.to_string(),LAST,peer.to_string(),FAULT])?;
h.execute(
"INSERT INTO helper_sync_meta VALUES(1,?,9,150,?,?,6756,NULL)",
params![peer.to_string(), LAST, id.to_string()],
)?;
Ok((a, l, h, binding, key))
}