Skip to content

Commit 8e8b74b

Browse files
committed
test(node): cover mirror-only, empty, and count/list-consistency dedup cases
Follow-ups from code review on the dedup change: - list_all_repos_deduped/count_repos_deduped: mirror-only group survives, empty table returns empty/0, and count_repos_deduped equals the deduped list length (guards the two independent SQL queries against grouping-key drift). - Document list_all_repos as the raw, non-deduped enumeration path (object lookup only), so it is not mistaken for a listing-surface method.
1 parent 694fab1 commit 8e8b74b

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

  • crates/gitlawb-node/src/db

‎crates/gitlawb-node/src/db/mod.rs‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,11 @@ impl Db {
855855
Ok(rows.into_iter().map(row_to_repo).collect())
856856
}
857857

858+
/// Raw list of every repo row — NOT deduped (a mirror row and its canonical
859+
/// row both appear) and without stars. For enumeration callers that must see
860+
/// every physical row (e.g. the IPFS object scan in `api::ipfs`), not for
861+
/// listing surfaces. Listing surfaces dedupe via `list_all_repos_deduped` or
862+
/// `list_all_repos_with_stars` + `dedupe_canonical_repos`.
858863
pub async fn list_all_repos(&self) -> Result<Vec<RepoRecord>> {
859864
let rows = sqlx::query(
860865
"SELECT id, name, owner_did, description, is_public, default_branch,
@@ -3276,4 +3281,64 @@ mod dedup_db_tests {
32763281
"canonical wins by structural id marker despite carrying the mirror description"
32773282
);
32783283
}
3284+
3285+
/// A mirror row with no canonical twin survives dedup as the sole entry for its
3286+
/// group (it is not dropped just because it is the mirror).
3287+
#[sqlx::test]
3288+
async fn deduped_mirror_only_group_survives(pool: PgPool) {
3289+
let db = db(pool).await;
3290+
db.upsert_mirror_repo("z6Lonely", "orphan", "/srv/m", None)
3291+
.await
3292+
.unwrap();
3293+
3294+
let out = db.list_all_repos_deduped().await.unwrap();
3295+
assert_eq!(out.len(), 1, "a mirror-only group still yields one logical repo");
3296+
assert_eq!(out[0].id, "z6Lonely/orphan");
3297+
assert_eq!(db.count_repos_deduped().await.unwrap(), 1);
3298+
}
3299+
3300+
/// Degenerate empty table: deduped list is empty and the count is 0, no error.
3301+
#[sqlx::test]
3302+
async fn deduped_empty_table(pool: PgPool) {
3303+
let db = db(pool).await;
3304+
assert!(db.list_all_repos_deduped().await.unwrap().is_empty());
3305+
assert_eq!(db.count_repos_deduped().await.unwrap(), 0);
3306+
}
3307+
3308+
/// count_repos_deduped and list_all_repos_deduped must agree: the count is the
3309+
/// number of logical repos the list returns. Guards the two independent SQL
3310+
/// queries against drifting on the grouping key.
3311+
#[sqlx::test]
3312+
async fn deduped_count_matches_list_len(pool: PgPool) {
3313+
let db = db(pool).await;
3314+
// Two logical repos: one canonical+mirror pair, one standalone canonical.
3315+
db.create_repo(&rec(
3316+
"uuid-1",
3317+
"did:key:z6Pair",
3318+
"shared",
3319+
"real",
3320+
"2026-01-01T00:00:00Z",
3321+
"2026-01-01T00:00:00Z",
3322+
))
3323+
.await
3324+
.unwrap();
3325+
db.upsert_mirror_repo("z6Pair", "shared", "/srv/m", None)
3326+
.await
3327+
.unwrap();
3328+
db.create_repo(&rec(
3329+
"uuid-2",
3330+
"did:key:z6Solo",
3331+
"solo",
3332+
"real",
3333+
"2026-01-02T00:00:00Z",
3334+
"2026-01-02T00:00:00Z",
3335+
))
3336+
.await
3337+
.unwrap();
3338+
3339+
let list_len = db.list_all_repos_deduped().await.unwrap().len() as i64;
3340+
let count = db.count_repos_deduped().await.unwrap();
3341+
assert_eq!(list_len, 2);
3342+
assert_eq!(count, list_len, "count must equal the deduped list length");
3343+
}
32793344
}

0 commit comments

Comments
 (0)