Merge remote-tracking branch 'origin/issue/265-supersede-failure' into blitz/download-visibility

This commit is contained in:
Miguel Palhas
2026-08-26 12:55:20 +01:00
2 changed files with 58 additions and 2 deletions
+56
View File
@@ -1698,6 +1698,18 @@ async fn season_import_failures(
WHERE f.owner_kind = 'episode' AND f.owner_id = e.id
)
)
-- A later attempt owns the headline while it is still in
-- flight. Keep the failed grab recorded; it is simply no
-- longer the current explanation for the gap.
AND NOT EXISTS (
SELECT 1 FROM grabs newer
WHERE newer.target_kind = 'season'
AND newer.target_id = g.target_id
AND newer.state != 'failed'
AND (newer.grabbed_at > coalesce(g.failed_at, g.grabbed_at)
OR (newer.grabbed_at = coalesce(g.failed_at, g.grabbed_at)
AND newer.id > g.id))
)
ORDER BY coalesce(g.failed_at, g.grabbed_at), g.id"#,
series_id
)
@@ -2103,6 +2115,7 @@ mod tests {
/// season read `0/10` with nothing anywhere saying a grab had been tried.
/// The season row, its deck and the deck's blacklisted release now each
/// carry the failure and the reason it failed on.
#[allow(clippy::too_many_lines)]
#[tokio::test]
async fn an_abandoned_pack_is_visible_on_the_season_and_its_deck() {
let (_dir, state, base) = application().await;
@@ -2161,6 +2174,49 @@ mod tests {
.await
.expect("failed pack grab");
// A newer attempt supersedes the old failure while it is in flight.
let newer_name = "Rick.And.Morty.S08.720p.WEB-DL.x264-NEW";
let newer_release_id = sqlx::query_scalar::<_, i64>(
"INSERT INTO releases (indexer_id, guid, name, size, download_url, parsed, verdict)
VALUES (7, 'new-pack', ?, 1000, 'url', ?, 'eligible') RETURNING id",
)
.bind(newer_name)
.bind(serde_json::to_string(&parsed).expect("parsed json"))
.fetch_one(pool)
.await
.expect("newer release");
sqlx::query(
"INSERT INTO grabs (release_id, target_kind, target_id, infohash, state, grabbed_at)
VALUES (?, 'season', ?, 'new123', 'sent', '2026-01-03T00:00:00.000Z')",
)
.bind(newer_release_id)
.bind(season_id)
.execute(pool)
.await
.expect("newer in-flight grab");
let seasons = seasons_json(&base, series_id).await;
assert!(
seasons[0]["import_failure"].is_null(),
"a newer in-flight grab supersedes the old failure"
);
let pack_state: serde_json::Value = reqwest::get(format!(
"{base}/api/series/{series_id}/seasons/8/pack-state"
))
.await
.expect("pack state")
.json()
.await
.expect("pack state json");
assert!(
pack_state["import_failure"].is_null(),
"the pack-state endpoint uses the same supersession rule"
);
sqlx::query("DELETE FROM grabs WHERE infohash = 'new123'")
.execute(pool)
.await
.expect("remove test attempt");
// The failure with no blacklist row yet: still a failure, and the
// reason is simply not known. Rows written before the blacklist
// carried one read this way and must keep rendering.