Skip to content

New-test-suite#462

Merged
randrescastaneda merged 30 commits intoDEVfrom
new-test-suite
Mar 17, 2026
Merged

New-test-suite#462
randrescastaneda merged 30 commits intoDEVfrom
new-test-suite

Conversation

@randrescastaneda
Copy link
Member

@randrescastaneda randrescastaneda commented Mar 17, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added robust data validation and lookup structure verification across core API functions.
    • Introduced new utility functions for auxiliary data access, censoring, and estimate-type classification.
  • Bug Fixes

    • Fixed handling of invalid country codes and improved error messages.
  • Deprecated

    • Removed group_by parameter from the main /api/v1/pip endpoint; use /api/v1/pip-grp for aggregation instead.
  • Chores

    • Released version 1.5.0 with code reorganization and internal refactoring for improved maintainability.
    • Reorganized utility functions into specialized modules for better code organization.

randrescastaneda and others added 30 commits March 5, 2026 09:38
A2.1 - Remove debug statements:
- fg_pip.R: removed print('here') from fg_remove_duplicates(), #print('ZP:...')

A2.2 - Remove commented-out code blocks:
- compute_fgt_new.R: removed commented pov_from_DT2() body
- zzz.R: removed dead assign/memo_norm/detectCores commented blocks
- fg_pip.R: removed commented fg_standardize_cache_id() block

A2.3 - Remove unused functions:
- compute_fgt_new.R: removed DT_fgt_by_rl, lt_to_dt, map_lt_to_dt, map_fgt, pov_from_DT
- utils-pipdata.R: removed transform_input, get_rl_rows_single, get_rl_rows, get_dt_dist_stats, get_lt_attr
- utils.R: removed collapse_rows, convert_empty
- pip_grp_new.R: removed list_code_column_values
- create_lkups.R: removed coerce_chr_to_fct + 3 commented call sites

A2.4 - TO BE REMOVED blocks in pip_new_lineups.R left in place:
  group_by param still flows through plumber endpoint; needs discussion before removal

A2.5+A2.6 - Convert TEMP markers to TODO:
- rg_pip.R, pip_new_lineups.R, utils.R: TEMPORARY FIX -> TODO with description
- create_lkups.R: all TEMP START/END markers converted to descriptive TODO comments
…sts (A1)

A1.1 - tests/testdata/generate_snapshots.R:
  Run manually with PIPAPI_DATA_ROOT_FOLDER_LOCAL set to generate 8 .rds
  snapshot files covering: single country, all years, fill-gaps, all countries,
  multi-reporting-level, aggregation, multi-poverty-line, popshare.

A1.2 - tests/testthat/test-snapshot-baseline.R:
  Regression tests using expect_equal(tolerance=1e-10) against saved snapshots.
  Tests skip cleanly when snapshots or data folder are unavailable.
  Run with: devtools::test(filter = 'snapshot')
…t test

- Remove interactive rstudioapi/remotes lines from generate_snapshots.R
- Add header comment explaining PROD version pin and why not to change it
- Add rlang::abort() guard for missing env var
- Add missing 9th test (snap_pip_wld_pov) to test-snapshot-baseline.R
…s (A2.4)

- Remove both **** TO BE REMOVED **** blocks from pip_new_lineups()
- Remove group_by param from function signature, roxygen @param, and match.arg
- Remove group_by example from @examples block
- /api/v1/pip endpoint: mark group_by as deprecated in doc, strip it from
  params before do.call so existing callers don't error
- Aggregation is now exclusively via pip_agg() / /api/v1/pip-grp
utils.R (~900 lines, 30+ functions) split into 6 files by responsibility:
- utils-lkup.R:   lookup/filter helpers (subset_lkup, select_country, etc.)
- utils-stats.R:  stats enrichment (add_dist_stats, add_pg, add_spl, etc.)
- utils-censor.R: censoring + estimate_type classifiers
- utils-aux.R:    thin wrappers over get_aux_table() for specific datasets
- utils-query.R:  API query controls + .check_group_by()
- utils-misc.R:   general helpers (is_empty, get_caller_names, etc.)

Zero logic changes. Package loads cleanly after split.
…il (B2)

Extract ~80 lines of identical post-processing logic from pip_new_lineups()
and pip_old_lineups() into a new shared helper pip_lineups_format_output()
in R/pip_lineups_postprocess.R.

The only divergence between the two pathways is the dist-stats merge:
- new pathway: add_dist_stats(df, lkup, fill_gaps)
- old pathway: add_dist_stats_old(df, dist_stats = lkup[[dist_stats]])
This is handled via use_old_dist_stats = FALSE/TRUE.
…s_dt (B3)

- load_data_list() relocated from compute_fgt_new.R to utils-pipdata.R
  where it sits alongside other survey data I/O helpers.
- process_dt() in compute_fgt_new.R now has full roxygen2 documentation
  (@param, @return, @Keywords internal).
…x snapshot test setup

- pip.R: stop passing group_by= to pip_new_lineups() (new pathway dropped
  that parameter in A2.4); old pathway still receives it unchanged.
- test-snapshot-baseline.R: wrap create_versioned_lkups() in tryCatch so
  a missing file skips rather than errors; pin to SNAP_VINTAGE so tests
  use the same data version as the saved snapshots.
…C1+C2); add unit tests for compute_fgt, pip_lineups_format_output, utils-stats, utils-pipdata (C3-C6); add roxygen @noRd/@Keywords internal to undocumented internals (C7)
…coutnry_code typo (P2); drop stale header comment, fix %||% in test, add .cg-docs to .Rbuildignore (P2/P3)
…, sort_versions edge cases, create_return_cols (Step 2f)
…tors and get_additional_indicators_grp (Step 2h)
P1 test-pip-unit.R: replace undefined lkups with 	est_lkups
  and add skip_if guard so CI never hard-errors on missing data.

P2 test-pip_grp-unit.R, test-integ-regional-agg.R: move
  local_mocked_bindings() inside each test_that() block so the
  get_caller_names mock is properly scoped and cannot leak across
  test files.

P3 test-add_agg_stats.R: replace informal 'This test is wrong'
  comment with a TODO comment.

P3 test-censor_rows.R: guard top-level readRDS() calls with a
  skip() when fixture files are missing.

P3 test-pip.R, test-pip_grp.R: replace empty RETIRED stubs with
  a single skip() test so testthat reports them cleanly.

P3 test-compute_fgt.R: add explicit assertions for the documented
  collapse::setv() edge case (poverty_gap/severity = 0 for n=1)
  so any future regression is caught immediately.
@randrescastaneda randrescastaneda merged commit 1818502 into DEV Mar 17, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ce70464b-465e-439b-90f4-d560c90f2b52

📥 Commits

Reviewing files that changed from the base of the PR and between defa4b4 and 12b97fb.

📒 Files selected for processing (52)
  • .Rbuildignore
  • .gitignore
  • DESCRIPTION
  • NEWS.md
  • R/add_agg_stats.R
  • R/compute_fgt_new.R
  • R/create_lkups.R
  • R/fg_pip.R
  • R/pip.R
  • R/pip_agg.R
  • R/pip_grp_new.R
  • R/pip_lineups_postprocess.R
  • R/pip_new_lineups.R
  • R/pip_old_lineups.R
  • R/rg_pip.R
  • R/utils-aux.R
  • R/utils-censor.R
  • R/utils-lkup.R
  • R/utils-misc.R
  • R/utils-pipdata.R
  • R/utils-query.R
  • R/utils-stats.R
  • R/utils.R
  • R/validate_lkup.R
  • R/zzz.R
  • inst/TMP/.gitignore
  • inst/TMP/TMP_data_testing.R
  • inst/plumber/v1/endpoints.R
  • tests/testdata/generate_snapshots.R
  • tests/testthat/helper-lkup.R
  • tests/testthat/test-add_agg_stats.R
  • tests/testthat/test-additional_indicators.R
  • tests/testthat/test-censor_rows.R
  • tests/testthat/test-compute_fgt.R
  • tests/testthat/test-create_lkups.R
  • tests/testthat/test-fgt_cumsum.R
  • tests/testthat/test-input-validation.R
  • tests/testthat/test-integ-lineup-years.R
  • tests/testthat/test-integ-regional-agg.R
  • tests/testthat/test-integ-survey-years.R
  • tests/testthat/test-pip-unit.R
  • tests/testthat/test-pip.R
  • tests/testthat/test-pip_grp-unit.R
  • tests/testthat/test-pip_grp.R
  • tests/testthat/test-pip_lineups_postprocess.R
  • tests/testthat/test-plumber-future.R
  • tests/testthat/test-snapshot-baseline.R
  • tests/testthat/test-utils-lkup.R
  • tests/testthat/test-utils-pipdata.R
  • tests/testthat/test-utils-stats.R
  • tests/testthat/test-utils.R
  • tests/testthat/test-validate_lkup.R

📝 Walkthrough

Walkthrough

Major version release (1.5.0) reorganizing core utility functions across new modular files, refactoring FGT computation output structure, removing group_by parameter from pip function, adding comprehensive lookup validation, and expanding test coverage significantly. Large utils.R file split into specialized modules (utils-aux, utils-censor, utils-lkup, utils-misc, utils-query, utils-stats).

Changes

Cohort / File(s) Summary
Package Metadata
DESCRIPTION, NEWS.md, .Rbuildignore, .gitignore
Version bumped to 1.5.0; ignore patterns expanded for build artifacts and git exclusions.
FGT Computation Refactor
R/compute_fgt_new.R
Consolidated 7 helper functions; restructured compute_fgt_dt/compute_fgt output columns (headcount, poverty_gap, poverty_severity, watts instead of FGT0/FGT1/FGT2); corrected misspelled coutnry_code to country_code.
Lookup Validation & Filtering Infrastructure
R/validate_lkup.R, R/utils-lkup.R, R/create_lkups.R
Added lkup field validation utilities; extracted lookup filtering logic into dedicated module with select_country, select_years, select_reporting_level helpers; refactored create_lkups for clearer data path handling.
Pipeline Entry Points
R/pip.R, R/pip_agg.R, R/pip_new_lineups.R
Added upfront lkup validation; removed group_by parameter from pip_new_lineups; streamlined output via new pip_lineups_format_output helper.
Output Formatting & Distribution Stats
R/pip_lineups_postprocess.R, R/utils-stats.R, R/pip_old_lineups.R
New pip_lineups_format_output consolidates post-processing (censoring, rounding, ordering, deduplication); new add_dist_stats, add_distribution_type, add_pg, add_spl, add_agg_medians enhance data with auxiliary statistics.
Censoring & Estimate Type Classification
R/utils-censor.R
New module provides censor_rows, censor_stats, estimate_type_var, estimate_type_ctr_lnp for robust row removal and estimate-type labeling based on metaregion tables and per-statistic rules.
Auxiliary Data Retrieval
R/utils-aux.R
New wrappers (get_svy_data, get_spr_table, get_metaregion_table, get_pg_table) with safe empty-schema fallbacks when data unavailable.
Query Parameters & Misc Utilities
R/utils-query.R, R/utils-misc.R, R/utils-pipdata.R
New create_query_controls and .check_group_by for API validation; new is_empty, fillin_list, clear_cache, get_caller_names, unnest_dt_longer utilities; refactored add_attributes_as_columns via load_data_list.
Aggregation & Data Processing
R/add_agg_stats.R, R/fg_pip.R, R/rg_pip.R, R/zzz.R
Added negative_to_na and zeros_to_na helpers; formatting/minor logic adjustments in fg_pip and rg_pip; switched caching from qs to qs2 with added memoization of pip, pip_agg, ui_* functions.
Legacy Utils Removal & Reorganization
R/utils.R
Entire file (1582 lines) deleted; all functions extracted to specialized modules (utils-aux, utils-censor, utils-lkup, utils-misc, utils-query, utils-stats).
API & Test Infrastructure
inst/plumber/v1/endpoints.R, tests/testthat/helper-lkup.R, tests/testdata/generate_snapshots.R, inst/TMP/TMP_data_testing.R
Deprecated group_by on /pip endpoint; added test helper with TEST_VINTAGE and skip_if_no_lkup; new snapshot generation script; new data testing script.
Test Coverage Expansion
tests/testthat/test-*.R (new files)
Added comprehensive unit and integration tests: compute_fgt, fgt_cumsum, input_validation, integ-lineup-years, integ-regional-agg, integ-survey-years, pip-unit, pip_lineups_postprocess, snapshot-baseline, utils-lkup, utils-pipdata, utils-stats, validate_lkup, censor_rows, additional_indicators, create_lkups; retired old test-pip.R, test-pip_grp.R, test-plumber-future.R.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes


Poem

🐰 A grand refactor hops our way,
Utils split to files today,
FGT columns freshly named,
Group_by removed, validation claimed,
Test suites bloom from seed to tree—
Version one-point-five runs free!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch new-test-suite
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

@randrescastaneda randrescastaneda deleted the new-test-suite branch March 18, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant