mod cli_test_util;
use std::process::{Command, Output};
use std::time::{Duration, Instant};
#[ignore = "viewer-GUI e2e known-failing; deferred"]
#[tokio::test]
async fn viewer_plugin_route_applies_tag_verified_by_enqueue() {
let _state_dir = cli_test_util::test_base_dir();
let cli = cli_test_util::cli_binary();
let dir = cli_test_util::objectiveai_dir();
let state = cli_test_util::test_state_name();
let tag = format!("viewer-notify-{state}");
let body = serde_json::json!({ "tag": tag }).to_string();
let run = |args: &[&str]| -> Output {
Command::new(&cli)
.env("OBJECTIVEAI_DIR", &dir)
.env("OBJECTIVEAI_STATE", &state)
.args(args)
.output()
.expect("failed to run cli")
};
let deadline = Instant::now() + Duration::from_secs(60);
let mut last_enqueue: Option<Output> = None;
let applied = loop {
let _ = run(&["viewer", "send", "/plugin/viewer-notify/notify", &body]);
let enqueue = run(&["agents", "enqueue", "--agent-tag", &tag, "--simple", "ping"]);
if enqueue.status.success() {
break true;
}
last_enqueue = Some(enqueue);
if Instant::now() >= deadline {
break false;
}
tokio::time::sleep(Duration::from_secs(2)).await;
};
assert!(
applied,
"tag `{tag}` was never applied within the deadline — the plugin \
iframe did not receive the `/notify` notification or did not \
apply the tag. last `agents enqueue` stderr: {}",
last_enqueue
.map(|o| String::from_utf8_lossy(&o.stderr).into_owned())
.unwrap_or_default(),
);
}