Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor: simplify action window naming

ldm0c5868a5e2000
diff --git a/moli-action-window/src/tests.rs b/moli-action-window/src/tests.rs
index 4988d93cb..5caed78a4 100644
--- a/moli-action-window/src/tests.rs
+++ b/moli-action-window/src/tests.rs
@@ -457,7 +457,7 @@ fn cancel_scope_keeps_other_scope_and_original_deadline() {
window.push(SCOPE_A, click(10.0), at(base, 100));
window.push(SCOPE_B, scroll(20.0), at(base, 200));
- assert_eq!(window.cancel_scope(&SCOPE_A), 2);
+ assert_eq!(window.cancel_scope(&SCOPE_A).len(), 2);
assert_eq!(window.next_deadline(), Some(at(base, 1_000)));
assert_eq!(window.pending_retained_action_count(), 1);
let batch = window.take_due(at(base, 1_000)).expect("scope B batch");
@@ -470,8 +470,8 @@ fn canceling_last_scope_returns_to_idle() {
let mut window = default_window();
window.push(SCOPE_A, scroll(10.0), base);
- assert_eq!(window.cancel_scope(&SCOPE_A), 1);
- assert_eq!(window.cancel_scope(&SCOPE_A), 0);
+ assert_eq!(window.cancel_scope(&SCOPE_A).len(), 1);
+ assert!(window.cancel_scope(&SCOPE_A).is_empty());
assert!(window.is_idle());
assert_eq!(window.next_deadline(), None);
}
@@ -484,7 +484,7 @@ fn canceling_an_intervening_scope_normalizes_scroll_runs() {
window.push(SCOPE_B, ordered("separator"), at(base, 100));
window.push(SCOPE_A, scroll(20.0), at(base, 200));
- assert_eq!(window.cancel_scope(&SCOPE_B), 1);
+ assert_eq!(window.cancel_scope(&SCOPE_B).len(), 1);
assert_eq!(window.pending_planned_action_count(), 1);
let batch = window.take_due(at(base, 1_000)).expect("batch");
assert_eq!(scroll_deltas(&batch.actions()[0]), vec![10.0, 20.0]);
diff --git a/moli-action-window/src/window.rs b/moli-action-window/src/window.rs
index 5f622afbf..f461ef982 100644
--- a/moli-action-window/src/window.rs
+++ b/moli-action-window/src/window.rs
@@ -340,20 +340,13 @@ impl<S: PartialEq, O> ActionWindow<S, O> {
.map(|window| window.into_batch(now, ActionBatchCause::Barrier(barrier)))
}
- /// Cancels all pending actions for a scope.
+ /// Cancels all pending actions for a scope and returns their retained
+ /// sequences in execution order.
///
/// If no actions remain, the old deadline is canceled and the queue
- /// returns to idle.
- pub fn cancel_scope(&mut self, scope: &S) -> usize {
- self.cancel_scope_sequences(scope).len()
- }
-
- /// Cancels all pending actions for a scope and returns the retained
- /// sequences that were removed, in their execution order.
- ///
- /// Hosts with renderer-specific sidecars can use these identities to
- /// retire the matching payloads atomically with the semantic actions.
- pub fn cancel_scope_sequences(&mut self, scope: &S) -> Vec<ActionSequence> {
+ /// returns to idle. Hosts can use the returned identities to retire
+ /// matching sidecar payloads at the same boundary.
+ pub fn cancel_scope(&mut self, scope: &S) -> Vec<ActionSequence> {
let Some(window) = self.open.as_mut() else {
return Vec::new();
};
diff --git a/moli-action-window/tests/public_api.rs b/moli-action-window/tests/public_api.rs
index 3d545c13d..6243885ae 100644
--- a/moli-action-window/tests/public_api.rs
+++ b/moli-action-window/tests/public_api.rs
@@ -163,7 +163,7 @@ fn canceling_unknown_scope_is_a_noop_and_preserves_deadline() {
);
let deadline = window.next_deadline();
- assert_eq!(window.cancel_scope(&"missing".to_owned()), 0);
+ assert!(window.cancel_scope(&"missing".to_owned()).is_empty());
assert_eq!(window.next_deadline(), deadline);
assert_eq!(window.pending_admitted_action_count(), 1);
assert_eq!(window.pending_retained_action_count(), 1);
@@ -171,7 +171,7 @@ fn canceling_unknown_scope_is_a_noop_and_preserves_deadline() {
}
#[test]
-fn scope_cancellation_reports_retained_sequences_for_host_sidecar_cleanup() {
+fn cancel_scope_returns_retained_sequences() {
let base = Instant::now();
let mut window = ActionWindow::<&str, &str>::default();
let first_scroll = window.push(
@@ -202,7 +202,7 @@ fn scope_cancellation_reports_retained_sequences_for_host_sidecar_cleanup() {
let original_deadline = window.next_deadline();
assert_eq!(
- window.cancel_scope_sequences(&"retired"),
+ window.cancel_scope(&"retired"),
vec![
first_scroll.sequence(),
retained_click.sequence(),
diff --git a/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs b/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
index 0fe9f4eb8..9c064b7fb 100644
--- a/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
@@ -132,7 +132,7 @@ impl PageVm {
replacement.to == self.document_lifecycle.identity(),
"Document replacement admission targets a non-current identity"
);
- self.cancel_page_actions_for_document(replacement.from)?;
+ self.retire_document_actions(replacement.from)?;
}
let ready_admission =
diff --git a/moli-renderer-v8/src/runtime/page_vm/page_action_window.rs b/moli-renderer-v8/src/runtime/page_vm/page_action_window.rs
index a7a6ca048..dbb1b2051 100644
--- a/moli-renderer-v8/src/runtime/page_vm/page_action_window.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/page_action_window.rs
@@ -128,14 +128,11 @@ impl PageVm {
Ok(true)
}
- pub(super) fn cancel_page_actions_for_document(
+ pub(super) fn retire_document_actions(
&mut self,
document: RendererDocumentLifecycleIdentity,
- ) -> Result<usize> {
- let sequences = self
- .page_action_window
- .window
- .cancel_scope_sequences(&document);
+ ) -> Result<()> {
+ let sequences = self.page_action_window.window.cancel_scope(&document);
for sequence in &sequences {
anyhow::ensure!(
self.page_action_window
@@ -153,7 +150,7 @@ impl PageVm {
"canceled renderer actions for a retired Document"
);
}
- Ok(sequences.len())
+ Ok(())
}
fn apply_page_action_batch(
@@ -162,7 +159,7 @@ impl PageVm {
) -> Result<()> {
let batch_id = batch.id().get();
let cause = batch.cause();
- let current_document = self.document_lifecycle.identity();
+ let batch_document = self.document_lifecycle.identity();
let mut events = Vec::with_capacity(batch.retained_action_count());
for action in batch.into_actions() {
match action {
@@ -178,7 +175,7 @@ impl PageVm {
step.sequence().get()
)
})?;
- if scope == current_document {
+ if scope == batch_document {
events.push((scope, event));
}
}
@@ -197,10 +194,10 @@ impl PageVm {
self.vm_mut().begin_batched_mouse_event_dispatch();
let mut first_error = None;
- let mut skipped_after_document_replacement = 0_usize;
+ let mut skipped_events = 0_usize;
for (document, event) in events {
if self.document_lifecycle.identity() != document {
- skipped_after_document_replacement += 1;
+ skipped_events += 1;
continue;
}
let result = self
@@ -223,18 +220,18 @@ impl PageVm {
first_error = Some(error);
}
}
- if skipped_after_document_replacement != 0 {
+ if skipped_events != 0 {
tracing::debug!(
batch_id,
- skipped_action_count = skipped_after_document_replacement,
+ skipped_action_count = skipped_events,
"discarded remaining renderer actions after an in-batch Document replacement"
);
}
let dispatch_result = first_error.map_or(Ok(()), Err);
- let commit_scroll_effects = self.document_lifecycle.identity() == current_document;
+ let document_unchanged = self.document_lifecycle.identity() == batch_document;
let result = self
.vm_mut()
- .finish_batched_mouse_event_dispatch(dispatch_result, commit_scroll_effects);
+ .finish_batched_mouse_event_dispatch(dispatch_result, document_unchanged);
tracing::debug!(batch_id, ?cause, "applied renderer action batch");
result
}
@@ -253,7 +250,7 @@ impl PageVm {
}
#[cfg(test)]
- pub(super) fn pending_page_action_counts_for_test(&self) -> (usize, usize) {
+ pub(super) fn pending_action_counts_for_test(&self) -> (usize, usize) {
(
self.page_action_window
.window
diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs b/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
index 2a9ff9bab..94741ed09 100644
--- a/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
@@ -53,7 +53,7 @@ fn stale_domcontentloaded_barrier_preserves_current_document_frontend_bindings()
}
#[tokio::test]
-async fn action_window_is_preserved_for_same_document_history_and_canceled_on_document_open() {
+async fn history_keeps_action_window_but_document_open_cancels_it() {
run_page_vm_async_test(async move {
let page_vm = test_page_vm();
let local_executor = page_vm.local_executor.clone();
@@ -74,13 +74,12 @@ async fn action_window_is_preserved_for_same_document_history_and_canceled_on_do
0,
)?;
assert!(outcome.handled);
- let original_deadline = page_vm
+ let deadline = page_vm
.next_action_window_deadline()
.expect("the first wheel should open an action window");
- assert_eq!(page_vm.pending_page_action_counts_for_test(), (1, 1));
+ assert_eq!(page_vm.pending_action_counts_for_test(), (1, 1));
- let same_document_snapshot =
- page_vm.document_replacement_lifecycle_action_snapshot();
+ let history_snapshot = page_vm.document_replacement_lifecycle_action_snapshot();
assert_eq!(
page_vm
.vm_mut()
@@ -91,7 +90,7 @@ async fn action_window_is_preserved_for_same_document_history_and_canceled_on_do
assert!(
page_vm
.reconcile_document_replacement_lifecycle_after_owner_action(
- same_document_snapshot,
+ history_snapshot,
&mut pending_document_lifecycle_turn,
)
.await?
@@ -100,27 +99,27 @@ async fn action_window_is_preserved_for_same_document_history_and_canceled_on_do
assert_eq!(page_vm.document_lifecycle.identity(), initial_document);
assert_eq!(
page_vm.next_action_window_deadline(),
- Some(original_deadline),
+ Some(deadline),
"same-Document history must retain the existing action window"
);
- assert_eq!(page_vm.pending_page_action_counts_for_test(), (1, 1));
+ assert_eq!(page_vm.pending_action_counts_for_test(), (1, 1));
- let replacement_snapshot = page_vm.document_replacement_lifecycle_action_snapshot();
+ let open_snapshot = page_vm.document_replacement_lifecycle_action_snapshot();
assert_eq!(
page_vm.vm_mut().eval("document.open(); 'opened'")?,
"opened"
);
- let replacement_document = page_vm.document_lifecycle.identity();
+ let opened_document = page_vm.document_lifecycle.identity();
assert_eq!(
- replacement_document.document, initial_document.document,
+ opened_document.document, initial_document.document,
"document.open keeps the cross-document token generation"
);
assert_ne!(
- replacement_document.epoch, initial_document.epoch,
+ opened_document.epoch, initial_document.epoch,
"document.open must still create a new exact Document lifecycle"
);
assert_eq!(
- page_vm.pending_page_action_counts_for_test(),
+ page_vm.pending_action_counts_for_test(),
(1, 1),
"cancellation belongs to the owner lifecycle reconciliation boundary"
);
@@ -128,7 +127,7 @@ async fn action_window_is_preserved_for_same_document_history_and_canceled_on_do
assert!(
page_vm
.reconcile_document_replacement_lifecycle_after_owner_action(
- replacement_snapshot,
+ open_snapshot,
&mut pending_document_lifecycle_turn,
)
.await?
@@ -137,7 +136,7 @@ async fn action_window_is_preserved_for_same_document_history_and_canceled_on_do
);
assert_eq!(page_vm.next_action_window_deadline(), None);
assert_eq!(
- page_vm.pending_page_action_counts_for_test(),
+ page_vm.pending_action_counts_for_test(),
(0, 0),
"retiring the exact Document must remove semantic actions and host payloads"
);
diff --git a/moli-renderer-v8/src/runtime/tests.rs b/moli-renderer-v8/src/runtime/tests.rs
index 2d0e260f2..706213bdd 100644
--- a/moli-renderer-v8/src/runtime/tests.rs
+++ b/moli-renderer-v8/src/runtime/tests.rs
@@ -12663,7 +12663,7 @@ addEventListener("wheel", event => {
}
#[tokio::test(flavor = "multi_thread")]
-async fn wheel_batch_stops_when_an_event_replaces_the_exact_document() {
+async fn wheel_batch_stops_on_document_replacement() {
let runtime = initialize_layout_test_runtime();
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default())
.expect("default resource request client");
@@ -12675,15 +12675,15 @@ async fn wheel_batch_stops_when_an_event_replaces_the_exact_document() {
r#"<!doctype html>
<style>html, body { margin: 0; } body { height: 1200px; }</style>
<script>
-globalThis.__lmRetiredDocumentWheelDeltas = [];
-globalThis.__lmReplacementDocumentWheelDeltas = [];
+globalThis.__lmRetiredDeltas = [];
+globalThis.__lmReplacementDeltas = [];
document.addEventListener("wheel", event => {
- __lmRetiredDocumentWheelDeltas.push(event.deltaY);
+ __lmRetiredDeltas.push(event.deltaY);
document.open();
document.write("<!doctype html><body style='height:1200px'>replacement</body>");
document.close();
document.addEventListener("wheel", replacementEvent => {
- __lmReplacementDocumentWheelDeltas.push(replacementEvent.deltaY);
+ __lmReplacementDeltas.push(replacementEvent.deltaY);
}, { capture: true });
}, { capture: true, once: true });
</script>"#,
@@ -12701,8 +12701,8 @@ document.addEventListener("wheel", event => {
let (state, _) = page
.run_async_command(RendererPageCommand::EvaluateExpression {
expression: r#"JSON.stringify({
- retired: __lmRetiredDocumentWheelDeltas,
- replacement: __lmReplacementDocumentWheelDeltas
+ retired: __lmRetiredDeltas,
+ replacement: __lmReplacementDeltas
})"#
.to_owned(),
await_promise: false,
diff --git a/moli-renderer-v8/src/script_vm/input_dispatch.rs b/moli-renderer-v8/src/script_vm/input_dispatch.rs
index fbe70cce5..50b42a868 100644
--- a/moli-renderer-v8/src/script_vm/input_dispatch.rs
+++ b/moli-renderer-v8/src/script_vm/input_dispatch.rs
@@ -386,13 +386,13 @@ impl ScriptVm {
pub(crate) fn finish_batched_mouse_event_dispatch(
&mut self,
dispatch_result: Result<()>,
- commit_scroll_observable_effects: bool,
+ commit_effects: bool,
) -> Result<()> {
let effects = self
._context_host
.borrow_mut()
.finish_scroll_observable_effect_batch();
- let effects_result = match effects.filter(|_| commit_scroll_observable_effects) {
+ let effects_result = match effects.filter(|_| commit_effects) {
Some(effects) => self.with_default_context_scope(|scope, runtime_ptr| {
crate::native_bridge::element::apply_scroll_observable_effects(
scope,