use std::path::PathBuf;
use chrono::Utc;
use super::injection_status::InjectionStatus;
use super::record::{ManagedSessionId, ManagedSessionState, SessionRecord};
#[test]
fn record_without_injection_status_field_defaults_to_not_applicable() {
let legacy_json = serde_json::json!({
"id": ManagedSessionId::new(),
"tmux_name": "tmpm-legacy",
"cwd": "/tmp",
"task": "legacy task",
"state": "active",
"created_at": Utc::now().to_rfc3339(),
"last_activity_at": null,
"workspace_path": null,
"repo_url": null,
"branch": null,
"pending_decision": null,
"proposed_default": null
})
.to_string();
let back: SessionRecord = serde_json::from_str(&legacy_json).expect("deserialize legacy");
assert_eq!(back.injection_status, InjectionStatus::NotApplicable);
}
#[test]
fn record_round_trips_injection_status() {
let mut record = SessionRecord {
id: ManagedSessionId::new(),
tmux_name: "tmpm-injected".into(),
cwd: PathBuf::from("/tmp"),
task: "task".into(),
state: ManagedSessionState::Active,
created_at: Utc::now(),
last_activity_at: None,
workspace_path: None,
repo_url: None,
branch: None,
pending_decision: None,
proposed_default: None,
correlation: Default::default(),
runtime: Default::default(),
ephemeral: false,
workspace_owned: false,
source_id: None,
claude_session_id: None,
scrollback_path: None,
last_cwd: None,
deliverable_id: None,
pane_id: None,
tmux_server: None,
injection_status: InjectionStatus::Pending,
worktree_owner: None,
terminal_at: None,
stop_cause: None,
kind: Default::default(),
};
record.injection_status = InjectionStatus::Success;
let json = serde_json::to_string(&record).expect("serialize");
let back: SessionRecord = serde_json::from_str(&json).expect("deserialize");
assert_eq!(back.injection_status, InjectionStatus::Success);
}