poi-tracker 0.15.0

Package-of-interest tracker for Fedora, EPEL, and CentOS SIGs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! `triage-retired` subcommand.
//!
//! For each package in the inventory, check whether it's retired
//! on the configured dist-git branch (a `dead.package` file
//! present on that branch). Retired packages have no live spec
//! to update, so any open release-monitoring bug filed against
//! that branch can be closed as `CANTFIX`.

use std::collections::BTreeMap;

use sandogasa_bugzilla::BzClient;
use sandogasa_bugzilla::models::Bug;
use sandogasa_distgit::DistGitClient;
use sandogasa_inventory::Inventory;

/// Anitya / the-new-hotness reporter address.
pub const RELEASE_MONITORING_REPORTER: &str = "upstream-release-monitoring@fedoraproject.org";

/// One planned bug close.
#[derive(Debug, Clone)]
pub struct BugClose {
    pub bug_id: u64,
    pub component: String,
    /// Dist-git branch whose retirement justifies the closure.
    pub branch: String,
    pub summary: String,
    pub current_status: String,
}

/// Per-package outcome from planning.
#[derive(Debug)]
pub enum PackageOutcome {
    /// The package is still live on this branch — nothing to do.
    NotRetired,
    /// Retired, but no open release-monitoring bugs for this
    /// branch.
    RetiredNoBugs,
    /// One or more bugs queued for closure.
    RetiredClose(Vec<BugClose>),
}

/// Decide what to do for one package on one branch: which (if
/// any) open bugs to close. Pure function over the dist-git check
/// + fetched bug list so it's easy to unit-test.
pub fn plan_package(package: &str, branch: &str, retired: bool, bugs: &[Bug]) -> PackageOutcome {
    if !retired {
        return PackageOutcome::NotRetired;
    }
    let opens: Vec<BugClose> = bugs
        .iter()
        .filter(|b| b.status != "CLOSED")
        .map(|b| BugClose {
            bug_id: b.id,
            component: package.to_string(),
            branch: branch.to_string(),
            summary: b.summary.clone(),
            current_status: b.status.clone(),
        })
        .collect();
    if opens.is_empty() {
        PackageOutcome::RetiredNoBugs
    } else {
        PackageOutcome::RetiredClose(opens)
    }
}

/// Build the Bugzilla product + version pair to scope the search
/// to bugs filed against the dist-git branch being retired.
///
/// Conventions: `rawhide` maps to product `Fedora` / version
/// `rawhide`; anything starting with `epel` maps to `Fedora EPEL`
/// / `<branch>`; everything else maps to `Fedora` / `<branch>`
/// (so an `f43` branch retirement still narrows correctly).
pub fn product_version_for_branch(branch: &str) -> (&'static str, String) {
    if branch.starts_with("epel") {
        ("Fedora EPEL", branch.to_string())
    } else {
        ("Fedora", branch.to_string())
    }
}

/// Build the Bugzilla search query for retired-package triage:
/// the component's open bugs against the retirement branch's
/// product/version pair. By default the search is scoped to
/// release-monitoring bugs (the Anitya / the-new-hotness bot);
/// with `all_reporters` the reporter filter is dropped so every
/// open bug on the retired branch is matched, regardless of who
/// filed it.
pub fn bug_search_query(component: &str, branch: &str, all_reporters: bool) -> String {
    let (product, version) = product_version_for_branch(branch);
    let mut parts = vec![
        format!("component={}", urlencode(component)),
        format!("product={}", urlencode(product)),
        format!("version={}", urlencode(&version)),
    ];
    if !all_reporters {
        parts.push(format!(
            "reporter={}",
            urlencode(RELEASE_MONITORING_REPORTER)
        ));
    }
    parts.push("bug_status=__open__".to_string());
    parts.join("&")
}

fn urlencode(s: &str) -> String {
    let mut out = String::with_capacity(s.len());
    for b in s.bytes() {
        match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                out.push(b as char);
            }
            _ => out.push_str(&format!("%{b:02X}")),
        }
    }
    out
}

/// Print one package's planned closures as soon as they're
/// known, so a long inventory run gives live feedback instead of
/// accumulating everything to a final block.
pub fn print_package_closes(component: &str, closes: &[BugClose]) {
    println!("{component} ({} bug(s)):", closes.len());
    for c in closes {
        println!(
            "  bug {} [{}] ({}): {}",
            c.bug_id, c.current_status, c.branch, c.summary
        );
    }
}

/// From a component's batch-mode bug list, keep only the bugs
/// filed against `branch` (matched via the same product/version
/// mapping the per-branch query uses).
pub fn bugs_for_branch(bugs: &[Bug], branch: &str) -> Vec<Bug> {
    let (product, version) = product_version_for_branch(branch);
    bugs.iter()
        .filter(|b| b.product == product && b.version.iter().any(|v| v == &version))
        .cloned()
        .collect()
}

/// Retry an async fallible operation a few times, sleeping a
/// little longer between each attempt. Used for transient
/// network failures from Pagure / Bugzilla — the failure
/// message includes the operation label so users can see what's
/// being retried.
pub async fn retry<F, Fut, T, E>(
    label: &str,
    attempts: usize,
    mut f: F,
    verbose: bool,
) -> Result<T, E>
where
    F: FnMut() -> Fut,
    Fut: std::future::Future<Output = Result<T, E>>,
    E: std::fmt::Display,
{
    let mut last: Option<E> = None;
    for attempt in 1..=attempts {
        match f().await {
            Ok(v) => return Ok(v),
            Err(e) => {
                if attempt < attempts {
                    let backoff = 1u64 << (attempt - 1).min(4); // 1, 2, 4, 8s
                    if verbose {
                        eprintln!(
                            "[poi-tracker] {label} attempt {attempt}/{attempts} failed: {e}; \
                             retrying in {backoff}s"
                        );
                    }
                    tokio::time::sleep(std::time::Duration::from_secs(backoff)).await;
                }
                last = Some(e);
            }
        }
    }
    Err(last.expect("loop ran at least once"))
}

/// Default number of attempts for transient-network retries.
pub const RETRY_ATTEMPTS: usize = 3;

/// The comment body added when closing a retired-package bug.
pub fn close_comment(package: &str, branch: &str) -> String {
    format!(
        "Package `{package}` is retired on the `{branch}` dist-git \
         branch (the `dead.package` marker is present); closing as \
         CANTFIX since there's no live package to update."
    )
}

/// One `(package, branch)` retirement check performed during a
/// run, retained so `--mark` can record the results in the
/// inventory afterwards.
#[derive(Debug, Clone)]
pub struct BranchCheck {
    pub package: String,
    pub branch: String,
    pub retired: bool,
}

/// Apply branch-check results to the inventory's `retired_on`
/// markers: a checked-and-retired branch is added, a
/// checked-and-live branch removed (so un-retirement heals the
/// marker). Branches that weren't checked this run are left
/// alone. Returns how many packages changed.
pub fn apply_retirement_marks(inventory: &mut Inventory, checks: &[BranchCheck]) -> usize {
    let mut changed = 0usize;
    for pkg in &mut inventory.package {
        let mut branches = pkg.retired_on.clone().unwrap_or_default();
        let mut touched = false;
        for check in checks.iter().filter(|c| c.package == pkg.name) {
            touched = true;
            if check.retired {
                if !branches.contains(&check.branch) {
                    branches.push(check.branch.clone());
                }
            } else {
                branches.retain(|b| b != &check.branch);
            }
        }
        if !touched {
            continue;
        }
        branches.sort();
        branches.dedup();
        let new = (!branches.is_empty()).then_some(branches);
        if new != pkg.retired_on {
            pkg.retired_on = new;
            changed += 1;
        }
    }
    changed
}

/// Summary returned from `run` so the caller can pick an exit
/// code without re-counting.
#[derive(Debug, Default)]
pub struct RunReport {
    pub packages_checked: usize,
    pub packages_retired: usize,
    pub closes_planned: usize,
    pub closes_applied: usize,
    pub failures: usize,
    /// Every retirement check performed, for `--mark`.
    pub checks: Vec<BranchCheck>,
}

/// Run the whole `triage-retired` flow.
#[allow(clippy::too_many_arguments)]
pub async fn run(
    inventory: &Inventory,
    bz: &BzClient,
    dg: &DistGitClient,
    branches: &[String],
    all_reporters: bool,
    filter: &crate::WalkFilterArgs,
    batch_email: Option<&str>,
    claim: bool,
    claim_email: Option<&str>,
    dry_run: bool,
    yes: bool,
    verbose: bool,
) -> Result<RunReport, String> {
    let mut all_closes: Vec<BugClose> = Vec::new();
    let mut packages_checked = 0usize;
    let mut packages_retired = 0usize;
    let mut checks: Vec<BranchCheck> = Vec::new();

    // Batch mode: one Bugzilla query up front for every open bug
    // assigned to or CC'ing the email, matched locally against
    // (package, branch) — instead of one query per retired
    // package per branch. Honors --all-reporters by dropping the
    // reporter filter from the query.
    let batch_bugs: Option<BTreeMap<String, Vec<Bug>>> = match batch_email {
        Some(email) => {
            if verbose {
                eprintln!("[poi-tracker] batch: querying bugs for {email}");
            }
            let query = crate::triage_updates::batch_bug_query(email, all_reporters);
            let bugs = retry(
                "batch bug search",
                RETRY_ATTEMPTS,
                || bz.search(&query, 0),
                verbose,
            )
            .await
            .map_err(|e| format!("Bugzilla batch search: {e}"))?;
            Some(crate::triage_updates::group_bugs_by_component(bugs))
        }
        None => None,
    };

    for pkg in &inventory.package {
        if !filter.matches(&pkg.name) {
            continue;
        }
        packages_checked += 1;
        // Each package is checked on every requested branch; a
        // package retired on one branch but live on another only
        // gets its bugs closed for the branch(es) where it's dead.
        let mut pkg_closes: Vec<BugClose> = Vec::new();
        let mut retired_anywhere = false;
        for branch in branches {
            if verbose {
                eprintln!(
                    "[poi-tracker] {}: checking retirement on {branch}",
                    pkg.name
                );
            }
            let retired = retry(
                &format!("is_retired({}, {branch})", pkg.name),
                RETRY_ATTEMPTS,
                || dg.is_retired(&pkg.name, branch),
                verbose,
            )
            .await
            .map_err(|e| format!("dist-git is_retired for {} on {branch}: {e}", pkg.name))?;
            checks.push(BranchCheck {
                package: pkg.name.clone(),
                branch: branch.clone(),
                retired,
            });
            if !retired {
                continue;
            }
            retired_anywhere = true;

            let bugs = match &batch_bugs {
                Some(map) => map
                    .get(&pkg.name)
                    .map(|all| bugs_for_branch(all, branch))
                    .unwrap_or_default(),
                None => {
                    if verbose {
                        eprintln!(
                            "[poi-tracker] {}: retired on {branch}, searching open bugs",
                            pkg.name
                        );
                    }
                    let query = bug_search_query(&pkg.name, branch, all_reporters);
                    retry(
                        &format!("bug search for {} on {branch}", pkg.name),
                        RETRY_ATTEMPTS,
                        || bz.search(&query, 0),
                        verbose,
                    )
                    .await
                    .map_err(|e| format!("Bugzilla search for {} on {branch}: {e}", pkg.name))?
                }
            };
            match plan_package(&pkg.name, branch, true, &bugs) {
                PackageOutcome::NotRetired => unreachable!("retired check passed above"),
                PackageOutcome::RetiredNoBugs => {
                    if verbose {
                        eprintln!(
                            "[poi-tracker] {}: retired on {branch} but no open bugs to close",
                            pkg.name
                        );
                    }
                }
                PackageOutcome::RetiredClose(closes) => pkg_closes.extend(closes),
            }
        }
        if retired_anywhere {
            packages_retired += 1;
        }
        if !pkg_closes.is_empty() {
            print_package_closes(&pkg.name, &pkg_closes);
            all_closes.extend(pkg_closes);
        }
    }

    if all_closes.is_empty() {
        println!("No retired packages with open release-monitoring bugs.");
    } else {
        print_tally(&all_closes);
    }

    let mut report = RunReport {
        packages_checked,
        packages_retired,
        closes_planned: all_closes.len(),
        closes_applied: 0,
        failures: 0,
        checks,
    };

    if all_closes.is_empty() {
        return Ok(report);
    }
    if dry_run {
        eprintln!("\n(dry-run: not applying)");
        return Ok(report);
    }
    // Offer to claim ownership before the main confirm so the
    // user sees one prompt-then-confirm flow. With `--claim`,
    // skip the prompt. With `-y` and no `--claim`, don't claim.
    // Without a configured email there's nothing to assign to,
    // so just skip silently.
    let want_claim = if claim {
        claim_email.is_some()
    } else if yes || claim_email.is_none() {
        false
    } else {
        confirm(&format!(
            "Also claim ownership (assigned_to = {})?",
            claim_email.unwrap()
        ))?
    };
    let active_claim_email = if want_claim {
        let e = claim_email.unwrap();
        eprintln!("claiming ownership as {e}");
        Some(e.to_string())
    } else {
        None
    };

    if !yes && !confirm(&format!("\nClose {} bug(s) as CANTFIX?", all_closes.len()))? {
        eprintln!("aborted.");
        return Ok(report);
    }

    for c in &all_closes {
        let mut body = serde_json::json!({
            "status": "CLOSED",
            "resolution": "CANTFIX",
            "comment": { "body": close_comment(&c.component, &c.branch) },
        });
        if let Some(ref email) = active_claim_email {
            body["assigned_to"] = serde_json::json!(email);
        }
        match bz.update(c.bug_id, &body).await {
            Ok(()) => {
                report.closes_applied += 1;
                eprintln!(
                    "closed bug {} ({}): {} -> CLOSED/CANTFIX",
                    c.bug_id, c.component, c.current_status
                );
            }
            Err(e) => {
                report.failures += 1;
                eprintln!("error: bug {} ({}): {e}", c.bug_id, c.component);
            }
        }
    }
    Ok(report)
}

/// One-line-per-package recap printed after the loop, so the
/// reader can scan everything that's about to be closed (or that
/// was just closed) without scrolling back through the live
/// per-package blocks.
fn print_tally(closes: &[BugClose]) {
    let mut by_pkg: BTreeMap<&str, Vec<&BugClose>> = BTreeMap::new();
    for c in closes {
        by_pkg.entry(c.component.as_str()).or_default().push(c);
    }
    println!(
        "\nTotal: {} closure(s) across {} package(s):",
        closes.len(),
        by_pkg.len()
    );
    for (pkg, bugs) in &by_pkg {
        let ids: Vec<String> = bugs
            .iter()
            .map(|b| format!("rhbz#{} ({})", b.bug_id, b.branch))
            .collect();
        println!("  {pkg}: {}", ids.join(", "));
    }
}

fn confirm(prompt: &str) -> Result<bool, String> {
    use std::io::{BufRead, Write};
    eprint!("{prompt} [y/N]: ");
    std::io::stderr().flush().map_err(|e| e.to_string())?;
    let mut line = String::new();
    std::io::stdin()
        .lock()
        .read_line(&mut line)
        .map_err(|e| e.to_string())?;
    Ok(line.trim().eq_ignore_ascii_case("y"))
}

#[cfg(test)]
mod tests {
    use super::*;

    fn make_bug(id: u64, status: &str, summary: &str) -> Bug {
        serde_json::from_value(serde_json::json!({
            "id": id,
            "summary": summary,
            "status": status,
            "resolution": "",
            "product": "Fedora",
            "component": ["foo"],
            "severity": "unspecified",
            "priority": "unspecified",
            "assigned_to": "nobody@fedoraproject.org",
            "creator": RELEASE_MONITORING_REPORTER,
            "creation_time": "2026-01-01T00:00:00Z",
            "last_change_time": "2026-01-01T00:00:00Z",
        }))
        .unwrap()
    }

    #[test]
    fn plan_skips_live_packages() {
        let outcome = plan_package("foo", "rawhide", false, &[make_bug(1, "NEW", "x")]);
        assert!(matches!(outcome, PackageOutcome::NotRetired));
    }

    #[test]
    fn plan_no_bugs_when_retired_with_empty_search() {
        let outcome = plan_package("foo", "rawhide", true, &[]);
        assert!(matches!(outcome, PackageOutcome::RetiredNoBugs));
    }

    #[test]
    fn plan_closes_only_open_bugs_when_retired() {
        let bugs = vec![
            make_bug(1, "NEW", "foo 1.0 available"),
            make_bug(2, "ASSIGNED", "foo 0.9 available"),
            // The query filters to open already, but a defensive
            // check guards against a stray CLOSED slipping in.
            make_bug(3, "CLOSED", "foo 0.8 available"),
        ];
        let outcome = plan_package("foo", "epel9", true, &bugs);
        match outcome {
            PackageOutcome::RetiredClose(closes) => {
                assert_eq!(closes.len(), 2);
                let ids: Vec<u64> = closes.iter().map(|c| c.bug_id).collect();
                assert_eq!(ids, vec![1, 2]);
                // Each close is tagged with the branch it's for.
                assert!(closes.iter().all(|c| c.branch == "epel9"));
            }
            other => panic!("expected RetiredClose, got {other:?}"),
        }
    }

    #[test]
    fn product_version_picks_epel_for_epel_branches() {
        assert_eq!(
            product_version_for_branch("epel10"),
            ("Fedora EPEL", "epel10".to_string())
        );
        assert_eq!(
            product_version_for_branch("epel9"),
            ("Fedora EPEL", "epel9".to_string())
        );
    }

    #[test]
    fn product_version_picks_fedora_for_rawhide_and_fnn() {
        assert_eq!(
            product_version_for_branch("rawhide"),
            ("Fedora", "rawhide".to_string())
        );
        assert_eq!(
            product_version_for_branch("f43"),
            ("Fedora", "f43".to_string())
        );
    }

    #[test]
    fn bug_search_query_scopes_to_branch() {
        let q = bug_search_query("python-django6", "epel10", false);
        assert!(q.contains("component=python-django6"));
        assert!(q.contains("product=Fedora%20EPEL"));
        assert!(q.contains("version=epel10"));
        assert!(q.contains("bug_status=__open__"));
        assert!(q.contains("reporter=upstream-release-monitoring%40fedoraproject.org"));

        let q = bug_search_query("foo", "rawhide", false);
        assert!(q.contains("product=Fedora&"));
        assert!(q.contains("version=rawhide"));
    }

    #[test]
    fn bug_search_query_all_reporters_drops_reporter_filter() {
        let q = bug_search_query("python-django3", "epel8", true);
        assert!(q.contains("component=python-django3"));
        assert!(q.contains("product=Fedora%20EPEL"));
        assert!(q.contains("version=epel8"));
        assert!(q.contains("bug_status=__open__"));
        // No reporter scoping — every open bug on the branch matches.
        assert!(!q.contains("reporter="));
    }

    #[test]
    fn close_comment_mentions_package_and_branch() {
        let c = close_comment("python-django6", "epel10");
        assert!(c.contains("python-django6"));
        assert!(c.contains("epel10"));
        assert!(c.contains("CANTFIX"));
    }

    // ---- apply_retirement_marks ----

    fn check(package: &str, branch: &str, retired: bool) -> BranchCheck {
        BranchCheck {
            package: package.to_string(),
            branch: branch.to_string(),
            retired,
        }
    }

    fn inventory_with(packages: &[(&str, Option<Vec<&str>>)]) -> Inventory {
        let mut toml =
            String::from("[inventory]\nname = \"t\"\ndescription = \"t\"\nmaintainer = \"t\"\n");
        for (name, retired_on) in packages {
            toml.push_str(&format!("\n[[package]]\nname = \"{name}\"\n"));
            if let Some(branches) = retired_on {
                let list: Vec<String> = branches.iter().map(|b| format!("\"{b}\"")).collect();
                toml.push_str(&format!("retired_on = [{}]\n", list.join(", ")));
            }
        }
        toml::from_str(&toml).unwrap()
    }

    #[test]
    fn apply_marks_adds_retired_branches_sorted() {
        let mut inv = inventory_with(&[("foo", None)]);
        let changed = apply_retirement_marks(
            &mut inv,
            &[check("foo", "rawhide", true), check("foo", "epel8", true)],
        );
        assert_eq!(changed, 1);
        assert_eq!(
            inv.package[0].retired_on,
            Some(vec!["epel8".to_string(), "rawhide".to_string()])
        );
    }

    #[test]
    fn apply_marks_removes_unretired_branch_and_clears_empty() {
        // Un-retirement heals the marker; an emptied list drops
        // the field entirely.
        let mut inv = inventory_with(&[("foo", Some(vec!["rawhide"]))]);
        let changed = apply_retirement_marks(&mut inv, &[check("foo", "rawhide", false)]);
        assert_eq!(changed, 1);
        assert_eq!(inv.package[0].retired_on, None);
    }

    #[test]
    fn apply_marks_leaves_unchecked_branches_alone() {
        let mut inv = inventory_with(&[("foo", Some(vec!["epel8"]))]);
        let changed = apply_retirement_marks(&mut inv, &[check("foo", "rawhide", true)]);
        assert_eq!(changed, 1);
        assert_eq!(
            inv.package[0].retired_on,
            Some(vec!["epel8".to_string(), "rawhide".to_string()])
        );
    }

    #[test]
    fn apply_marks_no_change_counts_zero() {
        let mut inv = inventory_with(&[("foo", Some(vec!["rawhide"])), ("bar", None)]);
        // foo already marked; bar not checked at all.
        let changed = apply_retirement_marks(&mut inv, &[check("foo", "rawhide", true)]);
        assert_eq!(changed, 0);
        assert_eq!(inv.package[1].retired_on, None);
    }

    #[test]
    fn bugs_for_branch_filters_by_product_and_version() {
        let mut rawhide = make_bug(1, "NEW", "foo 1.0 is available");
        rawhide.version = vec!["rawhide".to_string()];
        let mut epel8 = make_bug(2, "NEW", "foo 1.0 is available");
        epel8.product = "Fedora EPEL".to_string();
        epel8.version = vec!["epel8".to_string()];
        let bugs = vec![rawhide, epel8];

        let on_rawhide = bugs_for_branch(&bugs, "rawhide");
        assert_eq!(on_rawhide.len(), 1);
        assert_eq!(on_rawhide[0].id, 1);

        let on_epel8 = bugs_for_branch(&bugs, "epel8");
        assert_eq!(on_epel8.len(), 1);
        assert_eq!(on_epel8[0].id, 2);

        assert!(bugs_for_branch(&bugs, "epel9").is_empty());
    }
}