From 4d61692f056353c7e5302e02e4f680744eb2a5d8 Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Sat, 18 Jul 2026 13:40:54 -0400 Subject: [PATCH] feat: export cog_manifest() accessor + pin CPI coverage 1967-present --- NAMESPACE | 1 + R/manifest.R | 15 +++++++++++++++ man/cog_manifest.Rd | 18 ++++++++++++++++++ tests/testthat/test-adjust.R | 7 +++++++ tests/testthat/test-manifest.R | 11 +++++++++++ 5 files changed, 52 insertions(+) create mode 100644 man/cog_manifest.Rd diff --git a/NAMESPACE b/NAMESPACE index 518e06d..19baa13 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(cog_explain) export(cog_find_peers) export(cog_geographic_rollup) export(cog_gov_search) +export(cog_manifest) export(cog_mirror) export(cog_peer_compare) export(cog_revenue) diff --git a/R/manifest.R b/R/manifest.R index bc7eb70..c248ec6 100644 --- a/R/manifest.R +++ b/R/manifest.R @@ -146,3 +146,18 @@ } `%||%` <- function(a, b) if (is.null(a) || (length(a) == 1 && is.na(a))) b else a + +#' Return the parsed corpus manifest for the active session. +#' +#' Opens a session (connecting to the configured corpus) if none is active, +#' then returns the manifest exactly as parsed from `manifest.json`. Useful +#' for consumers that need the published year range (`years` block, schema +#' v5+) or the partition list without issuing a data query. +#' +#' @return Named list: `schema_version`, `built_at`, `pipeline_commit`, +#' `data_vintage`, `scope`, `years` (schema v5+), `schema`, `files`. +#' @export +cog_manifest <- function() { + .ensure_session() + .uscogdata_env$manifest +} diff --git a/man/cog_manifest.Rd b/man/cog_manifest.Rd new file mode 100644 index 0000000..a04718f --- /dev/null +++ b/man/cog_manifest.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/manifest.R +\name{cog_manifest} +\alias{cog_manifest} +\title{Return the parsed corpus manifest for the active session.} +\usage{ +cog_manifest() +} +\value{ +Named list: `schema_version`, `built_at`, `pipeline_commit`, + `data_vintage`, `scope`, `years` (schema v5+), `schema`, `files`. +} +\description{ +Opens a session (connecting to the configured corpus) if none is active, +then returns the manifest exactly as parsed from `manifest.json`. Useful +for consumers that need the published year range (`years` block, schema +v5+) or the partition list without issuing a data query. +} diff --git a/tests/testthat/test-adjust.R b/tests/testthat/test-adjust.R index b10e3e6..57f19a2 100644 --- a/tests/testthat/test-adjust.R +++ b/tests/testthat/test-adjust.R @@ -41,3 +41,10 @@ test_that(".inflate preserves NA amounts", { expect_true(is.na(result[2])) expect_false(any(is.na(result[c(1, 3)]))) }) + +test_that("bundled CPI covers the full 1967+ corpus era through this year", { + cpi <- .cpi_table() + expect_lte(min(cpi$year), 1967L) + expect_gte(max(cpi$year), as.integer(format(Sys.Date(), "%Y"))) + expect_false(any(is.na(cpi$cpi))) +}) diff --git a/tests/testthat/test-manifest.R b/tests/testthat/test-manifest.R index 0c4a20c..c8e5f54 100644 --- a/tests/testthat/test-manifest.R +++ b/tests/testthat/test-manifest.R @@ -99,3 +99,14 @@ test_that("remote manifest fetch does not poison cache when response is HTML", { 0L ) }) + +test_that("cog_manifest returns the active session's parsed manifest", { + with_fixture_corpus({ + m <- cog_manifest() + expect_type(m, "list") + expect_true(m$schema_version >= 4L) + yrs <- vapply(m$files$long_partitions, function(p) as.integer(p$year), + integer(1)) + expect_setequal(yrs, c(2019L, 2020L)) + }) +}) -- 2.54.0