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 gen check, raea solid info and raea project scan write Findings

shinyobjectza0b770709fde
diff --git a/Cargo.lock b/Cargo.lock
index 1615fb76..3619fd79 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13683,6 +13683,7 @@ name = "raea-app-registry"
version = "0.1.0"
dependencies = [
"oxc",
+ "raea-core-facts",
"serde_json",
]
@@ -13691,6 +13692,7 @@ name = "raea-app-solid"
version = "0.1.0"
dependencies = [
"raea-app-judge",
+ "raea-core-facts",
"raea-core-meshcheck",
"raea-core-shape",
"raea-core-solidinfo",
@@ -14218,6 +14220,7 @@ name = "raea-io-gen"
version = "0.1.0"
dependencies = [
"image",
+ "raea-core-facts",
"raea-core-meshcheck",
"raea-io-gen-comfy",
"raea-io-gen-core",
diff --git a/apps/solid/Cargo.toml b/apps/solid/Cargo.toml
index 7a46b16c..39d60af7 100644
--- a/apps/solid/Cargo.toml
+++ b/apps/solid/Cargo.toml
@@ -8,6 +8,8 @@ description = "raea solid info and raea solid view: a solid file run, its parts
[dependencies]
raea-core-solidinfo = { path = "../../core/solidinfo" }
+# what solid info finds, as raea's one Finding (docs/direction.feature DR3)
+raea-core-facts = { path = "../../core/facts" }
serde_json = "1"
# --set's and the CLI's flags, read as the bundler reads them
raea-runtime-bundle = { path = "../../runtime/bundle" }
diff --git a/apps/solid/src/lib.rs b/apps/solid/src/lib.rs
index 1c9f04cb..5fc2bdf8 100644
--- a/apps/solid/src/lib.rs
+++ b/apps/solid/src/lib.rs
@@ -11,6 +11,7 @@
use std::path::{Path, PathBuf};
+use raea_core_facts::{Finding, Level, finding};
use raea_runtime_bundle::flag;
use serde_json::{Map, Value, json};
@@ -173,22 +174,33 @@ pub fn cli(args: &[String]) -> Result<String, String> {
}
out["walk"] = json!(walk);
}
- let errors = out["errors"].as_u64().unwrap_or(0);
+ // what it found as raea's one Finding (docs/direction.feature DR3), about the part, or the solid's file
+ let name = file.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
+ let found = finding::ranked(out["found"].as_array().into_iter().flatten().filter_map(|v| Finding::of_value(v, "raea solid info")).map(|f| if f.about.is_empty() { f.about(&name, None) } else { f }).collect());
+ let errors = found.iter().any(|f| f.level == Level::Error);
+ if let Some(o) = out.as_object_mut() {
+ for k in ["found", "errors", "warnings"] {
+ o.remove(k);
+ }
+ }
+ out["count"] = json!(finding::count(&found));
+ out["findings"] = json!(found);
let text = if json_out {
serde_json::to_string_pretty(&out).unwrap_or_default()
} else {
let s = &out["solid"];
- let mut t: Vec<String> = out["found"].as_array().into_iter().flatten().filter(|f| !matches!(f["level"].as_str(), Some("ok"))).map(|f| format!("{:<8} {}{}", f["level"].as_str().unwrap_or(""), f["part"].as_str().map(|p| format!("{p}: ")).unwrap_or_default(), f["says"].as_str().unwrap_or(""))).collect();
+ let mut t: Vec<String> = found.iter().map(Finding::line).collect();
for p in out["parts"].as_array().into_iter().flatten() {
t.push(format!("part {}: {} m³, size {}, {} pieces, genus {}", p["part"].as_str().unwrap_or(""), p["volume"], p["box"]["size"], p["pieces"], p["genus"]));
}
for w in out["walk"].as_array().into_iter().flatten() {
t.push(format!("walk {} = {}: {}{}", w["param"].as_str().unwrap_or(""), w["value"], w["verdict"].as_str().unwrap_or(""), w["says"].as_str().map(|s| format!(" ({s})")).unwrap_or_default()));
}
- t.push(format!("solid: {} m³, size {} m, {} pieces, genus {}, {} triangles; {errors} errors, {} warnings", s["volume"], s["box"]["size"], s["pieces"], s["genus"], s["tris"], out["warnings"]));
+ t.push(format!("solid: {} m³, size {} m, {} pieces, genus {}, {} triangles", s["volume"], s["box"]["size"], s["pieces"], s["genus"], s["tris"]));
+ t.push(format!("raea solid info: {}", finding::count(&found)));
t.join("\n")
};
- if errors > 0 {
+ if errors {
println!("{text}");
std::process::exit(1);
}
diff --git a/apps/workspace/registry/Cargo.toml b/apps/workspace/registry/Cargo.toml
index d2866891..28c87c59 100644
--- a/apps/workspace/registry/Cargo.toml
+++ b/apps/workspace/registry/Cargo.toml
@@ -10,3 +10,5 @@ description = "A raea project's compositions, components and controllers, read f
# the version engine/bundle parses TSX with
oxc = { version = "=0.152.0", features = ["ast_visit"] }
serde_json = "1"
+# what the scan finds, as raea's one Finding (docs/direction.feature DR3)
+raea-core-facts = { path = "../../../core/facts" }
diff --git a/apps/workspace/registry/src/lib.rs b/apps/workspace/registry/src/lib.rs
index ccbfacb6..bf203b1e 100644
--- a/apps/workspace/registry/src/lib.rs
+++ b/apps/workspace/registry/src/lib.rs
@@ -263,7 +263,7 @@ impl Registry {
})).collect::<Vec<_>>(),
"components": self.components.iter().map(|c| json!({ "file": c.file, "usedBy": c.used_by })).collect::<Vec<_>>(),
"controllers": self.controllers.iter().map(|c| json!({ "id": c.id, "file": c.file, "line": c.line })).collect::<Vec<_>>(),
- "lint": self.lint.iter().map(Lint::json).collect::<Vec<_>>(),
+ "findings": self.lint.iter().map(Lint::finding).collect::<Vec<_>>(),
})
}
@@ -299,7 +299,8 @@ impl Registry {
out.trim_end().to_string()
}
- /// What it found, for a person: a line each for the counts, then each lint as file:line, what, and the fix.
+ /// What it found, for a person: a line for the counts and one each composition, then its findings worst first,
+ /// each about its file:line with the fix, and their count last.
pub fn text(&self) -> String {
let mut out = format!(
"{}: {} compositions, {} components, {} controllers",
@@ -311,9 +312,12 @@ impl Registry {
for c in &self.compositions {
out.push_str(&format!("\n composition {} ({}:{}{})", c.id, c.file, c.line, if c.how == How::Default { ", its default export" } else { "" }));
}
- for l in &self.lint {
- out.push_str(&format!("\n{}", l.line()));
+ let found = raea_core_facts::finding::ranked(self.lint.iter().map(Lint::finding).collect());
+ for f in &found {
+ let at = f.about.first().map(|a| a.key.clone().unwrap_or_else(|| a.name.clone())).unwrap_or_default();
+ out.push_str(&format!("\n{at}: {}", f.line()));
}
+ out.push_str(&format!("\nraea project scan: {}", raea_core_facts::finding::count(&found)));
out
}
}
diff --git a/apps/workspace/registry/src/lint.rs b/apps/workspace/registry/src/lint.rs
index 47889220..e4deafb3 100644
--- a/apps/workspace/registry/src/lint.rs
+++ b/apps/workspace/registry/src/lint.rs
@@ -3,7 +3,7 @@
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
-use serde_json::{Value, json};
+use raea_core_facts::{Finding, finding};
use super::{File, How, Prop, Registry, is_path, resolve, stem};
@@ -37,12 +37,14 @@ pub struct Lint {
}
impl Lint {
- pub fn json(&self) -> Value {
- json!({
- "file": self.file, "line": self.line, "rule": self.rule,
- "level": if self.level == Level::Warn { "warn" } else { "info" },
- "says": self.says, "fix": self.fix, "fixable": self.action.is_some(),
- })
+ /// As raea's one Finding (docs/direction.feature DR3): about its file, keyed file:line; a warn, or a note for
+ /// what only the render knows. A fix `raea doctor --fix` applies starts by saying so.
+ pub fn finding(&self) -> Finding {
+ let level = if self.level == Level::Warn { finding::Level::Warn } else { finding::Level::Note };
+ let name = if self.file.is_empty() { "." } else { self.file.as_str() };
+ let key = (self.line > 0).then(|| format!("{name}:{}", self.line));
+ let fix = if self.action.is_some() && !self.fix.starts_with("raea doctor --fix") { format!("raea doctor --fix does it: {}", self.fix) } else { self.fix.clone() };
+ Finding::new(self.rule, level, &self.says, "raea project scan").about(name, key).fix(fix)
}
/// file:line: what (the fix)
@@ -77,8 +79,12 @@ pub(super) fn lint(reg: &Registry, files: &[File], used_by: &BTreeMap<String, BT
out.push(warn(&f.rel, 1, "broken", format!("doesn't parse: {why}"), "fix the syntax: nothing reads a file that doesn't parse"));
continue;
}
+ // a registerRoot whose compositions a helper makes (`<>{shotComps(SHOTS)}</>`): registered, but not listed here
+ if f.facts.roots && f.facts.registered.is_empty() {
+ out.push(Lint { file: f.rel.clone(), line: 1, rule: "computed-root", level: Level::Info, says: "registers its root through code the scan doesn't follow (a helper that makes its <Composition>s), so its compositions aren't listed".into(), fix: "known when it renders; write each <Composition> inside registerRoot to have them listed before".into(), action: None });
+ }
// a .tsx that is neither a composition nor reached from one
- if f.rel.ends_with(".tsx") && !comp_files.contains(f.rel.as_str()) && !used_by.contains_key(&f.rel) && !controller_files.contains(f.rel.as_str()) {
+ if f.rel.ends_with(".tsx") && !f.facts.roots && !comp_files.contains(f.rel.as_str()) && !used_by.contains_key(&f.rel) && !controller_files.contains(f.rel.as_str()) {
out.push(warn(&f.rel, 1, "orphan", "isn't a composition, and no composition imports it".into(), "register it (a default export or a registerRoot <Composition>), import it from a composition, or delete it"));
}
for (spec, line) in f.facts.imports.iter().filter(|(s, _)| is_path(s)) {
diff --git a/apps/workspace/registry/src/read.rs b/apps/workspace/registry/src/read.rs
index d008872d..d6064fc7 100644
--- a/apps/workspace/registry/src/read.rs
+++ b/apps/workspace/registry/src/read.rs
@@ -62,6 +62,8 @@ pub struct Facts {
pub raea_names: Vec<String>,
/// why it didn't parse (the first diagnostic), when it didn't
pub broken: Option<String>,
+ /// it calls registerRoot (its compositions may come from a helper the scan doesn't follow)
+ pub roots: bool,
}
/// The file's facts; `tsx` for .tsx (JSX on), else plain TypeScript.
@@ -118,8 +120,9 @@ pub fn read(source: &str, tsx: bool) -> Facts {
_ => {}
}
}
- let mut v = Compositions { src: source, depth: 0, found: Vec::new(), consts: consts(&parsed.program) };
+ let mut v = Compositions { src: source, depth: 0, roots: false, found: Vec::new(), consts: consts(&parsed.program) };
v.visit_program(&parsed.program);
+ f.roots = v.roots;
f.registered = v.found.into_iter().map(|(at, mut r)| {
r.line = line(at);
r
@@ -230,6 +233,8 @@ fn number(e: &Expression, k: &HashMap<String, f64>) -> Option<f64> {
struct Compositions<'s> {
src: &'s str,
depth: usize,
+ /// it calls registerRoot, whether or not a <Composition> is written inside it
+ roots: bool,
found: Vec<(u32, Registered)>,
consts: HashMap<String, f64>,
}
@@ -237,6 +242,7 @@ struct Compositions<'s> {
impl<'a> Visit<'a> for Compositions<'_> {
fn visit_call_expression(&mut self, it: &CallExpression<'a>) {
let root = matches!(&it.callee, Expression::Identifier(id) if id.name == "registerRoot");
+ self.roots |= root;
self.depth += root as usize;
walk::walk_call_expression(self, it);
self.depth -= root as usize;
diff --git a/apps/workspace/registry/src/tests.rs b/apps/workspace/registry/src/tests.rs
index 5dcce4ca..a33661a6 100644
--- a/apps/workspace/registry/src/tests.rs
+++ b/apps/workspace/registry/src/tests.rs
@@ -16,6 +16,7 @@ fn project() -> (tempdir::Dir, PathBuf) {
w("card.tsx", "import Glyph from \"./lib/glyph\";\nimport { gone } from \"./nope\";\nimport { far } from \"../outside\";\nexport function Card() { return <Glyph />; }\n");
w("lib/glyph.tsx", "export default function Glyph() { return <span />; }\n");
w("stray.tsx", "export function Stray() { return null; }\n");
+ w("shots.tsx", "import { registerRoot } from \"raea\";\nimport { shotComps, SHOTS } from \"./lib/glyph\";\nregisterRoot(() => <>{shotComps(SHOTS)}</>);\n");
w("bare.tsx", "import { AbsoluteFill } from \"raea\";\nexport default function Bare() { return <AbsoluteFill />; }\n");
w("bare.render.json", "{\"width\": 1080, \"height\": 1080, \"fps\": 30, \"frames\": [{}, {}, {}]}");
w("anon.tsx", "export default () => <div />;\n");
@@ -89,6 +90,13 @@ fn what_isnt_connected_is_linted_with_its_place_and_fix() {
assert!(bare.action.is_some());
let anon = r.lint.iter().find(|l| l.rule == "unregistered" && l.file == "anon.tsx").unwrap();
assert!(anon.action.is_none() && anon.fix.contains("name the default export"));
+ // a registerRoot whose compositions a helper makes is no orphan: it says the scan can't list them
+ assert!(!r.lint.iter().any(|l| l.rule == "orphan" && l.file == "shots.tsx"));
+ assert!(has("computed-root", "shots.tsx", 1));
+ // as Findings (DR3): about the file at its line, a fix --fix applies saying so, the count last
+ let home = r.lint.iter().find(|l| l.rule == "controller-home").unwrap().finding();
+ assert_eq!((home.about[0].key.as_deref(), home.fix.as_deref().map(|f| f.starts_with("raea doctor --fix does it: move it to"))), (Some("settings/look.ts:3"), Some(true)));
+ assert!(r.text().lines().last().unwrap().starts_with("raea project scan: 0 errors, "));
}
#[test]
diff --git a/io/gen/Cargo.toml b/io/gen/Cargo.toml
index 2ecfa1e4..cef69eed 100644
--- a/io/gen/Cargo.toml
+++ b/io/gen/Cargo.toml
@@ -12,6 +12,8 @@ raea-io-gen-core = { path = "../gen-core" }
raea-io-home = { path = "../home" }
# a generated model measured and fitted after its step (raea gen check; fit.rs)
raea-core-meshcheck = { path = "../../core/meshcheck" }
+# what gen check finds, as raea's one Finding (docs/direction.feature DR3)
+raea-core-facts = { path = "../../core/facts" }
serde_json = "1"
# image.crop, image.scale, image.stitch, run here (native.rs)
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp"] }
diff --git a/io/gen/src/fit.rs b/io/gen/src/fit.rs
index 16692627..07fbd132 100644
--- a/io/gen/src/fit.rs
+++ b/io/gen/src/fit.rs
@@ -6,6 +6,7 @@
use std::path::Path;
+use raea_core_facts::{Finding, finding};
use raea_core_meshcheck::{Glb, Want, check, fix};
use serde_json::{Value as J, json};
@@ -20,11 +21,44 @@ pub fn want_of(v: &J) -> Want {
Want { h: v["h"].as_f64(), dims, faces: v["faces"].as_u64().map(|f| f as usize), turn: v["turn"].as_f64().unwrap_or(0.0), seen: v["seen"].as_f64(), parts, rig: v["rig"] == true, solid: v["solid"] == true, file: None }
}
+/// The report's `found` as raea's Findings (docs/direction.feature DR3), each about the model, worst first, with
+/// their count; its passes are not findings. A fix's command was in its words, and is its fix now.
+fn as_findings(mut r: J) -> J {
+ let file = r["file"].as_str().unwrap_or("model").to_string();
+ let fs = finding::ranked(
+ r["found"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter_map(|v| Finding::of_value(v, "raea gen check"))
+ .map(|mut f| {
+ if let Some(cut) = f.fix.as_ref().and_then(|x| f.says.strip_suffix(&format!("; fix: {x}"))) {
+ f.says = cut.to_string();
+ }
+ if f.about.is_empty() { f.about(&file, None) } else { f }
+ })
+ .collect(),
+ );
+ if let Some(o) = r.as_object_mut() {
+ for k in ["found", "errors", "warnings"] {
+ o.remove(k);
+ }
+ }
+ r["count"] = json!(finding::count(&fs));
+ r["findings"] = json!(fs);
+ r
+}
+
+/// Whether a report holds an error.
+fn failed(r: &J) -> bool {
+ r["findings"].as_array().into_iter().flatten().any(|f| f["level"] == "error")
+}
+
/// One model measured, and written fitted to `out` when given (`out` may be the model itself).
pub fn check_file(path: &Path, want: &Want, out: Option<&Path>) -> Result<J, String> {
let p = path.display().to_string();
if let Some(f) = raea_core_meshcheck::blender::unloadable(&p) {
- return Ok(json!({"file": p, "errors": 1, "warnings": 0, "found": [f]}));
+ return Ok(as_findings(json!({"file": p, "found": [f]})));
}
let g = Glb::read(&p)?;
let mut r = check(&g, g.bytes.len(), &Want { file: Some(p.clone()), ..want.clone() })?;
@@ -47,7 +81,7 @@ pub fn check_file(path: &Path, want: &Want, out: Option<&Path>) -> Result<J, Str
}
r["wrote"] = json!(o.display().to_string());
}
- Ok(r)
+ Ok(as_findings(r))
}
/// `raea gen check ...`
@@ -69,23 +103,21 @@ pub fn command(args: &[String]) -> Result<String, String> {
} else {
say(&r)
};
- if r["errors"].as_u64().unwrap_or(0) > 0 {
+ if failed(&r) {
println!("{text}");
std::process::exit(1);
}
Ok(text)
}
-/// The findings as lines, lint's way: warnings and errors, then one line of totals.
+/// The findings as lines, worst first, then what was measured, then their count.
pub fn say(r: &J) -> String {
- let mut t = Vec::new();
- for f in r["found"].as_array().into_iter().flatten().filter(|f| f["level"] != "ok") {
- t.push(format!("{:<8} {}", f["level"].as_str().unwrap_or(""), f["says"].as_str().unwrap_or("")));
- }
+ let mut t: Vec<String> = r["findings"].as_array().into_iter().flatten().filter_map(|f| serde_json::from_value::<Finding>(f.clone()).ok()).map(|f| f.line()).collect();
let m = &r["measured"];
// a file raea can't read has no measures: its summary says so instead of nulls
let measured = if m["triangles"].is_null() { "not read".to_string() } else { format!("{} triangles, {} x {} x {} m", m["triangles"], m["size"][0], m["size"][1], m["size"][2]) };
- t.push(format!("{}: {measured}, {} errors, {} warnings{}", r["file"].as_str().unwrap_or("model"), r["errors"], r["warnings"], r["wrote"].as_str().map(|w| format!("; fitted copy {w}")).unwrap_or_default()));
+ t.push(format!("{}: {measured}{}", r["file"].as_str().unwrap_or("model"), r["wrote"].as_str().map(|w| format!("; fitted copy {w}")).unwrap_or_default()));
+ t.push(format!("raea gen check: {}", r["count"].as_str().unwrap_or("")));
t.join("\n")
}
@@ -105,7 +137,7 @@ pub fn after_run(flow: &Flow, result: &mut J) {
for f in files.iter().filter(|f| f.to_ascii_lowercase().ends_with(".glb")) {
let p = Path::new(f);
let fitted = want.h.is_some() || want.turn != 0.0;
- let r = check_file(p, &want, fitted.then_some(p)).unwrap_or_else(|e| json!({"file": f, "errors": 1, "found": [{"check": "read", "level": "error", "says": e}]}));
+ let r = check_file(p, &want, fitted.then_some(p)).unwrap_or_else(|e| as_findings(json!({"file": f, "found": [{"check": "read", "level": "error", "says": e}]})));
eprintln!("raea gen: {}", say(&r).replace('\n', "\nraea gen: "));
checks.insert(name.clone(), r);
}