forge
Explore
Log in

Don't you dare go Hollow

Store tests share their store and merge into tables

Browse files at this commit

7a15066c93d6e3f6632a9146dc339159838db412Ahmet Kaan GümüşParent: 965436c
  • test
    • store tests share their store and merge into tables
Show full message
✅ test: store tests share their store and merge into tables

Test counts per file, before -> after (58 -> 33 in scope):
mirrors 9 -> 5, releases 6 -> 2, repo_listing 5 -> 1, profile_pins 5 -> 1,
advisories 5 -> 3, signatures 4 -> 3, backup_runs 4 -> 3, admin_alerts 2 -> 1,
lfs 2 -> 1, push_recent 2 -> 1, replication 2 -> 1, wiki 2 -> 1,
snippets 4 -> 4, migrate 4 -> 4, contributions 1 -> 1, health 1 -> 1.

Scenarios that ran on a fresh store now share one store, each on its own
repo or owner, with the case label on every assert. No test was deleted
for lack of logic. The persisted snippet visibility and signature status
literals now have explicit checks.
crates/forge-core/src/store/admin_alerts.rsmodified+11 -6
@@ -311,9 +311,7 @@ mod tests {
311311 (store, dir)
312312 }
313313
314- #[tokio::test]
315- async fn an_alert_is_raised_once_until_it_resolves() {
316- let (store, _dir) = store().await;
314+ async fn an_alert_is_raised_once_until_it_resolves(store: &Store) {
317315 assert!(
318316 store
319317 .raise_alert("runner_offline:r1", "runner_offline", "ci-1", "")
@@ -352,9 +350,7 @@ mod tests {
352350 );
353351 }
354352
355- #[tokio::test]
356- async fn events_fire_once_and_are_never_active() {
357- let (store, _dir) = store().await;
353+ async fn events_fire_once_and_are_never_active(store: &Store) {
358354 assert!(
359355 store
360356 .record_alert_event("ci_killed:run1", "ci_killed", "ci-1", "")
@@ -369,4 +365,13 @@ mod tests {
369365 );
370366 assert!(store.active_alerts().await.unwrap().is_empty());
371367 }
368+
369+ // One store serves both. Events run first: they must not be active, and
370+ // the raised alert below would otherwise show up in that empty check.
371+ #[tokio::test]
372+ async fn events_and_raised_alerts_share_one_store() {
373+ let (store, _dir) = store().await;
374+ events_fire_once_and_are_never_active(&store).await;
375+ an_alert_is_raised_once_until_it_resolves(&store).await;
376+ }
372377 }
crates/forge-core/src/store/advisories.rsmodified+70 -55
@@ -575,10 +575,14 @@ mod tests {
575575 (store, repo.id)
576576 }
577577
578+ // Advisories are global, so each block replaces the advisory set it needs
579+ // before scanning. The per-repo alert checks use their own repo.
578580 #[tokio::test]
579- async fn scan_opens_reconciles_and_keeps_dismissed() {
581+ async fn scans_reconcile_alerts_and_replace_per_ecosystem() {
580582 let dir = tempfile::tempdir().unwrap();
581583 let (store, repo) = store_with_repo(&dir).await;
584+
585+ // A scan opens alerts, closes fixed ones, and keeps dismissed ones.
582586 store
583587 .replace_advisories(
584588 "crates.io",
@@ -599,9 +603,14 @@ mod tests {
599603 ScanOutcome {
600604 opened: 2,
601605 fixed: 0
602- }
606+ },
607+ "first scan opens both"
608+ );
609+ assert_eq!(
610+ store.dependency_count(&repo).await.unwrap(),
611+ 2,
612+ "two dependencies"
603613 );
604- assert_eq!(store.dependency_count(&repo).await.unwrap(), 2);
605614
606615 // Upgrading `other` past its fix closes its alert. `old` stays vulnerable.
607616 let second = store
@@ -613,7 +622,8 @@ mod tests {
613622 ScanOutcome {
614623 opened: 0,
615624 fixed: 1
616- }
625+ },
626+ "upgrade closes one"
617627 );
618628 let third = store
619629 .scan_repo(&repo, &[dep("old", "1.0.0")])
@@ -624,36 +634,39 @@ mod tests {
624634 ScanOutcome {
625635 opened: 0,
626636 fixed: 0
627- }
637+ },
638+ "nothing changes"
628639 );
629640
630641 let alerts = store.list_alerts(&repo).await.unwrap();
631- assert_eq!(alerts.len(), 2);
642+ assert_eq!(alerts.len(), 2, "two alerts on the repo");
632643 let open = alerts
633644 .iter()
634645 .find(|a| a.key.advisory_id == "RUSTSEC-1")
635646 .unwrap();
636- assert_eq!(open.state, AlertState::Open);
637- assert_eq!(open.summary, "RUSTSEC-1 summary");
638- assert_eq!(open.severity, "HIGH");
647+ assert_eq!(open.state, AlertState::Open, "open alert");
648+ assert_eq!(open.summary, "RUSTSEC-1 summary", "summary copied");
649+ assert_eq!(open.severity, "HIGH", "severity copied");
639650 let fixed = alerts
640651 .iter()
641652 .find(|a| a.key.advisory_id == "RUSTSEC-2")
642653 .unwrap();
643- assert_eq!(fixed.state, AlertState::Fixed);
654+ assert_eq!(fixed.state, AlertState::Fixed, "fixed alert");
644655
645656 // Dismiss, then a scan keeps it dismissed; a reopen moves it back.
646657 assert!(
647658 store
648659 .set_alert_state(&repo, &open.key, AlertState::Open, AlertState::Dismissed)
649660 .await
650- .unwrap()
661+ .unwrap(),
662+ "dismiss applied"
651663 );
652664 assert!(
653665 !store
654666 .set_alert_state(&repo, &open.key, AlertState::Open, AlertState::Dismissed)
655667 .await
656- .unwrap()
668+ .unwrap(),
669+ "second dismiss is a no-op"
657670 );
658671 let kept = store
659672 .scan_repo(&repo, &[dep("old", "1.0.0")])
@@ -664,34 +677,38 @@ mod tests {
664677 ScanOutcome {
665678 opened: 0,
666679 fixed: 0
667- }
680+ },
681+ "dismissed alert stays put"
668682 );
669683 assert!(
670684 store
671685 .set_alert_state(&repo, &open.key, AlertState::Dismissed, AlertState::Open)
672686 .await
673- .unwrap()
687+ .unwrap(),
688+ "reopen applied"
674689 );
675- }
676690
677- #[tokio::test]
678- async fn fixed_alert_reopens_when_the_match_returns() {
679- let dir = tempfile::tempdir().unwrap();
680- let (store, repo) = store_with_repo(&dir).await;
691+ // A fixed alert reopens when the vulnerable match returns (own repo).
692+ let owner = store.repo_by_id(&repo).await.unwrap().unwrap().owner_id;
693+ let back = store
694+ .create_repo(&owner, "back", "", crate::Visibility::Private, "main")
695+ .await
696+ .unwrap()
697+ .id;
681698 store
682699 .replace_advisories("crates.io", &[advisory("RUSTSEC-3", "back", "2.0.0")])
683700 .await
684701 .unwrap();
685702 store
686- .scan_repo(&repo, &[dep("back", "1.0.0")])
703+ .scan_repo(&back, &[dep("back", "1.0.0")])
687704 .await
688705 .unwrap();
689706 store
690- .scan_repo(&repo, &[dep("back", "2.0.0")])
707+ .scan_repo(&back, &[dep("back", "2.0.0")])
691708 .await
692709 .unwrap();
693710 let again = store
694- .scan_repo(&repo, &[dep("back", "1.0.1")])
711+ .scan_repo(&back, &[dep("back", "1.0.1")])
695712 .await
696713 .unwrap();
697714 assert_eq!(
@@ -699,11 +716,38 @@ mod tests {
699716 ScanOutcome {
700717 opened: 1,
701718 fixed: 0
702- }
719+ },
720+ "the match returns and reopens"
703721 );
704- let alerts = store.list_alerts(&repo).await.unwrap();
705- assert_eq!(alerts.len(), 2);
706- assert_eq!(alerts[0].state, AlertState::Open);
722+ let alerts = store.list_alerts(&back).await.unwrap();
723+ assert_eq!(alerts.len(), 2, "alert count on the back repo");
724+ assert_eq!(alerts[0].state, AlertState::Open, "reopened alert is open");
725+
726+ // Replacing advisories for one ecosystem leaves the others alone.
727+ store
728+ .replace_advisories("crates.io", &[advisory("RUSTSEC-4", "a", "2.0.0")])
729+ .await
730+ .unwrap();
731+ store.replace_advisories("npm", &[]).await.unwrap();
732+ assert_eq!(
733+ store
734+ .advisories_for_package("crates.io", "a")
735+ .await
736+ .unwrap()
737+ .len(),
738+ 1,
739+ "crates.io advisory kept"
740+ );
741+ store
742+ .replace_advisories("crates.io", &[advisory("RUSTSEC-5", "a", "3.0.0")])
743+ .await
744+ .unwrap();
745+ let rows = store
746+ .advisories_for_package("crates.io", "a")
747+ .await
748+ .unwrap();
749+ assert_eq!(rows.len(), 1, "replaced in place");
750+ assert_eq!(rows[0].id, "RUSTSEC-5", "the new advisory");
707751 }
708752
709753 #[tokio::test]
@@ -756,33 +800,4 @@ mod tests {
756800 .unwrap();
757801 assert!(unread.is_empty());
758802 }
759-
760- #[tokio::test]
761- async fn replacing_advisories_is_scoped_to_one_ecosystem() {
762- let dir = tempfile::tempdir().unwrap();
763- let (store, _repo) = store_with_repo(&dir).await;
764- store
765- .replace_advisories("crates.io", &[advisory("RUSTSEC-4", "a", "2.0.0")])
766- .await
767- .unwrap();
768- store.replace_advisories("npm", &[]).await.unwrap();
769- assert_eq!(
770- store
771- .advisories_for_package("crates.io", "a")
772- .await
773- .unwrap()
774- .len(),
775- 1
776- );
777- store
778- .replace_advisories("crates.io", &[advisory("RUSTSEC-5", "a", "3.0.0")])
779- .await
780- .unwrap();
781- let rows = store
782- .advisories_for_package("crates.io", "a")
783- .await
784- .unwrap();
785- assert_eq!(rows.len(), 1);
786- assert_eq!(rows[0].id, "RUSTSEC-5");
787- }
788803 }
crates/forge-core/src/store/backup_runs.rsmodified+27 -21
@@ -228,6 +228,33 @@ mod tests {
228228 #[tokio::test]
229229 async fn start_and_finish_round_trip() {
230230 let (_dir, store) = store().await;
231+
232+ // The repo list starts empty and follows repo creation.
233+ assert!(
234+ store.repo_ids().await.expect("ids").is_empty(),
235+ "no repos yet"
236+ );
237+ let user = store
238+ .create_user("tahinli", None, "hash", false)
239+ .await
240+ .expect("user");
241+ let repo = store
242+ .create_repo(
243+ &user.id,
244+ "demo",
245+ "",
246+ crate::model::Visibility::Private,
247+ "main",
248+ )
249+ .await
250+ .expect("repo");
251+ assert_eq!(
252+ store.repo_ids().await.expect("ids"),
253+ vec![repo.id],
254+ "one repo listed"
255+ );
256+
257+ // A run starts unfinished, then finishes with its outcome.
231258 let id = store
232259 .start_run(RunKind::Backup, RunTrigger::Manual)
233260 .await
@@ -325,25 +352,4 @@ mod tests {
325352 assert_eq!(runs[1].id, ids[1]);
326353 assert_eq!(store.recent_runs(0).await.expect("recent").len(), 1);
327354 }
328-
329- #[tokio::test]
330- async fn repo_ids_lists_every_repo() {
331- let (_dir, store) = store().await;
332- assert!(store.repo_ids().await.expect("ids").is_empty());
333- let user = store
334- .create_user("tahinli", None, "hash", false)
335- .await
336- .expect("user");
337- let repo = store
338- .create_repo(
339- &user.id,
340- "demo",
341- "",
342- crate::model::Visibility::Private,
343- "main",
344- )
345- .await
346- .expect("repo");
347- assert_eq!(store.repo_ids().await.expect("ids"), vec![repo.id]);
348- }
349355 }
crates/forge-core/src/store/lfs.rsmodified+29 -17
@@ -71,30 +71,42 @@ mod tests {
7171 (store, repo.id, user.id)
7272 }
7373
74+ // One store serves both checks. Deleting a repo runs first, so the link
75+ // check below starts from a store with no links at all.
7476 #[tokio::test]
75- async fn links_are_per_repo_and_idempotent() {
77+ async fn lfs_links_per_repo_idempotent_and_removed_with_repo() {
7678 let dir = tempfile::tempdir().unwrap();
77- let (store, repo_id, _) = repo_fixture(&dir).await;
78- assert_eq!(store.lfs_object_size(&repo_id, OID).await.unwrap(), None);
79- assert!(!store.lfs_oid_is_linked(OID).await.unwrap());
79+ let (store, repo_id, user_id) = repo_fixture(&dir).await;
80+
81+ let gone = store
82+ .create_repo(&user_id, "gone", "", Visibility::Public, "main")
83+ .await
84+ .unwrap()
85+ .id;
86+ store.insert_lfs_object(&gone, OID, 3).await.unwrap();
87+ store.delete_repo(&gone).await.unwrap();
88+ assert!(
89+ !store.lfs_oid_is_linked(OID).await.unwrap(),
90+ "delete_repo drops the link"
91+ );
92+
93+ assert_eq!(
94+ store.lfs_object_size(&repo_id, OID).await.unwrap(),
95+ None,
96+ "not linked yet"
97+ );
98+ assert!(
99+ !store.lfs_oid_is_linked(OID).await.unwrap(),
100+ "no link anywhere"
101+ );
80102
81103 store.insert_lfs_object(&repo_id, OID, 12).await.unwrap();
82104 store.insert_lfs_object(&repo_id, OID, 12).await.unwrap();
83105 assert_eq!(
84106 store.lfs_object_size(&repo_id, OID).await.unwrap(),
85- Some(12)
107+ Some(12),
108+ "one link, size kept"
86109 );
87- assert!(store.lfs_oid_is_linked(OID).await.unwrap());
88- }
89-
90- #[tokio::test]
91- async fn delete_repo_removes_lfs_rows() {
92- let dir = tempfile::tempdir().unwrap();
93- let (store, repo_id, _) = repo_fixture(&dir).await;
94- store.insert_lfs_object(&repo_id, OID, 3).await.unwrap();
95-
96- store.delete_repo(&repo_id).await.unwrap();
97-
98- assert!(!store.lfs_oid_is_linked(OID).await.unwrap());
110+ assert!(store.lfs_oid_is_linked(OID).await.unwrap(), "linked");
99111 }
100112 }
crates/forge-core/src/store/mirrors.rsmodified+97 -71
@@ -424,9 +424,21 @@ mod tests {
424424 );
425425 }
426426
427+ async fn add_repo(store: &Store, owner: &User, name: &str) -> Repo {
428+ store
429+ .create_repo(&owner.id, name, "", Visibility::Public, "main")
430+ .await
431+ .unwrap()
432+ }
433+
434+ // Pull and push rules, interval checks, the result/delete path, repo
435+ // deletion and the push-mirror cap share one store. Each block works on
436+ // its own repo so the cases cannot interfere with each other.
427437 #[tokio::test]
428- async fn one_pull_mirror_per_repo() {
429- let (store, _tahinli, repo, _dir) = setup().await;
438+ async fn mirror_rules_and_lifecycle_per_repo() {
439+ let (store, tahinli, repo, _dir) = setup().await;
440+
441+ // One pull mirror per repo; push mirrors are not limited by that slot.
430442 let first = store
431443 .create_mirror(&pull(&repo, "https://a.example/x.git"))
432444 .await
@@ -435,34 +447,105 @@ mod tests {
435447 assert!(first.enabled);
436448 assert_eq!(
437449 store.pull_mirror(&repo.id).await.unwrap().map(|m| m.id),
438- Some(first.id.clone())
450+ Some(first.id.clone()),
451+ "pull slot holds the first mirror"
439452 );
440453 let second = store
441454 .create_mirror(&pull(&repo, "https://b.example/y.git"))
442455 .await;
443- assert!(matches!(second, Err(Error::Conflict(_))), "{second:?}");
444- // Push mirrors are not limited by the pull slot.
456+ assert!(
457+ matches!(second, Err(Error::Conflict(_))),
458+ "second pull: {second:?}"
459+ );
445460 store
446461 .create_mirror(&push(&repo, "https://c.example/z.git"))
447462 .await
448463 .unwrap();
449- assert_eq!(store.list_mirrors(&repo.id).await.unwrap().len(), 2);
450- }
464+ assert_eq!(
465+ store.list_mirrors(&repo.id).await.unwrap().len(),
466+ 2,
467+ "one pull plus one push"
468+ );
451469
452- #[tokio::test]
453- async fn at_most_ten_push_mirrors() {
454- let (store, _tahinli, repo, _dir) = setup().await;
470+ // Intervals: 5 minutes is too short, 0 means manual sync only.
471+ let interval_repo = add_repo(&store, &tahinli, "interval").await;
472+ let too_short = store
473+ .create_mirror(&NewMirror {
474+ interval_minutes: 5,
475+ ..pull(&interval_repo, "https://a.example/x.git")
476+ })
477+ .await;
478+ assert!(
479+ matches!(too_short, Err(Error::Invalid(_))),
480+ "5 minutes: {too_short:?}"
481+ );
482+ let manual = store
483+ .create_mirror(&NewMirror {
484+ interval_minutes: 0,
485+ ..pull(&interval_repo, "https://a.example/x.git")
486+ })
487+ .await
488+ .unwrap();
489+ assert_eq!(manual.interval_minutes, 0, "manual interval kept");
490+
491+ // Recording a result, then deleting the mirror.
492+ let record_repo = add_repo(&store, &tahinli, "record").await;
493+ let m = store
494+ .create_mirror(&pull(&record_repo, "https://a.example/x.git"))
495+ .await
496+ .unwrap();
497+ let next = stamp_after(Duration::from_secs(3600));
498+ store
499+ .record_mirror_result(&m.id, false, Some("boom"), &next)
500+ .await
501+ .unwrap();
502+ let after = store.mirror(&m.id).await.unwrap().unwrap();
503+ assert_eq!(after.last_ok, Some(false), "result recorded");
504+ assert_eq!(after.last_error.as_deref(), Some("boom"), "error recorded");
505+ assert!(after.last_sync_at.is_some(), "sync time recorded");
506+ assert_eq!(after.next_sync_at, next, "next sync recorded");
507+ store.delete_mirror(&m.id).await.unwrap();
508+ assert!(
509+ store.mirror(&m.id).await.unwrap().is_none(),
510+ "mirror deleted"
511+ );
512+ assert!(
513+ matches!(store.delete_mirror(&m.id).await, Err(Error::NotFound)),
514+ "deleting twice is NotFound"
515+ );
516+
517+ // Deleting the repo removes its mirrors.
518+ let gone = add_repo(&store, &tahinli, "gone").await;
519+ let g = store
520+ .create_mirror(&pull(&gone, "https://a.example/x.git"))
521+ .await
522+ .unwrap();
523+ store.delete_repo(&gone.id).await.unwrap();
524+ assert!(
525+ store.mirror(&g.id).await.unwrap().is_none(),
526+ "delete_repo removes mirrors"
527+ );
528+
529+ // The push cap: ten per repo, the eleventh is refused.
530+ let ten = add_repo(&store, &tahinli, "ten").await;
455531 for n in 0..MAX_PUSH_MIRRORS {
456532 store
457- .create_mirror(&push(&repo, &format!("https://h{n}.example/r.git")))
533+ .create_mirror(&push(&ten, &format!("https://h{n}.example/r.git")))
458534 .await
459535 .unwrap();
460536 }
461537 let eleventh = store
462- .create_mirror(&push(&repo, "https://h11.example/r.git"))
538+ .create_mirror(&push(&ten, "https://h11.example/r.git"))
463539 .await;
464- assert!(matches!(eleventh, Err(Error::Invalid(_))), "{eleventh:?}");
465- assert_eq!(store.list_mirrors(&repo.id).await.unwrap().len(), 10);
540+ assert!(
541+ matches!(eleventh, Err(Error::Invalid(_))),
542+ "eleventh push: {eleventh:?}"
543+ );
544+ assert_eq!(
545+ store.list_mirrors(&ten.id).await.unwrap().len(),
546+ 10,
547+ "cap holds"
548+ );
466549 }
467550
468551 #[tokio::test]
@@ -631,61 +714,4 @@ mod tests {
631714 store.schedule_mirror(&future.id, &now).await.unwrap();
632715 assert_eq!(store.due_mirrors(&now, 10).await.unwrap().len(), 3);
633716 }
634-
635- #[tokio::test]
636- async fn record_result_and_delete() {
637- let (store, _tahinli, repo, _dir) = setup().await;
638- let m = store
639- .create_mirror(&pull(&repo, "https://a.example/x.git"))
640- .await
641- .unwrap();
642- let next = stamp_after(Duration::from_secs(3600));
643- store
644- .record_mirror_result(&m.id, false, Some("boom"), &next)
645- .await
646- .unwrap();
647- let after = store.mirror(&m.id).await.unwrap().unwrap();
648- assert_eq!(after.last_ok, Some(false));
649- assert_eq!(after.last_error.as_deref(), Some("boom"));
650- assert!(after.last_sync_at.is_some());
651- assert_eq!(after.next_sync_at, next);
652-
653- store.delete_mirror(&m.id).await.unwrap();
654- assert!(store.mirror(&m.id).await.unwrap().is_none());
655- assert!(matches!(
656- store.delete_mirror(&m.id).await,
657- Err(Error::NotFound)
658- ));
659- }
660-
661- #[tokio::test]
662- async fn interval_is_validated() {
663- let (store, _tahinli, repo, _dir) = setup().await;
664- let too_short = store
665- .create_mirror(&NewMirror {
666- interval_minutes: 5,
667- ..pull(&repo, "https://a.example/x.git")
668- })
669- .await;
670- assert!(matches!(too_short, Err(Error::Invalid(_))));
671- let manual = store
672- .create_mirror(&NewMirror {
673- interval_minutes: 0,
674- ..pull(&repo, "https://a.example/x.git")
675- })
676- .await
677- .unwrap();
678- assert_eq!(manual.interval_minutes, 0);
679- }
680-
681- #[tokio::test]
682- async fn delete_repo_removes_mirrors() {
683- let (store, _tahinli, repo, _dir) = setup().await;
684- let m = store
685- .create_mirror(&pull(&repo, "https://a.example/x.git"))
686- .await
687- .unwrap();
688- store.delete_repo(&repo.id).await.unwrap();
689- assert!(store.mirror(&m.id).await.unwrap().is_none());
690- }
691717 }
crates/forge-core/src/store/profile_pins.rsmodified+72 -47
@@ -146,68 +146,93 @@ mod tests {
146146 .collect()
147147 }
148148
149+ // One store serves every scenario. Each scenario gets its own owner, so
150+ // pin sets and the "repo-N" names never collide.
149151 #[tokio::test]
150- async fn pins_keep_the_order_given_and_replace_the_old_set() {
151- let (store, tahinli, _, _dir) = fixture().await;
152+ async fn profile_pin_rules() {
153+ let (store, tahinli, foreign, _dir) = fixture().await;
154+
155+ // Pins keep the order given and each save replaces the old set.
152156 let ids = make_repos(&store, &tahinli, 3).await;
153157 store
154158 .set_profile_pins(&tahinli, &[ids[2].clone(), ids[0].clone()])
155159 .await
156160 .unwrap();
157- assert_eq!(pinned_names(&store, &tahinli).await, ["repo-2", "repo-0"]);
158-
161+ assert_eq!(
162+ pinned_names(&store, &tahinli).await,
163+ ["repo-2", "repo-0"],
164+ "order kept"
165+ );
159166 store
160167 .set_profile_pins(&tahinli, &[ids[1].clone()])
161168 .await
162169 .unwrap();
163- assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]);
164-
170+ assert_eq!(
171+ pinned_names(&store, &tahinli).await,
172+ ["repo-1"],
173+ "old set replaced"
174+ );
165175 store.set_profile_pins(&tahinli, &[]).await.unwrap();
166- assert!(pinned_names(&store, &tahinli).await.is_empty());
167- }
168-
169- #[tokio::test]
170- async fn more_than_six_pins_is_refused_and_keeps_the_old_pins() {
171- let (store, tahinli, _, _dir) = fixture().await;
172- let ids = make_repos(&store, &tahinli, 7).await;
173- store.set_profile_pins(&tahinli, &ids[..2]).await.unwrap();
174- let too_many = store.set_profile_pins(&tahinli, &ids).await;
175- assert!(matches!(too_many, Err(Error::Invalid(_))));
176- assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0", "repo-1"]);
177- }
178-
179- #[tokio::test]
180- async fn foreign_and_repeated_repos_are_refused_atomically() {
181- let (store, tahinli, foreign, _dir) = fixture().await;
182- let ids = make_repos(&store, &tahinli, 1).await;
183- store.set_profile_pins(&tahinli, &ids[..1]).await.unwrap();
184-
176+ assert!(
177+ pinned_names(&store, &tahinli).await.is_empty(),
178+ "empty clears the pins"
179+ );
180+
181+ // More than six pins is refused and the old pins stay.
182+ let big = store.create_user("big", None, "h", false).await.unwrap();
183+ let ids = make_repos(&store, &big.id, 7).await;
184+ store.set_profile_pins(&big.id, &ids[..2]).await.unwrap();
185+ let too_many = store.set_profile_pins(&big.id, &ids).await;
186+ assert!(
187+ matches!(too_many, Err(Error::Invalid(_))),
188+ "seven pins: {too_many:?}"
189+ );
190+ assert_eq!(
191+ pinned_names(&store, &big.id).await,
192+ ["repo-0", "repo-1"],
193+ "old pins kept"
194+ );
195+
196+ // Foreign and repeated repos are refused atomically.
197+ let strict = store.create_user("strict", None, "h", false).await.unwrap();
198+ let ids = make_repos(&store, &strict.id, 1).await;
199+ store.set_profile_pins(&strict.id, &ids[..1]).await.unwrap();
185200 let stolen = store
186- .set_profile_pins(&tahinli, &[ids[0].clone(), foreign])
201+ .set_profile_pins(&strict.id, &[ids[0].clone(), foreign.clone()])
187202 .await;
188- assert!(matches!(stolen, Err(Error::Invalid(_))));
203+ assert!(
204+ matches!(stolen, Err(Error::Invalid(_))),
205+ "foreign repo: {stolen:?}"
206+ );
189207 let repeated = store
190- .set_profile_pins(&tahinli, &[ids[0].clone(), ids[0].clone()])
208+ .set_profile_pins(&strict.id, &[ids[0].clone(), ids[0].clone()])
191209 .await;
192- assert!(matches!(repeated, Err(Error::Invalid(_))));
193- assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0"]);
194- }
195-
196- #[tokio::test]
197- async fn deleting_a_pinned_repo_removes_its_pin() {
198- let (store, tahinli, _, _dir) = fixture().await;
199- let ids = make_repos(&store, &tahinli, 2).await;
200- store.set_profile_pins(&tahinli, &ids).await.unwrap();
210+ assert!(
211+ matches!(repeated, Err(Error::Invalid(_))),
212+ "repeated repo: {repeated:?}"
213+ );
214+ assert_eq!(
215+ pinned_names(&store, &strict.id).await,
216+ ["repo-0"],
217+ "nothing changed"
218+ );
219+
220+ // Deleting a pinned repo removes its pin.
221+ let gone = store.create_user("gone", None, "h", false).await.unwrap();
222+ let ids = make_repos(&store, &gone.id, 2).await;
223+ store.set_profile_pins(&gone.id, &ids).await.unwrap();
201224 store.delete_repo(&ids[0]).await.unwrap();
202- assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]);
203- }
204-
205- #[tokio::test]
206- async fn owner_repos_by_activity_lists_every_owned_repo() {
207- let (store, tahinli, foreign, _dir) = fixture().await;
208- make_repos(&store, &tahinli, 2).await;
209- let listed = store.owner_repos_by_activity(&tahinli).await.unwrap();
210- assert_eq!(listed.len(), 2);
211- assert!(listed.iter().all(|r| r.id != foreign));
225+ assert_eq!(
226+ pinned_names(&store, &gone.id).await,
227+ ["repo-1"],
228+ "deleted pin removed"
229+ );
230+
231+ // The activity list holds every owned repo and no foreign one.
232+ let active = store.create_user("active", None, "h", false).await.unwrap();
233+ make_repos(&store, &active.id, 2).await;
234+ let listed = store.owner_repos_by_activity(&active.id).await.unwrap();
235+ assert_eq!(listed.len(), 2, "both owned repos listed");
236+ assert!(listed.iter().all(|r| r.id != foreign), "no foreign repo");
212237 }
213238 }
crates/forge-core/src/store/push_recent.rsmodified+8 -8
@@ -116,8 +116,10 @@ mod tests {
116116 (dir, store, tahinli.id, bob.id, demo.id, other.id)
117117 }
118118
119+ // One store serves both checks. The first one needs the store to hold only
120+ // its own pushes, so the "now" push of the second one runs after it.
119121 #[tokio::test]
120- async fn keeps_latest_per_branch_and_skips_deletions_and_others() {
122+ async fn recent_branch_pushes_rules_and_empty_inputs() {
121123 let (_dir, store, tahinli, bob, demo, other) = store_with_repos().await;
122124 let since = stamp_before(Duration::from_secs(3600));
123125 let older = stamp_before(Duration::from_secs(600));
@@ -169,13 +171,11 @@ mod tests {
169171 .unwrap();
170172 assert_eq!(
171173 rows,
172- vec![(demo.clone(), "feature".to_string(), newer.clone())]
174+ vec![(demo.clone(), "feature".to_string(), newer.clone())],
175+ "only the newest recent branch push"
173176 );
174- }
175177
176- #[tokio::test]
177- async fn empty_repo_list_and_future_since() {
178- let (_dir, store, tahinli, _bob, demo, _other) = store_with_repos().await;
178+ // No repo ids, or a `since` in the future, gives nothing.
179179 store
180180 .record_push_event(&demo, &tahinli, "refs/heads/feature", ZERO, OID, "test")
181181 .await
@@ -184,12 +184,12 @@ mod tests {
184184 .recent_branch_pushes(&[], &tahinli, &stamp_before(Duration::from_secs(3600)))
185185 .await
186186 .unwrap();
187- assert!(none.is_empty());
187+ assert!(none.is_empty(), "empty repo list");
188188 let future = stamp_after(Duration::from_secs(3600));
189189 let none = store
190190 .recent_branch_pushes(&[demo.as_str()], &tahinli, &future)
191191 .await
192192 .unwrap();
193- assert!(none.is_empty());
193+ assert!(none.is_empty(), "future since");
194194 }
195195 }
crates/forge-core/src/store/releases.rsmodified+90 -53
@@ -398,24 +398,44 @@ mod tests {
398398 }
399399 }
400400
401+ async fn add_repo(store: &Store, user: &str, name: &str) -> String {
402+ store
403+ .create_repo(user, name, "", crate::Visibility::Public, "main")
404+ .await
405+ .unwrap()
406+ .id
407+ }
408+
409+ // Every scenario gets its own repo in one shared store, so the per-repo
410+ // assertions cannot see another scenario's releases or assets.
401411 #[tokio::test]
402- async fn drafts_are_unpublished_and_tags_are_unique_per_repo() {
403- let (_dir, store, user, repo) = store_with_repo().await;
412+ async fn release_lifecycle_per_repo() {
413+ let (_dir, store, user, _repo) = store_with_repo().await;
414+
415+ // Drafts stay unpublished, and tags are unique per repo.
416+ let repo = add_repo(&store, &user, "drafts").await;
404417 let draft = store
405418 .create_release(&new_release(&repo, &user, "v1", true))
406419 .await
407420 .unwrap();
408- assert!(draft.draft && draft.published_at.is_none());
409- assert!(store.latest_release(&repo).await.unwrap().is_none());
421+ assert!(
422+ draft.draft && draft.published_at.is_none(),
423+ "draft is unpublished"
424+ );
425+ assert!(
426+ store.latest_release(&repo).await.unwrap().is_none(),
427+ "no latest draft"
428+ );
410429 let again = store
411430 .create_release(&new_release(&repo, &user, "v1", false))
412431 .await;
413- assert!(matches!(again, Err(Error::Conflict(_))));
414- }
432+ assert!(
433+ matches!(again, Err(Error::Conflict(_))),
434+ "duplicate tag: {again:?}"
435+ );
415436
416- #[tokio::test]
417- async fn publishing_sets_published_at_once_and_latest_skips_prereleases() {
418- let (_dir, store, user, repo) = store_with_repo().await;
437+ // Publishing sets published_at once; a prerelease is not "latest".
438+ let repo = add_repo(&store, &user, "publish").await;
419439 let rel = store
420440 .create_release(&new_release(&repo, &user, "v1", true))
421441 .await
@@ -426,10 +446,13 @@ mod tests {
426446 draft: false,
427447 prerelease: false,
428448 };
429- assert!(store.update_release(&rel.id, &edit).await.unwrap());
449+ assert!(
450+ store.update_release(&rel.id, &edit).await.unwrap(),
451+ "publish applied"
452+ );
430453 let published = store.release(&rel.id).await.unwrap().unwrap();
431454 let stamp = published.published_at.clone();
432- assert!(stamp.is_some());
455+ assert!(stamp.is_some(), "publish stamps the release");
433456 let edit = ReleaseEdit {
434457 title: "v1b",
435458 body: "",
@@ -439,7 +462,8 @@ mod tests {
439462 store.update_release(&rel.id, &edit).await.unwrap();
440463 assert_eq!(
441464 store.release(&rel.id).await.unwrap().unwrap().published_at,
442- stamp
465+ stamp,
466+ "the stamp is set once"
443467 );
444468 let pre = store
445469 .create_release(&NewRelease {
@@ -448,16 +472,15 @@ mod tests {
448472 })
449473 .await
450474 .unwrap();
451- assert!(pre.published_at.is_some());
475+ assert!(pre.published_at.is_some(), "prerelease is published");
452476 assert_eq!(
453477 store.latest_release(&repo).await.unwrap().unwrap().id,
454- rel.id
478+ rel.id,
479+ "latest skips the prerelease"
455480 );
456- }
457481
458- #[tokio::test]
459- async fn assets_count_downloads_and_deleting_a_release_returns_its_blob_ids() {
460- let (_dir, store, user, repo) = store_with_repo().await;
482+ // Downloads are counted; deleting a release returns its blob ids.
483+ let repo = add_repo(&store, &user, "assets").await;
461484 let rel = store
462485 .create_release(&new_release(&repo, &user, "v1", false))
463486 .await
@@ -474,7 +497,7 @@ mod tests {
474497 })
475498 .await
476499 .unwrap();
477- assert_eq!(asset.size, 3);
500+ assert_eq!(asset.size, 3, "asset size");
478501 store.count_asset_download("a1").await.unwrap();
479502 store.count_asset_download("a1").await.unwrap();
480503 let counted = store
@@ -482,27 +505,33 @@ mod tests {
482505 .await
483506 .unwrap()
484507 .unwrap();
485- assert_eq!(counted.download_count, 2);
508+ assert_eq!(counted.download_count, 2, "two downloads counted");
486509 assert_eq!(
487510 store.repo_release_asset_ids(&repo).await.unwrap(),
488- vec!["a1".to_string()]
511+ vec!["a1".to_string()],
512+ "repo lists its asset"
489513 );
490514 let removed = store.delete_release(&rel.id).await.unwrap();
491- assert_eq!(removed, Some(vec!["a1".to_string()]));
492- assert!(store.release(&rel.id).await.unwrap().is_none());
493- assert_eq!(store.delete_release(&rel.id).await.unwrap(), None);
494- }
515+ assert_eq!(removed, Some(vec!["a1".to_string()]), "blob ids returned");
516+ assert!(
517+ store.release(&rel.id).await.unwrap().is_none(),
518+ "release deleted"
519+ );
520+ assert_eq!(
521+ store.delete_release(&rel.id).await.unwrap(),
522+ None,
523+ "second delete"
524+ );
495525
496- #[tokio::test]
497- async fn replacing_an_asset_swaps_its_file_and_keeps_name_and_count() {
498- let (_dir, store, user, repo) = store_with_repo().await;
526+ // Replacing an asset swaps its file but keeps its name and counter.
527+ let repo = add_repo(&store, &user, "replace").await;
499528 let rel = store
500529 .create_release(&new_release(&repo, &user, "v1", false))
501530 .await
502531 .unwrap();
503532 store
504533 .add_asset(&NewAsset {
505- id: "a1",
534+ id: "b1",
506535 release_id: &rel.id,
507536 name: "app.bin",
508537 size: 3,
@@ -512,13 +541,12 @@ mod tests {
512541 })
513542 .await
514543 .unwrap();
515- store.count_asset_download("a1").await.unwrap();
516-
544+ store.count_asset_download("b1").await.unwrap();
517545 let replaced = store
518546 .replace_asset(
519- "a1",
547+ "b1",
520548 &NewAsset {
521- id: "a2",
549+ id: "b2",
522550 release_id: &rel.id,
523551 name: "app.bin",
524552 size: 5,
@@ -529,23 +557,26 @@ mod tests {
529557 )
530558 .await
531559 .unwrap();
532- assert_eq!(replaced.id, "a2");
533- assert_eq!(replaced.name, "app.bin");
534- assert_eq!(replaced.size, 5);
535- assert_eq!(replaced.sha256, "y");
536- assert_eq!(replaced.content_type, "text/plain");
560+ assert_eq!(replaced.id, "b2", "new id");
561+ assert_eq!(replaced.name, "app.bin", "name kept");
562+ assert_eq!(replaced.size, 5, "new size");
563+ assert_eq!(replaced.sha256, "y", "new hash");
564+ assert_eq!(replaced.content_type, "text/plain", "new content type");
537565 assert_eq!(replaced.download_count, 1, "the counter survives");
538- assert!(store.release_asset_by_id("a1").await.unwrap().is_none());
566+ assert!(
567+ store.release_asset_by_id("b1").await.unwrap().is_none(),
568+ "old id gone"
569+ );
539570 assert_eq!(
540571 store.repo_release_asset_ids(&repo).await.unwrap(),
541- vec!["a2".to_string()]
572+ vec!["b2".to_string()],
573+ "only the new asset remains"
542574 );
543-
544575 let gone = store
545576 .replace_asset(
546- "a1",
577+ "b1",
547578 &NewAsset {
548- id: "a3",
579+ id: "b3",
549580 release_id: &rel.id,
550581 name: "app.bin",
551582 size: 1,
@@ -555,12 +586,13 @@ mod tests {
555586 },
556587 )
557588 .await;
558- assert!(matches!(gone, Err(Error::NotFound)), "{gone:?}");
559- }
589+ assert!(
590+ matches!(gone, Err(Error::NotFound)),
591+ "replacing a missing asset: {gone:?}"
592+ );
560593
561- #[tokio::test]
562- async fn retagging_moves_the_release_and_refuses_a_tag_another_release_uses() {
563- let (_dir, store, user, repo) = store_with_repo().await;
594+ // Retagging moves the release, but not onto a tag another release uses.
595+ let repo = add_repo(&store, &user, "retag").await;
564596 let first = store
565597 .create_release(&new_release(&repo, &user, "v1", true))
566598 .await
@@ -574,18 +606,23 @@ mod tests {
574606 store
575607 .set_release_tag(&first.id, "v1b", new_target)
576608 .await
577- .unwrap()
609+ .unwrap(),
610+ "retag applied"
578611 );
579612 let moved = store.release(&first.id).await.unwrap().unwrap();
580- assert_eq!(moved.tag, "v1b");
581- assert_eq!(moved.target_oid, new_target);
613+ assert_eq!(moved.tag, "v1b", "tag moved");
614+ assert_eq!(moved.target_oid, new_target, "target moved");
582615 let taken = store.set_release_tag(&first.id, "v2", new_target).await;
583- assert!(matches!(taken, Err(Error::Conflict(_))), "{taken:?}");
616+ assert!(
617+ matches!(taken, Err(Error::Conflict(_))),
618+ "taken tag: {taken:?}"
619+ );
584620 assert!(
585621 !store
586622 .set_release_tag("missing", "v9", new_target)
587623 .await
588- .unwrap()
624+ .unwrap(),
625+ "unknown release is not retagged"
589626 );
590627 }
591628
crates/forge-core/src/store/replication.rsmodified+46 -42
@@ -123,9 +123,43 @@ mod tests {
123123 (dir, store)
124124 }
125125
126+ // One store serves both checks. The list check runs first, so its exact
127+ // subject list is not affected by the "r1" row used further down.
126128 #[tokio::test]
127- async fn ok_and_error_keep_the_other_fields() {
129+ async fn status_list_delete_and_ok_or_error_keep_other_fields() {
128130 let (_dir, store) = store().await;
131+
132+ store.record_replication_ok("db", None).await.expect("db");
133+ store
134+ .record_replication_error("b-repo", "x")
135+ .await
136+ .expect("b");
137+ store
138+ .record_replication_error("a-repo", "y")
139+ .await
140+ .expect("a");
141+ let subjects: Vec<String> = store
142+ .list_replication_status()
143+ .await
144+ .expect("list")
145+ .into_iter()
146+ .map(|s| s.subject)
147+ .collect();
148+ assert_eq!(subjects, ["a-repo", "b-repo", "db"], "ordered by subject");
149+
150+ store
151+ .delete_replication_status("a-repo")
152+ .await
153+ .expect("delete");
154+ assert!(
155+ store
156+ .replication_status("a-repo")
157+ .await
158+ .expect("get")
159+ .is_none(),
160+ "deleted row is gone"
161+ );
162+
129163 assert!(store.replication_status("r1").await.expect("get").is_none());
130164
131165 store
@@ -137,9 +171,9 @@ mod tests {
137171 .await
138172 .expect("get")
139173 .expect("row");
140- assert!(first.last_ok_at.is_some());
141- assert_eq!(first.refs_sha256.as_deref(), Some("abc"));
142- assert_eq!(first.last_error, None);
174+ assert!(first.last_ok_at.is_some(), "success stamped");
175+ assert_eq!(first.refs_sha256.as_deref(), Some("abc"), "refs hash kept");
176+ assert_eq!(first.last_error, None, "no error yet");
143177
144178 store
145179 .record_replication_error("r1", "push failed")
@@ -150,12 +184,16 @@ mod tests {
150184 .await
151185 .expect("get")
152186 .expect("row");
153- assert_eq!(failed.last_error.as_deref(), Some("push failed"));
187+ assert_eq!(
188+ failed.last_error.as_deref(),
189+ Some("push failed"),
190+ "error stored"
191+ );
154192 assert_eq!(
155193 failed.last_ok_at, first.last_ok_at,
156194 "a failure keeps the last success"
157195 );
158- assert_eq!(failed.refs_sha256.as_deref(), Some("abc"));
196+ assert_eq!(failed.refs_sha256.as_deref(), Some("abc"), "refs hash kept");
159197
160198 store.record_replication_ok("r1", None).await.expect("ok");
161199 let healed = store
@@ -163,41 +201,7 @@ mod tests {
163201 .await
164202 .expect("get")
165203 .expect("row");
166- assert_eq!(healed.last_error, None);
167- assert_eq!(healed.refs_sha256.as_deref(), Some("abc"));
168- }
169-
170- #[tokio::test]
171- async fn list_is_ordered_and_delete_removes_rows() {
172- let (_dir, store) = store().await;
173- store.record_replication_ok("db", None).await.expect("db");
174- store
175- .record_replication_error("b-repo", "x")
176- .await
177- .expect("b");
178- store
179- .record_replication_error("a-repo", "y")
180- .await
181- .expect("a");
182- let subjects: Vec<String> = store
183- .list_replication_status()
184- .await
185- .expect("list")
186- .into_iter()
187- .map(|s| s.subject)
188- .collect();
189- assert_eq!(subjects, ["a-repo", "b-repo", "db"]);
190-
191- store
192- .delete_replication_status("a-repo")
193- .await
194- .expect("delete");
195- assert!(
196- store
197- .replication_status("a-repo")
198- .await
199- .expect("get")
200- .is_none()
201- );
204+ assert_eq!(healed.last_error, None, "success clears the error");
205+ assert_eq!(healed.refs_sha256.as_deref(), Some("abc"), "refs hash kept");
202206 }
203207 }
crates/forge-core/src/store/repo_listing.rsmodified+19 -21
@@ -237,9 +237,7 @@ mod tests {
237237 .id
238238 }
239239
240- #[tokio::test]
241- async fn strangers_and_anonymous_viewers_never_see_private_repos() {
242- let fx = fixture().await;
240+ async fn strangers_and_anonymous_viewers_never_see_private_repos(fx: &Fixture) {
243241 let stranger = fx
244242 .store
245243 .create_user("mira", None, "h", false)
@@ -254,9 +252,7 @@ mod tests {
254252 );
255253 }
256254
257- #[tokio::test]
258- async fn a_collaborator_sees_the_private_repo_they_work_on() {
259- let fx = fixture().await;
255+ async fn a_collaborator_sees_the_private_repo_they_work_on(fx: &Fixture) {
260256 let carol = fx
261257 .store
262258 .create_user("carol", None, "h", false)
@@ -274,9 +270,7 @@ mod tests {
274270 );
275271 }
276272
277- #[tokio::test]
278- async fn an_admin_sees_everything() {
279- let fx = fixture().await;
273+ async fn an_admin_sees_everything(fx: &Fixture) {
280274 let admin = fx.store.create_user("root", None, "h", true).await.unwrap();
281275 let scope = RepoScope::OwnedBy(&fx.owner.id);
282276 assert_eq!(
@@ -308,13 +302,11 @@ mod tests {
308302 }
309303 }
310304
311- #[tokio::test]
312- async fn org_roles_match_org_repo_role() {
313- let fx = fixture().await;
305+ async fn org_roles_match_org_repo_role(fx: &Fixture) {
314306 let org = fx.store.create_org("acme", &fx.owner.id).await.unwrap();
315307 let member = fx
316308 .store
317- .create_user("mira", None, "h", false)
309+ .create_user("ines", None, "h", false)
318310 .await
319311 .unwrap();
320312 let outsider = fx.store.create_user("zed", None, "h", false).await.unwrap();
@@ -369,14 +361,8 @@ mod tests {
369361 check(&outsider, &[]).await;
370362 }
371363
372- #[tokio::test]
373- async fn stars_scope_filters_search_and_pages() {
374- let fx = fixture().await;
375- let fan = fx
376- .store
377- .create_user("mira", None, "h", false)
378- .await
379- .unwrap();
364+ async fn stars_scope_filters_search_and_pages(fx: &Fixture) {
365+ let fan = fx.store.create_user("fan", None, "h", false).await.unwrap();
380366 for name in ["open", "closed"] {
381367 let id = repo_id(&fx.store, "tahinli", name).await;
382368 fx.store.star(&fan.id, &id).await.unwrap();
@@ -406,4 +392,16 @@ mod tests {
406392 assert_eq!(rows.len(), 1);
407393 assert_eq!(rows[0].0.name, "open");
408394 }
395+
396+ // The listing rules share one fixture; each check only adds what it needs,
397+ // and the collaborator grant runs before the later checks.
398+ #[tokio::test]
399+ async fn repo_visibility_and_listing_rules() {
400+ let fx = fixture().await;
401+ strangers_and_anonymous_viewers_never_see_private_repos(&fx).await;
402+ a_collaborator_sees_the_private_repo_they_work_on(&fx).await;
403+ an_admin_sees_everything(&fx).await;
404+ org_roles_match_org_repo_role(&fx).await;
405+ stars_scope_filters_search_and_pages(&fx).await;
406+ }
409407 }
crates/forge-core/src/store/signatures.rsmodified+47 -16
@@ -323,37 +323,48 @@ mod tests {
323323 }
324324
325325 #[tokio::test]
326- async fn gpg_key_round_trip_and_duplicate_fingerprint() {
326+ async fn gpg_keys_add_list_and_delete_only_for_owner() {
327327 let (store, tahinli, _, _dir) = setup().await;
328328 let emails = vec!["tahinli@example.com".to_string()];
329329 let key = store
330330 .add_gpg_key(&tahinli, "ABCD", "-----BEGIN-----", &emails)
331331 .await
332332 .unwrap();
333- assert_eq!(key.emails, emails);
333+ assert_eq!(key.emails, emails, "emails kept");
334334 let listed = store.list_gpg_keys(&tahinli).await.unwrap();
335- assert_eq!(listed, vec![key.clone()]);
336- assert_eq!(store.all_gpg_keys().await.unwrap().len(), 1);
335+ assert_eq!(listed, vec![key.clone()], "listed once");
336+ assert_eq!(
337+ store.all_gpg_keys().await.unwrap().len(),
338+ 1,
339+ "one key overall"
340+ );
337341 let dup = store.add_gpg_key(&tahinli, "ABCD", "x", &emails).await;
338- assert!(matches!(dup, Err(Error::Conflict(_))));
339- }
342+ assert!(
343+ matches!(dup, Err(Error::Conflict(_))),
344+ "duplicate fingerprint: {dup:?}"
345+ );
340346
341- #[tokio::test]
342- async fn delete_gpg_key_only_for_owner() {
343- let (store, tahinli, _, _dir) = setup().await;
347+ // Another user cannot delete the key; the owner can.
344348 let bob = store.create_user("bob", None, "hash", false).await.unwrap();
345- let key = store.add_gpg_key(&tahinli, "ABCD", "x", &[]).await.unwrap();
346349 assert!(
347350 store
348351 .delete_gpg_key(&bob.id, &key.id)
349352 .await
350353 .unwrap()
351- .is_none()
354+ .is_none(),
355+ "not the owner"
356+ );
357+ assert_eq!(
358+ store.list_gpg_keys(&tahinli).await.unwrap().len(),
359+ 1,
360+ "still there"
352361 );
353- assert_eq!(store.list_gpg_keys(&tahinli).await.unwrap().len(), 1);
354362 let removed = store.delete_gpg_key(&tahinli, &key.id).await.unwrap();
355- assert_eq!(removed, Some(key));
356- assert!(store.list_gpg_keys(&tahinli).await.unwrap().is_empty());
363+ assert_eq!(removed, Some(key), "owner removes it");
364+ assert!(
365+ store.list_gpg_keys(&tahinli).await.unwrap().is_empty(),
366+ "list empty"
367+ );
357368 }
358369
359370 #[tokio::test]
@@ -411,11 +422,31 @@ mod tests {
411422 SigStatus::UnknownKey,
412423 SigStatus::Bad,
413424 ] {
414- assert_eq!(s.as_str().parse::<SigStatus>().unwrap(), s);
425+ assert_eq!(
426+ s.as_str().parse::<SigStatus>().unwrap(),
427+ s,
428+ "round trip {s:?}"
429+ );
415430 }
416431 for k in [SigKind::Ssh, SigKind::Gpg] {
417- assert_eq!(k.as_str().parse::<SigKind>().unwrap(), k);
432+ assert_eq!(
433+ k.as_str().parse::<SigKind>().unwrap(),
434+ k,
435+ "round trip {k:?}"
436+ );
437+ }
438+ // Stored in the signature cache, so the literals must not change.
439+ for (s, literal) in [
440+ (SigStatus::Verified, "verified"),
441+ (SigStatus::Unverified, "unverified"),
442+ (SigStatus::Unsigned, "unsigned"),
443+ (SigStatus::UnknownKey, "unknown_key"),
444+ (SigStatus::Bad, "bad"),
445+ ] {
446+ assert_eq!(s.as_str(), literal, "stored literal of {s:?}");
418447 }
448+ assert_eq!(SigKind::Ssh.as_str(), "ssh", "stored literal of ssh");
449+ assert_eq!(SigKind::Gpg.as_str(), "gpg", "stored literal of gpg");
419450 assert!("nope".parse::<SigStatus>().is_err());
420451 }
421452 }
crates/forge-core/src/store/snippets.rsmodified+18 -1
@@ -492,7 +492,24 @@ mod tests {
492492 #[test]
493493 fn visibility_names_round_trip() {
494494 for v in SnippetVisibility::ALL {
495- assert_eq!(SnippetVisibility::parse(v.as_str()), Some(v));
495+ assert_eq!(
496+ SnippetVisibility::parse(v.as_str()),
497+ Some(v),
498+ "round trip {v:?}"
499+ );
500+ }
501+ // The stored literals: changing one breaks saved snippets.
502+ for (v, literal) in [
503+ (SnippetVisibility::Public, "public"),
504+ (SnippetVisibility::Unlisted, "unlisted"),
505+ (SnippetVisibility::Private, "private"),
506+ ] {
507+ assert_eq!(v.as_str(), literal, "stored literal of {v:?}");
508+ assert_eq!(
509+ SnippetVisibility::parse(literal),
510+ Some(v),
511+ "parse {literal}"
512+ );
496513 }
497514 assert_eq!(SnippetVisibility::parse("secret"), None);
498515 }
crates/forge-core/src/store/wiki.rsmodified+21 -19
@@ -44,7 +44,7 @@ mod tests {
4444 use crate::model::Visibility;
4545
4646 #[tokio::test]
47- async fn wiki_is_on_by_default_and_can_be_switched() {
47+ async fn wiki_is_on_by_default_can_be_switched_and_unknown_repo_is_not_found() {
4848 let dir = tempfile::tempdir().unwrap();
4949 let store = Store::open(&dir.path().join("forge.db")).await.unwrap();
5050 let tahinli = store
@@ -55,26 +55,28 @@ mod tests {
5555 .create_repo(&tahinli.id, "proj", "", Visibility::Public, "main")
5656 .await
5757 .unwrap();
58- assert!(store.wiki_enabled(&repo.id).await.unwrap());
58+ assert!(store.wiki_enabled(&repo.id).await.unwrap(), "on by default");
5959 store.set_wiki_enabled(&repo.id, false).await.unwrap();
60- assert!(!store.wiki_enabled(&repo.id).await.unwrap());
60+ assert!(!store.wiki_enabled(&repo.id).await.unwrap(), "switched off");
6161 store.set_wiki_enabled(&repo.id, true).await.unwrap();
62- assert!(store.wiki_enabled(&repo.id).await.unwrap());
63- }
62+ assert!(store.wiki_enabled(&repo.id).await.unwrap(), "switched on");
6463
65- #[tokio::test]
66- async fn unknown_repo_is_not_found() {
67- let dir = tempfile::tempdir().unwrap();
68- let store = Store::open(&dir.path().join("forge.db")).await.unwrap();
69- assert!(matches!(
70- store.wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV").await,
71- Err(Error::NotFound)
72- ));
73- assert!(matches!(
74- store
75- .set_wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV", false)
76- .await,
77- Err(Error::NotFound)
78- ));
64+ // An id that is no repo is not found, for read and for write.
65+ assert!(
66+ matches!(
67+ store.wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV").await,
68+ Err(Error::NotFound)
69+ ),
70+ "unknown repo read"
71+ );
72+ assert!(
73+ matches!(
74+ store
75+ .set_wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV", false)
76+ .await,
77+ Err(Error::NotFound)
78+ ),
79+ "unknown repo write"
80+ );
7981 }
8082 }