Skip to content
46 changes: 45 additions & 1 deletion apps/rocmd/src/test_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
//! split into focused modules (see `docs/architecture.md`).

use anyhow::Result;
use rocm_core::{AppPaths, ManagedServiceRecord, unix_time_millis};
use rocm_core::{
AppPaths, AutomationRuntimeState, ManagedServiceRecord, WatcherMode, WatcherRuntimeSnapshot,
unix_time_millis,
};
use std::fs;
use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
Expand Down Expand Up @@ -186,6 +189,47 @@ pub(crate) fn assert_unconfirmed_stop_kept_the_service(
assert!(key_kept, "an unconfirmed stop must keep the endpoint key");
}

/// One enabled watcher snapshot in `mode`, for tests that build an automation
/// runtime state by hand.
pub(crate) fn test_watcher_snapshot(
id: &str,
mode: WatcherMode,
last_event_unix_ms: Option<u128>,
) -> WatcherRuntimeSnapshot {
WatcherRuntimeSnapshot {
id: id.to_owned(),
enabled: true,
mode,
summary: "test watcher".to_owned(),
last_event: None,
last_event_unix_ms,
}
}

/// A running automation runtime state carrying `active_watchers`.
pub(crate) fn test_runtime_state(
active_watchers: Vec<WatcherRuntimeSnapshot>,
) -> AutomationRuntimeState {
AutomationRuntimeState {
running: true,
automations_enabled: true,
daemon_pid: 1,
started_at_unix_ms: 1,
last_tick_unix_ms: 1,
local_webhook_endpoint: None,
active_watchers,
}
}

/// How many pending proposals to queue behind the one under test so it sits
/// beyond a recent-window read: more than the reviewed-retention cap, and
/// more than the 100 the code once read, so the tests keep guarding that
/// window even if the cap is ever lowered below it.
pub(crate) fn proposals_beyond_a_recent_window() -> usize {
const WINDOW_THE_CODE_ONCE_READ: usize = 100;
rocm_core::REVIEWED_PROPOSALS_RETAINED.max(WINDOW_THE_CODE_ONCE_READ) + 1
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading
Loading