Files
shinyobjectz bbd7369548 One loop, raea goal: every rule in TypeScript, held at edit, render, publish and done; raea make is the asset tools
The rules are raea/goal's (sdk/goal), run by `raea goal check` at four moments: the hook after a save, every
render's end, raea cloud's publish, and the Stop hook. Rust's cut and goal gates and the box's word, sound, frame and
place checks are packs (MK30-MK39); runtime/cut-plan, runtime/goal-plan, raea make status and the box's check code
are gone with no alias (MK41).

brief.ts is the one registered root (MK43): raea runs it, and every file that imports raea must be reached from it
(the registered check, an error at publish and done). Its tasks are its `plan` (MK44), read from its run and written
back where each is written by `raea goal tasks`, the one path for the app, agents and the box. Its `goal` is one
goal or a workflow of several (MK46), each with its step, after and rules, checked and reported alone. Taste lines
and signed asks run inside the loop (MK47).

`raea goal check|tasks|seen|judge|gates|next` is the loop; `raea make clothes|motion|solid|wear|splat|physics|bake|
sao|tokensynth|sounds|component|blockout|...` the asset tools (MK45). Old names are refused with where they went.
docs/make.feature is docs/goal.feature; tools/legacy-names.sh holds the old names out.

raea's Node mode on JavaScriptCore now gives a CommonJS package's names as named exports (React's jsx), loads a
file a tool imports by URL, keeps process.exit's code from a promise callback, and reads stdin as fd 0, so the goal
runner runs on the shipped binary.
2026-11-29 16:02:31 -08:00

197 lines
9.7 KiB
Rust

use std::path::PathBuf;
use std::time::{Duration, SystemTime};
use raea_core_brief::{goal::Goal, read};
use raea_core_facts::record::Entry;
use serde_json::{Value, json};
use crate::asked::Ledger;
use crate::gates::{Job, gates, stalled};
fn dir(name: &str) -> PathBuf {
let d = std::env::temp_dir().join(format!("raea-make-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(&d).unwrap();
d
}
fn put(d: &PathBuf, rel: &str, text: &str) {
let p = d.join(rel);
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
std::fs::write(p, text).unwrap();
}
fn kit() -> Goal {
read("make", r#"{"kind": "kit", "style": "1970s desk, maker Aurora", "objects": [{"id": "phone", "label": "Phone", "h": 0.12, "prompt": "a rotary phone"}]}"#).unwrap()
}
fn delivered(d: &PathBuf) {
for f in ["out/kit/phone/phone.glb", "out/kit/phone/phone_lod1.glb", "out/kit/thumbs/phone.png", "out/kit/lineup.png", "out/kit/kit.json", "review/refs.png"] {
put(d, f, "x");
}
put(d, "NOTES.md", "# Notes\n\n## What the skill got wrong\n- nothing yet\n");
}
fn round(pass: bool, mean: f64, defects: Value) -> Value {
json!({"dir": "review/r1", "kind": "kit", "pass": pass, "mean": mean, "defects": defects})
}
fn run(make: &Goal, d: &PathBuf, record: &[Entry], rounds: &[Value], judged_at: Option<SystemTime>) -> Value {
run_with(make, d, record, rounds, judged_at, &Ledger::default())
}
fn run_with(make: &Goal, d: &PathBuf, record: &[Entry], rounds: &[Value], judged_at: Option<SystemTime>, ledger: &Ledger) -> Value {
gates(&Job { make, dir: d, project: None, record, rounds, verdict: None, judged_at, ledger, score_gates: false })
}
fn later() -> Option<SystemTime> {
Some(SystemTime::now() + Duration::from_secs(5))
}
#[test]
fn delivered_and_judged_after_is_done() {
let d = dir("done");
delivered(&d);
let s = run(&kit(), &d, &[], &[round(true, 7.5, json!([]))], later());
assert_eq!(s["clear"], true, "{s:#}");
assert_eq!(s["short"], json!([]));
}
#[test]
fn a_round_older_than_the_newest_deliverable_is_stale() {
let d = dir("stale");
delivered(&d);
let s = run(&kit(), &d, &[], &[round(true, 7.5, json!([]))], Some(SystemTime::UNIX_EPOCH));
assert_eq!(s["clear"], false);
assert!(s["gates"].to_string().contains("came after the last round"), "{s:#}");
}
#[test]
fn a_blocking_defect_must_be_fixed_or_answered_in_the_notes() {
let d = dir("defect");
delivered(&d);
let defects = json!([{"defect": "floating", "present": true, "level": "blocking"}]);
let s = run(&kit(), &d, &[], &[round(false, 6.0, defects.clone())], later());
assert_eq!(s["clear"], false);
assert!(s["gates"].to_string().contains("floating"));
put(&d, "NOTES.md", "## What the skill got wrong\n- floating: the handset rests in its cradle; the judge read its shadow as a gap\n");
let s = run(&kit(), &d, &[], &[round(false, 6.0, defects.clone())], later());
assert_eq!(s["clear"], true, "{s:#}");
// once the judge is calibrated for kits, its score gates too: two passes in a row (MK6)
let (rounds, ledger) = ([round(false, 6.0, defects)], Ledger::default());
let s = gates(&Job { make: &kit(), dir: &d, project: None, record: &[], rounds: &rounds, verdict: None, judged_at: later(), ledger: &ledger, score_gates: true });
assert_eq!(s["clear"], false, "{s:#}");
assert!(s["gates"].to_string().contains("two needed"), "{s:#}");
}
#[test]
fn at_the_cap_it_is_delivered_short() {
let d = dir("cap");
// eight rounds, the last still blocked by a defect no one answered
let blocked = json!([{"defect": "floating", "present": true, "level": "blocking"}]);
let rounds: Vec<Value> = (0..8).map(|i| round(false, 5.0 + i as f64 * 0.5, blocked.clone())).collect();
let s = run(&kit(), &d, &[], &rounds, later());
assert_eq!(s["clear"], false, "{s:#}");
assert!(s["short"].to_string().contains("capped"), "{s:#}");
}
#[test]
fn three_rounds_without_beating_the_best_is_a_stall() {
let r = |m: f64| json!({"mean": m});
assert!(stalled(&[r(5.0), r(6.5), r(6.0), r(6.4), r(6.5)]));
assert!(!stalled(&[r(5.0), r(6.0), r(6.2), r(6.4), r(6.6)]));
assert!(!stalled(&[r(5.0), r(5.0), r(5.0)]), "too few rounds to call it");
}
#[test]
fn a_composition_needs_a_clean_check_newer_than_it() {
let d = dir("checks");
delivered(&d);
put(&d, "scene.tsx", "x");
let mut make = kit();
make.compositions = vec!["scene.tsx".into()];
let rounds = [round(true, 7.5, json!([]))];
let s = run(&make, &d, &[], &rounds, later());
assert!(s["gates"].to_string().contains("never rendered"), "{s:#}");
let entry = |at: u64, level: &str| -> Entry {
serde_json::from_value(json!({"id": "20261123-x", "at": at, "by": "raea render", "of": "scene.tsx",
"findings": [{"check": "float", "level": level, "says": "the mug floats 2 cm", "by": "raea scene lint"}]})).unwrap()
};
let future = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() + 60;
let s = run(&make, &d, &[entry(future, "error")], &rounds, later());
assert!(s["gates"].to_string().contains("the mug floats"), "{s:#}");
let s = run(&make, &d, &[entry(future, "warn")], &rounds, later());
assert_eq!(s["clear"], true, "a warn doesn't block: {s:#}");
let s = run(&make, &d, &[entry(1, "warn")], &rounds, later());
assert!(s["gates"].to_string().contains("changed since"), "{s:#}");
}
// MK24: a part a render showed closer than planned holds the job until it's replanned or answered in the notes
#[test]
fn a_part_seen_closer_than_planned_holds_the_job() {
let d = dir("lod");
delivered(&d);
put(&d, "scene.tsx", "x");
let mut make = kit();
make.compositions = vec!["scene.tsx".into()];
let future = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() + 60;
let entry: Entry = serde_json::from_value(json!({"id": "r1", "at": future, "by": "raea render", "of": "scene.tsx", "findings": [{"check": "lod-closer", "level": "warn", "about": [{"name": "kiosk"}], "says": "'kiosk' is planned at LOD 3", "by": "raea render"}]})).unwrap();
let s = run(&make, &d, &[entry.clone()], &[round(true, 7.5, json!([]))], later());
assert!(s["clear"] == false && s["gates"].to_string().contains("seen closer than planned at r1: kiosk"), "{s:#}");
put(&d, "NOTES.md", "- lod kiosk: one frame at the cut, left as a box\n## What the skill got wrong\n- nothing\n");
assert_eq!(run(&make, &d, &[entry], &[round(true, 7.5, json!([]))], later())["clear"], true);
}
#[test]
fn a_round_judged_on_another_kinds_rubric_does_not_count() {
// docs/goal.feature MK5: a kit is judged on the kit's rubric
let d = dir("rubric");
delivered(&d);
let old = json!({"dir": "review/r1", "pass": true, "mean": 8.0, "defects": []});
let s = run(&kit(), &d, &[], &[old], later());
assert_eq!(s["clear"], false);
assert!(s["gates"].to_string().contains("--kind kit"), "{s:#}");
}
#[test]
fn a_calibrated_ask_question_gates_and_an_uncalibrated_one_advises() {
// docs/goal.feature MK4
let d = dir("ask");
delivered(&d);
put(&d, "review/r1/clay.png", "clay sheet bytes");
put(&d, "review/r1/colour.png", "colour sheet bytes");
let rounds = [round(true, 7.5, json!([]))];
let floating = raea_core_ask::library::find("make.clay.floating", None).unwrap();
let mut ledger = Ledger::default();
// nothing calibrated: every question is advice, and the job is done
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert_eq!(s["clear"], true, "{s:#}");
assert!(s["gates"].to_string().contains("advice only"), "{s:#}");
// floating calibrated on the person's labels: it must be asked of this exact clay sheet
ledger.calibrations.insert(floating.version(), serde_json::from_value(json!({"auc": 0.9, "n": 40, "positives": 16, "threshold": 0.4, "date": "2026-11-23", "by": "you"})).unwrap());
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert_eq!(s["clear"], false);
let gates = s["gates"].to_string();
assert!(gates.contains("not asked of this clay sheet") && gates.contains("--std make.clay.floating"), "{gates}");
// asked, and it flagged: open until fixed or answered by its id in NOTES.md
let ident = raea_core_ask::ident::ident(&d.join("review/r1/clay.png")).unwrap();
ledger.idents.insert("c-1".into(), ident);
ledger.answers.push(json!({"id": "a-1", "at": "100", "call": "c-1", "question": "make.clay.floating", "flagged": true, "problem": 0.8}));
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert_eq!(s["clear"], false);
assert!(s["gates"].to_string().contains("make.clay.floating flagged (p 0.80)"), "{s:#}");
put(&d, "NOTES.md", "## What the skill got wrong\n- make.clay.floating: the handset's shadow, not a gap; checked on the low tile\n");
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert_eq!(s["clear"], true, "{s:#}");
// the sheet rendered again: the old answer was about other bytes, so it's asked again
put(&d, "review/r1/clay.png", "a new clay sheet");
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert!(s["gates"].to_string().contains("not asked of this clay sheet"), "{s:#}");
// an uncalibrated question that flags is said as advice, holding nothing
let ident = raea_core_ask::ident::ident(&d.join("review/r1/colour.png")).unwrap();
ledger.idents.insert("c-2".into(), ident);
ledger.answers.push(json!({"id": "a-2", "at": "101", "call": "c-2", "question": "make.colour.plastic", "flagged": true, "problem": 0.7}));
let s = run_with(&kit(), &d, &[], &rounds, later(), &ledger);
assert!(s["advice"].to_string().contains("make.colour.plastic says yes"), "{s:#}");
}