Skip to content

feat: add rounding as a protection mechanism#381

Open
ssrhaso wants to merge 4 commits intomainfrom
feat/rounding-mitigation-126
Open

feat: add rounding as a protection mechanism#381
ssrhaso wants to merge 4 commits intomainfrom
feat/rounding-mitigation-126

Conversation

@ssrhaso
Copy link
Copy Markdown
Contributor

@ssrhaso ssrhaso commented Apr 21, 2026

Adds a mitigation field on ACRO/Tables: "none", "suppress", or "round". "round" rounds every cell of crosstab / pivot_table output to the nearest round_base (default 5, set via safe_round_base in the yaml).

The old suppress bool, enable_suppression/disable_suppression, and the Stata suppress option still work as aliases, so existing scripts don't break. New helpers enable_rounding(base=...) / disable_rounding() mirror the suppression pair.

margins=True is rejected under rounding - rounded inner cells don't add up to rounded totals and that's a known attack vector (per the bounds-tightening discussion on #126). SDC audit records keep the raw disclosure-check results so rounding can't mask threshold failures.

If needed we can switch margins=True from hard-fail to warn-and-strip if thats better user experience. Left StrEnum for a follow up!

Closes #126.

Introduces a 'mitigation' field on ACRO / Tables that can be 'none',
'suppress', or 'round'. 'round' applies whole-table rounding to the
nearest 'round_base' (default 5, configurable via 'safe_round_base' in
the yaml). The old boolean 'suppress' is preserved as a backward-
compatible property. 'margins=True' is rejected under rounding because
rounded totals would not add up and are a known attack vector.

Implements issue #126.
@ssrhaso ssrhaso requested review from Copilot and jim-smith and removed request for Copilot April 21, 2026 10:08
@ssrhaso ssrhaso self-assigned this Apr 21, 2026
@ssrhaso ssrhaso requested a review from rpreen April 21, 2026 10:08
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.72%. Comparing base (aa8cb42) to head (23a54f6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #381      +/-   ##
==========================================
+ Coverage   99.70%   99.72%   +0.02%     
==========================================
  Files           9        9              
  Lines        1354     1457     +103     
==========================================
+ Hits         1350     1453     +103     
  Misses          4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ssrhaso added 3 commits April 21, 2026 11:17
Adds unit tests for mitigation/round_base options on acro init and for
the enable_rounding/disable_rounding session commands, lifting stata
parser patch coverage from 60% to 99%.
- Adds D213 summary-on-second-line and D413 trailing-blank-line to the
  four new docstrings Codacy flagged.
- Adds the missing Tables.__init__ docstring.
- Drops the unused round_base kwarg from Tables.__init__ (ACRO sets
  round_base via the property setter after reading yaml, so the kwarg
  path was dead in practice).
- Adds a unit test for the missing-values branch of _rounded_summary
  to close the codecov patch gap.
Codacy enables D212 and D213 simultaneously (they are mutually
exclusive), and pydocstringformatter strips the trailing blank line
D413 requires. Single-line docstrings sidestep all three. Type hints
still document the parameters.
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.

[Feature]Add rounding as a protection mechanism

1 participant