tests and schemas: Pulse in the kind enums, reply keys, vote replacement, one clock read per lease
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bd5a50e1d3
commit
90d4637c96
10 changed files with 26 additions and 12 deletions
|
|
@ -230,6 +230,7 @@ fn an_old_swarm_store_holding_a_dial_or_a_share_reads_as_held_undecodable_and_is
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = released_store(dir.path());
|
||||
let mut cache = CultCache::new();
|
||||
cache.register_entry_type::<Brake>().unwrap();
|
||||
cache.register_entry_type::<OldDial>().unwrap();
|
||||
cache.register_entry_type::<OldShare>().unwrap();
|
||||
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(swarm_path(dir.path()))).unwrap();
|
||||
|
|
|
|||
|
|
@ -288,10 +288,17 @@ fn the_beat_is_the_lower_median_of_the_minds_newest_votes() {
|
|||
rig.pulse(BOB, 100, Some(86_400), None);
|
||||
rig.poll();
|
||||
assert_eq!(rig.store.traces.borrow().last().unwrap().tempo_s, 60, "the lower median of two votes is the lower");
|
||||
// Ann's newest vote replaces her old one; a pulse with no vote keeps it.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_minds_newest_vote_replaces_her_old_one_and_a_pulse_with_no_vote_keeps_it() {
|
||||
let rig = Rig::new();
|
||||
rig.turn(ANN, 3000);
|
||||
rig.turn(BOB, 3000);
|
||||
rig.pulse(ANN, 100, Some(60), None);
|
||||
rig.pulse(ANN, 50, Some(7200), None);
|
||||
rig.pulse(ANN, 40, None, Some(10));
|
||||
rig.advance(1);
|
||||
rig.pulse(BOB, 100, Some(86_400), None);
|
||||
rig.poll();
|
||||
let trace = rig.store.traces.borrow().last().cloned().unwrap();
|
||||
assert_eq!(trace.tempo_s, 7200);
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ fn a_reply_is_decoded_as_the_one_type_and_nothing_else_is_scanned() {
|
|||
assert!(decode_reply(&says(&[("swarm", "x")]), &c.rooms).is_ok());
|
||||
for bad in [
|
||||
"I will start_self_run now",
|
||||
r#"{"say":[],"start_self_run":null} and more"#,
|
||||
r#"{"say":[],"start_self_run":null,"tempo_vote_beat_s":null,"urgency_permille":null} and more"#,
|
||||
r#"{"say":[],"start_self_run":null,"extra":1}"#,
|
||||
"",
|
||||
] {
|
||||
|
|
@ -477,7 +477,7 @@ fn a_start_outside_the_reply_bounds_fails_the_turn_without_an_admission_or_an_ac
|
|||
fn a_reply_without_start_self_run_is_not_a_reply_though_null_is() {
|
||||
let c = config();
|
||||
assert_eq!(decode_reply(r#"{"say":[]}"#, &c.rooms), Err(Failure::Undecodable), "the schema requires the field, so does the decoder");
|
||||
assert!(decode_reply(r#"{"say":[],"start_self_run":null}"#, &c.rooms).is_ok());
|
||||
assert!(decode_reply(r#"{"say":[],"start_self_run":null,"tempo_vote_beat_s":null,"urgency_permille":null}"#, &c.rooms).is_ok());
|
||||
let rig = Rig::new(vec![operator_says(1, "go")], &[r#"{"say":[{"room":"operator","text":"hi"}]}"#.into()]);
|
||||
let Outcome::Served { failure, .. } = rig.go() else { panic!("served") };
|
||||
assert_eq!(failure, Some(Failure::Undecodable));
|
||||
|
|
|
|||
|
|
@ -391,7 +391,8 @@ pub fn carry(mind: &dyn MindPort, clock: &dyn Clock, lender: &dyn Lender, spawne
|
|||
|
||||
#[allow(clippy::too_many_arguments, reason = "carry's ports, passed on whole")]
|
||||
fn lend_and_drive(mind: &dyn MindPort, clock: &dyn Clock, lender: &dyn Lender, spawner: &dyn Spawner, run_cap_s: u64, out: &mut dyn Write, run: &PipelineRef, heard: &mut Heard) -> Result<SelfRunOutcome> {
|
||||
let request = LeaseRequest { expires_at_unix_ms: unix_ms(clock.now()).saturating_add(run_cap_s.saturating_mul(1000)) };
|
||||
let started_ms = unix_ms(clock.now());
|
||||
let request = LeaseRequest { expires_at_unix_ms: started_ms.saturating_add(run_cap_s.saturating_mul(1000)) };
|
||||
let lease = match lender.lend(&request)? {
|
||||
Lent::Granted(lease) => lease,
|
||||
Lent::Refused(refused) if refused.kind == LeaseRefusalKind::Expired => {
|
||||
|
|
@ -401,7 +402,6 @@ fn lend_and_drive(mind: &dyn MindPort, clock: &dyn Clock, lender: &dyn Lender, s
|
|||
Lent::Refused(refused) => return close_refused(mind, clock, run, refused.kind),
|
||||
};
|
||||
let child = spawner.spawn(&claude_args(session_id(run)), lease.token())?;
|
||||
let started_ms = unix_ms(clock.now());
|
||||
drive(mind, clock, child, run, (lease.plan_quota(), started_ms), heard, out)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@
|
|||
"Instance",
|
||||
"Stewardship",
|
||||
"HandOff",
|
||||
"Run"
|
||||
"Run",
|
||||
"Pulse"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue