move the send and turn row markers into hive-types
This commit is contained in:
parent
e4a9005468
commit
6084fb6329
9 changed files with 119 additions and 43 deletions
|
|
@ -27,6 +27,8 @@ forgejo-api.workspace = true
|
|||
# decodes blobs it reads: forgejo's content and blob APIs carry base64,
|
||||
# never raw bytes.
|
||||
base64.workspace = true
|
||||
# `message_stream.rs` renders the history cutoff in the spelling of a row's `ts`.
|
||||
chrono.workspace = true
|
||||
# `agent_identity.rs` mints the per-agent queue secret, the one value in this
|
||||
# tree this daemon invents rather than receives. Straight from the kernel's
|
||||
# CSPRNG — see the workspace entry for why this and not `rand`.
|
||||
|
|
@ -69,6 +71,8 @@ sha2.workspace = true
|
|||
similar.workspace = true
|
||||
# The `Permission` names `/api/agents/{name}/permissions` accepts, the same
|
||||
# enum the hive enforces.
|
||||
# The send and turn row markers `message_stream.rs` reads a message back out
|
||||
# of.
|
||||
# Validates `POST /api/agents`' `name` before it becomes `agent`/`repo`
|
||||
# everywhere downstream — see `create_agent`'s doc comment for why this is
|
||||
# defense-in-depth, not the only gate (per an argus review finding).
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ use axum::extract::{Query, State};
|
|||
use axum::http::StatusCode;
|
||||
use axum::response::sse::{Event, KeepAlive, Sse};
|
||||
use futures_util::{Stream, StreamExt as _, stream};
|
||||
use hive_sh4re::term_msg::{SEND_ICON, TURN_ICON, iso8601_utc, send_recipient, turn_sender};
|
||||
use hive_types::term_msg::{SEND_ICON, TURN_ICON, send_recipient, turn_sender};
|
||||
use serde::Deserialize;
|
||||
use swarm_controller_api::messages::SwarmMessage;
|
||||
use swarm_queue_client::agent_term;
|
||||
|
|
@ -125,6 +125,17 @@ fn message_event(message: &SwarmMessage) -> Event {
|
|||
Event::default().data(serde_json::to_string(message).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// A unix-seconds stamp as ISO 8601 / RFC 3339 UTC, the spelling a row's `ts`
|
||||
/// carries, so the two compare as strings. It must equal
|
||||
/// `hive_sh4re::term_msg::iso8601_utc`, which stamps those rows.
|
||||
///
|
||||
/// A stamp outside the representable range renders as the epoch.
|
||||
fn iso8601_utc(unix_seconds: i64) -> String {
|
||||
chrono::DateTime::from_timestamp(unix_seconds, 0)
|
||||
.unwrap_or_default()
|
||||
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
|
||||
}
|
||||
|
||||
/// The messages in the newest rows of each of `roster`'s streams from the last
|
||||
/// `minutes`, oldest first. An agent whose stream cannot be read adds none.
|
||||
async fn history(
|
||||
|
|
@ -244,6 +255,19 @@ mod tests {
|
|||
|
||||
use crate::test_nats::TestNats;
|
||||
|
||||
/// The spelling is the one the agents stamp rows with (RFC 3339, whole
|
||||
/// seconds, `Z`): the history cutoff is compared with `ts` as a string.
|
||||
#[test]
|
||||
fn iso8601_utc_spells_a_stamp_the_way_a_row_ts_does() {
|
||||
assert_eq!(iso8601_utc(0), "1970-01-01T00:00:00Z");
|
||||
assert_eq!(iso8601_utc(1_789_302_903), "2026-09-13T12:35:03Z");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iso8601_utc_renders_an_out_of_range_stamp_as_the_epoch() {
|
||||
assert_eq!(iso8601_utc(i64::MAX), "1970-01-01T00:00:00Z");
|
||||
}
|
||||
|
||||
fn row(icon: &str, summary: &str, body: &str) -> bytes::Bytes {
|
||||
json!({
|
||||
"ts": "2026-10-18T12:00:00Z", "icon": icon, "level": "info",
|
||||
|
|
|
|||
Loading…
Reference in a new issue