feat: retain live page mounts and update shared UI references across aliases
Verify Tessera GUI / verify (push) Failing after 7m13s

This commit is contained in:
2026-10-20 20:58:41 +08:00
parent 9d3f766275
commit 757fa22d9b
8 changed files with 528 additions and 95 deletions
+79 -8
View File
@@ -1,5 +1,5 @@
//! Compile complete source in a fresh VM or retain a worker-owned Console VM.
//! Console publishes owned native snapshots only after a successful explicit render.
//! Console retains mounted native references and publishes immutable frames after successful inputs.
use anyhow::{Result, bail};
use endor_core::{ExecutionLimits, ObjectRef, Value, Vm, VmError};
use frontend::{
@@ -257,7 +257,9 @@ impl ReplSession {
let compiled = compile_plan_with_globals(&source, &plan, names)?;
// Parsing/compilation finish before any new statement runs. Successful earlier
// statements in a runtime-failed input remain live, as in an ordinary REPL.
self.bridge.take_rendered()?;
self.bridge.discard_pending()?;
self.bridge
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
self.inputs += 1;
self.ast_nodes += budget.nodes;
let offset = line_starts(&self.source).len();
@@ -313,7 +315,7 @@ impl ReplSession {
retained?;
rendered_value = repr?;
}
let document = if let Some(root) = self.bridge.take_rendered()? {
let document = if let Some(root) = self.bridge.prepare_frame()? {
let document = RenderDocument {
source: self.source.clone(),
root: Some(CodeNode {
@@ -324,10 +326,15 @@ impl ReplSession {
end_line: self.source.lines().count(),
children: self.nodes.clone(),
}),
frame: layout::frame(&root)?,
ui_root: Some(root),
frame: root
.as_ref()
.map(|root| layout::frame(root))
.transpose()?
.unwrap_or_default(),
ui_root: root.clone(),
};
document.validate()?;
self.bridge.commit_frame(root)?;
Some(document)
} else {
None
@@ -345,12 +352,14 @@ impl ReplSession {
})
})();
if result.is_err() {
self.bridge.take_rendered()?;
self.bridge.discard_pending()?;
if let Some(node) = self.nodes.last_mut() {
node.name
.push_str(" (error; earlier statements may remain live)");
}
}
self.bridge
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
result
}
}
@@ -605,7 +614,69 @@ mod tests {
const PAGE: &str = include_str!("../examples/page.endor");
#[test]
fn live_session_retains_real_objects_and_renders_only_on_request() {
fn mounted_aliases_update_nested_positions_unmount_and_reject_cycles() {
let mut session = ReplSession::new(10).unwrap();
session.execute("card = ui.rect(10, 20)\nother = card\ncontainer = ui.column(0, 0, other)\npage = ui.page()\npage.render(container)", "app.main").unwrap();
let identity = session.execute("other", "app.main").unwrap().value;
let updated = session
.execute("card = ui.rect(640, 200, 32)", "app.main")
.unwrap();
assert_eq!(updated.value, identity);
assert_eq!(
session.execute("other", "app.main").unwrap().value,
identity
);
let frame = updated.document.unwrap().frame;
assert!(matches!(
frame.commands[0],
RenderCommand::RoundedRect {
width: 640.0,
height: 200.0,
..
}
));
assert!(
session
.execute("card = ui.column(0, 0, other)", "app.main")
.is_err()
);
assert!(
session
.execute("other", "app.main")
.unwrap()
.document
.is_none()
);
let unmounted = session
.execute("page.unmount()", "app.main")
.unwrap()
.document
.unwrap();
assert!(unmounted.frame.commands.is_empty());
assert!(
session
.execute("card = ui.rect(80, 50)", "app.main")
.unwrap()
.document
.is_none()
);
let remounted = session
.execute("page.render(other)", "app.main")
.unwrap()
.document
.unwrap();
assert!(matches!(
remounted.frame.commands[0],
RenderCommand::RoundedRect {
width: 80.0,
height: 50.0,
..
}
));
}
#[test]
fn live_session_retains_objects_and_updates_only_after_mounting() {
let mut session = ReplSession::new(7).unwrap();
let created = session
.execute(
@@ -636,7 +707,7 @@ mod tests {
.execute(r#"title = ui.text("changed")"#, "app.main")
.unwrap()
.document
.is_none()
.is_some()
);
let updated = session
.execute("page.render(title)", "app.main")