"agg_repertoires counts single-chain receptors correctly"
"Sample1 should have 2 unique receptors"
"Sample2 should have 2 unique receptors"
"Shared receptor should have count of 2"
"agg_repertoires identifies double-counting in paired-chain data"
"agg_repertoires handles paired-chain data with shared receptors"
"agg_repertoires proportions are affected by double-counting"
"agg_repertoires n_repertoires calculation is correct for paired data"
"Shared receptor should appear in 2 repertoires"
"Unique receptor should appear in 1 repertoire"
"agg_repertoires preserves second chain data (no NAs)"
"Annotation table should retain rows for both chains (IGH and IGL)"
"Should find exactly one row for the IGL chain"
"IGL row should have valid v_call data (not NA)"
"Both chains of the same receptor should share the same count stats"
"Both chains should belong to the same repertoire ID"

agg_repertoires counts single-chain receptors correctly

Expected `sample2_stats$n_receptors` to equal 2.
Differences:
  `actual`:  NA
`expected`: 2.0

Sample2 should have 2 unique receptors

Expected `sample1_counts$total_count1[1]` to equal 2.
Differences:
  `actual`:  NA
`expected`: 2.0

Shared receptor should have count of 2

Expected `sample1_counts$total_count2[1]` to equal 2.
Differences:
  `actual`:  NA
`expected`: 2.0

Shared receptor should have count of 2

Expected `metadata_json$provenance$snapshot_root` to equal `file.path(normalized_out, "snapshots")`.
Differences:
actual vs expected
- "D:\\temp\\2026_03_15_21_45_17_13593\\Rtmp6NsfJN\\imd_snap_tests\\projectA\\snapshots"
+ "D:\\temp\\2026_03_15_21_45_17_13593\\Rtmp6NsfJN\\imd_snap_tests\\projectA/snapshots"

test_that("read_immundata() upgrades legacy v1 metadata on the fly", {
sample_file <- system.file("extdata/tsv", "sample_0_1k.tsv", package = "immundata")
idata <- read_immundata(legacy_path, verbose = FALSE),
expect_equal(prov$current_path, normalizePath(legacy_path, mustWork = FALSE))
test_that("ImmunData$provenance is read-only and matches helper output", {
test_that("read_repertoires() writes metadata with lineage array and provenance", {
metadata_json <- jsonlite::read_json(metadata_path, simplifyVector = FALSE)
normalized_out <- normalizePath(output_dir, mustWork = FALSE)
test_that("write_immundata() appends snapshot lineage event", {
before_json <- jsonlite::read_json(metadata_path, simplifyVector = FALSE)
after_json <- jsonlite::read_json(metadata_path, simplifyVector = FALSE)
test_that("read_repertoires() writes metadata-derived files in ingestion lineage", {
md_path <- system.file("extdata/tsv", "metadata.tsv", package = "immundata")
test_that("write_immundata() auto-creates snapshot folders and increments versions", {
idata_v1 <- write_immundata(idata, output_folder = NULL, tag = "baseline")
idata_v2 <- write_immundata(idata_v1, output_folder = NULL, tag = "baseline")
normalizePath(file.path(output_dir, "snapshots", "baseline", "v002"), mustWork = FALSE)
test_that("snapshot tests use projectA/projectB tree in temporary snapshot root", {
write_immundata(idata, output_folder = NULL, tag = "baseline")
read_immundata(output_dir, tag = "baseline", version = 1),
write_immundata(idata, output_folder = NULL, tag = "treated")
write_immundata(idata, output_folder = rehome_dir, rehome = TRUE)
test_that("read_immundata() resolves tag latest and specific versions", {
write_immundata(read_immundata(output_dir, tag = "baseline", version = 1), output_folder = NULL, tag = "baseline")
latest <- read_immundata(output_dir, tag = "baseline")
version1 <- read_immundata(output_dir, tag = "baseline", version = 1)
normalizePath(file.path(output_dir, "snapshots", "baseline", "v001"), mustWork = FALSE)
test_that("snapshot path resolution validates missing tags and versions", {
read_immundata(output_dir, tag = "baseline", version = 99),
read_immundata(file.path(output_dir, "snapshots", "baseline", "v001"), tag = "baseline"),
test_that("write_immundata() validates tags and missing provenance for auto-snapshots", {
annotations_tbl <- idata$annotations |> collect()
write_immundata(idata, output_folder = NULL, tag = "../bad"),
test_that("write_immundata() rehome controls future auto-snapshot root", {
moved_without_rehome <- write_immundata(idata, output_folder = alt_output_dir, rehome = FALSE)
auto_from_old_home <- write_immundata(moved_without_rehome, output_folder = NULL, tag = "baseline")
moved_with_rehome <- write_immundata(idata, output_folder = alt_output_dir, rehome = TRUE)
auto_from_new_home <- write_immundata(moved_with_rehome, output_folder = NULL, tag = "baseline")
normalizePath(file.path(alt_output_dir, "snapshots", "baseline", "v001"), mustWork = FALSE)
test_that("operation outputs preserve provenance for auto-snapshots", {
snap <- write_immundata(filtered, output_folder = NULL, tag = "ops")
normalizePath(file.path(output_dir, "snapshots", "ops", "v001"), mustWork = FALSE)
test_that("write_immundata_internal() validates lineage as complete set", {
test_that("write_immundata_internal() validates lineage fields", {
renamed = list(requested = character(), applied = character(), not_found = character()),
metadata_lineage_pipeline = list(preprocess = character(), postprocess = character())