Skip to main content

trellis_testing/
host_status.rs

1use trellis_core::{HostResourceStatus, ResourceKey, Revision, ScopeId, TransactionId};
2
3/// Explicit host status event fed to tests after plan application.
4pub type HostStatusEvent = HostResourceStatus;
5
6/// Recorded classification for a host status event.
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct HostStatusRecord {
9    /// Status supplied by the fake host.
10    pub status: HostStatusEvent,
11    /// Deterministic classification assigned by the ledger.
12    pub class: HostStatusClass,
13    /// Last command transaction known for this resource key, if any.
14    pub last_transaction_id: Option<TransactionId>,
15    /// Last command revision known for this resource key, if any.
16    pub last_command_revision: Option<Revision>,
17}
18
19/// Classification for host status delivery.
20#[derive(Copy, Clone, Debug, Eq, PartialEq)]
21pub enum HostStatusClass {
22    /// Status matches the current resource/scope/revision.
23    Current,
24    /// Status duplicates the last accepted status revision.
25    Duplicate,
26    /// Status targets an old command revision.
27    Stale,
28    /// Status targets a command revision newer than the ledger has observed.
29    Future,
30    /// Status targets a scope that no longer owns the resource.
31    Late,
32}
33
34#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
35pub(crate) struct HostStatusIdentity {
36    resource_key: ResourceKey,
37    scope: ScopeId,
38    command_revision: Revision,
39    status_revision: Revision,
40}
41
42impl From<&HostStatusEvent> for HostStatusIdentity {
43    fn from(status: &HostStatusEvent) -> Self {
44        Self {
45            resource_key: status.resource_key.clone(),
46            scope: status.scope,
47            command_revision: status.command_revision,
48            status_revision: status.status_revision,
49        }
50    }
51}