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
15 changes: 13 additions & 2 deletions pkgs/fleet/crates/fleet-queue/src/queue_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,16 @@ fn dispatch(st: &State, path: &str, req: &Value) -> Value {
};
let offset =
crate::client::list_offset_or_default(req.get("offset").and_then(|o| o.as_i64()));
// #9420 parity with the Turso verb_list: omit the queue
// predicate when no queue is named (queue=eq. with an
// empty value matches nothing and breaks exact readback).
let queue_pred = if queue.is_empty() {
String::new()
} else {
format!("&queue=eq.{}", quote(queue, ""))
};
let mut path = format!(
"tasks?select={select}&queue=eq.{}&order=priority.asc,created_at.asc,id.asc&limit={limit}&offset={offset}",
quote(queue, "")
"tasks?select={select}{queue_pred}&order=priority.asc,created_at.asc,id.asc&limit={limit}&offset={offset}"
);
// #7871: --task narrows to one task id, so a worker can
// verify a single recent completion from list output
Expand All @@ -1196,6 +1203,10 @@ fn dispatch(st: &State, path: &str, req: &Value) -> Value {
if let Some(s) = req.get("status").and_then(|s| s.as_str()) {
path += &format!("&status=eq.{}", quote(s, ""));
}
// #9420: dedupe_key narrows to the task carrying that key.
if let Some(d) = req.get("dedupe_key").and_then(|d| d.as_str()) {
path += &format!("&dedupe_key=eq.{}", quote(d, ""));
}
if let Some(nb) = req.get("not_before").and_then(|s| s.as_str()) {
path += &format!("&or=(not_before.is.null,not_before.lte.{})", quote(nb, ":"));
}
Expand Down
48 changes: 46 additions & 2 deletions pkgs/fleet/crates/fleet-queue/src/turso_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6424,8 +6424,16 @@ fn verb_list(t: &TursoBackend, req: &Value) -> Value {
} else {
"id, queue, title, priority, status, dedupe_key, created_at, not_before, platform"
};
let mut sql = format!("SELECT {select} FROM tasks WHERE queue = ?");
let mut args: Vec<Arg> = vec![Arg::Text(queue)];
// #9420: the queue predicate applies only when a queue is named;
// an unnamed queue must not become `queue = ''`, which by
// construction returns zero rows and breaks exact-task readback
// ({"task": id} / {"dedupe_key": key} with no queue).
let mut sql = format!("SELECT {select} FROM tasks WHERE 1 = 1");
let mut args: Vec<Arg> = vec![];
if !queue.is_empty() {
sql += " AND queue = ?";
args.push(Arg::Text(queue));
}
if let Some(s) = req_str(req, "status") {
sql += " AND status = ?";
args.push(Arg::Text(s.to_string()));
Expand All @@ -6451,6 +6459,12 @@ fn verb_list(t: &TursoBackend, req: &Value) -> Value {
sql += " AND id = ?";
args.push(Arg::Int(id));
}
// #9420: dedupe_key narrows to the task carrying that key (the
// delivery publisher's enqueue readback verifies by dedupe key).
if let Some(d) = req_str(req, "dedupe_key") {
sql += " AND dedupe_key = ?";
args.push(Arg::Text(d.to_string()));
}
let offset = crate::client::list_offset_or_default(req_i64(req, "offset"));
sql += &format!(
" ORDER BY (priority IS NULL), priority ASC, created_at ASC, id ASC LIMIT {limit} OFFSET {offset}"
Expand Down Expand Up @@ -7762,6 +7776,36 @@ mod tests {
);
}

#[test]
fn list_exact_readback_filters_9420() {
// #9420 oracle: exact-task readback works on the Turso
// verb_list — the task filter, a dedupe_key filter, and a
// queue predicate that applies only when a queue is named (an
// unnamed queue must not degenerate into queue = ''). The
// PostgREST /list handler carries the same contract.
let src = include_str!("turso_queue.rs");
let seg = seg8217(src, "fn verb_list(", "\nfn verb_health");
assert!(seg.contains("req_i64(req, \"task\")"), "task filter present");
assert!(seg.contains("AND id = ?"), "task filter narrows by id");
assert!(
seg.contains("req_str(req, \"dedupe_key\")") && seg.contains("AND dedupe_key = ?"),
"dedupe_key filter present"
);
assert!(
seg.contains("if !queue.is_empty()"),
"queue predicate is conditional on a named queue"
);
let broker = include_str!("queue_broker.rs");
assert!(
broker.contains("dedupe_key=eq."),
"PostgREST /list applies the dedupe_key filter"
);
assert!(
broker.contains("queue_pred"),
"PostgREST /list omits the queue predicate when unnamed"
);
}

#[test]
fn stack_storage_wiring_8582() {
// Source oracle for increment 2 of #8582: the schema applies
Expand Down