There were three answers to "how do I test against a daemon", and the CLI
— the thinnest client — had none, so its formatting and error handling
were exercised by compiling and forking the real binary plus tmux.
Adds crates/maestro-testing with a MockDaemon that serves the real /api/*
surface from maestro-protocol types, backed by a Vec<Session>. It replaces
two ad-hoc stubs: maestro-web's, which returned [{"id":"session-1"}] —
not a valid Session — and maestro-tui's scripted socket with a hardcoded
timeline.
maestro-cli gets its first tests against a daemon: six cases covering the
catalog, that DaemonInfo carries the version and presets its old private
copy dropped, that a structured failure surfaces the daemon's own message,
and that connection-refused stays distinguishable from an HTTP rejection.
maestro-web's proxy suite gains an end-to-end check that an upstream
rejection reaches the browser as a 4502 close carrying the daemon's
message — upstream_close_reason had only unit tests.
e2e keeps the tmux-shaped tests. cli_list_reads_from_daemon still runs the
shipped binary as a subprocess but now against MockDaemon, and
tui_integration.rs is deleted: the real daemon's /api/events contract is
covered by maestro-daemon/tests/local_api.rs and the client reducer by
maestro-tui/tests/catalog_ws.rs. The e2e suite drops from ~32s to ~20s.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
//! `CatalogStore::run_events_loop` against a daemon serving the real
|
|
//! `/api/events` contract, rather than a scripted socket.
|
|
|
|
use std::time::Duration;
|
|
|
|
use maestro_testing::{session, MockDaemon};
|
|
use maestro_tui::catalog::CatalogStore;
|
|
use uuid::Uuid;
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
async fn applies_the_snapshot_then_live_deltas() {
|
|
let mock = MockDaemon::start().await;
|
|
mock.add_session(session(Uuid::from_u128(1), "/home/mock", "bash"));
|
|
|
|
let ws_url = mock.client().events_url().expect("events url");
|
|
let store = CatalogStore::default();
|
|
let bg = store.clone();
|
|
tokio::spawn(async move { bg.run_events_loop(ws_url).await });
|
|
|
|
tokio::time::timeout(Duration::from_secs(3), store.wait_for_initial_snapshot())
|
|
.await
|
|
.expect("initial snapshot");
|
|
assert_eq!(store.snapshot().sessions.len(), 1);
|
|
|
|
mock.add_session(session(Uuid::from_u128(2), "/home/mock", "claude"));
|
|
wait_until(|| store.snapshot().sessions.len() == 2).await;
|
|
|
|
mock.remove_session(Uuid::from_u128(1));
|
|
wait_until(|| store.snapshot().sessions.len() == 1).await;
|
|
assert_eq!(store.snapshot().sessions[0].id, Uuid::from_u128(2));
|
|
}
|
|
|
|
async fn wait_until(mut cond: impl FnMut() -> bool) {
|
|
let deadline = tokio::time::Instant::now() + Duration::from_secs(3);
|
|
while tokio::time::Instant::now() < deadline {
|
|
if cond() {
|
|
return;
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(10)).await;
|
|
}
|
|
panic!("timed out waiting for the catalog to converge");
|
|
}
|