← all branches

feat/tax-regime

safeviewing older commit
a72b534 · incrementalPR #302reviewed 2026-07-13 19:28 UTC0H · 0M · 0L · 5I
The branch
Purpose
Per-contract IVA regime for calculated bills — northern-border sites pay 8% (IVA Frontera Norte) not the hardcoded 16%
Goal
NaN-proof the resolveTaxRate decision function and findRateByCode query boundary; close the zero-rate false-falsy and undefined-passthrough gaps
Sub-goals
  • SG-1: tax_regime column + migration on utility_contracts
  • SG-2: TAX_REGIMES/TAX_REGIME_RATES threaded through type, mapper, decisions
  • SG-3: Shell wiring — resolveSiteTariffContext → computeBillShell (drops MX_IVA constant)
  • SG-4: NaN-proof at DB boundary (findRateByCode) and decision layer (resolveTaxRate)
  • SG-5: Test coverage — zero-rate hit, NaN/undefined miss, fallback chain
The changes (whole branch)
What
resolveTaxRate guard widened from !== null to typeof+isFinite; findRateByCode NaN-filters at DB boundary; two new unit tests added
Why
Prior review (92e5afa) identified zero-rate tableRate=0 as untested and undefined passthrough as unguarded; this commit closes both gaps
Areas
domains/utility+1554domains/cross-domain+534packages/api+72packages/database+670
Blast
27 files, +13263/-8 total (bulk is drizzle meta snapshots); functional billing changes in 8 files
ci· check-run API not accessible from runner; typecheck green per PR descriptioncoderabbit· no .coderabbit.yaml

Findings · 5

correctness1

info

findAllRates bulk map skips NaN-filter

domains/utility/src/tax-rate/tax-rate.queries.ts:22

findAllRates (unchanged) maps rows without isFinite guard. Low real-world risk (numeric Postgres type; main billing path uses findRateByCode), but bulk callers could get NaN from malformed DB row.

security1

info

Default 16% fallback is the safe (over-tax) direction

domains/utility/src/tax-rate/tax-rate.decisions.ts

TAX_REGIME_RATES.iva = 0.16 as ultimate default over-taxes unrecognised regimes; shell warns on source:'default'. Correct compliance stance.

conventions1

info

undefined cast in tests is intentional defensive coverage

domains/utility/src/tax-rate/__tests__/tax-rate.decisions.test.ts:14

undefined as unknown as number proves the guard works under TypeScript erasure. Acceptable pattern.

tests1

info

Infinity / -Infinity not explicitly asserted

domains/utility/src/tax-rate/__tests__/tax-rate.decisions.test.ts

Number.isFinite correctly rejects both; guard is provably right. Consider adding if this ever changes.

improvement1

info

typeof guard is slightly redundant but legitimate defense-in-depth

domains/utility/src/tax-rate/tax-rate.decisions.ts:23

Number.isFinite(null) is false so typeof check is redundant per type sig. But adds safety against TypeScript erasure. Intentional — not a target for simplification.

History · 6 commits

  1. a1f0898needs attentionincremental1H · 1M · 4L2026-07-13 20:37
  2. a72b534safeincremental0H · 0M · 0L2026-07-13 19:28current
  3. 92e5afaneeds attentionincremental1H · 1M · 8L2026-07-13 16:47
  4. 7f40d56needs attentionincremental1H · 4M · 5L2026-07-13 16:38
  5. 5088e00needs attentionincremental3H · 4M · 4L2026-07-13 02:47
  6. 1bda877blockedfull12H · 12M · 9L2026-07-13 02:30