Share helper reconciliation and verify Linux and Windows native fixtures
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -31,6 +31,7 @@ struct Fixture {
|
||||
binding: Binding,
|
||||
channel: Channel,
|
||||
clock: Clock,
|
||||
helper_identity: HelperIdentity,
|
||||
}
|
||||
impl Drop for Fixture {
|
||||
fn drop(&mut self) {
|
||||
@@ -77,6 +78,7 @@ impl Fixture {
|
||||
key,
|
||||
binding,
|
||||
channel,
|
||||
helper_identity: HelperIdentity::Root,
|
||||
clock: Clock {
|
||||
now: Utc::now(),
|
||||
trusted: true,
|
||||
@@ -84,7 +86,7 @@ impl Fixture {
|
||||
}
|
||||
}
|
||||
fn client(&self) -> ClientSync {
|
||||
ClientSync::new(self.binding.clone())
|
||||
ClientSync::new(self.binding.clone()).with_helper_identity(self.helper_identity)
|
||||
}
|
||||
fn prepare(&mut self, client: &mut ClientSync) -> PreparedSync {
|
||||
client
|
||||
@@ -216,7 +218,7 @@ impl Fixture {
|
||||
action: Action,
|
||||
) -> (JobOffer, Option<ExecutionPermitPayload>, Option<Envelope>) {
|
||||
let execution_identity = if matches!(action, Action::SetServiceState { .. }) {
|
||||
"root"
|
||||
self.helper_identity.as_str()
|
||||
} else {
|
||||
"agent_service"
|
||||
};
|
||||
@@ -1143,3 +1145,90 @@ fn signed_attempt_mutation_or_terminal_regression_is_rejected() {
|
||||
changed.attempts[0].previous_outcome_sha256 = Some(hash(b"other outcome"));
|
||||
assert!(f.apply(&mut c, &changed).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_helper_import_requires_explicit_system_identity_and_never_root_alias() {
|
||||
let mut f = Fixture::new();
|
||||
f.helper_identity = HelperIdentity::System;
|
||||
let mut unknown = success();
|
||||
unknown.state = "unknown".into();
|
||||
unknown.error_code = "HELPER_TRANSPORT_EFFECT_UNKNOWN".into();
|
||||
unknown.evidence = serde_json::json!({"postconditions_passed":false});
|
||||
let (offer, grant, old) = f.add(
|
||||
"unknown",
|
||||
true,
|
||||
Some(unknown),
|
||||
Action::SetServiceState {
|
||||
unit: "rmm-acceptance.service".into(),
|
||||
state: "running".into(),
|
||||
},
|
||||
);
|
||||
let grant = grant.unwrap();
|
||||
let mut definitive = success();
|
||||
definitive.stdout.clear();
|
||||
definitive.exit_code = None;
|
||||
let bytes = canonical_outcome_bytes(&definitive).unwrap();
|
||||
let mut helper = HelperSnapshot {
|
||||
journal_id: Uuid::new_v4(),
|
||||
checkpoint: 3,
|
||||
previous_decision_id: None,
|
||||
attempts: vec![SyncAttempt {
|
||||
job_id: offer.job_id.clone(),
|
||||
attempt_id: offer.attempt_id.clone(),
|
||||
job_payload_hash: offer.job_payload_hash.clone(),
|
||||
grant_id: grant.grant_id.to_string(),
|
||||
consumption: "consumed".into(),
|
||||
state: "succeeded".into(),
|
||||
revision: 1,
|
||||
original_boot_id: f.channel.boot_id.to_string(),
|
||||
outcome_sha256: hash(&bytes),
|
||||
outcome_bytes: bytes,
|
||||
..Default::default()
|
||||
}],
|
||||
};
|
||||
let mut wrong = ClientSync::new(f.binding.clone());
|
||||
assert!(
|
||||
wrong
|
||||
.prepare(
|
||||
&mut f.db,
|
||||
&f.ledger,
|
||||
f.channel.clone(),
|
||||
Some(&helper),
|
||||
&f.clock
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
let mut c = f.client();
|
||||
let p = c
|
||||
.prepare(
|
||||
&mut f.db,
|
||||
&f.ledger,
|
||||
f.channel.clone(),
|
||||
Some(&helper),
|
||||
&f.clock,
|
||||
)
|
||||
.unwrap();
|
||||
let imported = p.request.attempts[0].result_envelope.as_ref().unwrap();
|
||||
assert_ne!(imported.message_id, old.unwrap().message_id);
|
||||
assert_eq!(p.request.attempts[0].state, "succeeded");
|
||||
assert_eq!(p.request.attempts[0].revision, 2);
|
||||
let d = f.decision(&p, true);
|
||||
let applied = f.apply(&mut c, &d).unwrap();
|
||||
assert!(applied.helper_instruction.is_some());
|
||||
c.apply_consumption(&mut f.ledger, &f.clock).unwrap();
|
||||
assert!(!c.can_start(&f.channel, true, &f.clock));
|
||||
helper.previous_decision_id = Some(d.decision_id);
|
||||
c.confirm_helper(&helper).unwrap();
|
||||
assert!(c.can_start(&f.channel, true, &f.clock));
|
||||
let retained: i64 =
|
||||
f.db.query_row("SELECT count(*) FROM reconcile_results", [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(retained, 2);
|
||||
let tombstones: i64 = f
|
||||
.ledger
|
||||
.query_row("SELECT count(*) FROM consumed", [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(tombstones, 1);
|
||||
let changed = c.with_helper_identity(HelperIdentity::Root);
|
||||
assert!(!changed.can_start(&f.channel, true, &f.clock));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user