feat: notify Endor objects of mount lifecycle transitions
Verify Tessera GUI / verify (push) Failing after 7m23s

This commit is contained in:
2026-10-21 02:29:46 +08:00
parent 8886bdbd2d
commit d2f167e71f
10 changed files with 373 additions and 49 deletions
+154 -3
View File
@@ -312,7 +312,7 @@ impl ReplSession {
pub fn execute(&mut self, source: &str, namespace: &str) -> Result<ReplResult> {
if self.faulted {
bail!(
"runtime stopped after an event failure; reset the session or replace its program"
"runtime stopped after a callback or rendering failure; reset the session or replace its program"
);
}
if source.len() > MAX_SOURCE_BYTES {
@@ -492,7 +492,7 @@ impl ReplSession {
pub fn dispatch(&mut self, input: &crate::events::Input) -> Result<ReplResult> {
if self.faulted {
bail!("runtime stopped after an event failure");
bail!("runtime stopped after a callback or rendering failure");
}
if input.session != self.id {
bail!("event belongs to another runtime session");
@@ -576,7 +576,7 @@ impl Drop for Candidate {
}
}
fn runtime_error(vm: &Vm, error: VmError) -> anyhow::Error {
pub(crate) fn runtime_error(vm: &Vm, error: VmError) -> anyhow::Error {
let locations = vm
.last_traceback()
.iter()
@@ -795,6 +795,157 @@ mod tests {
const EXAMPLE: &str = include_str!("../examples/hello.endor");
const PAGE: &str = include_str!("../examples/page.endor");
#[test]
fn mount_hooks_run_per_occurrence_settle_and_unmount_before_parent() {
let (mut session, initial) = ReplSession::load(
include_str!("../examples/mount-lifecycle.endor"),
"app.main",
51,
1,
)
.unwrap();
initial.validate().unwrap();
for (expression, expected) in [
("log.mounted.value", "2"),
("log.parentMounted", "1"),
("log.childMounted", "3"),
] {
assert_eq!(
session.execute(expression, "app.main").unwrap().value,
expected
);
}
session
.execute(
"saved = child.mounts().at(0)\nchild.setColor(\"#237A45\")",
"app.main",
)
.unwrap();
assert_eq!(
session
.execute("log.mounted.value", "app.main")
.unwrap()
.value,
"2"
);
let closed = session
.execute("page.close()", "app.main")
.unwrap()
.document
.unwrap();
assert!(closed.frame.mounts.is_empty());
assert_eq!(
session
.execute("log.unmounted.value", "app.main")
.unwrap()
.value,
"2"
);
assert_eq!(
session
.execute("log.childUnmounted", "app.main")
.unwrap()
.value,
"5"
);
assert_eq!(
session
.execute("log.parentUnmounted", "app.main")
.unwrap()
.value,
"6"
);
assert_eq!(
session.execute("saved.mounted", "app.main").unwrap().value,
"false"
);
assert!(session.execute("saved.bounds()", "app.main").is_err());
session.execute("page.open()", "app.main").unwrap();
assert_eq!(
session
.execute("log.mounted.value", "app.main")
.unwrap()
.value,
"4"
);
assert_eq!(
session.execute("saved.mounted", "app.main").unwrap().value,
"false"
);
}
#[test]
fn page_switch_replaces_mount_context_even_for_shared_root() {
let (mut session, _) = ReplSession::load(
include_str!("../examples/mount-lifecycle.endor"),
"app.main",
52,
1,
)
.unwrap();
session
.execute(
"saved = child.mounts().at(0)\nsecond = Page()\nsecond.render(root)",
"app.main",
)
.unwrap();
assert_eq!(
session
.execute("log.mounted.value", "app.main")
.unwrap()
.value,
"4"
);
assert_eq!(
session
.execute("log.unmounted.value", "app.main")
.unwrap()
.value,
"2"
);
assert_eq!(
session.execute("saved.mounted", "app.main").unwrap().value,
"false"
);
assert_eq!(
session
.execute("child.mounts().at(0).page()", "app.main")
.unwrap()
.value,
session.execute("second", "app.main").unwrap().value
);
session.execute("page.activate()", "app.main").unwrap();
assert_eq!(
session
.execute("log.mounted.value", "app.main")
.unwrap()
.value,
"6"
);
}
#[test]
fn lifecycle_hook_can_edit_container_without_session_lock_and_failure_stops_domain() {
let source = r#"class GrowingColumn: Column {
function onMount(self: GrowingColumn, mount: Mount): Unit { self.append(TextBlock("from hook")) }
}
root = GrowingColumn(0, 0)
page = Page()
page.render(root)"#;
let (_, document) = ReplSession::load(source, "app.main", 53, 1).unwrap();
assert!(document.frame.commands.iter().any(
|command| matches!(command, RenderCommand::Text { value, .. } if value == "from hook")
));
let mut session = ReplSession::new(54).unwrap();
let source = r#"class BrokenText: TextBlock {
function onMount(self: BrokenText, mount: Mount): Unit { self.setText(1) }
}
page = Page()
page.render(BrokenText("x"))"#;
assert!(session.execute(source, "app.main").is_err());
assert!(session.is_faulted());
}
fn event_session(extra: &str) -> (ReplSession, RenderDocument) {
let source = format!("{}\n{}", include_str!("../examples/events.endor"), extra);
ReplSession::load(&source, "app.main", 41, 1).unwrap()