test(examples): forbid low-level resource plumbing

Lock canonical examples to generated resource APIs instead of raw ids, OUT_DIR includes, global exports, or low-level runtime/plumbing types.

req: dx/002

req: ceremony/002

req: ceremony/004

req: examples/003
This commit is contained in:
slhx agent
2026-06-01 23:55:31 +02:00
parent 6f2bed3529
commit eaa5479b42
+45
View File
@@ -39,6 +39,51 @@ fn canonical_examples_do_not_author_browser_javascript() {
assert!(failures.is_empty(), "{}", failures.join("\n"));
}
#[test]
fn canonical_examples_do_not_author_low_level_resource_plumbing() {
// req: dx/002 req: ceremony/002 req: ceremony/004 req: examples/003
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let examples = root.join("examples");
let forbidden = [
"ResourceId::new",
".id().id",
"include!(concat!",
"OUT_DIR",
"global_exports(",
"EffectWriter",
"RuntimeOpcode",
"data-hid",
"data-sid",
"data-fid",
"data-aid",
"data-handle-id",
"data-slot-id",
"data-form-id",
"data-atom-id",
];
let mut failures = Vec::new();
scan_examples(&examples, &mut |path, text| {
if path.components().any(|part| part.as_os_str() == "tests") {
return;
}
if path.extension().and_then(|ext| ext.to_str()) != Some("rs") {
return;
}
let runtime_source = text.split("#[cfg(test)]").next().unwrap_or(text);
for (line_no, line) in runtime_source.lines().enumerate() {
if let Some(token) = forbidden.iter().find(|token| line.contains(*token)) {
failures.push(format!(
"{}:{}: example runtime code must use generated resources, not `{token}`",
path.display(),
line_no + 1
));
}
}
});
assert!(failures.is_empty(), "{}", failures.join("\n"));
}
#[test]
fn browser_e2e_does_not_shortcut_product_interactions() {
// req: examples/005