Skip to content

Standardize frontend on country_id instead of tax_benefit_model_name#803

Merged
anth-volk merged 9 commits intomove-to-api-v2from
feat/v1-v2-migration-script
Mar 14, 2026
Merged

Standardize frontend on country_id instead of tax_benefit_model_name#803
anth-volk merged 9 commits intomove-to-api-v2from
feat/v1-v2-migration-script

Conversation

@anth-volk
Copy link
Collaborator

@anth-volk anth-volk commented Mar 9, 2026

Fixes #802
Fixes #818

Summary

v1-to-v2 report migration script

  • Strategy/orchestrator architecture for migrating v1 reports to v2
  • Individual strategies for policies, households, populations, economy simulations, user report associations
  • Orchestrator coordinates multi-step migration with per-report error handling
  • Detection and cleanup utilities for localStorage references

Standardize frontend on country_id

  • All API calls now send country_id ("us" or "uk") instead of tax_benefit_model_name ("policyengine_us" etc)
  • Core Household type field changed from tax_benefit_model_name to country_id
  • Updated all v2 API modules, adapters, hooks, migration orchestrators, utilities
  • Deprecated countryIdToModelName/modelNameToCountryId as identity functions
  • Updated all 45 test fixture files and 17 unit test files (82 files total)

Test plan

  • TypeScript typecheck passes with 0 errors
  • All modified unit tests pass (141 tests across 9 test files verified)
  • Verify migration script correctly migrates a v1 household report end-to-end
  • Verify migration script correctly migrates a v1 economy report end-to-end
  • Verify household creation sends country_id to API
  • Verify parameter tree loads correctly with country_id query param

Companion API PR: PolicyEngine/policyengine-api-v2-alpha#109

🤖 Generated with Claude Code

anth-volk and others added 2 commits March 8, 2026 21:56
…itecture

Replace the old migration code (which only copied association pointers
without migrating base entities) with a proper layered system:

- Detection: pure localStorage reads to find v1 reports on page load
- Strategies: single-purpose functions for each record type (policy,
  household, geography, and all user-association types)
- Orchestrators: compose strategies to migrate full report trees
  (policy → household → analysis endpoint → user associations)
- Cleanup: remove only successfully-migrated records from localStorage
- Reports page: detection banner with progress UI and migrate button
- Tests: 41 tests across detect, strategies, orchestrators, and cleanup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…_name

All API calls, types, adapters, hooks, and utilities now use country_id
('us' or 'uk') instead of tax_benefit_model_name ('policyengine_us' etc).
Updates Household type field, all v2 API modules (datasets, regions,
parameters, variables, economyAnalysis, simulations, households), adapters,
migration orchestrators, and all test fixtures/unit tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-app-v2 Ready Ready Preview, Comment Mar 14, 2026 1:14am
policyengine-calculator Ready Ready Preview, Comment Mar 14, 2026 1:14am

Request Review

@anth-volk anth-volk changed the base branch from main to move-to-api-v2 March 9, 2026 17:53
…chestrator

Replace single policy_id with baseline_policy_id + reform_policy_id in
economy and household analysis TypeScript interfaces, strategy classes,
useCreateReport hook, and v1-v2 migration orchestrator. Orchestrator now
fetches both v1 simulations and migrates both policies independently.

Updates all corresponding tests and fixtures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Migration orchestrator now passes run: false to both analysis endpoints,
creating reports with EXECUTION_DEFERRED status instead of triggering
immediate computation. Adds execution_deferred to frontend ReportStatus
types. Fixes 3 pre-existing ESLint errors (duplicate import, missing
curly braces, unused import).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Surface unmapped v1 policy parameters as warnings in the migration
  banner (strategies → orchestrator → UI pipeline)
- Show report labels and v1 report IDs in error/warning details
- Style the pre-migration banner with design token grayscale background
- Use teal for success, yellow for warnings-only, orange for errors
- Add enabled guards (!!userId) to simulation, household, and policy
  hooks to prevent 422 errors from empty user_id
- Flip storeBackend to 'api' and update useUserReports for UUID-based
  v1/v2 classification with v2 full-endpoint fetching
- Add brittleness analysis document for migration code
- Fix test fixtures and mocks for updated types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address code review findings: fix sentence case in column headers,
correct indentation in orchestrator early-return blocks, surface
migration errors to the user via Alert, and log errors in cleanup
catch blocks. Enable actual localStorage removal of migrated v1
records instead of dry-run counting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update variables test to match new country_id-based API (no upfront
unknown country validation). Update useUserHousehold test to expect
disabled query with empty userId (enabled guard). Fix duplicate
import in apiV2Mocks. Apply prettier formatting across codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anth-volk
Copy link
Collaborator Author

Requires completion of PolicyEngine/policyengine-api-v2-alpha#109 before review/merge

@anth-volk anth-volk marked this pull request as ready for review March 14, 2026 00:01
…wallowing them

cleanup.ts now returns errors in CleanupSummary instead of silently returning 0.
detectV1Reports now returns DetectionResult with error field so callers can
distinguish "no reports" from "corrupt localStorage". Reports page surfaces
detection errors to the UI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anth-volk anth-volk merged commit 2fc131d into move-to-api-v2 Mar 14, 2026
7 checks passed
@anth-volk anth-volk deleted the feat/v1-v2-migration-script branch March 14, 2026 01:20
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.

Standardize frontend on country_id instead of tax_benefit_model_name

1 participant