Skip to content

refactor: split billConverters into focused, testable modules#75

Open
mikaalnaik wants to merge 1 commit into
mainfrom
mikaal/refactor-bill-converters
Open

refactor: split billConverters into focused, testable modules#75
mikaalnaik wants to merge 1 commit into
mainfrom
mikaal/refactor-bill-converters

Conversation

@mikaalnaik

@mikaalnaik mikaalnaik commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

What

Refactors the single 298-line src/utils/billConverters.ts into a billConverters/ directory with one responsibility per file, and adds unit tests.

File Responsibility
index.ts Barrel re-export — keeps every existing @/utils/billConverters import working unchanged
types.ts UnifiedBill interface
normalize-final-judgment.ts Pure judgment normalizer (tested)
default-analysis.ts Default 8-tenet BillAnalysis factory + tenet constant
from-build-canada-db-bill.ts Pure DB→unified converter (tested)
from-civics-project-api-bill.ts Async API→unified converter (DB/AI deps)

Why

The converters were a single large file with no tests and duplicated logic. Splitting them makes the pure pieces individually testable.

Notable change

The final_judgment logic was duplicated inline in both converters with a subtle inconsistency — the DB version cast the raw value (so "YES" passed through un-lowercased) while the API version lowercased it. Both now use a single pure normalizeFinalJudgment(value, fallback) returning a clean lowercase "yes" | "no" | "abstain". Behaviorally equivalent downstream (consumers like shouldShowDetermination already lowercase); the fallback param preserves the API converter's behavior of falling back to the default analysis judgment rather than always "abstain".

Tests

12 new tests (5 for normalizeFinalJudgment, 7 for fromBuildCanadaDbBill). Full suite: 41 passing. type-check and biome clean.

🤖 Generated with Claude Code

Break the single billConverters.ts into a billConverters/ directory with
one responsibility per file (types, default analysis, the two converters,
and a shared final_judgment normalizer). An index.ts barrel preserves the
existing @/utils/billConverters import path.

Unify the two duplicated, slightly-inconsistent final_judgment normalizers
into a single pure normalizeFinalJudgment() and add unit tests for it and
for fromBuildCanadaDbBill.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mikaalnaik mikaalnaik self-assigned this Jun 30, 2026
@mikaalnaik
mikaalnaik requested a review from xrendan June 30, 2026 18:01
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