use std::fs;
use std::path::PathBuf;

#[test]
fn service_console_html_stays_on_service_ws_boundary() {
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let html_path = manifest_dir
        .join("frontend")
        .join("service-console")
        .join("sg_claw_service_console.html");
    let source = fs::read_to_string(&html_path).expect("service console html should exist");

    assert!(source.contains("ws://127.0.0.1:42321"));
    assert!(source.contains("submit_task"));
    assert!(source.contains("addEventListener(\"close\""));
    assert!(source.contains("setTimeout(() => connectOrDisconnectService(true)"));
    assert!(source.contains("connectTimeoutTimer"));
    assert!(source.contains("lastHeartbeatAt"));
    assert!(source.contains("heartbeat missed, forcing reconnect"));
    assert!(source.contains("service websocket connect timed out"));
    assert!(!source.contains("/sgclaw/browser-helper.html"));
    assert!(!source.contains("/sgclaw/callback/ready"));
    assert!(!source.contains("/sgclaw/callback/events"));
    assert!(!source.contains("/sgclaw/callback/commands/next"));
    assert!(!source.contains("/sgclaw/callback/commands/ack"));
    assert!(!source.contains("ws://127.0.0.1:12345"));
}
