Pin heartbeat module seams with tests

This commit is contained in:
Meta Vens 2026-05-18 00:43:57 +01:00
commit 12ad6e17b0
5 changed files with 114 additions and 4 deletions

View file

@ -269,3 +269,65 @@ fn participant_constraints(role_id: &str) -> Vec<&'static str> {
role_specific,
]
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn default_state_defines_the_fixed_lane_catalog() {
let state = default_heartbeat_state(1.5);
assert_eq!(state.target_heartbeat_rate, 1.5);
assert_eq!(state.pacing_policy.work_base_recovery, 6.0);
assert_eq!(state.pacing_policy.idle_base_recovery, 2.0);
assert_eq!(
state
.participants
.iter()
.map(|participant| participant.role_id.as_str())
.collect::<Vec<_>>(),
ROLE_ORDER
);
assert_eq!(
state
.participants
.iter()
.find(|participant| participant.role_id == "face")
.map(|participant| participant.agent_id.as_str()),
Some("epiphany.face")
);
}
#[test]
fn ghostlight_scene_state_replaces_maintenance_lanes_with_scene_characters() -> Result<()> {
let state = ghostlight_scene_heartbeat_state(
0.5,
"room",
vec![GhostlightSceneParticipantSeed {
agent_id: "Ariadne Prime".to_string(),
display_name: "Ariadne".to_string(),
initiative_speed: 1.2,
reaction_bias: 0.8,
interrupt_threshold: 0.4,
constraints: vec!["Speak only in the room.".to_string()],
}],
)?;
assert_eq!(state.participants.len(), 1);
let participant = &state.participants[0];
assert_eq!(participant.role_id, "ghostlight.character.ariadne-prime");
assert_eq!(participant.arena, HEARTBEAT_ARENA_SCENE);
assert_eq!(participant.participant_kind, PARTICIPANT_KIND_CHARACTER);
assert_eq!(
state
.extra
.get("protocol")
.and_then(|value| value.get("domain"))
.and_then(|value| value.as_str()),
Some("ghostlight")
);
Ok(())
}
}

View file

@ -192,3 +192,49 @@ pub fn validate_heartbeat_state(state: &EpiphanyHeartbeatStateEntry) -> Result<(
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::heartbeat_state::default_heartbeat_state;
use pretty_assertions::assert_eq;
#[test]
fn round_trips_state_and_cognition_documents() -> Result<()> {
let temp = tempfile::tempdir()?;
let store_path = temp.path().join("heartbeats.msgpack");
let state = default_heartbeat_state(1.0);
write_heartbeat_state_entry(&store_path, &state)?;
let loaded = load_heartbeat_state_entry(&store_path)?
.expect("heartbeat state should round-trip through CultCache");
assert_eq!(loaded.schema_version, HEARTBEAT_STATE_SCHEMA_VERSION);
assert_eq!(loaded.participants.len(), state.participants.len());
let cognition = EpiphanyHeartbeatCognitionEntry {
schema_version: HEARTBEAT_COGNITION_SCHEMA_VERSION.to_string(),
updated_at: "2026-05-17T00:00:00Z".to_string(),
latest_run_id: Some("run-1".to_string()),
latest_artifact_ref: None,
source: Some("unit-test".to_string()),
sleep_cycle: None,
memory_resonance: None,
incubation: None,
thought_lanes: None,
bridge: None,
candidate_interventions: None,
appraisals: None,
reactions: None,
extra: BTreeMap::new(),
};
write_heartbeat_cognition_entry(&store_path, &cognition)?;
let loaded_cognition = load_heartbeat_cognition_entry(&store_path)?
.expect("heartbeat cognition should round-trip through CultCache");
assert_eq!(loaded_cognition.schema_version, HEARTBEAT_COGNITION_SCHEMA_VERSION);
assert_eq!(loaded_cognition.latest_run_id.as_deref(), Some("run-1"));
Ok(())
}
}

View file

@ -59,6 +59,7 @@ remembers doctrine; the branch remembers the blade.
- Thread config helpers now live in `codex_message_processor/thread_config.rs`: instruction-source loading, thread config override construction, config-load error shaping, and dynamic-tool validation. The pure dynamic-tool validation contract has module-local unit tests.
- Turn control routes now live in `codex_message_processor/turn_routes.rs`: turn start, thread item injection, app-server client info setting, turn steer, turn interrupt, mode normalization, and input-limit validation with module-local unit tests.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
- Thread projection now lives in `codex_message_processor/thread_projection.rs`: state-db/thread-store/rollout summary projection, `ConversationSummary` to API `Thread` mapping, thread-title attachment helpers, turn pagination, and rollout turn reconstruction. `codex_message_processor.rs` is about 1,009 lines after this extraction and mostly owns JSON-RPC dispatch, processor construction, shared thread lookup/submit/error helpers, and lifecycle shutdown.
- Turn paging/reconstruction now lives in `codex_message_processor/thread_turn_projection.rs`; `thread_projection.rs` keeps state-db/thread-store/rollout summary projection and `ConversationSummary` to API `Thread` mapping. Focused `thread_turns_list` cursor tests and stale in-progress turn interruption coverage pass.
- The `thread/turns/list` route handler now lives in `codex_message_processor/thread_turn_routes.rs`, beside the turn projection helpers it consumes. `thread_read_routes.rs` is back to persisted/live thread listing, `thread/read`, loaded-thread listing, and summary reads.

Binary file not shown.

File diff suppressed because one or more lines are too long