Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

DR3: raea render counts its findings last and exits 1 on an error not let through

shinyobjectz898a0068df75
diff --git a/Cargo.lock b/Cargo.lock
index 63d1fa47..1615fb76 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13610,6 +13610,7 @@ dependencies = [
name = "raea-app-direction"
version = "0.1.0"
dependencies = [
+ "raea-core-facts",
"raea-runtime-bundle",
"raea-runtime-world",
"serde_json",
diff --git a/apps/check/src/quick.rs b/apps/check/src/quick.rs
index 1504fd6c..a6bcc747 100644
--- a/apps/check/src/quick.rs
+++ b/apps/check/src/quick.rs
@@ -23,7 +23,8 @@ pub fn quick(args: &[String], tastes: Vec<raea_core_brief::Taste>) -> R<(String,
let manifest = tmp.join("render.json");
let me = std::env::current_exe().map_err(|e| e.to_string())?;
let out = std::process::Command::new(me).arg("render").arg(file).args(["--at", &at, "-o"]).arg(format!("{}/", tmp.display())).arg("--manifest").arg(&manifest).output().map_err(|e| e.to_string())?;
- let result = if out.status.success() {
+ // rendered when its manifest was written: a render whose stills clip exits 1 (DR3), and those findings are read here
+ let result = if manifest.is_file() {
on_manifest(file, &manifest, args, tastes)
} else {
// a render that fails is the finding: the agent sees why
diff --git a/apps/direction/Cargo.toml b/apps/direction/Cargo.toml
index 581d4de6..d33503e3 100644
--- a/apps/direction/Cargo.toml
+++ b/apps/direction/Cargo.toml
@@ -9,4 +9,5 @@ description = "How raea takes direction (docs/direction.feature): `raea world`,
[dependencies]
raea-runtime-world = { path = "../../runtime/world" }
raea-runtime-bundle = { path = "../../runtime/bundle" }
+raea-core-facts = { path = "../../core/facts" }
serde_json = "1"
diff --git a/apps/direction/src/lib.rs b/apps/direction/src/lib.rs
index c2fadfec..3cc5c56f 100644
--- a/apps/direction/src/lib.rs
+++ b/apps/direction/src/lib.rs
@@ -3,3 +3,7 @@
mod world;
pub use world::{cli, find, Find, USAGE};
+
+// how `raea render` ends: its findings counted last, and 1 on an error not let through (DR3)
+mod rendered;
+pub use rendered::rendered;
diff --git a/apps/direction/src/rendered.rs b/apps/direction/src/rendered.rs
new file mode 100644
index 00000000..dc4c3da5
--- /dev/null
+++ b/apps/direction/src/rendered.rs
@@ -0,0 +1,70 @@
+//! How `raea render` ends (docs/direction.feature DR3): what the render found, counted on the last line it prints
+//! whatever its output is piped through, and its exit: 1 while an error stands that nothing lets through. An error is
+//! let through by `--despite CHECK WHY` (a check's name, or `all`), or for a harness that renders many pieces and
+//! compares pixels, not scenes, by RAEA_DESPITE="CHECK: why" (which a raea before this ignores, as it would refuse the
+//! flag). What was let through, and why, is written into the render's manifest.
+
+use raea_core_facts::{Finding, Level, finding};
+use serde_json::{Value, json};
+
+/// Each `--despite CHECK WHY`, then RAEA_DESPITE's.
+fn despite(args: &[String], env: Option<String>) -> Vec<(String, String)> {
+ let mut out: Vec<(String, String)> = args.windows(3).filter(|w| w[0] == "--despite").map(|w| (w[1].clone(), w[2].clone())).collect();
+ if let Some((check, why)) = env.as_deref().and_then(|e| e.split_once(':')) {
+ out.push((check.trim().to_string(), why.trim().to_string()));
+ }
+ out
+}
+
+/// The last line and the exit, for `found` with `through` letting errors past.
+fn ending(found: &[Finding], through: &[(String, String)]) -> (String, i32) {
+ let excused = |f: &Finding| through.iter().any(|(c, _)| c == "all" || *c == f.check);
+ let errors = |past: bool| found.iter().filter(|f| f.level == Level::Error && excused(f) == past).count();
+ let mut line = format!("raea render: {}", finding::count(found));
+ if errors(true) > 0 {
+ let why: Vec<String> = through.iter().map(|(c, w)| format!("--despite {c} {w:?}")).collect();
+ line.push_str(&format!("; {} let through by {}", errors(true), why.join(", ")));
+ }
+ (line, i32::from(errors(false) > 0))
+}
+
+/// `raea render`'s exit, once its findings' count is printed; 0 for any other command.
+pub fn rendered(args: &[String]) -> i32 {
+ if args.first().map(String::as_str) != Some("render") {
+ return 0;
+ }
+ let found = finding::taken();
+ let through = despite(args, std::env::var("RAEA_DESPITE").ok());
+ if let (Some(m), false) = (raea_runtime_bundle::flag(args, "--manifest"), through.is_empty()) {
+ // the reasons beside the findings they let through
+ if let Some(mut v) = std::fs::read(&m).ok().and_then(|b| serde_json::from_slice::<Value>(&b).ok()) {
+ v["despite"] = Value::Array(through.iter().map(|(c, w)| json!({"check": c, "why": w})).collect());
+ let _ = std::fs::write(&m, v.to_string());
+ }
+ }
+ let (line, code) = ending(&found, &through);
+ println!("{line}");
+ code
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn s(v: &[&str]) -> Vec<String> {
+ v.iter().map(|a| a.to_string()).collect()
+ }
+
+ #[test]
+ fn an_error_fails_the_render_unless_it_is_let_through_and_says_by_what() {
+ let found = vec![Finding::new("clips", Level::Error, "rider in seat", "raea render"), Finding::new("tilted", Level::Warn, "vase leans", "raea render")];
+ assert_eq!(ending(&found, &[]), ("raea render: 1 error, 1 warn, 0 notes".into(), 1));
+ let through = despite(&s(&["render", "a.tsx", "--despite", "clips", "the rider is posed through it"]), None);
+ assert_eq!(ending(&found, &through), ("raea render: 1 error, 1 warn, 0 notes; 1 let through by --despite clips \"the rider is posed through it\"".into(), 0));
+ // another check's despite lets nothing through
+ assert_eq!(ending(&found, &despite(&s(&["render", "--despite", "floats", "x"]), None)).1, 1);
+ // a harness's
+ assert_eq!(ending(&found, &despite(&s(&["render"]), Some("all: P26 compares pixels".into()))).1, 0);
+ assert_eq!(ending(&[], &[]), ("raea render: 0 errors, 0 warns, 0 notes".into(), 0));
+ }
+}
diff --git a/bench/p26-baseline/compare.sh b/bench/p26-baseline/compare.sh
index dae31440..9c1fa868 100755
--- a/bench/p26-baseline/compare.sh
+++ b/bench/p26-baseline/compare.sh
@@ -58,7 +58,7 @@ for rel in $(jq -r '.composition' "$HERE/manifest.jsonl" | awk '!seen[$0]++'); d
[ -n "$cands" ] || cands=$(for i in 0 1 2 3 4 5 6 7 8; do echo $((last * i / 8)); done | awk '!seen[$0]++' | paste -sd, -)
rm -rf "$WORK/r" && mkdir -p "$WORK/r" "$OUT/frames/$slug"
# each row's render log kept at $OUT/logs/<slug>.log (a frame that came out black and was redrawn says so there)
- if ! (cd "$dir" && RAEA_PAGE=$PAGE "$bin" render "$src" ${copt[@]+"${copt[@]}"} --at "$cands" -o "$WORK/r/") > "$WORK/log" 2>&1; then
+ if ! (cd "$dir" && RAEA_PAGE=$PAGE RAEA_DESPITE="all: P26 compares a row's pixels; what its scene clips is in the log" "$bin" render "$src" ${copt[@]+"${copt[@]}"} --at "$cands" -o "$WORK/r/") > "$WORK/log" 2>&1; then
cp "$WORK/log" "$OUT/logs/$slug.log"
why=$(grep -E 'REFUSED|error|Error|panicked' "$WORK/log" | head -1 | cut -c1-300)
for f in ${frames//,/ }; do
diff --git a/bench/p26-baseline/recapture.sh b/bench/p26-baseline/recapture.sh
index ca91ceb8..078c7e3e 100755
--- a/bench/p26-baseline/recapture.sh
+++ b/bench/p26-baseline/recapture.sh
@@ -58,7 +58,7 @@ for entry in "$@"; do
cands=$(for i in 0 1 2 3 4 5 6 7 8; do echo $((last * i / 8)); done | awk '!seen[$0]++' | paste -sd, -)
fi
rm -rf "$WORK/r" && mkdir -p "$WORK/r"
- if ! (cd "$dir" && RAEA_PAGE=$PAGE "$bin" render "$src" ${copt[@]+"${copt[@]}"} --at "$cands" -o "$WORK/r/") > "$WORK/log" 2>&1; then
+ if ! (cd "$dir" && RAEA_PAGE=$PAGE RAEA_DESPITE="all: P26 compares a row's pixels; what its scene clips is in the log" "$bin" render "$src" ${copt[@]+"${copt[@]}"} --at "$cands" -o "$WORK/r/") > "$WORK/log" 2>&1; then
echo "recapture.sh: $rel didn't render: $(grep -E 'REFUSED|error|Error|panicked' "$WORK/log" | head -1 | cut -c1-300)" >&2; exit 1
fi
IFS=, read -ra list <<< "$cands"
diff --git a/core/facts/src/finding.rs b/core/facts/src/finding.rs
index e5f99375..3bbe4f41 100644
--- a/core/facts/src/finding.rs
+++ b/core/facts/src/finding.rs
@@ -126,6 +126,18 @@ impl Finding {
}
}
+static SAID: std::sync::Mutex<Vec<Finding>> = std::sync::Mutex::new(Vec::new());
+
+/// Findings a command has said as it went (a render's clipping, from its own thread), kept for its count at the end.
+pub fn said(fs: &[Finding]) {
+ SAID.lock().unwrap_or_else(|e| e.into_inner()).extend(fs.iter().cloned());
+}
+
+/// Every finding said so far, taken: what the command ends by counting.
+pub fn taken() -> Vec<Finding> {
+ std::mem::take(&mut *SAID.lock().unwrap_or_else(|e| e.into_inner()))
+}
+
/// Findings worst first, each level in the order found.
pub fn ranked(mut fs: Vec<Finding>) -> Vec<Finding> {
fs.sort_by_key(|f| f.level);
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index b705c326..211c86c3 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -59,7 +59,7 @@ pub fn cli(args: &[String]) -> i32 {
for line in [msg].into_iter().chain(said).filter(|m| !m.is_empty()) {
println!("{line}");
}
- 0
+ raea_app_direction::rendered(args) // a render's findings counted last; 1 on an error not let through (DR3)
}
Err(e) => {
raea_io_trace::event("refused", json!({"error": e}));
diff --git a/systems/contact/src/found.rs b/systems/contact/src/found.rs
index a9ad4616..76f3cc78 100644
--- a/systems/contact/src/found.rs
+++ b/systems/contact/src/found.rs
@@ -5,25 +5,21 @@
use raea_core_facts::{Finding, Level};
use serde_json::Value;
-fn text<'a>(v: &'a Value, k: &str) -> Option<&'a str> {
- v.get(k).and_then(Value::as_str)
-}
-
/// The lint's faults on `frame` as Findings: sunk, floats, air, tilted, clips, a model it can't load or that's over
/// budget, and what it skipped (a note). A part that rests, is mounted or is the ground is no finding.
pub fn lint_findings(found: &[Value], frame: i64, by: &str) -> Vec<Finding> {
found
.iter()
- .filter(|v| text(v, "level").is_some_and(|l| l != "ok"))
+ .filter(|v| v["level"].as_str().is_some_and(|l| l != "ok"))
.map(|v| {
- let check = text(v, "check").unwrap_or("lint");
- let mut f = Finding::new(check, Level::of_word(text(v, "level").unwrap_or("")), text(v, "says").unwrap_or_default(), by).frames(frame, frame + 1);
+ let check = v["check"].as_str().unwrap_or("lint");
+ let mut f = Finding::new(check, Level::of_word(v["level"].as_str().unwrap_or("")), v["says"].as_str().unwrap_or_default(), by).frames(frame, frame + 1);
for k in ["part", "into", "on"] {
- if let Some(name) = text(v, k) {
+ if let Some(name) = v[k].as_str() {
f = f.about(name, None);
}
}
- let num = |k: &str| v.get(k).and_then(Value::as_f64);
+ let num = |k: &str| v[k].as_f64();
if let Some(g) = num("gap").filter(|_| matches!(check, "sunk" | "floats")) {
f = f.measure("gap", g, "m", None);
} else if let Some(d) = num("depth") {
@@ -44,14 +40,14 @@ pub fn clip_findings(found: &[Value], by: &str) -> Vec<Finding> {
found
.iter()
.map(|v| {
- let at = |k: &str| v.get(k).and_then(Value::as_i64).unwrap_or(0);
- let mut f = Finding::new("clips", Level::Error, text(v, "says").unwrap_or_default(), by).frames(at("from"), at("to"));
+ let at = |k: &str| v[k].as_i64().unwrap_or(0);
+ let mut f = Finding::new("clips", Level::Error, v["says"].as_str().unwrap_or_default(), by).frames(at("from"), at("to"));
for k in ["part", "into"] {
- if let Some(name) = text(v, k) {
+ if let Some(name) = v[k].as_str() {
f = f.about(name, None);
}
}
- if let Some(d) = v.get("depth").and_then(Value::as_f64) {
+ if let Some(d) = v["depth"].as_f64() {
f = f.measure("depth", d, "m", None);
}
if let (Some(axis), Some(step)) = (v.pointer("/move/axis").and_then(Value::as_str), v.pointer("/move/by").and_then(Value::as_f64)) {
diff --git a/systems/contact/src/lib.rs b/systems/contact/src/lib.rs
index 1c4f9dc6..2955d584 100644
--- a/systems/contact/src/lib.rs
+++ b/systems/contact/src/lib.rs
@@ -406,6 +406,7 @@ pub fn told(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec<
for f in &found {
eprintln!("raea: {}", f.line());
}
+ raea_core_facts::finding::said(&found);
if std::env::var_os("RAEA_TIMES").is_some() {
eprintln!("raea times: the clipping check {:.0} ms", t.elapsed().as_secs_f64() * 1e3);
}