use std::process::Command;
use chrono::Utc;
use tempfile::TempDir;
use super::manager::SessionManager;
use super::record::{ManagedSessionId, ManagedSessionState, SessionRecord};
use super::tests::FakeTmuxDriver;
#[tokio::test]
async fn reconcile_backfills_source_id_from_workspace_git_remote() {
let tmp_ws = TempDir::new().unwrap();
let ws_path = tmp_ws.path().to_path_buf();
let git = |args: &[&str]| {
Command::new("git")
.arg("-C")
.arg(&ws_path)
.args(args)
.output()
.map(|o| o.status.success())
.unwrap_or(false)
};
if !git(&["init"]) {
return; }
git(&[
"remote",
"add",
"origin",
"git@github.com:testowner/testrepo.git",
]);
let dir = TempDir::new().unwrap();
let fake = FakeTmuxDriver::new();
let tmux_name = "tmpm-backfill-test".to_string();
fake.seeded_names.lock().unwrap().push(tmux_name.clone());
let mgr = SessionManager::new(dir.path(), fake.clone())
.await
.expect("manager");
let record = SessionRecord {
id: ManagedSessionId::new(),
tmux_name: tmux_name.clone(),
cwd: ws_path.clone(),
task: "test task".into(),
state: ManagedSessionState::Active,
created_at: Utc::now(),
last_activity_at: None,
workspace_path: Some(ws_path.clone()),
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,
injection_status: Default::default(),
worktree_owner: None,
};
mgr.store.write().await.upsert(record).await.expect("seed");
mgr.reconcile_on_boot(false).await.expect("reconcile");
let updated = mgr.list().await;
let r = updated
.iter()
.find(|r| r.tmux_name == tmux_name)
.expect("record must still be present after reconcile");
assert_eq!(
r.source_id.as_deref(),
Some("testowner/testrepo"),
"reconcile must backfill source_id from the workspace git remote (#1780)"
);
}
#[tokio::test]
async fn reconcile_backfills_source_id_for_stopped_record() {
let tmp_ws = TempDir::new().unwrap();
let ws_path = tmp_ws.path().to_path_buf();
let git = |args: &[&str]| {
Command::new("git")
.arg("-C")
.arg(&ws_path)
.args(args)
.output()
.map(|o| o.status.success())
.unwrap_or(false)
};
if !git(&["init"]) {
return; }
git(&[
"remote",
"add",
"origin",
"git@github.com:testowner/stopped-repo.git",
]);
let dir = TempDir::new().unwrap();
let fake = FakeTmuxDriver::new();
let tmux_name = "tmpm-stopped-backfill".to_string();
let mgr = SessionManager::new(dir.path(), fake.clone())
.await
.expect("manager");
let record = SessionRecord {
id: ManagedSessionId::new(),
tmux_name: tmux_name.clone(),
cwd: ws_path.clone(),
task: "stopped task".into(),
state: ManagedSessionState::Active, created_at: Utc::now(),
last_activity_at: None,
workspace_path: Some(ws_path.clone()),
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,
injection_status: Default::default(),
worktree_owner: None,
};
mgr.store.write().await.upsert(record).await.expect("seed");
mgr.reconcile_on_boot(false).await.expect("reconcile");
let updated = mgr.list().await;
let r = updated
.iter()
.find(|r| r.tmux_name == tmux_name)
.expect("record must still be present after reconcile");
assert_eq!(
r.state,
ManagedSessionState::Stopped,
"session not in seeded_names → must be Stopped after reconcile"
);
assert_eq!(
r.source_id.as_deref(),
Some("testowner/stopped-repo"),
"backfill must set source_id even on Stopped records (#1780)"
);
}