revert: drop the I3(b) suppression pre-check gate (#9)

Scoped re-review measured .needs_suppression_query() against the fixture
and found it doesn't pay for itself: it skips the round trip on ~3% of
healthy candidate-bearing calls, ~0% of the multi-govid batch shape
(cog_geographic_rollup()/cog_peer_compare()) it was meant to help, and
reaching the gate costs an unconditional metadata query that on its own
roughly cancels the expected saving -- net slower on the fixture. The
gate was also correct (0 unsound skips) but left an untested exactness
invariant (result$codes_included and the anti-join sharing the harmonized
item_code space) whose silent violation would kill signposting, which is
the exact failure class uscogdata#9 exists to prevent.

Owner's call: revert it and keep the code simple. A batch-aware
optimization, if warranted, is a separate issue.

Removes .needs_suppression_query() entirely (function, roxygen, call
site, comp_rows/flow_components), restoring .build_suggestions() to call
.suppressed_components() directly -- unchanged from f77adb6 except that
it still threads flow_prefixes through (I1, kept). Also removes the two
tests that existed solely to exercise the gate (the five-branch synthetic
test and the local_mocked_bindings call-counter test); no test asserting
real signposting behavior was touched.

I1 (flow_prefixes filter), I2 (schema wording + ig_recipe_id required),
I3(a) (restated NOT EXISTS literals for partition pruning), and M4
(reworded scope claims) are all untouched by this revert.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-05 07:59:19 -04:00
co-authored by Claude Opus 5
parent 4b749205a5
commit 77074621d8
2 changed files with 15 additions and 152 deletions
-62
View File
@@ -245,68 +245,6 @@ test_that(".select_long_view maps annotated view bases to their long views", {
"spending_long")
})
# --- I3(b): the free pre-check gating .suppressed_components() -------------
test_that(".needs_suppression_query skips only when the evidence rules out suppression", {
# Every requested (govid, year) already accounts for every component code:
# .suppressed_components() is guaranteed to find nothing, so it is safe to
# skip the round trip.
result_full <- tibble::tibble(
year = c(2019L, 2019L, 2020L, 2020L),
canonical_govid = c("A", "B", "A", "B"),
codes_included = c("E01,E02", "E01,E02,E03", "E01,E02", "E01,E02")
)
expect_false(uscogdata:::.needs_suppression_query(
c("E01", "E02"), result_full, govid = c("A", "B"), years = c(2019L, 2020L)))
# One (govid, year) is missing a component -- cannot rule out suppression,
# so the real measurement must still run.
result_gap <- result_full
result_gap$codes_included[result_gap$canonical_govid == "B" & result_gap$year == 2020L] <- "E01"
expect_true(uscogdata:::.needs_suppression_query(
c("E01", "E02"), result_gap, govid = c("A", "B"), years = c(2019L, 2020L)))
# A requested (govid, year) is entirely absent from `result` (e.g. a gap
# year, or one government of many in a batch call) -- conservatively TRUE.
result_absent <- result_full[!(result_full$canonical_govid == "B" & result_full$year == 2020L), ]
expect_true(uscogdata:::.needs_suppression_query(
c("E01", "E02"), result_absent, govid = c("A", "B"), years = c(2019L, 2020L)))
# No candidate component belongs to the calling verb's own flow family (the
# I1 cross-flow-family case) -- nothing could ever be measured, so skip.
expect_false(uscogdata:::.needs_suppression_query(
character(0), result_full, govid = c("A", "B"), years = c(2019L, 2020L)))
# An empty result (e.g. every requested year is a gap) can never positively
# rule out suppression -- conservatively TRUE.
expect_true(uscogdata:::.needs_suppression_query(
c("E01"), result_full[0, ], govid = "A", years = 2019L))
})
test_that("I3(b): a suppression-only fire (zero gap years) still runs the real measurement", {
# Public Welfare FY2011 for LA County has rows in every requested year (no
# gap_years), so this exercises exactly the path I3(b) must not break: the
# pre-check must return TRUE here, and the real .suppressed_components()
# round trip must actually execute, or the whole uscogdata#9 feature would
# go dark on its own motivating case.
skip_if_no_corpus()
called <- FALSE
orig <- uscogdata:::.suppressed_components
testthat::local_mocked_bindings(
.suppressed_components = function(...) {
called <<- TRUE
orig(...)
},
.package = "uscogdata"
)
r <- suppressMessages(
cog_spending("061037123085", years = 2011L, category = "Public Welfare"))
expect_true(called)
sugg <- attr(r, "provenance")$suggestions
triggers <- vapply(sugg, function(s) s$trigger, character(1))
expect_true(all(triggers == "suppressed_component"))
})
test_that(".suppressed_components measures the E67/E68 dollars Public Welfare drops", {
skip_if_no_corpus()
con <- uscogdata:::.ensure_session()