facet-wrapped-group/tests/groups.rs
//! **Every entry is in exactly one bundle group** (2026-09-29).
//!
//! Run once per group: `cargo test -p facet-wrapped-group --features docs` and
//! `--features model3d` (without a group feature this build is a second core build and
//! the per-group assertions are skipped by name).
use std::collections::BTreeSet;
use facet_wrapped_group::groups::{CORE, GROUP_ENTRIES, THIS_BUNDLE, group_of, wrong_bundle};
fn names(r: &facet_wrapped_group::Registry) -> BTreeSet<String> {
r.names().into_iter().map(String::from).collect()
}
#[test]
fn this_bundle_holds_exactly_its_group_and_the_core_bundle_none_of_it() {
let core: BTreeSet<String> = facet_wrapped::Registry::with_builtins().names().into_iter().map(String::from).collect();
// Core holds no grouped entry, and every core entry's group is core.
for (n, g) in GROUP_ENTRIES {
assert!(!core.contains(*n), "`{n}` ({g}) must not be in the core bundle");
}
assert!(core.iter().all(|n| facet_wrapped::groups::group_of(n) == CORE));
if THIS_BUNDLE == CORE {
eprintln!("built without a group feature: nothing group-specific to assert");
return;
}
let here = names(&facet_wrapped_group::Registry::with_builtins());
let want: BTreeSet<String> =
GROUP_ENTRIES.iter().filter(|(_, g)| *g == THIS_BUNDLE).map(|(n, _)| (*n).to_string()).collect();
assert_eq!(here, want, "the `{THIS_BUNDLE}` bundle holds exactly its group's entries");
assert!(here.is_disjoint(&core), "no entry is in two bundles");
let manifest = facet_wrapped_group::Registry::with_builtins().manifest_json();
let listed: BTreeSet<String> =
manifest.as_array().unwrap().iter().map(|e| e["name"].as_str().unwrap().to_string()).collect();
assert_eq!(listed, want, "the manifest lists exactly this group");
for n in &here {
assert_eq!(group_of(n), THIS_BUNDLE);
}
// A core entry asked of this bundle is refused, naming the core bundle.
let msg = wrong_bundle("table").expect("table is core");
assert!(msg.contains("`core` bundle"), "{msg}");
}
/// The shared source compiles against facet-wrapped's dependency tables; this package
/// must carry the same lines (plus its group deps), or the two builds drift.
#[test]
fn the_dependency_tables_match_facet_wrapped() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let deps = |p: &str| -> BTreeSet<String> {
let text = std::fs::read_to_string(root.join(p)).unwrap();
let body = &text[text.find("[dependencies]").expect("a dependency table")..];
let body = body.split("[dev-dependencies]").next().unwrap();
body.lines()
.map(str::trim)
.filter(|l| !l.is_empty() && !l.starts_with('#'))
.map(str::to_string)
.collect()
};
let core = deps("facet-wrapped/Cargo.toml");
let group = deps("facet-wrapped-group/Cargo.toml");
let missing: Vec<&String> = core.difference(&group).collect();
assert!(missing.is_empty(), "facet-wrapped-group lacks facet-wrapped dependency lines: {missing:?}");
}
/// **Entry → group has ONE source: the recipe.** `facett-build-thing`'s
/// `BUNDLE_GROUPS[..].entries` is what the loader routes by (it is emitted into
/// `bundles.json`); `groups::GROUP_ENTRIES` is the copy the wasm needs at compile time
/// for its own `wrong_bundle` refusal (the recipe is not a dependency of the wasm —
/// adding one would move the core bundle's bytes). This holds the copy to the source,
/// both directions, and the recipe's group names/features to this package's.
#[test]
fn group_entries_are_the_recipes() {
use facett_build_thing::{BUNDLE_GROUPS, CORE_GROUP, GROUP_PACKAGE};
let recipe: BTreeSet<(String, String)> = BUNDLE_GROUPS
.iter()
.flat_map(|g| g.entries.iter().map(move |e| ((*e).to_string(), g.name.to_string())))
.collect();
let here: BTreeSet<(String, String)> =
GROUP_ENTRIES.iter().map(|(e, g)| ((*e).to_string(), (*g).to_string())).collect();
assert_eq!(here, recipe, "groups::GROUP_ENTRIES drifted from the recipe's BUNDLE_GROUPS entries");
assert_eq!(CORE, CORE_GROUP);
// Every non-core group is THIS package, built with a feature this manifest declares.
let manifest = std::fs::read_to_string(std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")).unwrap();
for g in BUNDLE_GROUPS.iter().filter(|g| g.name != CORE_GROUP) {
assert_eq!(g.package, GROUP_PACKAGE);
assert_eq!(env!("CARGO_PKG_NAME"), GROUP_PACKAGE);
for f in g.features {
assert!(manifest.lines().any(|l| l.starts_with(&format!("{f} = "))), "the recipe builds `--features {f}`, which {GROUP_PACKAGE} does not declare");
}
}
}