@@ -849,6 +849,65 @@ mod tests { |
849 | 849 | .to_string() |
850 | 850 | } |
851 | 851 |
|
| 852 | + /// One parked task row in TASK_COLS order with a broker-owned |
| 853 | + /// ready condition, for the #16006 sweeper oracle. Cells are |
| 854 | + /// keyed by column name so a TASK_COLS addition cannot silently |
| 855 | + /// shift the row (same pattern as task_row_13091). |
| 856 | + fn parked_row_16006(id: i64, condition: &Value) -> Value { |
| 857 | + let text = |v: &str| json!({"type": "text", "value": v}); |
| 858 | + let int = |v: i64| json!({"type": "integer", "value": v.to_string()}); |
| 859 | + let null = json!({"type": "null"}); |
| 860 | + let mut cells: std::collections::HashMap<&str, Value> = std::collections::HashMap::new(); |
| 861 | + cells.insert("id", int(id)); |
| 862 | + cells.insert("queue", text("repo-health-code-pilot")); |
| 863 | + cells.insert("title", text("probe")); |
| 864 | + cells.insert("payload", text("{}")); |
| 865 | + cells.insert( |
| 866 | + "dedupe_key", |
| 867 | + text("repo-health:v1:fix:developing-today/code:issue:16006"), |
| 868 | + ); |
| 869 | + cells.insert("priority", int(30)); |
| 870 | + cells.insert("status", text("parked")); |
| 871 | + cells.insert("attempts", int(1)); |
| 872 | + cells.insert("max_attempts", int(1000)); |
| 873 | + cells.insert("progress", text("{}")); |
| 874 | + cells.insert("result", text("{}")); |
| 875 | + cells.insert("park_kind", text("condition")); |
| 876 | + cells.insert("wait_kind", text("condition")); |
| 877 | + cells.insert("ready_condition", text(&condition.to_string())); |
| 878 | + cells.insert("last_checked_at", text("2026-11-20T00:00:00Z")); |
| 879 | + cells.insert("created_at", text("2026-11-20T00:00:00Z")); |
| 880 | + cells.insert("updated_at", text("2026-11-20T00:00:00Z")); |
| 881 | + let cols: Vec<&str> = TASK_COLS.split(", ").map(str::trim).collect(); |
| 882 | + Value::Array( |
| 883 | + cols.iter() |
| 884 | + .map(|c| cells.get(c).cloned().unwrap_or_else(|| null.clone())) |
| 885 | + .collect(), |
| 886 | + ) |
| 887 | + } |
| 888 | + |
| 889 | + fn status_reply_16006(status: &str) -> String { |
| 890 | + json!({"results": [ |
| 891 | + {"type": "ok", "response": {"type": "execute", "result": { |
| 892 | + "cols": [{"name": "status"}], |
| 893 | + "rows": [[{"type": "text", "value": status}]], |
| 894 | + "affected_row_count": 0, "last_insert_rowid": null}}}, |
| 895 | + {"type": "ok", "response": {"type": "close"}} |
| 896 | + ]}) |
| 897 | + .to_string() |
| 898 | + } |
| 899 | + |
| 900 | + fn count_reply_16006(n: i64) -> String { |
| 901 | + json!({"results": [ |
| 902 | + {"type": "ok", "response": {"type": "execute", "result": { |
| 903 | + "cols": [{"name": "n"}], |
| 904 | + "rows": [[{"type": "integer", "value": n.to_string()}]], |
| 905 | + "affected_row_count": 0, "last_insert_rowid": null}}}, |
| 906 | + {"type": "ok", "response": {"type": "close"}} |
| 907 | + ]}) |
| 908 | + .to_string() |
| 909 | + } |
| 910 | + |
852 | 911 | /// A #12744-shaped packet whose payload carries labels, so the |
853 | 912 | /// mirror enrichment (and its backend call) is skipped and the |
854 | 913 | /// first backend call is the dedupe read. |
@@ -3010,6 +3069,99 @@ mod tests { |
3010 | 3069 | ); |
3011 | 3070 | } |
3012 | 3071 |
|
| 3072 | + #[test] |
| 3073 | + fn default_sweep_releases_satisfied_condition_parks_16006() { |
| 3074 | + // #16006 oracle (cherry-picked end-to-end sweep proof offered |
| 3075 | + // on #16022 from branch queue/26155-16006-revalidation-default): |
| 3076 | + // the default scheduled path — /sweep with revalidate and NO |
| 3077 | + // observe_only flag — releases satisfied broker-condition |
| 3078 | + // parks, keeps an unsatisfied one parked, and never releases |
| 3079 | + // a person_answer park (that waits for /wake). The pick |
| 3080 | + // exclusion (#13143) strands these rows without this path. |
| 3081 | + // Reuses the #13091 routed stub (identical wire shape). |
| 3082 | + let parked = task_select_reply_13091(vec![ |
| 3083 | + parked_row_16006(401, &json!({"kind": "task_terminal", "task_id": 100})), |
| 3084 | + parked_row_16006( |
| 3085 | + 402, |
| 3086 | + &json!({"kind": "task_status", "task_id": 200, "status": "blocked"}), |
| 3087 | + ), |
| 3088 | + parked_row_16006( |
| 3089 | + 403, |
| 3090 | + &json!({"kind": "event_seen", "task_id": 300, "event_kind": "wake_ping"}), |
| 3091 | + ), |
| 3092 | + parked_row_16006(404, &json!({"kind": "person_answer"})), |
| 3093 | + ]); |
| 3094 | + // Sweeper call routing: target-status reads answer per |
| 3095 | + // task id (100 done, 200 still queued), the wake-event count |
| 3096 | + // is seen, and every write gets a bare ok. |
| 3097 | + let (url, captured) = stub_pipeline_routed_13091(vec![ |
| 3098 | + ("\"value\":\"100\"", status_reply_16006("done")), |
| 3099 | + ("\"value\":\"200\"", status_reply_16006("queued")), |
| 3100 | + ("FROM events WHERE task_id", count_reply_16006(1)), |
| 3101 | + ("FROM tasks WHERE status = 'parked'", parked), |
| 3102 | + ]); |
| 3103 | + let backend = TursoBackend::new(url, "test".to_string(), ureq::agent()); |
| 3104 | + // No observe_only key: the request exercises the broker |
| 3105 | + // default, which #16006 flips to mutating. |
| 3106 | + let out = verb_sweep( |
| 3107 | + &backend, |
| 3108 | + &json!({ |
| 3109 | + "revalidate": true, |
| 3110 | + "expire": false, |
| 3111 | + "dep_recheck": false, |
| 3112 | + "quarantine_recheck": false, |
| 3113 | + "time_recheck": false, |
| 3114 | + "closed_bound": false, |
| 3115 | + "labels_sync": false, |
| 3116 | + }), |
| 3117 | + ); |
| 3118 | + assert_eq!(out["ok"], true, "{out}"); |
| 3119 | + let rev = &out["row"]["revalidation"]; |
| 3120 | + assert_eq!(out["row"]["observe_only"], false, "{out}"); |
| 3121 | + assert_eq!(rev["released"], 2, "{out}"); |
| 3122 | + assert_eq!(rev["confirmed"], 1, "{out}"); |
| 3123 | + assert_eq!(rev["stale"], 1, "{out}"); |
| 3124 | + assert_eq!(rev["would_release"], 0, "{out}"); |
| 3125 | + // Exactly the two satisfied rows release to queued (401: |
| 3126 | + // terminal task done; 403: wake event seen); the |
| 3127 | + // unsatisfied task_status (402) and the person_answer park |
| 3128 | + // (404) only get their check stamps and stay parked. |
| 3129 | + let bodies = captured.lock().unwrap(); |
| 3130 | + let updates: Vec<&String> = bodies |
| 3131 | + .iter() |
| 3132 | + .filter(|b| b.contains("UPDATE tasks SET")) |
| 3133 | + .collect(); |
| 3134 | + assert_eq!(updates.len(), 4, "{bodies:?}"); |
| 3135 | + let releases: Vec<&&String> = updates |
| 3136 | + .iter() |
| 3137 | + .filter(|b| b.contains("SET status = 'queued'")) |
| 3138 | + .collect(); |
| 3139 | + assert_eq!(releases.len(), 2, "{bodies:?}"); |
| 3140 | + for r in &releases { |
| 3141 | + let v: Value = serde_json::from_str(r).unwrap(); |
| 3142 | + let args = &v["requests"][0]["stmt"]["args"]; |
| 3143 | + let id = args.as_array().unwrap().last().unwrap(); |
| 3144 | + assert!( |
| 3145 | + id["value"] == "401" || id["value"] == "403", |
| 3146 | + "only the satisfied parks release: {r}" |
| 3147 | + ); |
| 3148 | + } |
| 3149 | + let stamps: Vec<&&String> = updates |
| 3150 | + .iter() |
| 3151 | + .filter(|b| !b.contains("SET status = 'queued'")) |
| 3152 | + .collect(); |
| 3153 | + assert_eq!(stamps.len(), 2, "{bodies:?}"); |
| 3154 | + for s in &stamps { |
| 3155 | + let v: Value = serde_json::from_str(s).unwrap(); |
| 3156 | + let args = &v["requests"][0]["stmt"]["args"]; |
| 3157 | + let id = args.as_array().unwrap().last().unwrap(); |
| 3158 | + assert!( |
| 3159 | + id["value"] == "402" || id["value"] == "404", |
| 3160 | + "only the unsatisfied/person parks stamp: {s}" |
| 3161 | + ); |
| 3162 | + } |
| 3163 | + } |
| 3164 | + |
3013 | 3165 | #[test] |
3014 | 3166 | fn dedupe_partition_live_hit_wins_and_terminal_is_newest() { |
3015 | 3167 | let rows = vec![ |
|