1use std::collections::BTreeMap;
9use std::io::Write as _;
10
11use lean_ctx_time::{Duration, UtcDateTime};
12
13use lean_ctx::core::agents::AgentEntry;
14use lean_ctx::core::agents::friction::{self, Event};
15
16use super::CloudStore;
17use super::bus::v2::{self, About, CollabCounts, MessageType, Publish, Window};
18use super::vault::VaultMap;
19
20const HOURS_FILE: &str = "friction.jsonl";
23const STATE_FILE: &str = "friction-state.json";
25const CATCH_UP_HOURS: i64 = 24;
27
28#[derive(Default, serde::Serialize, serde::Deserialize)]
29struct EmitState {
30 last_hour_ms: Option<i64>,
31}
32
33pub fn emit_due(store: &CloudStore, now: UtcDateTime) -> usize {
38 if !super::bus::relay_v2::speaks_v2(store) {
39 return 0;
40 }
41 let Ok(Some(instance)) = store.instance() else {
42 return 0;
43 };
44 let Ok(this_hour) = now.duration_trunc(Duration::hours(1)) else {
45 return 0;
46 };
47 let dir = store.data_dir();
48 let state_path = dir.join(STATE_FILE);
49 let mut state: EmitState = std::fs::read(&state_path)
50 .ok()
51 .and_then(|bytes| serde_json::from_slice(&bytes).ok())
52 .unwrap_or_default();
53 let first = state
54 .last_hour_ms
55 .and_then(UtcDateTime::from_timestamp_millis)
56 .map_or(this_hour - Duration::hours(1), |last| {
57 (last + Duration::hours(1)).max(this_hour - Duration::hours(CATCH_UP_HOURS))
58 });
59 let registry = lean_ctx::core::agents::AgentRegistry::load_or_create();
60 let agents = registry.list_all();
61 let vaults = VaultMap::load(dir);
62 let active: std::collections::BTreeSet<&str> = registry
63 .list_active(None)
64 .into_iter()
65 .map(|a| a.agent_id.as_str())
66 .collect();
67 let worker_of = |agent: &AgentEntry| {
71 if agent.is_engine_placeholder() {
73 return None;
74 }
75 let (host, role) = super::workers::attach::agent_worker_key(agent);
76 if active.contains(agent.agent_id.as_str()) {
77 super::workers::attach::attach(store, &instance.instance_id, &host, &role)
78 .ok()
79 .map(|attached| attached.worker.worker_id)
80 } else {
81 super::workers::attach::known(store, &instance.instance_id, &host, &role)
82 .map(|worker| worker.worker_id)
83 }
84 };
85 let now_ms = u64::try_from(now.timestamp_millis()).unwrap_or(0);
86 let mut queued = 0;
87 let mut hour = first;
88 while hour < this_hour {
89 let end = hour + Duration::hours(1);
90 let events = friction::events(hour, end);
91 for finding in hour_findings(dir, &events, agents, &vaults, &worker_of, hour, end) {
92 if let Err(error) = super::bus::relay_v2::queue_publish(store, finding.publish(now_ms))
93 {
94 store.record_error(&format!("collaboration finding: {error}"));
95 continue;
96 }
97 append_hour(dir, &finding);
98 queued += 1;
99 }
100 state.last_hour_ms = Some(hour.timestamp_millis());
101 hour = end;
102 }
103 if let Ok(bytes) = serde_json::to_vec(&state) {
104 let _ = super::state::write_private(dir, STATE_FILE, &bytes);
105 }
106 queued
107}
108
109fn append_hour(dir: &std::path::Path, finding: &HourFinding) {
110 let line = serde_json::json!({
111 "hour": finding.from_ms,
112 "worker_id": finding.worker_id,
113 "place": finding.to,
114 "counts": finding.counts,
115 });
116 let mut options = std::fs::OpenOptions::new();
117 options.create(true).append(true);
118 #[cfg(unix)]
119 std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600);
120 if let Ok(mut file) = options.open(dir.join(HOURS_FILE)) {
121 let _ = writeln!(file, "{line}");
122 }
123}
124
125pub fn sample_merge_conflicts(store: &CloudStore, seen: &mut std::collections::BTreeSet<String>) {
130 let vaults = VaultMap::load(store.data_dir());
131 let registry = lean_ctx::core::agents::AgentRegistry::load_or_create();
132 let mut roots: BTreeMap<&str, &str> = BTreeMap::new();
133 for agent in registry.list_active(None) {
134 if crate::unlinked::shared_record(store.data_dir(), &vaults, &agent.project_root).is_some()
137 {
138 roots
139 .entry(agent.project_root.as_str())
140 .or_insert(agent.agent_id.as_str());
141 }
142 }
143 seen.retain(|root| roots.contains_key(root.as_str()));
144 for (root, agent) in roots {
145 if has_unmerged_paths(root) {
146 if seen.insert(root.to_string()) {
147 friction::record_for(friction::MERGE_CONFLICT, Some(agent), Some(root));
148 }
149 } else {
150 seen.remove(root);
151 }
152 }
153}
154
155fn has_unmerged_paths(root: &str) -> bool {
157 std::process::Command::new("git")
158 .args(["-C", root, "ls-files", "-u", "-z"])
159 .stdin(std::process::Stdio::null())
160 .stderr(std::process::Stdio::null())
161 .output()
162 .is_ok_and(|out| out.status.success() && !out.stdout.is_empty())
163}
164
165pub const COUNT_KEYS: [&str; 8] = [
167 "claim_refused",
168 "claim_expired",
169 "registration_renewed",
170 "wait_timeout",
171 "merge_conflict",
172 "gate_reruns",
173 "agent_seconds",
174 "idle_seconds",
175];
176
177const FRICTION_KEYS: [&str; 6] = [
179 "claim_refused",
180 "claim_expired",
181 "registration_renewed",
182 "wait_timeout",
183 "merge_conflict",
184 "gate_reruns",
185];
186
187pub fn count_key(signal: &str) -> Option<&'static str> {
190 Some(match signal {
191 friction::CLAIM_REFUSED_PRESENCE
192 | friction::CLAIM_REFUSED_ROLE
193 | friction::CLAIM_REFUSED_PERMIT => "claim_refused",
194 friction::CLAIM_EXPIRED => "claim_expired",
195 friction::REGISTRATION_RENEWED => "registration_renewed",
196 friction::WAIT_TIMEOUT => "wait_timeout",
197 friction::MERGE_CONFLICT => "merge_conflict",
198 _ => return None,
199 })
200}
201
202#[derive(Debug, Clone, PartialEq, Eq)]
204pub struct HourFinding {
205 pub to: String,
207 pub worker_id: String,
210 pub from_ms: i64,
211 pub to_ms: i64,
212 pub counts: BTreeMap<&'static str, u32>,
214}
215
216impl HourFinding {
217 pub fn statement(&self) -> String {
220 let hhmm = |ms: i64| {
221 UtcDateTime::from_timestamp_millis(ms)
222 .map_or_else(String::new, |t| t.format("%H:%M").to_string())
223 };
224 let signals: u32 = FRICTION_KEYS
225 .iter()
226 .filter_map(|key| self.counts.get(key))
227 .sum();
228 let seconds = self.counts.get("agent_seconds").copied().unwrap_or(0);
229 format!(
230 "Collaboration friction from {} to {}: {signals} signals in {:.1} agent-hours.",
231 hhmm(self.from_ms),
232 hhmm(self.to_ms),
233 f64::from(seconds) / 3600.0
234 )
235 }
236
237 pub fn publish(&self, now_ms: u64) -> Publish {
241 let get = |key: &str| self.counts.get(key).copied();
242 Publish {
243 schema: v2::BUS_SCHEMA.to_string(),
244 client_msg_id: v2::new_ulid(now_ms),
245 to: self.to.clone(),
246 kind: MessageType::Finding,
247 worker_id: self.worker_id.clone(),
248 thread_id: None,
249 reply_to: None,
250 refs: Vec::new(),
251 body: serde_json::json!({"statement": self.statement(), "evidence": "observed"}),
252 ck_wrapped: None,
253 epoch: None,
254 about: Some(About::Collaboration),
255 counts: Some(CollabCounts {
256 registration_renewed: get("registration_renewed"),
257 wait_timeout: get("wait_timeout"),
258 merge_conflict: get("merge_conflict"),
259 claim_refused: get("claim_refused"),
260 claim_expired: get("claim_expired"),
261 gate_reruns: get("gate_reruns"),
262 agent_seconds: get("agent_seconds"),
263 idle_seconds: get("idle_seconds"),
264 }),
265 window: Some(Window {
266 from_ms: u64::try_from(self.from_ms).unwrap_or(0),
267 to_ms: u64::try_from(self.to_ms).unwrap_or(0),
268 }),
269 }
270 }
271}
272
273pub(crate) fn hour_findings(
280 data_dir: &std::path::Path,
281 events: &[Event],
282 agents: &[AgentEntry],
283 vaults: &VaultMap,
284 worker_of: &dyn Fn(&AgentEntry) -> Option<String>,
285 from: UtcDateTime,
286 to: UtcDateTime,
287) -> Vec<HourFinding> {
288 let place_of = |root: &str| {
291 crate::unlinked::shared_record(data_dir, vaults, root).map(super::bus::relay_v2::address_of)
292 };
293 let mut time: BTreeMap<String, BTreeMap<String, i64>> = BTreeMap::new();
295 let mut counts: BTreeMap<String, BTreeMap<&'static str, u32>> = BTreeMap::new();
296 for agent in agents {
297 let Some(place) = place_of(&agent.project_root) else {
300 continue;
301 };
302 let Some(worker) = worker_of(agent) else {
303 continue;
304 };
305 let start = agent.started_at.max(from);
306 let end = agent.last_active.min(to);
307 let seconds = (end - start).num_seconds().max(0);
308 *time.entry(place).or_default().entry(worker).or_default() += seconds;
309 }
310 for event in events {
311 let Some(key) = count_key(&event.signal) else {
312 continue;
313 };
314 let agent = event
315 .agent
316 .as_deref()
317 .and_then(|id| agents.iter().find(|a| a.agent_id == id));
318 let root = event
319 .root
320 .as_deref()
321 .or_else(|| agent.map(|a| a.project_root.as_str()));
322 let Some(place) = root.and_then(place_of) else {
323 continue;
324 };
325 if let Some(worker) = agent.and_then(worker_of) {
326 time.entry(place.clone())
327 .or_default()
328 .entry(worker)
329 .or_default();
330 }
331 let count = counts.entry(place).or_default().entry(key).or_default();
332 *count = count.saturating_add(1);
333 }
334 time.into_iter()
335 .filter_map(|(place, workers)| {
336 let worker_id = workers
337 .iter()
338 .max_by(|a, b| a.1.cmp(b.1).then_with(|| b.0.cmp(a.0)))
339 .map(|(id, _)| id.clone())?;
340 let seconds: i64 = workers.values().sum();
341 let mut counts = counts.remove(&place).unwrap_or_default();
342 if seconds > 0 {
343 counts.insert("agent_seconds", u32::try_from(seconds).unwrap_or(u32::MAX));
344 }
345 (!counts.is_empty()).then(|| HourFinding {
346 to: place,
347 worker_id,
348 from_ms: from.timestamp_millis(),
349 to_ms: to.timestamp_millis(),
350 counts,
351 })
352 })
353 .collect()
354}
355
356#[cfg(test)]
357mod tests {
358 use super::*;
359 use crate::vault::VaultRecord;
360 use lean_ctx::core::agents::AgentStatus;
361
362 fn at(s: &str) -> UtcDateTime {
363 lean_ctx_time::OffsetDateTime::parse_from_rfc3339(s)
364 .unwrap()
365 .to_utc()
366 }
367
368 fn agent(id: &str, root: &str, from: &str, to: &str) -> AgentEntry {
369 AgentEntry {
370 agent_id: id.into(),
371 agent_type: "claude".into(),
372 role: Some("engine".into()),
373 project_root: root.into(),
374 started_at: at(from),
375 last_active: at(to),
376 pid: 1,
377 process_identity: None,
378 durable_identity_id: None,
379 status: AgentStatus::Active,
380 status_message: None,
381 agent_status_message: None,
382 transport: None,
383 role_source: None,
384 parent: None,
385 app_session_id: None,
386 display_name: None,
387 }
388 }
389
390 fn event(signal: &str, agent: Option<&str>, root: Option<&str>) -> Event {
391 Event {
392 at: at("2026-10-24T08:30:00Z"),
393 signal: signal.into(),
394 agent: agent.map(Into::into),
395 root: root.map(Into::into),
396 }
397 }
398
399 fn vaults() -> VaultMap {
400 let mut map = VaultMap::default();
401 map.vaults.insert(
402 "v1".into(),
403 VaultRecord {
404 vault_id: "v1".into(),
405 ns: "acme".into(),
406 name: "payments".into(),
407 sealed: false,
408 roots: vec!["/w/pay".into()],
409 },
410 );
411 map
412 }
413
414 #[test]
417 fn unlink_of_a_worktree_sends_no_friction_findings() {
418 let base = tempfile::tempdir().unwrap();
419 let base = base.path().canonicalize().unwrap();
420 let (main, wt) = crate::unlinked::fake_worktree(&base);
421 let data = base.join("data");
422 let mut map = VaultMap::default();
423 map.vaults.insert(
424 "v1".into(),
425 VaultRecord {
426 vault_id: "v1".into(),
427 ns: "acme".into(),
428 name: "payments".into(),
429 sealed: false,
430 roots: vec![main.to_string_lossy().into_owned()],
431 },
432 );
433 let wt_text = wt.to_string_lossy().into_owned();
434 let agents = [agent(
435 "mcp-a",
436 &wt_text,
437 "2026-10-24T07:00:00Z",
438 "2026-10-24T10:00:00Z",
439 )];
440 let events = [event(friction::WAIT_TIMEOUT, None, Some(&wt_text))];
441 let worker_of = |a: &AgentEntry| Some(format!("wkr_{}", a.agent_id));
442 let run = || {
443 hour_findings(
444 &data,
445 &events,
446 &agents,
447 &map,
448 &worker_of,
449 at("2026-10-24T08:00:00Z"),
450 at("2026-10-24T09:00:00Z"),
451 )
452 };
453 assert!(!run().is_empty(), "shared through the main checkout");
454 crate::unlinked::add(&data, &wt).unwrap();
455 assert!(run().is_empty(), "{:?}", run());
456 }
457
458 #[test]
461 fn local_signals_map_onto_the_contract_keys() {
462 for (signal, key) in [
463 (friction::CLAIM_REFUSED_PRESENCE, "claim_refused"),
464 (friction::CLAIM_REFUSED_ROLE, "claim_refused"),
465 (friction::CLAIM_REFUSED_PERMIT, "claim_refused"),
466 (friction::CLAIM_EXPIRED, "claim_expired"),
467 (friction::REGISTRATION_RENEWED, "registration_renewed"),
468 (friction::WAIT_TIMEOUT, "wait_timeout"),
469 (friction::MERGE_CONFLICT, "merge_conflict"),
470 ] {
471 assert_eq!(count_key(signal), Some(key), "{signal}");
472 assert!(COUNT_KEYS.contains(&key));
473 }
474 assert_eq!(count_key("something_else"), None);
475 }
476
477 #[test]
481 fn an_hour_sums_into_one_finding_per_vault() {
482 let agents = [
483 agent(
484 "mcp-a",
485 "/w/pay",
486 "2026-10-24T07:00:00Z",
487 "2026-10-24T08:30:00Z",
488 ),
489 agent(
490 "mcp-b",
491 "/w/pay",
492 "2026-10-24T08:30:00Z",
493 "2026-10-24T10:00:00Z",
494 ),
495 agent(
496 "mcp-c",
497 "/w/scratch",
498 "2026-10-24T08:00:00Z",
499 "2026-10-24T09:00:00Z",
500 ),
501 ];
502 let worker_of = |a: &AgentEntry| Some(format!("wkr_{}", a.agent_id));
503 let events = [
504 event(friction::CLAIM_REFUSED_ROLE, Some("mcp-a"), None),
505 event(
506 friction::CLAIM_REFUSED_PRESENCE,
507 Some("mcp-b"),
508 Some("/w/pay"),
509 ),
510 event(friction::WAIT_TIMEOUT, None, Some("/w/pay")),
511 event(friction::CLAIM_EXPIRED, Some("mcp-c"), None),
512 event("unknown_signal", Some("mcp-a"), None),
513 ];
514 let findings = hour_findings(
515 std::path::Path::new("/nonexistent/cloud-data"),
516 &events,
517 &agents,
518 &vaults(),
519 &worker_of,
520 at("2026-10-24T08:00:00Z"),
521 at("2026-10-24T09:00:00Z"),
522 );
523 assert_eq!(
524 findings.len(),
525 1,
526 "a checkout outside every vault gets none: {findings:?}"
527 );
528 let finding = &findings[0];
529 assert_eq!(finding.to, "#acme/payments");
530 assert_eq!(
531 finding.worker_id, "wkr_mcp-a",
532 "a tie of 30 min each goes to the smaller id"
533 );
534 assert_eq!(
535 (finding.from_ms, finding.to_ms),
536 (1_792_828_800_000, 1_792_832_400_000)
537 );
538 assert_eq!(
539 finding.counts,
540 BTreeMap::from([
541 ("agent_seconds", 3600),
542 ("claim_refused", 2),
543 ("wait_timeout", 1)
544 ])
545 );
546 assert_eq!(
547 finding.statement(),
548 "Collaboration friction from 08:00 to 09:00: 3 signals in 1.0 agent-hours."
549 );
550 assert!(finding.counts.keys().all(|key| COUNT_KEYS.contains(key)));
551 }
552
553 #[test]
557 fn the_publish_matches_the_contract_fixture() {
558 let path = format!(
559 "{}/crates/lean-ctx-protocol/tests/fixtures/cloud-v2/bus/message.finding.collaboration.json",
560 concat!(env!("CARGO_MANIFEST_DIR"), "/../..")
561 );
562 let stored: serde_json::Value =
563 serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
564 let counts: BTreeMap<&'static str, u32> = COUNT_KEYS
565 .iter()
566 .filter_map(|key| {
567 let n = stored["counts"][*key].as_u64()?;
568 Some((*key, u32::try_from(n).unwrap()))
569 })
570 .collect();
571 let finding = HourFinding {
572 to: stored["to"].as_str().unwrap().to_string(),
573 worker_id: stored["worker_id"].as_str().unwrap().to_string(),
574 from_ms: stored["window"]["from_ms"].as_i64().unwrap(),
575 to_ms: stored["window"]["to_ms"].as_i64().unwrap(),
576 counts,
577 };
578 let publish = finding.publish(1_792_803_600_000);
579 publish.validate().expect("a valid v2 publish");
580 let sent = serde_json::to_value(&publish).unwrap();
581 for member in [
582 "schema",
583 "type",
584 "about",
585 "counts",
586 "window",
587 "to",
588 "worker_id",
589 ] {
590 assert_eq!(sent[member], stored[member], "{member}");
591 }
592 assert!(sent.get("refs").is_none(), "no refs");
593 assert_eq!(sent["body"]["evidence"], "observed");
594 assert_eq!(
595 sent["body"]["statement"],
596 "Collaboration friction from 00:00 to 01:00: 8 signals in 1.5 agent-hours.",
597 "the window in UTC"
598 );
599 }
600
601 #[test]
604 fn closed_hours_are_queued_once_and_only_for_a_v2_cloud() {
605 let _data = lean_ctx::core::data_dir::isolated_data_dir();
606 let dir = tempfile::tempdir().unwrap();
607 let store = CloudStore::at(dir.path().join("c"), dir.path().join("d"));
608 store
609 .write_config(
610 super::super::state::INSTANCE_FILE,
611 &super::super::state::InstanceRecord {
612 instance_id: "inst_a".into(),
613 org_id: "org_a".into(),
614 org_name: "Acme".into(),
615 label: "mac".into(),
616 url: "https://cloud.example".into(),
617 org_salt_id: "salt".into(),
618 enrolled_at: "2026-10-24T00:00:00Z".into(),
619 web_url: None,
620 org_kind: None,
621 company_name: None,
622 },
623 )
624 .unwrap();
625 let project = tempfile::tempdir().unwrap();
626 let root = project.path().to_string_lossy().into_owned();
627 let mut map = VaultMap::default();
628 map.vaults.insert(
629 "v1".into(),
630 VaultRecord {
631 vault_id: "v1".into(),
632 ns: "acme".into(),
633 name: "payments".into(),
634 sealed: false,
635 roots: vec![root.clone()],
636 },
637 );
638 map.save(store.data_dir()).unwrap();
639 let mut registry = lean_ctx::core::agents::AgentRegistry::new();
640 let agent = registry
641 .register("claude", Some("engine"), &root, None)
642 .unwrap();
643 registry.save().unwrap();
644 friction::record_for(friction::WAIT_TIMEOUT, Some(&agent), Some(&root));
645 let next_hour = UtcDateTime::now() + Duration::hours(1);
646
647 super::super::bus::relay_v2::record_protocol(&store, false).unwrap();
648 assert_eq!(
649 emit_due(&store, next_hour),
650 0,
651 "a 1.x LeanCTX Cloud server gets none"
652 );
653
654 super::super::bus::relay_v2::record_protocol(&store, true).unwrap();
655 assert_eq!(emit_due(&store, next_hour), 1);
656 assert_eq!(emit_due(&store, next_hour), 0, "an hour is queued once");
657 let lines = std::fs::read_to_string(store.data_dir().join(HOURS_FILE)).unwrap();
658 let line: serde_json::Value = serde_json::from_str(lines.trim()).unwrap();
659 assert_eq!(line["place"], "#acme/payments");
660 assert_eq!(line["counts"]["wait_timeout"], 1);
661 assert!(line["worker_id"].as_str().unwrap().starts_with("wkr_"));
662 }
663
664 #[test]
668 fn a_merge_conflict_counts_once_per_conflict() {
669 let _data = lean_ctx::core::data_dir::isolated_data_dir();
670 let dir = tempfile::tempdir().unwrap();
671 let store = CloudStore::at(dir.path().join("c"), dir.path().join("d"));
672 let repo = tempfile::tempdir().unwrap();
673 let root = repo.path().to_string_lossy().into_owned();
674 let git = |args: &[&str]| {
675 let out = std::process::Command::new("git")
676 .args(["-c", "user.name=t", "-c", "user.email=t@t", "-C", &root])
677 .args(args)
678 .output()
679 .unwrap();
680 out.status.success()
681 };
682 assert!(git(&["init", "-q", "-b", "main"]));
683 std::fs::write(repo.path().join("f"), "base\n").unwrap();
684 assert!(git(&["add", "f"]) && git(&["commit", "-qm", "base"]));
685 assert!(git(&["checkout", "-qb", "other"]));
686 std::fs::write(repo.path().join("f"), "other\n").unwrap();
687 assert!(git(&["commit", "-qam", "other"]) && git(&["checkout", "-q", "main"]));
688 std::fs::write(repo.path().join("f"), "main\n").unwrap();
689 assert!(git(&["commit", "-qam", "main"]));
690 assert!(!git(&["merge", "-q", "other"]), "the merge conflicts");
691
692 let mut map = VaultMap::default();
693 map.vaults.insert(
694 "v1".into(),
695 VaultRecord {
696 vault_id: "v1".into(),
697 ns: "acme".into(),
698 name: "payments".into(),
699 sealed: false,
700 roots: vec![root.clone()],
701 },
702 );
703 map.save(store.data_dir()).unwrap();
704 let mut registry = lean_ctx::core::agents::AgentRegistry::new();
705 let agent = registry
706 .register("claude", Some("engine"), &root, None)
707 .unwrap();
708 registry.save().unwrap();
709
710 let conflicts = || {
711 friction::events(
712 UtcDateTime::now() - Duration::hours(1),
713 UtcDateTime::now() + Duration::hours(1),
714 )
715 .into_iter()
716 .filter(|e| e.signal == friction::MERGE_CONFLICT)
717 .collect::<Vec<_>>()
718 };
719 let mut seen = std::collections::BTreeSet::new();
720 sample_merge_conflicts(&store, &mut seen);
721 sample_merge_conflicts(&store, &mut seen);
722 let counted = conflicts();
723 assert_eq!(counted.len(), 1, "one conflict, two samples");
724 assert_eq!(counted[0].agent.as_deref(), Some(agent.as_str()));
725 assert_eq!(counted[0].root.as_deref(), Some(root.as_str()));
726
727 assert!(git(&["merge", "--abort"]));
728 sample_merge_conflicts(&store, &mut seen);
729 assert!(seen.is_empty(), "resolved");
730 assert!(!git(&["merge", "-q", "other"]));
731 sample_merge_conflicts(&store, &mut seen);
732 assert_eq!(conflicts().len(), 2, "a new conflict counts again");
733 }
734
735 #[test]
736 fn a_quiet_hour_has_no_finding() {
737 let agents = [agent(
738 "mcp-a",
739 "/w/pay",
740 "2026-10-24T05:00:00Z",
741 "2026-10-24T06:00:00Z",
742 )];
743 let findings = hour_findings(
744 std::path::Path::new("/nonexistent/cloud-data"),
745 &[],
746 &agents,
747 &vaults(),
748 &|a: &AgentEntry| Some(a.agent_id.clone()),
749 at("2026-10-24T08:00:00Z"),
750 at("2026-10-24T09:00:00Z"),
751 );
752 assert!(findings.is_empty(), "{findings:?}");
753 }
754}