mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* fix(meetings): report stopping meetings truthfully over the CLI `hex meetings stop` answered `unchanged` for the next `record` while the recorder was still closing the stopped meeting, so a caller couldn't tell its recording never started (`Already recording "…"`, exit 0), and `hex status` kept saying `recording`. The mirror now records that a stop is under way (`stopping` on the recording state the tray, menu bar, and status read) and clears it on transcribing, finished, discarded, or failed. Both control tables share one rule in `control::meetings`: a `record` while stopping answers `busy` (exit 1) with a plain message, a second `stop` is harmlessly unchanged, and `hex status` reports the `stopping` state with the recording's title and elapsed time. The tray and menu bar keep Record disabled while it stops, saying so. macOS settles `meetings stop` on `Transcribing`/`Finished` as docs/cli.md already promised, with its deadline fallback unchanged. * fix(macos): build the stopping menu state without struct update Functional record update is only for structs, and MeetingMenuState is an enum, so the macOS menu-bar test's ..recording_state(...) failed clippy with E0436. The test's helper now takes stopping and builds every field. * fix(meetings): hold a stop asked while a recording starts A stop requested while the recorder was still starting was never mirrored: the stop state only applied to a Recording, so `hex meetings record` answered "A meeting recording is already starting" (exit 0), `hex status` read starting, and the tray and menu bar offered Record again. Starting now carries `stopping`, set through `MeetingMenuState::stopping_requested` (shared by the Linux and Windows mirror and macOS's), so `record` answers busy, a repeated stop is unchanged, status reads stopping, and the tray and menu bar keep Record disabled and say so. A stopping meeting also keeps the tray's Restart to update held, as a recording does. `hex quit` advises waiting for a stopping or transcribing meeting instead of telling the caller to stop one, and the CLI docs now say that the 8 s stop fallback may answer while status still reads stopping, that macOS also answers on a discarded or failed recording, and that a stop during Starting reads stopping too. * docs(meetings): mark the macOS stop-failure reply and the starting case `meetings stop` answers a failure's error only on macOS (settle_meeting_waiters turns a Failed event into `failed`); on Linux and Windows the stop loop reads any Idle as done, so docs/cli.md and docs/features/control-cli.md now say so. control-cli.md's shared-rule sentence also names a start whose stop is under way, matching `control::meetings::plan`.
204 lines
7.6 KiB
Rust
204 lines
7.6 KiB
Rust
//! `hex meetings record|stop` and the meeting state `hex status` prints,
|
|
//! from the recorder state the app mirrors (`meeting::watcher::MeetingMenuState`).
|
|
//! Both the macOS host and the Linux and Windows host share these rules, so a
|
|
//! refusal reads the same wherever it reaches the recorder.
|
|
|
|
use crate::control::{ControlReply, MeetingReport};
|
|
use crate::meeting::MeetingRequest;
|
|
use crate::meeting::watcher::MeetingMenuState;
|
|
|
|
/// What `record` or `stop` asks the recorder for `state`, or the reply when
|
|
/// there is nothing to ask. Commands are idempotent: one the state already
|
|
/// answers changes nothing.
|
|
///
|
|
/// A stop under way keeps the recorder busy until it finishes transcribing,
|
|
/// whether it had a recording or was still starting one, so `record` answers
|
|
/// `busy` (a non-zero exit) rather than "already …", which would hide that
|
|
/// nothing started.
|
|
pub(crate) fn plan(
|
|
state: &MeetingMenuState,
|
|
stop: bool,
|
|
title: Option<String>,
|
|
) -> Result<MeetingRequest, ControlReply> {
|
|
match (state, stop) {
|
|
(
|
|
MeetingMenuState::Recording { stopping: true, .. }
|
|
| MeetingMenuState::Starting { stopping: true },
|
|
false,
|
|
) => Err(stopping_busy()),
|
|
(MeetingMenuState::Recording { title, .. }, false) => Err(ControlReply::unchanged(
|
|
format!("Already recording “{title}”"),
|
|
)),
|
|
(MeetingMenuState::Starting { stopping: false }, false) => Err(ControlReply::unchanged(
|
|
"A meeting recording is already starting",
|
|
)),
|
|
(MeetingMenuState::Transcribing, false) => Err(ControlReply::error(
|
|
"busy",
|
|
"the last meeting is still transcribing; try again when it finishes",
|
|
)),
|
|
(MeetingMenuState::Idle, false) => Ok(MeetingRequest::Start {
|
|
title: title.filter(|title| !title.trim().is_empty()),
|
|
}),
|
|
(MeetingMenuState::Idle, true) => Err(ControlReply::unchanged("No meeting is recording")),
|
|
(MeetingMenuState::Transcribing, true) => Err(ControlReply::unchanged(
|
|
"The meeting is already transcribing",
|
|
)),
|
|
// The stop already went to the recorder: asking again starts nothing.
|
|
(
|
|
MeetingMenuState::Recording { stopping: true, .. }
|
|
| MeetingMenuState::Starting { stopping: true },
|
|
true,
|
|
) => Err(ControlReply::unchanged("The meeting is already stopping")),
|
|
(MeetingMenuState::Starting { .. } | MeetingMenuState::Recording { .. }, true) => {
|
|
Ok(MeetingRequest::Stop)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// `record` while the recorder finishes with the last meeting.
|
|
fn stopping_busy() -> ControlReply {
|
|
ControlReply::error(
|
|
"busy",
|
|
"the last meeting is stopping; a new recording can start once it finishes transcribing",
|
|
)
|
|
}
|
|
|
|
/// The recorder as `hex status` reports it. `stopping` is a meeting whose
|
|
/// stop is under way — a recording, or one still starting — and it turns
|
|
/// `transcribing` or `idle` once the recorder finishes with it; only then
|
|
/// can a new recording start.
|
|
pub(crate) fn report(state: &MeetingMenuState) -> MeetingReport {
|
|
let plain = |state: &str| MeetingReport {
|
|
state: state.into(),
|
|
..Default::default()
|
|
};
|
|
match state {
|
|
MeetingMenuState::Idle => plain("idle"),
|
|
MeetingMenuState::Starting { stopping } => {
|
|
plain(if *stopping { "stopping" } else { "starting" })
|
|
}
|
|
MeetingMenuState::Recording {
|
|
started,
|
|
title,
|
|
stopping,
|
|
..
|
|
} => MeetingReport {
|
|
// A stop under way still names the recording, and keeps its
|
|
// elapsed time: only `transcribing` or `idle` lets a new one start.
|
|
state: (if *stopping { "stopping" } else { "recording" }).into(),
|
|
title: Some(title.clone()),
|
|
elapsed_seconds: Some(started.elapsed().as_secs()),
|
|
},
|
|
MeetingMenuState::Transcribing => plain("transcribing"),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use std::time::Instant;
|
|
|
|
fn recording(stopping: bool) -> MeetingMenuState {
|
|
MeetingMenuState::Recording {
|
|
started: Instant::now(),
|
|
id: "1700000000000".into(),
|
|
title: "Design sync".into(),
|
|
chapters: Vec::new(),
|
|
warning: None,
|
|
stopping,
|
|
}
|
|
}
|
|
|
|
fn code(reply: &ControlReply) -> &str {
|
|
match reply {
|
|
ControlReply::Error { code, .. } => code,
|
|
ControlReply::Done { changed: false, .. } => "unchanged",
|
|
_ => "changed",
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_stop_under_way_refuses_a_new_recording_with_busy() {
|
|
// The bug: this used to say "Already recording" and exit 0, so a
|
|
// caller couldn't tell its recording never started. A stop asked
|
|
// while the recorder started counts too.
|
|
for state in [
|
|
recording(true),
|
|
MeetingMenuState::Starting { stopping: true },
|
|
] {
|
|
let Err(reply) = plan(&state, false, None) else {
|
|
panic!("a stopping meeting must not start another");
|
|
};
|
|
assert_eq!(code(&reply), "busy");
|
|
assert!(matches!(
|
|
&reply,
|
|
ControlReply::Error { message, .. } if message.contains("stopping")
|
|
));
|
|
// Stopping it again is harmless: nothing is asked of the recorder.
|
|
let Err(reply) = plan(&state, true, None) else {
|
|
panic!("a stop already under way must not ask again");
|
|
};
|
|
assert_eq!(code(&reply), "unchanged");
|
|
}
|
|
let Err(reply) = plan(&recording(false), false, None) else {
|
|
panic!("a recording must not start another");
|
|
};
|
|
assert_eq!(code(&reply), "unchanged");
|
|
}
|
|
|
|
#[test]
|
|
fn each_state_asks_the_recorder_for_one_thing() {
|
|
assert_eq!(
|
|
plan(&MeetingMenuState::Idle, false, Some(" ".into())).unwrap(),
|
|
MeetingRequest::Start { title: None }
|
|
);
|
|
assert_eq!(
|
|
plan(&MeetingMenuState::Idle, false, Some("Design sync".into())).unwrap(),
|
|
MeetingRequest::Start {
|
|
title: Some("Design sync".into())
|
|
}
|
|
);
|
|
assert_eq!(
|
|
plan(&recording(false), true, None).unwrap(),
|
|
MeetingRequest::Stop
|
|
);
|
|
assert_eq!(
|
|
plan(&MeetingMenuState::Starting { stopping: false }, true, None).unwrap(),
|
|
MeetingRequest::Stop
|
|
);
|
|
assert_eq!(
|
|
code(&plan(&MeetingMenuState::Idle, true, None).unwrap_err()),
|
|
"unchanged"
|
|
);
|
|
assert_eq!(
|
|
code(&plan(&MeetingMenuState::Transcribing, true, None).unwrap_err()),
|
|
"unchanged"
|
|
);
|
|
assert_eq!(
|
|
code(&plan(&MeetingMenuState::Transcribing, false, None).unwrap_err()),
|
|
"busy"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn status_names_a_stopping_recording_and_keeps_its_title() {
|
|
let stopping = report(&recording(true));
|
|
assert_eq!(stopping.state, "stopping");
|
|
assert_eq!(stopping.title.as_deref(), Some("Design sync"));
|
|
assert_eq!(stopping.elapsed_seconds, Some(0));
|
|
assert_eq!(report(&recording(false)).state, "recording");
|
|
assert_eq!(report(&MeetingMenuState::Idle).state, "idle");
|
|
assert_eq!(
|
|
report(&MeetingMenuState::Starting { stopping: false }).state,
|
|
"starting"
|
|
);
|
|
assert_eq!(
|
|
report(&MeetingMenuState::Starting { stopping: true }).state,
|
|
"stopping"
|
|
);
|
|
assert_eq!(
|
|
report(&MeetingMenuState::Transcribing).state,
|
|
"transcribing"
|
|
);
|
|
}
|
|
}
|