wsb-daemon 0.248.6265

wsb's daemon: the workbench, the GitHub mirror's schedule and peer continuity, for every workspace on the machine
use super::*;

/// TEST20027: what the daemon logs reaches the workbench's Output panel.
///
/// The panel reads the process's log stream, and the daemon's subscriber was
/// a console formatter alone: the layer that fills the stream was never
/// installed, so the panel waited for lines that nothing would ever write.
/// Driven through the subscriber the daemon installs, and read from the
/// stream the panel reads, so a subscriber without the layer fails here.
#[tokio::test]
async fn test20027_the_daemon_log_reaches_the_stream_pages_read() {
    let (tx, ring) = wsb::logging::log_stream();
    let mut live = tx.subscribe();
    let marker = format!("daemon-subscriber-marker-{}", std::process::id());
    tracing::subscriber::with_default(subscriber(false), || tracing::info!("{marker}"));
    // Debug lines stay out of a daemon that was not asked for them.
    let quiet = format!("{marker}-debug");
    tracing::subscriber::with_default(subscriber(false), || tracing::debug!("{quiet}"));

    // Bounded: a subscriber that never feeds the stream would otherwise
    // leave this waiting for ever rather than failing.
    let line = tokio::time::timeout(std::time::Duration::from_secs(5), async {
        loop {
            let line = live.recv().await.expect("the stream delivers the daemon's line");
            if line.message == marker {
                break line;
            }
        }
    })
    .await
    .expect("the daemon's line never reached the stream");
    assert_eq!(line.level, "INFO");
    let history = ring.snapshot().await;
    assert!(history.iter().any(|line| line.message == marker));
    assert!(
        !history.iter().any(|line| line.message == quiet),
        "a debug line reached the panel of a daemon started without --debug"
    );
}