fix(maestro): close three holes in the wire contract
Each was a typed field that type-checked on both sides and carried nothing across. SessionStatus::Dead was never constructed by the daemon, yet the TUI, CLI and SPA all render it and DESIGN.md specifies the exited badge. Sessions were removed on death, never marked. They are now marked Dead and kept until the operator dismisses them, with the PtyBridge sealed rather than dropped: attached clients still get a Close frame (NAP-226), and the replay buffer survives so a later attach can read what a crashed agent printed. Previously that output was destroyed. Dead sessions are read-only and do not survive a daemon restart. CreateSessionRequest.env was accepted, stored, echoed back and dropped — new_session_piped had no env parameter. It now reaches tmux as sorted `-e KEY=VAL` flags. A key containing `=` or NUL is rejected, since tmux would parse it as a different assignment than the caller wrote. PROTOCOL_VERSION was written by the daemon and read by nobody. Adds `maestro_protocol::is_compatible`, compared on the major component only; `maestro list` shows the daemon version and the TUI warns on mismatch. Also stops mapping every non-404 session error to 502: an invalid env key is a client mistake and now answers 400. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #45.
This commit is contained in:
co-authored by
Claude Opus 5
parent
031c80a40b
commit
b20651c33e
@@ -25,6 +25,24 @@ use uuid::Uuid;
|
||||
/// The protocol version this crate implements. Advertised in `GET /api/info`.
|
||||
pub const PROTOCOL_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
/// True when a daemon advertising `daemon_version` speaks the same protocol as
|
||||
/// this build.
|
||||
///
|
||||
/// Compared on the major component only, per semver: within a major, added
|
||||
/// fields are `#[serde(default)]` and so are forward-compatible. An empty or
|
||||
/// unparseable version is treated as compatible — daemons that predate the
|
||||
/// field should not trip a warning.
|
||||
pub fn is_compatible(daemon_version: &str) -> bool {
|
||||
fn major(v: &str) -> Option<&str> {
|
||||
let m = v.split('.').next()?;
|
||||
(!m.is_empty() && m.bytes().all(|b| b.is_ascii_digit())).then_some(m)
|
||||
}
|
||||
match (major(daemon_version), major(PROTOCOL_VERSION)) {
|
||||
(Some(theirs), Some(ours)) => theirs == ours,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// A live or recently-dead tmux session managed by the daemon.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Session {
|
||||
@@ -275,6 +293,22 @@ pub enum ClientControl {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn version_compatibility_is_major_only() {
|
||||
assert!(is_compatible(PROTOCOL_VERSION));
|
||||
let ours_major = PROTOCOL_VERSION.split('.').next().unwrap();
|
||||
assert!(is_compatible(&format!("{ours_major}.99.99")));
|
||||
assert!(!is_compatible("99.0.0"));
|
||||
}
|
||||
|
||||
/// A daemon predating the field sends nothing; that must not read as a
|
||||
/// mismatch.
|
||||
#[test]
|
||||
fn version_compatibility_tolerates_unknown_versions() {
|
||||
assert!(is_compatible(""));
|
||||
assert!(is_compatible("unknown"));
|
||||
}
|
||||
|
||||
fn round_trip<T>(value: &T) -> T
|
||||
where
|
||||
T: Serialize + for<'de> Deserialize<'de>,
|
||||
|
||||
Reference in New Issue
Block a user