492
pub status_after: Option<String>,
493
}
494
495
+/// The post-commit outcome, given the status after the wait and the versions
496
+/// the Store reports (empty when they could not be read). Returns the versions
497
+/// worth reporting, or `None` when the result is not known yet, or an error on
498
+/// a genuine version mismatch after the commit.
499
+///
500
+/// While the status is still `CommitStarted` the new package is not ingested,
501
+/// so any versions the Store reports are the pre-commit ones. The outcome is
502
+/// unknown then, never a mismatch.
503
+fn post_commit_check(
504
+ id: &str,
505
+ current: &str,
506
+ after_versions: Vec<String>,
507
+ expected: Option<&str>,
508
+) -> Result<Option<Vec<String>>, String> {
509
+ if current == "CommitStarted" {
510
+ return Ok(None);
511
+ }
512
+ if let Some(expected) = expected {
513
+ if !after_versions.is_empty() && !after_versions.iter().any(|v| v == expected) {
514
+ return Err(format!(
515
+ "submission {id} was committed (status {current}) but carries package versions [{}], not {expected}",
516
+ after_versions.join(", ")
517
+ ));
518
+ }
519
+ }
520
+ Ok((!after_versions.is_empty()).then_some(after_versions))
521
+}
522
+
523
/// Commit the pending submission to certification.
524
///
525
/// Fails closed before writing when there is no pending submission or, with
587
));
588
}
589
if current != "CommitStarted" || std::time::Instant::now() >= deadline {
562
- // The Store has ingested the packages by now, so `version` is
563
- // there and the strict comparison applies. An empty list means
564
- // the wait ran out first: unknown, not a mismatch.
565
- let after = client.get_submission(product_id, &id).await.map_err(err)?;
566
- let after_versions = package_versions(&after);
567
- if let Some(expected) = expect_package_version {
568
- if !after_versions.is_empty() && !after_versions.iter().any(|v| v == expected) {
569
- return Err(format!(
570
- "submission {id} was committed (status {current}) but carries package versions [{}], not {expected}",
571
- after_versions.join(", ")
572
- ));
590
+ // Still CommitStarted means the wait ran out before ingestion, so
591
+ // the Store has no post-commit versions yet and there is nothing
592
+ // to read or check. Once it has left CommitStarted the packages
593
+ // are ingested and `version` is authoritative; the commit already
594
+ // succeeded, so a failed read here is reported as unknown, not as
595
+ // a commit failure.
596
+ let after_versions = if current == "CommitStarted" {
597
+ Vec::new()
598
+ } else {
599
+ match client.get_submission(product_id, &id).await {
600
+ Ok(after) => package_versions(&after),
601
+ Err(_) => return Ok(result(false, Some(current), None)),
602
}
574
- }
575
- let reported = (!after_versions.is_empty()).then_some(after_versions);
603
+ };
604
+ let reported =
605
+ post_commit_check(&id, ¤t, after_versions, expect_package_version)?;
606
return Ok(result(false, Some(current), reported));
607
}
608
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
675
assert!(check_expected_version(&submission(), "1.3.1.0").is_err());
676
}
677
678
+ #[test]
679
+ fn still_committing_reports_unknown_not_a_mismatch() {
680
+ // The deadline ran out while an older package version is carried over
681
+ // and the new one is not ingested yet: unknown, never a false
682
+ // mismatch, and nothing stale reported as the post-commit result.
683
+ let r = post_commit_check(
684
+ "s1",
685
+ "CommitStarted",
686
+ vec!["1.3.1.0".into()],
687
+ Some("1.3.2.0"),
688
+ );
689
+ assert_eq!(r, Ok(None));
690
+ }
691
+
692
+ #[test]
693
+ fn ingested_versions_are_checked_strictly_after_the_commit() {
694
+ assert_eq!(
695
+ post_commit_check(
696
+ "s1",
697
+ "PreProcessing",
698
+ vec!["1.3.2.0".into()],
699
+ Some("1.3.2.0")
700
+ ),
701
+ Ok(Some(vec!["1.3.2.0".into()]))
702
+ );
703
+ let wrong = post_commit_check(
704
+ "s1",
705
+ "PreProcessing",
706
+ vec!["1.3.1.0".into()],
707
+ Some("1.3.2.0"),
708
+ )
709
+ .unwrap_err();
710
+ assert!(wrong.contains("was committed") && wrong.contains("not 1.3.2.0"));
711
+ }
712
+
713
+ #[test]
714
+ fn an_unreadable_post_commit_version_list_is_unknown() {
715
+ // Empty means the extra read failed or returned nothing; don't call
716
+ // that a mismatch.
717
+ assert_eq!(
718
+ post_commit_check("s1", "PreProcessing", vec![], Some("1.3.2.0")),
719
+ Ok(None)
720
+ );
721
+ assert_eq!(
722
+ post_commit_check("s1", "PreProcessing", vec!["1.3.2.0".into()], None),
723
+ Ok(Some(vec!["1.3.2.0".into()]))
724
+ );
725
+ }
726
+
727
#[test]
728
fn only_committed_statuses_are_past_commit() {
729
for s in ["CommitStarted", "PreProcessing", "Certification", "Release"] {