facett-graphview/tests/mega_still.rs
//! **The MEGA composite still — render proof.** Generates a smaller composite headless
//! (4k nodes, a 2000²-ish tiled canvas) and asserts, as DATA:
//! * the SVG TEXT layer carries the expected labels (repo names + legend + counts + the
//! honest format note),
//! * the tiled GPU RASTER is non-empty (real lit pixels, not a blank/uniform frame),
//! * the composite PNG was actually written to disk (bytes > 0).
//!
//! Honest about the format ACTUALLY used: PNG, because there is NO pure-Rust JPEG2000
//! encoder on crates.io (every JP2 path binds C OpenJPEG — forbidden). Behind `gpu`
//! (the wgpu offscreen cloud + resvg). Registers `functional_status` rows under
//! `--features gpu,testmatrix`. Skips cleanly (does not fail) when no GPU adapter exists.
#![cfg(feature = "gpu")]
use facett_graphview::world::{layout_world, LayoutBudget, Lod, WorldGraph};
use facett_graphview::world_still::{
burn_svg_over_rgba, render_world_still_mega, world_text_svg, MegaLabels,
};
#[allow(dead_code)]
const COMP: &str = "facett-graphview::world_mega_still";
#[allow(unused_variables)]
fn emit(check: &str, ok: bool, detail: &str) {
#[cfg(feature = "testmatrix")]
facett_core::testmatrix::emit(COMP, check, ok, detail);
}
#[test]
fn mega_composite_still_raster_text_and_file() {
let target = 4_000usize;
let (mega, tile, halo) = (2000u32, 1792u32, 128u32);
let w = WorldGraph::synthetic(target, Lod::Functions, true);
let (pos, _lane) = layout_world(&w, &LayoutBudget::default());
// ── the crisp SVG TEXT layer (pure, no GPU) ──────────────────────────────
let opts = MegaLabels {
title: "facett — code universe (test)".into(),
node_count: w.n,
edge_count: w.edges.len(),
synthetic: w.synthetic_flag(),
timestamp: "test".into(),
..MegaLabels::default()
};
let svg = world_text_svg(&w, &pos, mega, mega, &opts);
let has_repo0 = svg.contains(">repo0<") || svg.contains("repo0 ·");
let has_repo1 = svg.contains(">repo1<") || svg.contains("repo1 ·");
let has_legend = svg.contains("legend — repo ↔ colour");
let has_counts = svg.contains(&format!("{} nodes", w.n));
let honest = svg.contains("no pure-Rust JPEG2000 encoder");
let text_ok = has_repo0 && has_repo1 && has_legend && has_counts && honest;
emit(
"svg_text_layer_labels",
text_ok,
&format!("repo0={has_repo0} repo1={has_repo1} legend={has_legend} counts={has_counts} honest_format={honest}"),
);
assert!(has_repo0 && has_repo1, "SVG text layer names the repos (repo0, repo1)");
assert!(has_legend, "SVG has the repo↔colour legend");
assert!(has_counts, "SVG carries the node count");
assert!(honest, "SVG states the honest raster format (PNG, no pure-Rust JP2)");
// ── the dense tiled GPU RASTER ───────────────────────────────────────────
let Some(mut raster) =
render_world_still_mega(&w, &pos, mega, mega, true, 60_000, tile, halo)
else {
// This used to file `ok = TRUE` for a skipped arm — a GREEN matrix cell for a
// half that never ran, on top of libtest's own `ok`. `gpu_skip` files it as NOT
// passing and fails a host that declares it has an adapter.
facett_core::testmatrix::gpu_skip(
COMP,
"mega_composite_still_raster_text_and_file",
"no GPU adapter",
"the dense tiled mega raster fills the full buffer, tiles it, and composites \
lit pixels over the dark background",
);
return;
};
assert_eq!(raster.rgba.len(), (mega * mega * 4) as usize, "full mega buffer");
assert!(raster.tiles >= 4, "canvas was tiled ({} tiles)", raster.tiles);
// Non-empty: real lit pixels above the dark background (not a blank/uniform frame).
let bright = raster
.rgba
.as_chunks::<4>().0.iter()
.filter(|p| p[0] as u16 + p[1] as u16 + p[2] as u16 > 120)
.count();
let lit_ratio = bright as f64 / (mega * mega) as f64;
let raster_ok = bright > 1_000 && lit_ratio < 0.98;
emit(
"raster_non_empty",
raster_ok,
&format!("bright_px={bright} lit_ratio={lit_ratio:.4} tiles={} scene_nodes={}", raster.tiles, raster.nodes),
);
assert!(bright > 1_000, "raster has real lit node pixels (bright={bright})");
// ── BURN IN + write the composite file ───────────────────────────────────
let burned = burn_svg_over_rgba(&mut raster.rgba, raster.width, raster.height, &svg);
emit("text_burned_in", burned, &format!("burned={burned}"));
assert!(burned, "SVG text layer burned over the raster");
let out = std::env::temp_dir().join("facett-mega-still-test.png");
image::save_buffer(&out, &raster.rgba, raster.width, raster.height, image::ColorType::Rgba8)
.expect("write composite PNG");
let bytes = std::fs::metadata(&out).map(|m| m.len()).unwrap_or(0);
let file_ok = bytes > 0;
emit(
"composite_file_written",
file_ok,
&format!("path={} bytes={bytes} format=PNG", out.display()),
);
assert!(file_ok, "composite PNG written ({} bytes) to {}", bytes, out.display());
let _ = std::fs::remove_file(&out);
}