feat: render source paint overrides with read-only object dependencies
Verify Tessera GUI / verify (push) Failing after 7m37s
Verify Tessera GUI / verify (push) Failing after 7m37s
This commit is contained in:
+103
-1
@@ -477,7 +477,13 @@ impl ReplSession {
|
||||
}
|
||||
mutated_mounts = true;
|
||||
self.bridge
|
||||
.commit_frame(&mut self.candidate.vm, root, &document.frame)?;
|
||||
.commit_frame(&mut self.candidate.vm, root.clone(), &document.frame)?;
|
||||
self.bridge.paint_frame(
|
||||
&mut self.candidate.vm,
|
||||
root.as_deref(),
|
||||
&mut document.frame,
|
||||
)?;
|
||||
document.validate()?;
|
||||
last = Some(document);
|
||||
})();
|
||||
if result.is_err() && mutated_mounts {
|
||||
@@ -795,6 +801,102 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn source_paint_overrides_native_commands_and_reacts_to_heap_field_writes() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../examples/source-paint.endor"),
|
||||
"app.main",
|
||||
71,
|
||||
1,
|
||||
)
|
||||
.unwrap();
|
||||
initial.validate().unwrap();
|
||||
assert_eq!(initial.frame.commands.iter().filter(|command| matches!(command, RenderCommand::RoundedRect { color, .. } if color == "#ED6A5A")).count(), 2);
|
||||
assert!(initial.frame.commands.iter().any(
|
||||
|command| matches!(command, RenderCommand::Text { color, .. } if color == "#FFFFFF")
|
||||
));
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let Value::Object(rect) = session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("rect".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("Block")
|
||||
};
|
||||
// No Console/global binding writes or focus changes: only the property
|
||||
// read by paint changes, proving the paint dependency is sufficient.
|
||||
session
|
||||
.candidate
|
||||
.vm
|
||||
.set_attr(rect, "tint", Value::Text("#526AC7".into()))
|
||||
.unwrap();
|
||||
let updated = session.refresh_document().unwrap().unwrap();
|
||||
assert_eq!(updated.frame.commands.iter().filter(|command| matches!(command, RenderCommand::RoundedRect { color, .. } if color == "#526AC7")).count(), 2);
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_paint_rejects_business_mutation_before_it_happens_and_restores_scope() {
|
||||
let source = r##"class BadPaint: RectBlock {
|
||||
tint: String
|
||||
function paint(self: BadPaint, mount: Mount, geometry: Bounds): DisplayList {
|
||||
self.tint = "#000000"
|
||||
return RectBlock.paint(self, mount, geometry)
|
||||
}
|
||||
}
|
||||
rect = BadPaint(100, 40, 0, "#DDEEFF", "#FF0000")
|
||||
page = Page()
|
||||
page.render(rect)"##;
|
||||
let mut session = ReplSession::new(72).unwrap();
|
||||
assert!(
|
||||
session
|
||||
.execute(source, "app.main")
|
||||
.err()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.contains("read-only")
|
||||
);
|
||||
assert!(session.is_faulted());
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let Value::Object(rect) = session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("rect".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("Block")
|
||||
};
|
||||
assert_eq!(
|
||||
session.candidate.vm.get_attr(rect, "tint").unwrap(),
|
||||
Value::Text("#FF0000".into())
|
||||
);
|
||||
session
|
||||
.candidate
|
||||
.vm
|
||||
.set_attr(rect, "tint", Value::Text("#526AC7".into()))
|
||||
.unwrap();
|
||||
let bad_color =
|
||||
include_str!("../examples/source-paint.endor").replace("#ED6A5A", "invalid color");
|
||||
assert!(ReplSession::load(&bad_color, "app.main", 73, 1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_paint_is_stable_when_mount_notifications_overflow_the_change_batch() {
|
||||
let fixture = include_str!("../examples/source-paint.endor");
|
||||
let mut source = fixture[..fixture.find("root = Column").unwrap()].to_owned();
|
||||
source.push_str("root = Column(0, 0");
|
||||
for _ in 0..1100 {
|
||||
source.push_str(", rect");
|
||||
}
|
||||
source.push_str(")\npage = Page()\npage.render(root)");
|
||||
let (mut session, document) = ReplSession::load(&source, "app.main", 74, 1).unwrap();
|
||||
assert_eq!(document.frame.commands.len(), 1100);
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_visual_methods_use_managed_values_and_match_real_geometry() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
|
||||
Reference in New Issue
Block a user