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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async fn a_second_close_waits_for_the_browser_to_finish_closing() {
.expect("second close follows the first")
.unwrap()
.unwrap();
assert!(browser.list_sessions().await.unwrap().is_empty());
assert_eq!(
browser.list_sessions().await.unwrap(),
Vec::<tinycomputer_bus::browser::SessionInfo>::new()
);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion crates/tinycomputer-engine/src/task/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ mod redaction_tests {
let candidate = &screen.candidates[0];
assert_eq!(candidate.name.as_deref(), Some("[hidden] action"));
assert_eq!(candidate.path, ["[hidden] parent"]);
assert!(candidate.states.is_empty());
assert_eq!(candidate.states, Vec::<String>::new());
assert!(candidate.value.as_ref().is_some_and(|value| {
value["[hidden]"] == "[hidden]" && value["[hidden]#2"] == "[hidden]"
}));
Expand Down
18 changes: 11 additions & 7 deletions crates/tinycomputer-engine/src/task/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ impl Tasks {
facts: Facts,
request: &StartTaskRequest,
) -> Option<Arc<Cell>> {
let number = self
.counter
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |value| {
value.checked_add(1)
})
.ok()?
.checked_add(1)?;
let number = loop {
let current = self.counter.load(Ordering::Relaxed);
let number = current.checked_add(1)?;
if self
.counter
.compare_exchange_weak(current, number, Ordering::Relaxed, Ordering::Relaxed)
.is_ok()
{
break number;
}
};
let id = TaskId::new(format!("t-{number}"));
let usage = Arc::new(UsageRecorder::default());
let view = TaskView {
Expand Down
35 changes: 23 additions & 12 deletions crates/tinycomputer-engine/src/task/task_tests/persistence_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,9 @@ async fn process_local_screenshot_handles_are_dropped_from_snapshots() {
..
}
));
assert!(
restored
.report(&imported.id)
.data
.unwrap()
.artifacts
.is_empty()
assert_eq!(
restored.report(&imported.id).data.unwrap().artifacts,
Vec::<tinycomputer_bus::browser::OutputRef>::new()
);
}

Expand Down Expand Up @@ -453,7 +449,10 @@ async fn import_rejects_unknown_versions_and_inconsistent_pending_state() {
.unwrap_err();
assert!(std::error::Error::source(&malformed).is_some());
assert!(malformed.to_string().contains("paused-task JSON"));
assert!(fresh.list().data.unwrap().is_empty());
assert_eq!(
fresh.list().data.unwrap(),
Vec::<tinycomputer_bus::agent::TaskView>::new()
);
}

#[tokio::test]
Expand All @@ -475,7 +474,10 @@ async fn import_refuses_invalid_ids_duplicate_tasks_and_unmatched_approval_state
.import_paused_task(&serde_json::to_vec(&invalid_id).unwrap())
.is_err()
);
assert!(fresh.list().data.unwrap().is_empty());
assert_eq!(
fresh.list().data.unwrap(),
Vec::<tinycomputer_bus::agent::TaskView>::new()
);

let (tasks, _) = controller(vec![gated_for_persistence("Send", "sending the email")]);
let view = start(
Expand All @@ -493,7 +495,10 @@ async fn import_refuses_invalid_ids_duplicate_tasks_and_unmatched_approval_state
.import_paused_task(&serde_json::to_vec(&malformed).unwrap())
.is_err()
);
assert!(fresh.list().data.unwrap().is_empty());
assert_eq!(
fresh.list().data.unwrap(),
Vec::<tinycomputer_bus::agent::TaskView>::new()
);
}

#[tokio::test]
Expand Down Expand Up @@ -548,7 +553,10 @@ fn task_id_allocator_refuses_to_wrap() {
..StartTaskRequest::default()
});
assert_eq!(code(&reply), "TOO_MANY_TASKS");
assert!(tasks.list().data.unwrap().is_empty());
assert_eq!(
tasks.list().data.unwrap(),
Vec::<tinycomputer_bus::agent::TaskView>::new()
);
}

#[tokio::test]
Expand Down Expand Up @@ -611,7 +619,10 @@ async fn persistence_refuses_secret_leaks_and_host_bound_browser_endpoints() {
fresh.import_paused_task(&serde_json::to_vec(&endpoint_snapshot).unwrap()),
Err(crate::PausedTaskError::HostBoundEndpoint)
));
assert!(fresh.list().data.unwrap().is_empty());
assert_eq!(
fresh.list().data.unwrap(),
Vec::<tinycomputer_bus::agent::TaskView>::new()
);
}

fn gated_for_persistence(target: &str, phrase: &str) -> DesktopResponse {
Expand Down
12 changes: 9 additions & 3 deletions crates/tinycomputer-engine/src/task/task_tests/plan_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ async fn a_payment_checkpoint_consumes_prefix_handoff_without_planning() {
.unwrap()
.handoff_to_planner
);
assert!(journaled(&script, "plan").is_empty());
assert_eq!(
journaled(&script, "plan"),
Vec::<(Option<TaskId>, serde_json::Value)>::new()
);
}

#[tokio::test]
Expand Down Expand Up @@ -420,8 +423,11 @@ async fn a_failed_prefix_does_not_handoff_to_planning() {
settle(&tasks, &started.id).await.status,
TaskStatus::Failed { .. }
));
assert!(script.requests.lock().unwrap().len() == 1);
assert!(journaled(&script, "plan").is_empty());
assert_eq!(script.requests.lock().unwrap().len(), 1);
assert_eq!(
journaled(&script, "plan"),
Vec::<(Option<TaskId>, serde_json::Value)>::new()
);
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion crates/tinycomputer/tests/public_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn the_crate_re_exports_the_contract_rather_than_redefining_it() {
#[test]
fn the_shipped_contract_binds_to_itself() {
assert!(is_compatible(CONTRACT_VERSION));
assert_eq!(CONTRACT_VERSION, (2, 22));
assert_eq!(CONTRACT_VERSION, (2, 24));
}

#[test]
Expand Down
Loading