fix(sql): add ORDER BY to all LIMIT queries for deterministic results
SQLite does not guarantee row order without ORDER BY, even with LIMIT. This was a systemic issue found during a multi-pass bug hunt: Production queries (explain.rs): - Outgoing reference query: ORDER BY target_entity_type, target_entity_iid - Incoming reference query: ORDER BY source_entity_type, COALESCE(iid) Without these, robot mode output was non-deterministic across calls, breaking clients expecting stable ordering. Test helper queries (5 locations across 3 files): - discussions_tests.rs: get_discussion_id() - mr_discussions.rs: get_mr_discussion_id() - queue.rs: setup_db_with_job(), release_all_locked_jobs_clears_locks() Currently safe (single-row inserts) but would break silently if tests expanded to multi-row fixtures.
This commit is contained in:
@@ -786,8 +786,12 @@ mod tests {
|
||||
}
|
||||
|
||||
fn get_mr_discussion_id(conn: &Connection) -> i64 {
|
||||
conn.query_row("SELECT id FROM discussions LIMIT 1", [], |row| row.get(0))
|
||||
.unwrap()
|
||||
conn.query_row(
|
||||
"SELECT id FROM discussions ORDER BY id LIMIT 1",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
Reference in New Issue
Block a user