fix(downloads): harden enqueue lifecycle races

Reject superseded enqueue generations in the queue manager and coordinate frontend dispatch, pause, removal, and property mutations.
This commit is contained in:
NimBold
2026-07-10 00:04:21 +03:30
parent fbb89cde8e
commit b1c84a0fb9
13 changed files with 471 additions and 158 deletions
+15
View File
@@ -101,6 +101,21 @@ async fn push_appends_to_pending_and_emits_queued() {
assert_eq!(order, vec!["a".to_string(), "b".to_string()]);
}
#[tokio::test]
async fn cancelled_enqueue_generation_cannot_register_after_a_newer_user_action() {
let (mgr, _spawner) = make_manager(2);
mgr.cancel_enqueue_generation("a", 4).await;
let stale = mgr.push_with_generation(sample_task("a"), 4).await;
assert!(stale.is_err(), "cancelled generation must not enter the queue");
assert!(!mgr.is_registered("a").await);
mgr.push_with_generation(sample_task("a"), 5)
.await
.expect("newer generation should be accepted");
assert_eq!(mgr.pending_order(None).await, vec!["a".to_string()]);
}
#[tokio::test]
async fn release_permit_is_idempotent() {
let (mgr, _spawner) = make_manager(2);