Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Keep one representative journey per user-visible flow; when a long spec carries
While the test holds a request the product will time out, run nothing slow between holding and releasing it, and give every observation poll in that window explicit `intervals`.
Playwright's default poll backoff grows to a second between attempts, which is time taken from the product's deadline.
A process start is slow in that sense: `a_slow_ask_for_one_home_does_not_hold_another_home_behind_it` in `hide-platform/tests/it/programs.rs` started the second home's login shell while it held the first home's ten-second ask, and at load 32 the first ask reached its deadline (issue 859); it now reads the second home's answer before the hold, so the held window starts no process, and counts the shell's starts to show it.
A test does not read through a product budget it is not about: `a_linked_node_s_closed_session_is_analyzed_through_its_link_and_waits_while_it_is_down` in `herdr-core/src/runtime/memory_analysis.rs` asked Memory's hook, whose answer the hook cuts at one second, and under load got none in more than a third of its runs; it asserts the scope the hook would read, and the hook's answer is `memory_hook`'s tests' to hold.

`web/e2e/pane-focus-ordering.spec.ts`'s rapid-click test showed the cost.
It holds the first focus request, whose transport deadline is five seconds, while it sends forty clicks.
Expand All @@ -100,6 +101,12 @@ When the behavior depends on the order of two events, the test fixes that order;
- A test that hands the delivery store its passes itself starts the store alone (`Worker::store`), not with the doorbell and watch producers (`Worker::spawn`), which pass on their own clocks.
The store still passes on its own while a registration move or end is asked for, so the test looks at what an event left under that event's own lock, and stops the store before it compares the ledger file with the published ledger.
`SleepingChild` in `herdr-core/src/runtime/tests/agent_sleep.rs` ran the producers, and in more than fifty recorded Linux CI runs a pass of theirs moved the woken pane's registration between the wake and the test's look; an order such a pass can make is a test of its own there (`a_pass_begun_before_the_wake_keeps_the_record_and_the_next_one_moves_the_registration`).
- An event whose worker answers at once is looked at under the event's own lock: dispatch it and read what it left (`loading`, `checking`) before releasing, or the answer may already have replaced it (`runtime/tests/ssh_hosts.rs`, `runtime/tests/inbound.rs`).
- A stand-in for the other side answers only what the test asks of it.
The held node link in `herdr-core/src/runtime/tests/inbound.rs` reaches a Herdr that waits until the link ends, because a socket that never existed was refused at once and the node's session sync then marked the node disconnected after the test had connected it.
A connect that swaps the current Herdr (`HerdrConnectTransition` in `runtime/tests/links.rs`) is taken only by the worker's own thread, because the control lane connects on the same connector beside it.
- A read is a barrier only when nothing else can have published it.
The suggestions worker's tests wait for a pen's own reply (`handled`), not for the next read, because a read an earlier command published could still be waiting, and the clock moved before the wake was taken.
- Before releasing, assert the barrier the race needs, such as the number of accepted requests, so a stale snapshot or an earlier diagnostic cannot satisfy it.
- After releasing, assert the outcome and the boundary's own record (`gate.requests`, `gate.maximum()`), which show the order the product actually saw.
- A race the test cannot order proves nothing either way; find the boundary to gate before writing the assertion.
Expand Down
42 changes: 24 additions & 18 deletions herdr-core/src/runtime/delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ pub(crate) mod tests {
fn only_the_attested_pane_asks_who_it_is() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, target, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -2839,7 +2839,7 @@ pub(crate) mod tests {
fn only_a_prompt_hook_of_the_panes_own_session_is_a_submission() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, target, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -2959,7 +2959,7 @@ pub(crate) mod tests {
fn a_tool_events_ask_hands_a_working_agent_its_due_letters_and_submits_nothing() {
let root = tempfile::tempdir().unwrap();
let (runtime, sender, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3090,7 +3090,7 @@ pub(crate) mod tests {
fn remote_delivery_uses_attested_pane_and_native_kind_without_a_remote_store() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3182,13 +3182,14 @@ pub(crate) mod tests {
assert_eq!(result["sender"]["kind"], "claude");
assert_eq!(result["sender"]["device_id"], "device");
assert_eq!(result["sender"]["pane_id"], caller);
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let stored = crate::delivery::ledger::load(&path).unwrap();
assert_eq!(stored.letters.len(), 1);
assert_eq!(
stored.letters[0].sender.session.as_deref(),
Some("remote-session")
);
drop(worker);
}

/// A core with its own `w1:p2`, `w1:p9` and unnamed `w1:p5`, `w1:p6`, and a
Expand Down Expand Up @@ -3251,7 +3252,7 @@ pub(crate) mod tests {
fn a_bare_pane_id_names_a_pane_on_the_callers_own_machine() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3396,17 +3397,18 @@ pub(crate) mod tests {
.as_deref(),
Some("caller_identity_conflict")
);
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let stored = crate::delivery::ledger::load(&path).unwrap();
assert_eq!(stored.letters.len(), 5);
drop(worker);
}

#[test]
fn a_checkout_bound_caller_is_refused_delivery_and_agent_commands_with_or_without_a_hint() {
let root = tempfile::tempdir().unwrap();
let (runtime, actor, _, path) = fixture(root.path());
let before = std::fs::read(&path).unwrap();
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3488,7 +3490,7 @@ pub(crate) mod tests {
let root = tempfile::tempdir().unwrap();
let (runtime, actor, _, path) = fixture(root.path());
let before = std::fs::read(&path).unwrap();
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3580,7 +3582,7 @@ pub(crate) mod tests {
fn moved_terminal_keeps_registration_letters_and_watch_after_restart() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3626,6 +3628,8 @@ pub(crate) mod tests {
Duration::from_secs(5),
)
.unwrap();
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let persisted = crate::delivery::ledger::load(&path).unwrap();
let child = &persisted.agents[1];
assert_eq!(child.id, "agent-2");
Expand All @@ -3638,7 +3642,6 @@ pub(crate) mod tests {
assert!(persisted.letters[0].recipient.same_identity(&child.actor));
assert!(!child.actor.same_identity(&old_child));
persisted.validate().unwrap();
drop(worker);
}

#[test]
Expand Down Expand Up @@ -3672,7 +3675,7 @@ pub(crate) mod tests {
fn remote_observation_without_a_local_socket_keeps_the_registered_session() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3710,14 +3713,15 @@ pub(crate) mod tests {
Duration::from_secs(5),
)
.unwrap();
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let persisted = crate::delivery::ledger::load(&path).unwrap();
let child = &persisted.agents[1];
assert_eq!(child.actor.pane_id, "remote:device:pane:moved-child");
assert_eq!(child.parent.as_deref(), Some("agent-1"));
assert!(!child.ended);
assert!(persisted.watches[0].target.same_identity(&child.actor));
persisted.validate().unwrap();
drop(worker);
}

fn only_lead() -> SessionSnapshotPayload {
Expand All @@ -3735,7 +3739,7 @@ pub(crate) mod tests {
fn herdr_closing_a_registered_pane_ends_the_registration_and_its_watches() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand All @@ -3755,6 +3759,8 @@ pub(crate) mod tests {
Duration::from_secs(5),
)
.unwrap();
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let persisted = crate::delivery::ledger::load(&path).unwrap();
let ended = |ledger: &Ledger| {
ledger
Expand All @@ -3773,7 +3779,6 @@ pub(crate) mod tests {
assert!(guard.delivery_registrations_gone().is_empty());
assert!(crate::coordination::resolve_actor(&persisted, "child").is_none());
drop(guard);
drop(worker);
}

/// The same close ends the answer wait of a request the closed pane's agent
Expand All @@ -3782,7 +3787,7 @@ pub(crate) mod tests {
fn herdr_closing_a_pane_ends_the_answer_wait_of_the_requests_it_held() {
let root = tempfile::tempdir().unwrap();
let (runtime, _, _, path) = fixture(root.path());
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down Expand Up @@ -3825,6 +3830,8 @@ pub(crate) mod tests {
Duration::from_secs(5),
)
.unwrap();
// Stopped before its file is read: the store passes on its own too.
drop(worker);
let mut persisted = crate::delivery::ledger::load(&path).unwrap();
let shown = crate::delivery::mailbox::apply(
&mut persisted,
Expand All @@ -3840,7 +3847,6 @@ pub(crate) mod tests {
assert!(!persisted.letters[0].open());
// The ended agent can no longer be the one who answers it.
assert!(crate::coordination::resolve_actor(&persisted, &child.name).is_none());
drop(worker);
}

/// A pane read ends only this Herdr's registrations it can vouch for:
Expand Down Expand Up @@ -4036,7 +4042,7 @@ pub(crate) mod tests {
json!({"type":"agent_list","agents":[
native("sender", "writer-session"), native("recipient", "reader-session")]})
});
let (worker, client) = Worker::spawn(
let (worker, client) = Worker::store(
Arc::downgrade(&runtime),
ChangeNotifier::noop(),
path.clone(),
Expand Down
29 changes: 6 additions & 23 deletions herdr-core/src/runtime/memory_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4553,29 +4553,12 @@ mod tests {
scope.store, fixture.database,
"the scope uses the core's single store"
);
let mut store = fixture.store();
let card = store
.item_by_number(&fixture.project_id, 1)
.unwrap()
.unwrap();
store
.confirm_card(&card.id, card.revision, None, &[], 1)
.unwrap();
drop(store);
let ask = crate::memory_hook::Ask::from_wire(
&json!({"runtime":"claude", "event":"SessionStart", "session":"greeting-session"}),
)
.unwrap();
let received = crate::memory_hook::answer(
&scope,
&ask,
std::time::Instant::now() + crate::memory_hook::WITHIN,
);
assert!(
received
.context
.unwrap()
.contains("Keep the hook under 100 ms")
// What a hook reads through the scope is `memory_hook`'s to test;
// read here under the hook's own one-second budget, the answer
// came back empty on a loaded machine.
assert_eq!(
scope.project.id, fixture.project_id,
"the scope names the device's Project"
);
let own = crate::memory_hook::project_identity(
runtime.own_node.as_ref(),
Expand Down
7 changes: 4 additions & 3 deletions herdr-core/src/runtime/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,10 @@ impl Runtime {
}

pub(super) fn confirm_cleanup(&mut self, payload: CleanupConfirmPayload) -> bool {
// A review worker that has published its answer may not have ended
// yet; a confirmation waits for it, so its end can never free the
// lane of the worker this one starts.
// A worker frees the lane under the lock that hands over its answer,
// so a review showing its answer has no worker left; one still
// running refuses, so its end can never free the lane of the worker
// this one starts.
if self.cleanup_worker.is_some() {
return false;
}
Expand Down
Loading
Loading