use pulsedb::{AgentId, ExperienceType, NewExperience};
use pulsehive_runtime::hivemind::HiveMind;
#[tokio::test]
async fn test_experiences_persist_across_hivemind_instances() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("persist.db");
{
let hive = HiveMind::builder().substrate_path(&path).build().unwrap();
let cid = hive
.substrate()
.get_or_create_collective("project")
.await
.unwrap();
let exp = NewExperience {
collective_id: cid,
content: "The authentication module uses JWT tokens with 24h expiry.".into(),
experience_type: ExperienceType::TechInsight {
technology: "auth".into(),
insight: "JWT with 24h expiry".into(),
},
embedding: None,
importance: 0.8,
confidence: 0.9,
domain: vec!["auth".into(), "security".into()],
source_agent: AgentId("agent-phase1".into()),
source_task: None,
related_files: vec![],
};
hive.record_experience(exp).await.unwrap();
}
{
let hive = HiveMind::builder().substrate_path(&path).build().unwrap();
let cid = hive
.substrate()
.get_or_create_collective("project")
.await
.unwrap();
let recent = hive.substrate().get_recent(cid, 10).await.unwrap();
assert!(
!recent.is_empty(),
"Experiences should persist across instances"
);
assert!(recent[0].content.contains("JWT tokens"));
}
}