facet-wrapped/tests/browser_info_names_the_device.rs
//! **A masked `AdapterInfo` must not be reported as a device with no name — and it
//! must not silently disarm the software check.**
//!
//! ## Measured on the 890M, in a real Chrome window, 2026-09-06
//!
//! `facet-wrapped` feeds [`record_adapter`] from `rs.adapter.get_info()`, which is the
//! right source on every native backend. On `BrowserWebGpu` it comes back **masked**.
//! With `--enable-features=Vulkan --use-angle=vulkan --enable-unsafe-webgpu`, on real
//! hardware, painting a real frame, `facet_adapter()` answered:
//!
//! ```json
//! { "backend":"BrowserWebGpu", "kind":"other", "name":"", "vendor":"0x0000",
//! "driver":"", "software":false, "reason":"other GPU preferred over 0 other adapter(s)" }
//! ```
//!
//! So the loader printed `GPU: (other, BrowserWebGpu)` — an **empty name on a genuine
//! Radeon** — while `the_canvas_names_its_adapter.rs` promises the device "a person
//! recognises". In the same window, in the same arm,
//! `(await navigator.gpu.requestAdapter()).info` gave `vendor: "amd"`,
//! `architecture: "rdna-3"`. **The identity was there the whole time; nothing asked
//! the browser for it.**
//!
//! ## Why this is a correctness test and not a cosmetics test
//!
//! `is_software_rasteriser` decides `software` by looking for `swiftshader`,
//! `llvmpipe`, `lavapipe` and friends **in the name and the driver**. Fed a masked
//! record those strings can never appear, so `software:false` was not a fact about the
//! device — it was an artefact of two empty strings. **The trap
//! `the_canvas_names_its_adapter.rs` exists to close was, in practice, still open**:
//! the field it tells drivers to assert on could not have said `true` no matter what
//! was painting. Chrome reports the SwiftShader adapter as vendor `google`,
//! architecture `swiftshader`, so composing the name from the browser's own fields is
//! what lets the EXISTING detector see it.
//!
//! Host-compilable on purpose, like its sibling: the composition and the detection are
//! pure, so they are provable without a browser. What this file cannot prove is that
//! the wasm actually asks the browser — that is `wasm.rs`'s enrichment step, and it was
//! verified by hand on the 890M.
use facet_wrapped::gpu::facts_from_browser_info;
use facett_core::render::adapter::is_software_rasteriser;
/// The real 890M reading. The name must become something a person recognises, and the
/// device must NOT be called software.
#[test]
fn the_real_radeon_gets_a_name_and_is_not_called_software() {
let facts = facts_from_browser_info("amd", "rdna-3", "", "", "BrowserWebGpu");
assert_eq!(
facts.name, "amd rdna-3",
"the browser's own identity, composed"
);
assert!(
!is_software_rasteriser(&facts),
"a Radeon is not a software rasteriser: {facts:?}"
);
}
/// **The row this whole surface exists for.** `--use-angle=swiftshader` hands Chrome a
/// working WebGPU adapter that a CPU paints, and every other observable in this crate
/// answers `webgpu` on it. Before this, the one field that could tell them apart was
/// computed from an empty string and answered `false`.
#[test]
fn swiftshader_is_caught_through_the_browsers_own_fields() {
// Vendor/architecture only — the shape Chrome gives when `description` is empty.
let facts = facts_from_browser_info("google", "swiftshader", "", "", "BrowserWebGpu");
assert!(
is_software_rasteriser(&facts),
"SwiftShader must be caught: {facts:?}"
);
// …and when the token is ONLY in `description`, which is the other shape seen.
let described = facts_from_browser_info(
"",
"",
"",
"Google SwiftShader Device (Subzero)",
"BrowserWebGpu",
);
assert!(
is_software_rasteriser(&described),
"SwiftShader in the description must be caught too: {described:?}"
);
}
/// **Empty in, empty out.** A browser that masks everything must produce an honest
/// blank, never a plausible-looking identity — the failure this whole file is about is
/// a value that reads fine by accident.
#[test]
fn a_browser_that_says_nothing_produces_no_invented_identity() {
let facts = facts_from_browser_info("", "", "", "", "BrowserWebGpu");
assert!(
facts.name.is_empty(),
"no identity was given, none invented"
);
assert!(facts.driver.is_empty());
}
/// `description` is preferred over the joined pair, because it is the most human of the
/// four fields — but the vendor tokens still reach `driver`, so the software check sees
/// them either way.
#[test]
fn description_wins_the_name_and_the_tokens_still_reach_driver() {
let facts = facts_from_browser_info(
"amd",
"rdna-3",
"0x150e",
"AMD Radeon 890M Graphics",
"BrowserWebGpu",
);
assert_eq!(facts.name, "AMD Radeon 890M Graphics");
assert_eq!(facts.driver, "amd rdna-3");
}