Run source measurement and arrangement in the frame pipeline
Verify Tessera GUI / verify (push) Failing after 7m30s
Verify Tessera GUI / verify (push) Failing after 7m30s
This commit is contained in:
+130
-8
@@ -452,6 +452,10 @@ impl ReplSession {
|
||||
let Some(root) = self.bridge.prepare_frame(&mut self.candidate.vm)? else {
|
||||
return Ok(last);
|
||||
};
|
||||
mutated_mounts = true;
|
||||
let frame = self
|
||||
.bridge
|
||||
.layout_frame(&mut self.candidate.vm, root.clone())?;
|
||||
let mut document = RenderDocument {
|
||||
source: self.source.clone(),
|
||||
root: Some(self.program_root.clone().unwrap_or_else(|| CodeNode {
|
||||
@@ -462,11 +466,7 @@ impl ReplSession {
|
||||
end_line: self.source.lines().count(),
|
||||
children: self.nodes.clone(),
|
||||
})),
|
||||
frame: root
|
||||
.as_ref()
|
||||
.map(|root| self.bridge.layout_frame(&self.candidate.vm, root))
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
frame,
|
||||
ui_root: root.clone(),
|
||||
};
|
||||
document.frame.session = self.id;
|
||||
@@ -475,9 +475,6 @@ impl ReplSession {
|
||||
if work > 200_000 {
|
||||
bail!("layout dependencies did not stabilize within the rendering work budget");
|
||||
}
|
||||
mutated_mounts = true;
|
||||
self.bridge
|
||||
.commit_frame(&mut self.candidate.vm, root.clone(), &document.frame)?;
|
||||
self.bridge.paint_frame(
|
||||
&mut self.candidate.vm,
|
||||
root.as_deref(),
|
||||
@@ -801,6 +798,131 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
const SOURCE_LAYOUT: &str = include_str!("../examples/source-layout.endor");
|
||||
|
||||
#[test]
|
||||
fn source_layout_uses_initial_mount_links_child_measurements_and_model_dependencies() {
|
||||
let (mut session, initial) = ReplSession::load(SOURCE_LAYOUT, "app.main", 91, 1).unwrap();
|
||||
let rect = initial
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.find(|mount| mount.width == 200.0 && mount.height == 60.0)
|
||||
.unwrap();
|
||||
assert_eq!((rect.x, rect.y), (44.0, 24.0));
|
||||
let id = rect.id;
|
||||
assert!(initial.frame.commands.iter().any(|command| matches!(command,RenderCommand::Text { value,y,.. } if value.starts_with("尺寸来自") && *y == 100.0)));
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let Value::Object(metrics) = session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("metrics".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("Metrics")
|
||||
};
|
||||
session
|
||||
.candidate
|
||||
.vm
|
||||
.set_attr(metrics, "width", Value::Number(260.into()))
|
||||
.unwrap();
|
||||
let next = session.refresh_document().unwrap().unwrap();
|
||||
let rect = next
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.find(|mount| mount.id == id)
|
||||
.unwrap();
|
||||
assert_eq!((rect.x, rect.width), (44.0, 260.0));
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_block_source_measurements_belong_to_each_occurrence() {
|
||||
let source = SOURCE_LAYOUT.replace(
|
||||
"page.render(root)",
|
||||
r#"otherMetrics = Metrics(140, 12)
|
||||
other = OffsetColumn(24, 16, rect, otherMetrics)
|
||||
page.render(Row(0, 0, root, other))"#,
|
||||
);
|
||||
let (mut session, initial) = ReplSession::load(&source, "app.main", 92, 1).unwrap();
|
||||
let globals = session.candidate.globals.unwrap();
|
||||
let Value::Object(rect) = session
|
||||
.candidate
|
||||
.vm
|
||||
.dict_get(globals, &Value::Text("rect".into()))
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("Rect")
|
||||
};
|
||||
let widths: Vec<_> = initial
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.filter(|mount| mount.block_id == rect.to_string())
|
||||
.map(|mount| mount.width)
|
||||
.collect();
|
||||
assert_eq!(widths, vec![200.0, 140.0]);
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_dependencies_changed_by_mount_hook_are_measured_again_before_publication() {
|
||||
let source = r##"class Metrics { width: Number }
|
||||
class InitialRect: RectBlock {
|
||||
metrics: Metrics
|
||||
function measure(self: InitialRect, mount: Mount, constraints: Constraints): MeasureResult {
|
||||
return MeasureResult(self.metrics.width, 20)
|
||||
}
|
||||
function onMount(self: InitialRect, mount: Mount): Unit { self.metrics.width = 140 }
|
||||
}
|
||||
metrics = Metrics(80)
|
||||
rect = InitialRect(80,20,0,"#DDEEFF",metrics)
|
||||
page = Page()
|
||||
page.render(rect)"##;
|
||||
let (mut session, document) = ReplSession::load(source, "app.main", 93, 1).unwrap();
|
||||
assert!(
|
||||
document
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.any(|mount| mount.width == 140.0 && mount.height == 20.0)
|
||||
);
|
||||
assert!(session.refresh_document().unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_layout_rejects_premature_geometry_writes_wrong_types_and_foreign_slots() {
|
||||
for (before, after, message) in [
|
||||
(
|
||||
"return MeasureResult(parent.block.metrics.width, 60)",
|
||||
"return mount.bounds()",
|
||||
"geometry is unavailable during measurement",
|
||||
),
|
||||
(
|
||||
"return MeasureResult(parent.block.metrics.width, 60)",
|
||||
"parent.block.metrics.width = 260\nreturn MeasureResult(260,60)",
|
||||
"read-only",
|
||||
),
|
||||
(
|
||||
"return MeasureResult(parent.block.metrics.width, 60)",
|
||||
"return Point(0,0)",
|
||||
"wrong result type",
|
||||
),
|
||||
(
|
||||
"positions.children.at(0).x = self.metrics.left",
|
||||
"positions.children.at(0).slot = 999999",
|
||||
"foreign child slot",
|
||||
),
|
||||
] {
|
||||
let source = SOURCE_LAYOUT.replace(before, after);
|
||||
let error = ReplSession::load(&source, "app.main", 94, 1).err().unwrap();
|
||||
assert!(error.to_string().contains(message), "{error}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_hit_filters_shape_falls_back_and_requires_matching_press_release() {
|
||||
for (press, release, expected_hits, expected_background) in [
|
||||
|
||||
Reference in New Issue
Block a user