The shipment preparation service has a small library that builds a text preview of the first N tasks and then confirms the selected tasks in a shared queue. After a recent PR, two symptoms appeared:
A review of the changes is needed to find the causes of the regressions.
Behavior requirements:
preview_batch must not modify the queue and must return a list of id=priority, separated by , , only for tasks with ready status, in the original order, no more than limit items;commit_batch must confirm only the passed ids, increment the committed counter by the number of actually confirmed tasks, and return an error if among the requested ids there is a missing element or an element not in ready status;commit_batch error, the queue state and the counter must not change partially.Given:
cargo test;src/lib.rs, no extra module wiring is required.You need to identify the defects in the PR changes, their consequences, and how to fix them.
Rust 1.85.0, edition 2021. No external crates. Verified locally via cargo test in the standard Cargo test profile. Single-threaded test execution is assumed; Arc<Mutex<...>> is used as a shared-state API model, not to demonstrate races.
Use line comments to explain the problem, its impact, the fix and how to test it.