From 64e9ee76b4448139f9b4e33cb07071c9d0181499 Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Tue, 6 Oct 2026 15:49:07 +0300 Subject: [PATCH] [control] test the cursor and replay key reads behind host listings FirehoseHandle::pds_info, Hydrant::list_hosts and the relay replay chunk reader decode stored firehose cursors and relay seqs with from_be_bytes passed as a value, so the representation audit missed them. pds_info and relay replay get their own tests. list_hosts was already checked by list_hosts_includes_seeded_hosts_without_cursors, which now also asks get_host_status, because that test is the inventory row for get_host_status but never called it. flipping any of these reads to from_le_bytes fails its test. --- src/control/firehose.rs | 21 +++++++++++++++++++++ src/control/hosts.rs | 3 +++ src/control/stream/relay.rs | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/control/firehose.rs b/src/control/firehose.rs index f1378f1..cc44c05 100644 --- a/src/control/firehose.rs +++ b/src/control/firehose.rs @@ -897,6 +897,27 @@ mod tests { Ok(()) } + #[tokio::test] + async fn pds_info_reads_a_stored_big_endian_cursor() -> Result<()> { + let dir = tempfile::tempdir().into_diagnostic()?; + let hydrant = Hydrant::new(test_config(&dir)).await?; + let url = Url::parse("wss://stored.example/").into_diagnostic()?; + hydrant + .state + .db + .cursors + .insert( + keys::firehose_cursor_key_from_url(&url), + [0, 0, 0, 0, 0, 0, 1, 2], + ) + .into_diagnostic()?; + + let meta = hydrant.state.pds_meta.load(); + let info = hydrant.firehose.pds_info(&url, &meta); + assert_eq!(info.map(|info| info.seq), Some(258)); + Ok(()) + } + #[tokio::test] async fn admin_override_clears_public_provenance_in_memory_and_db() -> Result<()> { let dir = tempfile::tempdir().into_diagnostic()?; diff --git a/src/control/hosts.rs b/src/control/hosts.rs index 9fb8a56..fa757e8 100644 --- a/src/control/hosts.rs +++ b/src/control/hosts.rs @@ -584,6 +584,9 @@ mod host_listing_tests { assert_eq!(active.account_count, 42); assert_eq!(active.status, HostStatus::Active); + let status = hydrant.get_host_status("active.example").await?; + assert_eq!(status.map(|host| host.seq), Some(123)); + Ok(()) } diff --git a/src/control/stream/relay.rs b/src/control/stream/relay.rs index 450ac3e..76d43d4 100644 --- a/src/control/stream/relay.rs +++ b/src/control/stream/relay.rs @@ -78,3 +78,27 @@ fn read_relay_replay_chunk( |_, frame| Some(bytes::Bytes::copy_from_slice(frame)), ) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::config::Config; + + #[test] + fn replay_reads_big_endian_relay_seqs() { + let tmp = tempfile::tempdir().unwrap(); + let db = crate::db::Db::open(&Config { + database_path: tmp.path().to_path_buf(), + ..Default::default() + }) + .unwrap(); + db.relay + .events + .insert([0, 0, 0, 0, 0, 0, 1, 2], b"frame") + .unwrap(); + + let chunk = read_relay_replay_chunk(&db.relay.events, Some(257), None, 8).unwrap(); + assert_eq!(chunk.last_seen, Some(258)); + assert_eq!(chunk.events, [bytes::Bytes::from_static(b"frame")]); + } +} -- 2.51.2