Merge M13.14 agent-interface audit + lazy open (worktree-agent-a5f8967ebd42ce98b)

The branch's commits say M13.14; on main that id is the puppet work, so this arc is M13.21.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 17:23:10 -04:00
co-authored by Claude Opus 5.5
38 changed files with 1838 additions and 117 deletions
+169
View File
@@ -0,0 +1,169 @@
//! The agent-interface audit (UI side, M13.14):
//!
//! - every registered engine command is reachable over the control channel (`engine.commands`
//! lists it; `engine.execute` routes it: an unknown parameter is rejected by that command);
//! - every panel kind, opened headless, registers an automation id for every interactive widget
//! it draws: egui's interactive widget rects of the frame are matched against the registered
//! automation elements, and any widget no element covers is a gap.
use effectcraft_engine::Session;
use effectcraft_ui_egui::EffectcraftApp;
use effectcraft_ui_egui::control::{self, ControlRequest, Outcome};
use effectcraft_ui_egui::dock::PanelKind;
use egui::Rect;
use egui_kittest::Harness;
use serde_json::{Value, json};
fn session() -> Session {
let mut s = Session::default();
s.execute("file.openDemoProject", json!({})).unwrap();
s
}
fn harness(s: Session) -> Harness<'static, EffectcraftApp> {
let mut h = Harness::builder().with_size(egui::vec2(1680.0, 1020.0)).build_eframe(|_| EffectcraftApp::new(s));
h.run_steps(3);
h
}
fn send(h: &mut Harness<'_, EffectcraftApp>, method: &str, params: Value) -> Value {
let ctx = h.ctx.clone();
let (req, _rx) = ControlRequest::new(method, params);
match control::handle(h.state_mut(), &ctx, &req) {
Outcome::Done(v) => v,
_ => panic!("{method}: no immediate reply"),
}
}
#[test]
fn every_engine_command_is_reachable_over_the_control_channel() {
let mut h = harness(session());
let listed = send(&mut h, "engine.commands", json!({}));
let ids: std::collections::HashSet<String> = listed["result"].as_array().unwrap().iter().map(|c| c["id"].as_str().unwrap().to_string()).collect();
for spec in effectcraft_engine::command_specs() {
assert!(ids.contains(spec.id), "engine.commands misses {}", spec.id);
let v = send(&mut h, "engine.execute", json!({"command": spec.id, "params": {"__audit": 1}}));
let e = v["error"].as_str().unwrap_or_default();
assert!(v["ok"] == false && e.contains("unknown parameter") && e.contains(spec.id), "{}: {v}", spec.id);
}
}
/// Interactive widgets (click or drag sense, enabled, visible) of the last frame, in screen
/// points, with their accessibility label when egui knows one.
fn interactive(ctx: &egui::Context) -> Vec<(Rect, String)> {
let screen = ctx.content_rect();
ctx.viewport(|v| {
let w = &v.this_pass.widgets;
let mut out = vec![];
for (layer, rects) in w.layers() {
if layer.order == egui::Order::Tooltip || layer.order == egui::Order::Debug {
continue;
}
for r in rects {
let sense = r.sense;
if !(sense.senses_click() || sense.senses_drag()) || !r.enabled {
continue;
}
let ir = r.interact_rect.intersect(screen);
if ir.width() < 2.0 || ir.height() < 2.0 {
continue;
}
let info = w.info(r.id);
// Selectable text (labels sense drags to select their text) is not a control.
if info.is_some_and(|i| i.typ == egui::WidgetType::Label) {
continue;
}
out.push((ir, info.and_then(|i| i.label.clone()).unwrap_or_default()));
}
}
out
})
}
/// Automation elements that cover a widget: overlapping at least half of the smaller of the two,
/// and not a container many times the widget's size (a panel or a whole row).
fn covered(w: Rect, elements: &[Rect]) -> bool {
elements.iter().any(|e| {
let i = e.intersect(w);
if i.width() <= 0.0 || i.height() <= 0.0 {
return false;
}
let (aw, ae) = (w.area(), e.area());
i.area() >= 0.5 * aw.min(ae) && ae <= 40.0 * aw.max(64.0)
})
}
/// (panel, widget rect, label) of every interactive widget no automation element covers, for
/// one panel shown maximized.
fn gaps_of(h: &mut Harness<'_, EffectcraftApp>, p: PanelKind) -> Vec<String> {
h.state_mut().show_panel(p);
h.state_mut().ui.maximized = Some(p);
h.run_steps(4);
let ctx = h.ctx.clone();
let widgets = interactive(&ctx);
let app = h.state();
let elements: Vec<Rect> = app
.auto
.previous
.iter()
.chain(app.auto.elements.iter())
.map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
.collect();
let Some(panel) =
app.auto.find(&format!("panel.{}", p.id())).map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
else {
return vec![format!("{}: panel.{} not registered", p.title(), p.id())];
};
widgets
.into_iter()
.filter(|(r, _)| panel.contains(r.center()))
.filter(|(r, _)| !covered(*r, &elements))
.map(|(r, l)| format!("{}: [{:.0},{:.0} {:.0}x{:.0}] {l:?}", p.title(), r.min.x, r.min.y, r.width(), r.height()))
.collect()
}
#[test]
fn every_panel_registers_automation_ids_for_its_widgets() {
let mut s = session();
// Content for the selection-driven panels: the title (text with effects), a Render Queue
// item, a comp marker.
s.execute("layer.select", json!({"layers": ["EFFECTCRAFT"]})).unwrap();
s.execute("renderQueue.add", json!({"format": "png", "output": "/tmp/ec-audit-[#####].png"})).unwrap();
s.execute("markers.add", json!({})).ok();
let title = s.active_comp().unwrap().layers.iter().find(|l| l.name == "EFFECTCRAFT").map(|l| l.id.0).unwrap();
let mut h = harness(s);
h.state_mut().ui.layer_panel = Some(title);
// egui records widget types (to tell labels from controls) with this debug option.
h.ctx.all_styles_mut(|st| st.debug.show_interactive_widgets = true);
let mut gaps = vec![];
for p in PanelKind::ALL {
gaps.extend(gaps_of(&mut h, p));
}
// The timeline again with the title twirled open (properties, keys) and in the Graph Editor.
send(&mut h, "ui.set", json!({"timeline": {"openLayers": [title]}}));
gaps.extend(gaps_of(&mut h, PanelKind::Timeline));
send(&mut h, "ui.set", json!({"timeline": {"graphEditor": true}}));
gaps.extend(gaps_of(&mut h, PanelKind::Timeline));
send(&mut h, "ui.set", json!({"timeline": {"graphEditor": false}}));
// Outside the panels: the header and the menu bar.
h.state_mut().ui.maximized = None;
h.run_steps(3);
let ctx = h.ctx.clone();
let widgets = interactive(&ctx);
let app = h.state();
let elements: Vec<Rect> =
app.auto.previous.iter().map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3]))).collect();
let panels: Vec<Rect> = app
.auto
.previous
.iter()
.filter(|e| e.id.starts_with("panel.") && e.id.matches('.').count() == 1)
.map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
.collect();
for (r, l) in widgets {
if !panels.iter().any(|p| p.contains(r.center())) && !covered(r, &elements) {
gaps.push(format!("chrome: [{:.0},{:.0} {:.0}x{:.0}] {l:?}", r.min.x, r.min.y, r.width(), r.height()));
}
}
assert!(gaps.is_empty(), "{} interactive widgets without an automation id:\n{}", gaps.len(), gaps.join("\n"));
}
+120
View File
@@ -0,0 +1,120 @@
//! M13.14: the UI with a large project. The Project panel scrolls (only the rows in view are
//! drawn), reveals an item selected elsewhere and renders thumbnails off the UI thread; the
//! Timeline reaches the last of thousands of layers; the Progress panel lists the footage check
//! started by a lazy open.
use effectcraft_engine::Session;
use effectcraft_engine::perf::{LargeSpec, large_project};
use effectcraft_ui_egui::EffectcraftApp;
use effectcraft_ui_egui::dock::PanelKind;
use egui_kittest::Harness;
use serde_json::json;
fn spec() -> LargeSpec {
LargeSpec { comps: 8, main_layers: 1500, comp_layers: 3, footage: 90, sequence_frames: 12, nest_depth: 3, expression_every: 5, ..Default::default() }
}
fn harness(s: Session) -> Harness<'static, EffectcraftApp> {
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| EffectcraftApp::new(s));
h.run_steps(3);
h
}
fn large() -> Session {
let mut s = Session::default();
s.replace_project(large_project(&spec()), None);
s
}
#[test]
fn project_panel_scrolls_and_reveals_the_selection() {
let mut h = harness(large());
let folders: Vec<u64> = h.state().session.project.items.values().filter(|i| i.is_folder()).map(|i| i.id.0).collect();
h.state_mut().ui.project_open_folders.extend(folders);
h.state_mut().show_panel(PanelKind::Project);
h.run_steps(3);
// Far more rows than fit: a scroll bar, and the bottom rows aren't drawn yet.
assert!(h.state().auto.find("project.vscroll").is_some());
let drawn = |h: &Harness<'_, EffectcraftApp>| {
h.state().auto.previous.iter().filter(|e| e.id.starts_with("project.item.") && e.id.matches('.').count() == 2).count()
};
let rows = drawn(&h);
assert!(rows > 5 && rows < 80, "only the rows in view are drawn: {rows}");
// Selecting an item (a command, an agent) scrolls it into view.
let footage =
h.state().session.project.items.values().filter(|i| matches!(i.kind, effectcraft_engine::project::ItemKind::Footage(_))).map(|i| i.id.0).max().unwrap();
h.state_mut().session.execute("project.select", json!({"items": [footage]})).unwrap();
h.run_steps(3);
assert!(h.state().auto.find(&format!("project.item.{footage}")).is_some(), "selected item scrolled into view");
assert!(h.state().ui.project_scroll > 0.0);
// Scrolling to the end shows the last rows.
h.state_mut().ui.project_scroll = 1.0e6;
h.run_steps(2);
let shown: Vec<String> = h.state().auto.previous.iter().filter(|e| e.id.starts_with("project.item.")).map(|e| e.id.clone()).collect();
assert!(!shown.is_empty() && drawn(&h) < 80, "{shown:?}");
}
#[test]
fn comp_thumbnail_renders_off_the_ui_thread() {
let mut h = harness(large());
let main = h.state().session.active_comp_id().unwrap();
h.state_mut().session.execute("project.select", json!({"items": [main.0]})).unwrap();
h.state_mut().show_panel(PanelKind::Project);
// The frame that asks for the thumbnail doesn't wait for it; it lands a few frames later.
let mut landed = false;
for _ in 0..400 {
h.step();
if h.state().auto.find("project.thumbnail").is_some()
&& h.ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(egui::Id::new(("proj-thumb", main.0)))).is_some()
{
landed = true;
break;
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
assert!(landed, "thumbnail texture");
}
#[test]
fn timeline_reaches_the_last_of_many_layers() {
let mut h = harness(large());
h.state_mut().show_panel(PanelKind::Timeline);
h.state_mut().ui.maximized = Some(PanelKind::Timeline);
let last = h.state().session.active_comp().unwrap().layers.last().unwrap().id.0;
let first = h.state().session.active_comp().unwrap().layers[0].id.0;
h.run_steps(2);
assert!(h.state().auto.find(&format!("timeline.layer.{first}.bar")).is_some());
assert!(h.state().auto.find(&format!("timeline.layer.{last}.bar")).is_none(), "off-screen rows aren't drawn");
h.state_mut().ui.timeline.scroll_y = 1.0e7;
h.run_steps(2);
assert!(h.state().auto.find(&format!("timeline.layer.{last}.bar")).is_some());
// Track matte and parent menus list every layer only while open.
let pop = h.state().auto.find(&format!("timeline.layer.{last}.parent")).cloned();
assert!(pop.is_some());
}
#[test]
fn lazy_open_lists_the_footage_check_in_the_progress_panel() {
let path = std::env::temp_dir().join(format!("ec-ui-lazy-open-{}.ecproj", std::process::id()));
let mut s = large();
s.execute("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
let mut o = Session { check_footage_on_open: true, ..Default::default() };
o.execute("file.open", json!({"path": path.to_string_lossy()})).unwrap();
assert!(o.jobs().iter().any(|j| j.kind == "footageCheck"));
let mut h = harness(o);
h.state_mut().show_panel(PanelKind::Progress);
// The check finishes in the background; polling applies it: every file is missing.
for _ in 0..500 {
h.step();
if h.state().session.tasks.is_empty() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
assert!(h.state().session.tasks.is_empty());
let missing =
h.state().session.project.items.values().filter(|i| matches!(&i.kind, effectcraft_engine::project::ItemKind::Footage(f) if f.missing)).count();
assert_eq!(missing, spec().footage);
assert!(!h.state().session.is_dirty(), "the check doesn't modify the project");
let _ = std::fs::remove_file(path);
}