test_that("inventory does not require loading RDS content", { plan <- new_search_plan("test", sources = "crossref") mock <- function(url, headers, params, timeout) list(message = list(items = list())) snap <- run_search_plan(plan, requester = mock) path <- tempfile("archive-access-") on.exit(unlink(path, recursive = TRUE), add = TRUE) create_search_archive(snap, path) append_search_archive(snap, path) inventory <- list_search_archive_runs(path) expect_equal(nrow(inventory), 2L) expect_identical(inventory$integrity, rep("verified_sha256", 2L)) expect_identical(inventory$articles, c(0L, 0L)) expect_identical(read_search_archive_run(path, 1L), snap) expect_identical(read_search_archive_run(path, "latest"), snap) expect_identical(read_search_archive_run(path, "run_000002"), snap) expect_error(read_search_archive_run(path, 3L), "does not exist") }) test_that("unchecked inventories disclose reduced validation", { plan <- new_search_plan("test", sources = "crossref") mock <- function(url, headers, params, timeout) list(message = list(items = list())) path <- tempfile("archive-access-") on.exit(unlink(path, recursive = TRUE), add = TRUE) create_search_archive(run_search_plan(plan, requester = mock), path) fast <- list_search_archive_runs(path, verify_integrity = FALSE) expect_identical(fast$integrity, "unchecked") snapshot <- file.path(path, "runs", "run_000001", "snapshot.rds") cat("corrupted", file = snapshot, append = TRUE) expect_error(list_search_archive_runs(path), "checksum mismatch") expect_error(read_search_archive_run(path), "checksum mismatch") expect_identical(list_search_archive_runs(path, FALSE)$integrity, "unchecked") }) test_that("fast inventory rejects missing protected hashes and bad arguments", { plan <- new_search_plan("test", sources = "crossref") mock <- function(url, headers, params, timeout) list(message = list(items = list())) path <- tempfile("archive-access-") on.exit(unlink(path, recursive = TRUE), add = TRUE) create_search_archive(run_search_plan(plan, requester = mock), path) expect_error(list_search_archive_runs(path, NA), "verify_integrity") expect_error(read_search_archive_run(path, "unrecognized"), "run must") unlink(file.path(path, "runs", "run_000001", "integrity.json")) expect_error(list_search_archive_runs(path, FALSE), "integrity record is missing") })