//! Integration guard for the `aura chart` viewer's data transform.
//!
//! `chart-viewer.js` builds the uPlot configs in JavaScript, so the property
//! "buildCharts maps AURA_TRACES to the right per-mode uPlot config shape" cannot
//! be checked from Rust. This shells out to `node`, running
//! `tests/chart_viewer_build.mjs`, which loads the real viewer module and asserts
//! the overlay/panels config shape over a fixture — without instantiating uPlot
//! (which needs a DOM). `node` is REQUIRED: if absent this test FAILS.

use std::path::PathBuf;
use std::process::Command;

#[test]
fn chart_viewer_builds_overlay_and_panels_configs() {
    let script = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("chart_viewer_build.mjs");
    assert!(script.exists(), "guard script missing at {}", script.display());

    let out = match Command::new("node").arg(&script).output() {
        Ok(out) => out,
        Err(e) => panic!(
            "node is required for the chart-viewer guard but could not be run \
             ({e}); install Node.js or ensure `node` is on PATH"
        ),
    };

    let stdout = String::from_utf8_lossy(&out.stdout);
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        out.status.success(),
        "chart-viewer guard failed (exit {:?}).\n--- node stdout ---\n{stdout}\n--- node stderr ---\n{stderr}",
        out.status.code()
    );
}
