fix(suggestions): scope candidate recipes by category_type (#34) #70

Merged
jared merged 1 commits from fix/category-type-34 into main 2026-09-09 11:18:52 -04:00
Owner

Stacked on #69. .query_candidate_recipes() (extracted in #69) now filters candidates by category_type ('expenditure' vs 'revenue'), derived from the calling verb's own flow_prefixes.

Without this, a category shared across both flow families in summary_categories leaked cross-family recipes:

  • cog_revenue(category = "Corrections") surfaced the expenditure-only corrections_combined recipe (E04/E05) merely because "Corrections" is also a spending category name.
  • cog_spending(category = "IG Federal") surfaced the revenue-only ig_federal_b47_wide recipe.

Both are wrong: following either hint would attribute dollars to the wrong flow, or (IG Federal) fire the coverage-gap machinery for a category the calling verb structurally cannot report on at all.

Updates the two tests whose expected behavior this changes (test-expenditure-concept.R, test-recipes.R).

1078 tests pass, 0 fail, 2 skipped (live-corpus).

Closes #34.

🤖 Generated with Claude Code

Stacked on #69. `.query_candidate_recipes()` (extracted in #69) now filters candidates by `category_type` ('expenditure' vs 'revenue'), derived from the calling verb's own `flow_prefixes`. Without this, a category shared across both flow families in `summary_categories` leaked cross-family recipes: - `cog_revenue(category = "Corrections")` surfaced the expenditure-only `corrections_combined` recipe (E04/E05) merely because "Corrections" is also a spending category name. - `cog_spending(category = "IG Federal")` surfaced the revenue-only `ig_federal_b47_wide` recipe. Both are wrong: following either hint would attribute dollars to the wrong flow, or (IG Federal) fire the coverage-gap machinery for a category the calling verb structurally cannot report on at all. Updates the two tests whose expected behavior this changes (test-expenditure-concept.R, test-recipes.R). 1078 tests pass, 0 fail, 2 skipped (live-corpus). Closes #34. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared changed target branch from issue-33 to main 2026-09-09 11:18:21 -04:00
jared added 1 commit 2026-09-09 11:18:21 -04:00
fix(suggestions): scope candidate recipes by category_type (#34)
R-CMD-check / check (push) Successful in 4m15s
R-CMD-check / check (pull_request) Successful in 4m25s
392643bd74
.query_candidate_recipes() (extracted in #33) now filters candidates by
category_type ('expenditure' vs 'revenue'), derived from the calling
verb's own flow_prefixes (E/F/G -> 'expenditure', else 'revenue').

Without this, a category shared across both flow families in
summary_categories leaked cross-family recipes: cog_revenue(category =
"Corrections") surfaced the expenditure-only corrections_combined recipe
(E04/E05) merely because "Corrections" is also a spending category name,
and cog_spending(category = "IG Federal") surfaced the revenue-only
ig_federal_b47_wide recipe. Both are wrong: following either hint would
attribute dollars to the wrong flow, or (IG Federal) fire the
coverage-gap machinery for a category the calling verb structurally
cannot report on at all.

Updates the two tests this changes the expected behavior of:
- "a mis-scoped cog_spending() call never attaches an M/L counterpart to
  a revenue-flavored recipe" (test-expenditure-concept.R): IG Federal is
  revenue-only, so a spending call now finds zero candidates outright
  rather than firing the suggestion and then blocking its M/L
  counterpart as a second-order check.
- "cog_revenue never suggests expenditure-only recipes"
  (test-recipes.R, was "I1: ... never fabricates suppressed dollars"):
  corrections_combined is expenditure-only, so a revenue call now never
  considers it as a candidate, rather than considering it and reporting
  zero suppressed dollars.

All 1078 tests pass (2 skipped live-corpus), measured devtools::test()
against this commit in a clean worktree stacked on the #33 refactor.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
jared merged commit 56f610ea3f into main 2026-09-09 11:18:52 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Civilytics/uscogdata#70