From b3c73fd2cbb1c1c21ad0dc65f618feb72f19fff9 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Mon, 24 Aug 2026 19:30:11 +0100 Subject: [PATCH] test(maestro): assert the exported session env end to end through real tmux --- crates/maestro-daemon/src/tmux.rs | 19 +++++++++ .../maestro-daemon/tests/session_manager.rs | 41 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/crates/maestro-daemon/src/tmux.rs b/crates/maestro-daemon/src/tmux.rs index e0f7720..1d278b9 100644 --- a/crates/maestro-daemon/src/tmux.rs +++ b/crates/maestro-daemon/src/tmux.rs @@ -264,6 +264,25 @@ impl Tmux { check(out) } + /// `tmux show-environment -t maestro-`, parsed into KEY=VALUE pairs. + /// Test-facing view of what a spawned session actually inherits. + pub fn show_environment(&self, id: Uuid) -> Result, TmuxError> { + let name = session_name(id); + let out = self + .cmd() + .args(["show-environment", "-t", &name]) + .output()?; + check(out.clone())?; + let stdout = String::from_utf8_lossy(&out.stdout); + let mut env = BTreeMap::new(); + for line in stdout.lines() { + if let Some((k, v)) = line.split_once('=') { + env.insert(k.to_string(), v.to_string()); + } + } + Ok(env) + } + /// `tmux kill-server`. Best-effort cleanup used mostly by tests. pub fn kill_server(&self) -> Result<(), TmuxError> { let out = self.cmd().arg("kill-server").output()?; diff --git a/crates/maestro-daemon/tests/session_manager.rs b/crates/maestro-daemon/tests/session_manager.rs index 0e11df4..c90d9cc 100644 --- a/crates/maestro-daemon/tests/session_manager.rs +++ b/crates/maestro-daemon/tests/session_manager.rs @@ -1004,3 +1004,44 @@ async fn worktree_base_repo_records_the_main_checkout_not_the_request() { ); assert_ne!(wt.base_repo, inner_worktree, "the worktree is not the repo"); } + +/// #103: every tmux-spawned session carries the daemon's identity variables in +/// its environment — its UUID under `MAESTRO_SESSION_ID` and the daemon's base +/// URL under `MAESTRO_URL` — so the in-session reporting hook (#106) can find +/// both without any out-of-band channel. +#[tokio::test] +async fn spawned_sessions_export_maestro_session_id_and_url() { + let fx = DaemonFixture::new(); + fx.manager + .set_daemon_url("http://127.0.0.1:7071".to_string()); + let cwd = TempDir::new().unwrap(); + + let s = fx + .manager + .create(CreateSessionRequest { + cwd: cwd.path().to_path_buf(), + command: "sleep 30".into(), + env: HashMap::new(), + metadata: HashMap::new(), + worktree: None, + }) + .await + .expect("create"); + + let env = fx + .tmux + .tmux + .show_environment(s.id) + .expect("show-environment"); + assert_eq!( + env.get("MAESTRO_SESSION_ID"), + Some(&s.id.to_string()), + "session env: {env:?}" + ); + assert_eq!( + env.get("MAESTRO_URL"), + Some(&"http://127.0.0.1:7071".to_string()) + ); + + fx.manager.kill(s.id, false).await.expect("kill"); +}