Skip to content

v3 standalone household report and saved households, unreachable until v3 moves to the v2 routes - #1392

Draft
anth-volk wants to merge 47 commits into
v2plan/1e-112-v3-uk-us-householdsfrom
v2plan/1e-113-household-report-saved-households
Draft

anth-volk wants to merge 47 commits into
v2plan/1e-112-v3-uk-us-householdsfrom
v2plan/1e-113-household-report-saved-households

Conversation

@anth-volk

@anth-volk anth-volk commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1391

Stacked on #1386.

What changes

The code for v3's standalone household report and saved households. No route or control reaches it yet (see "Unreachable until v3 moves to the v2 routes"), so users see no change.

v2 household documents (models/household/v2DocumentCodec.ts, types/v2Households.ts). The app writes a household as API v1's /v2/households document exactly as API v1 translates a v1 household (translate_legacy_household): people and groups take ids in name order, v1 names are kept as source_name, group members become each person's memberships, the SPM settings go on the document, and no label is sent. So a household v3 saves deduplicates with the dual-write copy of the same v1 household. A stored household reads back into the app's model in its stored default_year. haveSameStoredContent compares two households as POST /v2/households takes them, since a stored household reads back with its groups in name order.

Saved households (api/savedHouseholdStore.ts, hooks/useSavedHouseholds.ts), with accounts on, signed in or signed out as the browser's unauthenticated user:

  • save: POST /v2/households (which returns the existing household for identical content), then POST /v2/user-households with the label and the v2 household_id;
  • list (most recently updated first; a row naming only a v1 household, or whose household fails to load, is listed as unavailable rather than failing the list), open, rename (PATCH of the name) and delete (the row only: stored households are shared);
  • save changes: edited content is stored, then one PATCH /v2/user-households/{id} points the saved household at it (household_id) with any new label, so it keeps its id; identical content changes no row; either step failing says "Your changes were not saved";
  • queries are cached per user and country; each stored household is fetched once per session (kept in the query client by country and id, as stored households never change).

Without accounts there are no saved households: each control says so, and nothing is saved in the browser.

Saved household interface (components/flagship/household/): a "Household label" field with Save (SaveHouseholdForm: a new household, changes to a saved one, or a rename alone; moving a saved household into the report's year is not an edit; "Saved" shows only while it describes what is on screen); a picker (SavedHouseholdPicker); and SavedHouseholds.page ("Your households") with Rename and Delete, which asks first.

Standalone household report (pages/flagship/HouseholdReport.page.tsx), for one household under a baseline and, optionally, a reform:

  • the net income headline: the change in net income with a reform (the report section's HouseholdImpactResult), or net income alone for a baseline-only household (HouseholdNetIncomeResult), including one whose reform is the baseline;
  • the net income tree, varying earnings and marginal tax rates (HouseholdBreakdowns);
  • the household's inputs (HouseholdSubPage), the policy summary (PolicySubPage) and Reproduce in Python (HouseholdReproducibility), each Python block given its own policy by id and pinned to the .py bundle its own calculation reported;
  • a year the reader chooses from the model's tax years (Add user-selectable year to standalone household creation #498): the household's inputs move to it with the report builder's copyHouseholdToYear; a household or saved household with inputs in several years opens in its own year, with the reason;
  • varying earnings also offers the amounts the household sets, such as tip income (App does not display all possible variables in "Varying your earnings" #1096; EarningsVariationSubPage's new alsoOfferInputs, passed only by this report; the SALT cap, the issue's other example, is a calculated variable the list already offers);
  • Reproduce in Python can end each block with a pandas DataFrame (Add dataframe-generating code to Reproduce in Python segment #1095; getHouseholdReproducibilityCode's new includeDataFrame option and HouseholdReproducibility's offerDataFrame, passed only by this report). Blocks generated for a UK household under a personal allowance reform (run against policyengine-uk 2.130.1) and for a US household under current law (policyengine-us 2.2.1) ran locally: the point block prints a four-row table and the earnings variation block a 401-row one;
  • the household builder as v3 configures it, the saved-household picker (disabled while a calculation runs) and the save form.

It calculates through API v1's /{country}/household routes, as the report section does; "Try again" never sends a household that cannot run.

Shared with the live report section and the saved reforms page, behaving as before (their existing tests are unchanged):

  • HouseholdBuilderPanel: the builder configuration the section used, now used by both;
  • useRequestedHouseholdRun (the run request: asking again for the same household, retrying only a household that can run; it passes main's onCreated on, which starts the Household tab's variation run, and sends every household through householdAsSent, below), householdRunParts (Calculate, progress with the run's start time, and failure) and householdResultParts (card, headline and output tabs; the tabs' hover color now applies). Money formatting is main's householdMoney;
  • newV3Household, the section's new household, moved to libs/flagship/householdReport;
  • DeleteConfirmationDialog, now rendered by DeleteReformDialog and the saved households list.

The existing household report output and the report section offer the same earnings variables and Python code as before: the new options default off.

Merged with #1386's updated branch (2026-11-28), which carries main (de9c9e570) and its redesigned Household tab (#1511). The tab keeps main's design (household switcher, Results and Inputs views, "Calculate again", the variation run started once the household is stored) and uses the shared parts above. main's HouseholdImpactResult has no card or title of its own, as the tab's panel names it, so the standalone report now gives it a card headed "Household impact", as its baseline-only result has. main also moved the variation run's start time to the breakdowns' caller and keeps the run with HouseholdVariationKeeper; the standalone report now does the same from when either variation output first opens (the tab starts it once the household is stored), so moving between Varying earnings and Marginal tax rates no longer starts the run and its progress bar again, and a new request starts a new run.

One way to send a household. householdAsSent (utils/householdAsSent.ts) prepares a household as v3 sends it to API v1: a UK builder household with #1240's claimant and partner roles for the loaded model. The run hook sends every household through it, for the Household tab and the standalone report alike (so the tab no longer adds the roles itself), and compares the household on screen in the same form; the standalone report's Reproduce in Python code reproduces the household as sent; SaveHouseholdForm stores households that way and compares the one on screen, the saved one and its last save in that form. The standalone report also waits for the model's variables, as the Household tab does (V3VariablesGate), so on the v2 routes no UK household is sent or saved before the roles' variable is known. The v2 report builder's own flows still add the roles themselves.

Calculator route. main's same-origin route to API v1 (/api/policyengine/…) forwards only the operations on its allow list (libs/publicApiRoute/allowList.ts). This PR adds the ones the saved-household store calls: "saved household" (GET, PATCH and DELETE /v2/user-households/{uuid}), "stored household creation" (POST /v2/households) and "stored household" (GET /v2/households/{uuid}), none cached. The route forwards them once this merges, though nothing in the app calls them until the saved-household pages are linked in.

Unreachable until v3 moves to the v2 routes

No runtime flag or environment variable; only the calculator route's allow list above changes live. Everything that works only on the v2 routes is gathered in app/src/pages/flagship/householdEntryPoints.ts, which nothing routed imports. householdEntryPoints.test.tsx checks that Build's "A household" option cannot be chosen, and that no file in the app or the calculator imports the household-only modules, by an @/ specifier or a relative path, except those modules themselves (confirmed to fail, naming Report.page.tsx, when that page imported one by a relative path). A report whose simulations are households still shows "This report cannot open here" (ReportLoadStates.test.tsx).

What the change that moves v3 to the v2 routes does to reach them:

  1. Enables Build's "A household" option (components/flagship/reform/PopulationPicker.tsx): choosing it offers SavedHouseholdPicker or a new household, and Build's run opens HouseholdReportPage with that household, the draft reform, and the run bar's year and baseline.
  2. Renders HouseholdReportPage in Report.page.tsx's householdReport branch for household reports saved through /v2/reports.
  3. Adds a saved households route (calculator-app/src/app/[countryId]/(workspace)/households/page.tsx rendering SavedHouseholdsPage), a "households" screen in workspaceRoutes.ts and libs/flagship/shellRoutes.ts, and a link in the workspace navigation.

Before then, the report's calculations move to /v2/household-calculations, and saving changes to a saved household needs API v1's PATCH /v2/user-households/{id} to accept household_id (today its update model accepts only legacy_household_id, name and description, so that request is refused and the form says the changes were not saved).

Tests

New or changed, all passing (155 tests, run by name after the merge; each count is the file's new or changed tests):

  • v2DocumentCodec.test.ts (15): US and UK documents match API v1's translation (checked against translate_legacy_household for three households: same canonical content hash and default year); no label is sent; a person outside a collection fails, naming it; read-back keeps the stored id and default_year (including inputs in two years, values without a year, and no default year).
  • savedHouseholdStore.test.ts (19): save, list (order, unavailable rows), open, rename, delete; save changes (one PATCH keeping the id, identical content, either step failing); each stored household fetched once, a failed fetch asked again.
  • useSavedHouseholds.test.tsx (8): the hooks against routed API v1 responses, including no accounts, a country change for the same user, and one stored-household cache across hooks.
  • SaveHouseholdForm.test.tsx (12), SavedHouseholdPicker.test.tsx (9), SavedHouseholds.page.test.tsx (8), DeleteConfirmationDialog.test.tsx (4), HouseholdBuilderPanel.test.tsx (5), HouseholdNetIncomeResult.test.tsx (4).
  • HouseholdReport.page.test.tsx (37): a reform's change, under its "Household impact" heading, and a baseline-only household's net income; a UK household sent, reproduced in Python and saved with its claimant and partner roles, and one saved without them opening with nothing to save; the report waiting for the model's variables; the variation run keeping its start time between outputs, and starting afresh for a new request; baseline-only breakdowns; the inputs, policy and Reproduce in Python sections, each block with its own policy and bundle; trying again (including after an edit that cannot run); Calculate disabled for the household shown; years (Add user-selectable year to standalone household creation #498); the result describing the household calculated; tip income in varying earnings (App does not display all possible variables in "Varying your earnings" #1096); national poverty thresholds for a new US household; a UK household in pounds; saved households (save, save changes, a failed save, opening from the picker or on entry, another year, a save finishing after another household is opened, no picker during a calculation, no accounts).
  • householdEntryPoints.test.tsx (5), reproducibilityCode.test.ts (+3), HouseholdReproducibility.test.tsx (+2), EarningsVariationInputs.test.tsx (2), HouseholdBreakdownsInputs.test.tsx (2), householdReport.test.ts (1).
  • householdAsSent.test.ts (2).
  • allowList.test.ts (+10, and its two whole-list checks): the five saved-household operations, and their refused neighbours; publicApiRouteCalls.test.ts (+5): the saved-household store's calls go through the same-origin route, which forwards them.

Each commit's tests were run failing first, then passing; refactor and style commits say so where there was no behavior to fail first. After the merge of #1386's updated branch, the tests above were run by name (Node 26) and pass, and tsc (app, website and calculator), ESLint and Prettier are clean on the changed files.

Three review rounds were run on this branch: the first found two bugs (a retry could send a household that cannot run; "Saved" stayed after an edit) and the second one (a save finishing after another saved household was opened pointed the form at the wrong saved household); each was fixed with a failing test first, with the material quality findings. The third found none. After the merge of #1386's updated branch, three more rounds reviewed the changes it needed (the heading, the variation run, the route's allow list): the second found one bug (a kept variation run was never reset, so a cached result brought it back), fixed with a failing test first; the first and third found none. Two more rounds reviewed the one-way sending of households: the first found two bugs (a save's "Saved" status compared in the model information of its time; on the v2 routes the report could send a UK household before the model's variables loaded), each fixed with a failing test first; the second found none. Each round's quality findings were fixed.

Environment variables

None added or changed, and no route reaches the new code. The allow list change reads no environment variable. When reached, it uses the app's existing clients: VITE_API_URL (set as NEXT_PUBLIC_API_URL or VITE_API_URL) for API v1's address, and the existing sign-in configuration (NEXT_PUBLIC_AUTH_ENABLED, NEXT_PUBLIC_AUTH0_DOMAIN, NEXT_PUBLIC_AUTH0_CLIENT_ID, NEXT_PUBLIC_AUTH0_AUDIENCE, or their VITE_ names), all from the Vercel build environment and mapped in calculator-app/next.config.ts. Their Vercel values were not re-checked here.

Before merging

Overlaps

  • Draft Send explicit UK claimant roles and stop reading an adult dependant as the partner #1240 (UK claimant roles): not modified; no file in common.
  • Draft Use compact typed SPM provenance contracts #1239 (compact SPM provenance) also edits utils/reproducibilityCode.ts and drops spmConfig from HouseholdReproduction. Whichever merges second adapts: here the options object and the DataFrame code are independent of the SPM settings, and the household report passes each block's spmConfig, which would then be left out.
  • v3's saved reforms on /v2/policies also add v2 client code here; the household wire types are in their own types/v2Households.ts and use the existing V2UserClient and AccountAssociationRoutes.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
policyengine-calculator-next Ready Ready Preview Nov 27, 2026 10:36pm UTC
policyengine-website Ready Ready Preview Nov 27, 2026 10:36pm UTC

Request Review

anth-volk and others added 16 commits November 2, 2026 18:53
…tores them

Saved households in v3 will live on the Public API's /v2/households
(immutable, deduplicated content) and /v2/user-households (the user's
name for one), so the app needs the v2 household document:

- types/v2Households.ts: the wire types for both routes. The PATCH body
  includes household_id, which points a saved household at another
  stored household once the Public API accepts it.
- householdToV2CreateBody builds the document exactly as the Public API
  translates a v1 household (translate_legacy_household): ids in name
  order, v1 names kept as source_name, group members as each person's
  memberships, the SPM settings on the document, and no label. So a
  household v3 saves deduplicates with the dual-write copy of the same
  v1 household. A person outside a collection, which v2 rejects, fails
  here first, naming the collection.
- householdFromV2Item reads a stored household back into the app's
  model, with the stored id, people in the builder's order, and a
  record's id as its name when it has no v1 name.

Tests first: the codec tests failed to import the missing module. The
fixtures' documents were checked against the Public API's own
translation: for the US single parent, the UK single parent and the US
couple with two children, translate_legacy_household on the same v1
households gives the same canonical content hash and default year.

Nothing uses it yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store behind v3's saved households, with accounts on, signed in or
signed out as the browser's unauthenticated user:

- save: POST /v2/households (which returns the existing household for
  identical content), then POST /v2/user-households with the label and
  the v2 household_id;
- list, most recently updated first; a row naming only a v1 household,
  or whose household fails to load, is listed as unavailable rather
  than failing the list;
- open, rename (PATCH of the name) and delete (the row only: stored
  households are shared);
- saveChanges: edited content is stored, and one PATCH points the saved
  household at it (household_id) together with any new label, so the
  saved household keeps its id, name and creation date. Identical
  content changes no row. If the PATCH fails, the reader is told the
  changes were not saved; the saved household is as it was.

Pointing a saved household at another stored household needs the
Public API's PATCH /v2/user-households to accept household_id; until it
does, nothing reaches this code.

Tests first: the store's tests (15) failed to import the missing module,
then pass against Public API responses routed by method and path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
useSavedHouseholds lists the session's saved households (signed in, or
signed out as the browser's unauthenticated user), useSavedHousehold
opens one, and save, rename, delete and saveChanges are mutations that
read the list and every opened saved household again once they
succeed. Cached saved households are keyed by whose they are, as v3's
other saved work is. Without accounts nothing is listed or asked for,
and saving fails plainly ("Saved households need an account.") rather
than saving in the browser.

Tests first: the hook tests (6) failed to import the missing module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SaveHouseholdForm, for the household in the builder: a "Household
label" field and a Save button. A new household is saved under the
label. For a saved household, "Save changes" saves only what changed:
edited content is stored and the saved household pointed at it, with
any new label in the same request, so the saved household keeps its id;
a new label alone only renames it. A household counts as edited only
when its content differs as POST /v2/households takes it
(haveSameStoredContent in the codec), since a household read back from
the Public API lists its groups in name order and would otherwise read
as changed. A failed save says why; without accounts the form says
saved households are not available, with nothing to press.

Tests first: the form's tests (9) failed to import the missing
component, and the comparison's tests (4) failed with
haveSameStoredContent not a function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SavedHouseholdPicker lists the session's saved households in a country,
each by its label (or "Untitled household") with who it describes, in
the year its inputs are in, and hands the chosen one on with its
household. The saved household the builder holds is marked as chosen.
One that cannot open (its row names only a v1 household, or its
household failed to load) is listed but cannot be chosen. While loading,
on a failed load, with none saved, and without accounts, it says so.

savedHouseholdDisplay holds what the save form, this picker and the
saved-household list share: the name, the description, the notice shown
instead of a list, and the "not available" text the save form now
imports.

Tests first: the picker's tests (8) failed to import the missing
component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SavedHouseholdsPage ("Your households") lists the session's saved
households, each by its name with who it describes, to rename or
delete:

- Rename opens the shared rename dialog; the new label is saved with a
  PATCH of the name. A failed rename keeps the dialog open with the
  reason.
- Delete asks first, then deletes the saved row only (the stored
  household stays). A failed delete names the household and the reason
  above the list, and the household stays listed.
- A saved household that cannot open is listed and can still be renamed
  or deleted.

Without accounts it says saved households are not available. No route
renders the page yet.

Tests first: the page's tests (8) failed to import the missing page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Issue #1095 asks for code that goes from a household result straight to
a pandas DataFrame for charts. getHouseholdReproducibilityCode takes its
options as named fields ({ earningVariation, includeDataFrame }) rather
than positional booleans, and includeDataFrame appends:

- for a point calculation, one row per household result (net income,
  market income, tax, benefits);
- for an earnings variation, one row per earnings level, with the
  household's employment income (summed to the household) beside each
  result, ready to chart.

The four variables exist in the US and UK models. Generated blocks were
run locally: for a UK household under a personal allowance reform
against policyengine-uk 2.130.1, and for a US household under current
law against policyengine-us 2.2.1, the point block prints four rows and
the variation block 401.

HouseholdReproducibility offers the switch ("Include a pandas
DataFrame") only when offerDataFrame is passed. Nothing passes it yet,
so the existing household report's Reproduce in Python is unchanged.

Tests first: the code tests failed (no DataFrame code; the options
object did not type-check) and the component's switch test failed (no
such switch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…old report

Issue #1096: "Varying your earnings" never offers tip income, even for a
household with tips, because the variable list leaves out every input
variable, and tip_income is an input.

- EarningsVariationSubPage takes alsoOfferInputs: inputs offered beside
  the calculated variables when the variation returns values for them.
  Other inputs stay out.
- householdAmountInputs lists the nonzero amounts a household itself sets
  (tip income, for one with tips), leaving out the earnings the chart
  varies and age, which every household carries.
- HouseholdBreakdownSource takes householdInputs, which reach only the
  earnings variation.

Nothing passes them yet, so the existing household report and v3's
report section offer the same variables as before; the standalone
household report will pass the household's inputs. The SALT cap, the
issue's other example, is calculated, so the list already offers it.

Tests first: householdReport.test.ts failed to import the missing
module; the variation page offered no tip income when asked; the
breakdowns did not pass the household's inputs on; the new props did
not type-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e household report

HouseholdBuilderPanel is the household builder as v3 configures it:
inputs grouped by topic with the country's featured inputs first, a
variable search that lists only the household's own state's programs,
only inputs that describe a household and no twin of a field the
builder already shows, the country's names for people (a UK household's
children), labelled inputs, and the SPM geography choice the builder
shows for a US household. The report section's household card now
renders it, passing its suggestions and analytics callbacks, so the
standalone household report can use the same configuration instead of
a copy that could drift.

The section behaves as before: its tests, which render a stand-in for
the builder and check what it is given, pass unchanged.

Tests first: the panel's tests (5) failed to import the missing
component; the filter test also failed until the test's model
information listed employment income as a basic field, showing the
twin rule is checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…households

HouseholdNetIncomeResult shows a household's result when there is no
reform to compare: its annual net income in whole dollars or pounds,
then the v2 breakdowns under that one policy (the net income tree
first, varying earnings and marginal tax rates), with the calculation's
SPM methodology under the net income tree and not under the variation
views, which show their own.

householdResultParts holds what it shares with HouseholdImpactResult:
the money formatting, the card style and the output tabs. The impact
result now uses them and behaves as before (its tests and the section's
analytics tests pass unchanged).

Nothing renders the new result yet; the standalone household report
will, for a household with no reform.

Tests first: the result's tests (4) failed to import the missing
component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HouseholdReportPage reports one household under a baseline and,
optionally, a reform:

- the net income headline, calculated once: the change in net income
  with a reform (HouseholdImpactResult), or net income alone for a
  baseline-only household, including one whose reform is the baseline
  (HouseholdNetIncomeResult);
- the net income tree, varying earnings and marginal tax rates, with the
  amounts the household sets, such as tip income, offered in varying
  earnings (#1096);
- the household's inputs, the policy summary, and Reproduce in Python
  with the pandas DataFrame option (#1095); each Python block is given
  its own policy by id (so a policy that fails to load is never given to
  the other block) and pinned to the .py bundle its own calculation
  reported;
- a year the reader chooses from the model's tax years (#498): the
  household's inputs move to it with the report builder's
  copyHouseholdToYear, a household or saved household from another year
  opens in the report's year, and a year change clears the result;
- the household builder as v3 configures it (HouseholdBuilderPanel; a
  new US household starts on national poverty thresholds), the
  saved-household picker and the save form, whose confirmation or error
  stays on screen after a save.

Calculate is disabled while the household on screen is the one
calculated; after a failure, "Try again" asks for the same household
once more. The result keeps describing the household calculated after
the builder changes. It calculates through the Public API's v1
household routes, as the report section does.

newV3Household, the report section's new household (with a UK nation's
place), moves to libs/flagship/householdReport so both use it; the
section behaves as before.

Tests first: the page's tests (23) failed to import the missing page.
Two then failed for their own setup (one rendered nothing; one stored a
different household from the one sent) and were fixed in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oves to v2

householdEntryPoints.ts gathers the standalone household report, the
saved households page, the saved-household picker and the save form,
and says what the change that moves v3 to the Public API's v2 routes
does to reach them: enable Build's "A household" option, render the
report for household reports saved through /v2/reports, and add a
saved households route. No runtime flag or environment variable.

householdEntryPoints.test.tsx checks that:

- Build's "A household" option is listed but cannot be chosen;
- no file in the app or the calculator imports a household-only module
  (the report, the saved households page and list, the picker, the save
  form and their shared parts, the hooks, the store and the v2 codec),
  by an @/ specifier or a relative path, except those modules
  themselves;
- the entry points are the four above.

Tests first: the tests failed to import the missing module. The import
check was confirmed to fail, naming Report.page.tsx, when that page
imported the saved households page by a relative path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review found that the household report's "Try again" asked for the
household the builder held whenever it differed from the one that
failed, without checking that it could run, so a household the
Calculate button refused (for example county poverty thresholds without
a county) could reach the Public API. The report section already tried
the failed household again in that case.

The request handling the two shared by copy now lives in one hook,
useRequestedHouseholdRun: what was asked for, running, failed and the
result, asking again for the same household, whether the builder's
household is the one shown, and retry, which asks for the household as
it is now only when it can run, and otherwise for the household that
failed. The report section and the household report both use it; the
section's analytics and behavior are unchanged.

Tests first: a report test that fails a calculation, edits the
household into one that cannot run and presses "Try again" failed (the
edited household, with tip income, was sent); it passes now, and the
section's tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… screen

Review found that after a save the form kept saying "Saved" when the
household was then edited (or moved to another year), next to an
enabled "Save changes"; only a label edit cleared it. The form now
remembers the household and label its last save stored, and shows
"Saved" only while the builder's household has the same stored content
and the label is unchanged. A failed save clears it.

Tests first: a test that saves, then gives the form an edited household,
failed ("Saved" was still shown); it passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he report opens one

Review found two uneven year rules:

- householdFromV2Item took a stored household's year from the latest
  year its values name, not the stored default_year. A household with
  inputs in two years read back in the later one, and one whose values
  name no year (which the v2 document allows) read back with no year,
  showing "No year set" and always counting as changed. It now reads
  back in default_year.
- The household report opens a household that cannot move into the
  report's year (inputs in several years) in its own year, with the
  reason, but the saved-household picker refused to open one at all.
  The picker's choice now opens the same way.

Tests first: the codec's two cases failed (2027 and null instead of
2026), and a report test that opens a two-year saved household from the
picker in a later report year failed (the builder kept its household);
they pass now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review found the saved-household queries were keyed only by whose they
are, while the store lists one country's saved households, unlike v3's
other saved work, which keys by user and country. In a query client
shared across countries, the same user's list for one country was shown
for the other. savedHouseholdKeys now include the store's country, and
changes invalidate that country's queries.

Tests first: a hook test that lists a user's US households, then
switches the same user to the UK with the same query client, failed
(the US list was shown); it passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PavelMakarchuk

Copy link
Copy Markdown
Contributor

Heads-up: #1511 (v3 Household tab rework) merged to main. It changes HouseholdImpactSection.tsx, HouseholdImpactResult.tsx and EarningsVariationSubPage.tsx, plus HouseholdBreakdowns.tsx and useFlagshipHousehold.ts, so this branch now needs a rebase onto main with conflict fixes in those files.

anth-volk and others added 12 commits November 28, 2026 00:25
…report-saved-households

Brings in #1386's branch at d0c1608, which has main (de9c9e5) merged
in, including the Household tab's household switcher and its
background variation run (#1511).

Conflicts, resolved keeping main's behavior in the Household tab and
this branch's shared parts:

- HouseholdImpactSection: main's panel (switcher, results and inputs
  views, Calculate again, the variation run started once the household
  is stored), with this branch's HouseholdBuilderPanel,
  useRequestedHouseholdRun (now passed main's onCreated), the shared
  run progress and failure, and newV3Household. The household's summary
  with its earnings is worked out from the household asked for, as the
  run hook keeps it.
- useFlagshipHousehold: main's onCreated callback and v2 policies, with
  useRequestedHouseholdRun, which passes onCreated through.
- HouseholdImpactResult: main's result without a frame or title, its
  tips and programmes; this branch's shared headline styles and output
  tabs; main's householdMoney.ts for money, so householdResultParts no
  longer keeps its own copy (HouseholdNetIncomeResult reads main's).
- HouseholdBreakdowns and EarningsVariationSubPage: both props kept
  (tidyChart from main, alsoOfferInputs from this branch).
- HouseholdRunProgress takes the run's start time, as main's section
  passes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's HouseholdImpactResult no longer frames or titles itself, as the
Household tab's panel names it. The standalone household report has no
such panel, so its reform result showed with no heading or card, while
its baseline-only result keeps both. This test fails until the report
gives it them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ehold impact"

main's HouseholdImpactResult has no card or heading of its own, as the
Household tab's panel names it. The standalone report gives it both, as
its baseline-only result ("Household net income") has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…art time

main moved the variation run's start time out of HouseholdBreakdowns
into its caller (variationStartedAt, onVariationOpen), and the Household
tab's card keeps the run going with HouseholdVariationKeeper. The
standalone report passes neither, so its progress bar, and the run with
it, starts again whenever the reader moves between Varying earnings and
Marginal tax rates. These tests fail until the report keeps the run.

The heading test now also checks that the heading and the result share
one card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The report starts the variation run (Varying earnings, Marginal tax
rates) when either output first opens and keeps it, with its start
time, while that result shows: HouseholdVariationKeeper holds the two
variation queries, as the Household tab's card does, and both result
views pass variationStartedAt and onVariationOpen to the breakdowns
(HouseholdNetIncomeResult now takes them too). A new calculation, year
or policy lets the earlier run go. Unlike the Household tab, nothing
runs before the reader opens an output, as before.

The test compares the household id as the attribute's string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…size

The comments and test names this branch adds say API v1 for
policyengine-api, as #1386's branch now does. The baseline-only
result's summary is the size main's HouseholdImpactResult gives its
own, so the standalone report's two results match. Wording and style
only: no behavior to fail first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…un is let go

The report keeps the variation run by its household id, year and
policies, and never resets it. The household's run is cached, so the
same household calculated again after its result cleared (another
year, then its own year again) shows the result already held, and the
earlier variation run comes back with it: its keeper sends the
variation requests before any output opens, and its progress bar counts
from the earlier start. This test fails until a new request starts
afresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The kept variation run now also names the request it was opened for,
so the same household asked for again after its result cleared starts
a new run, with a new start time, when an output opens, rather than
bringing back the earlier one before any output opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The keeper's comment now names both callers: the Household tab's card,
which starts it once the household is stored, and the standalone
household report, which starts it when either output first opens. A
test comment loses a stray "the". Comments only: no behavior to fail
first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alls

The calculator's same-origin route to API v1 forwards only the
operations on its allow list, which has the saved households list and
creation but not the store's other calls: a saved household's read,
rename and deletion (GET, PATCH and DELETE /v2/user-households/{id}),
and a stored household's creation and read (POST /v2/households, GET
/v2/households/{id}). These tests send each of them, and fail until the
allow list has them. Neighbouring requests stay refused: listing,
changing or deleting stored households, and ids that are not UUIDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The allow list gains three operations for api/savedHouseholdStore.ts:
"saved household" (GET, PATCH and DELETE /v2/user-households/{uuid}),
"stored household creation" (POST /v2/households) and "stored
household" (GET /v2/households/{uuid}); a stored household never
changes, so it is only created and read. None is cached. Nothing in the
app calls them until the saved-household pages are linked in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…comments that match

The page's kept variation run has a named type and one check,
isKeptFor, used both where the run is shown and where it is kept on
open. The reset test now also opens an output again and checks that the
run starts afresh, with a later start time. Comments say who holds the
variation run (the Household tab while another household or tab is
open; the standalone report while that result shows), that the allow
list's PATCH on a saved household also points it at another stored
household, and when the list was last checked. The refactor and
comments change no behavior; the extended test passes against the
earlier fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…report-saved-households

Brings in #1386's branch at 41c8e6a: the Household tab sends UK
households with #1240's claimant and partner roles
(creationPayloadOf), and compares what is on screen in the same form.

On this branch the tab's run request and that comparison are made by
useRequestedHouseholdRun, so the conflicts in HouseholdImpactSection
keep its request() and shows(), and the hook takes an optional
payloadOf, which the tab passes as creationPayloadOf. Without it, the
hook sends the household's own v1 creation payload, as before, so the
standalone household report is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 27, 2026
…-save API

#1386's UK claimant and partner roles reach useRequestedHouseholdRun as
payloadOf, the payload a household is sent as. The one conflict, the
hook's arguments, keeps both payloadOf and this branch's onCreated type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk and others added 5 commits November 28, 2026 01:58
… UK roles

The Household tab sends a UK household with #1240's claimant and
partner roles; the standalone household report, its Reproduce in
Python code and the households it saves do not. These tests fail until
one function (householdAsSent, and householdCreationPayload for API
v1's payload) prepares every v3 household that is calculated, reproduced
or saved: a UK lone parent and their adult child are sent with their
roles, the result is not out of date, the Python code names the roles,
and a saved household is stored with them, with nothing left to save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er it starts

householdAsSent (and householdCreationPayload, for API v1's payload)
prepares a household as the app sends it: a UK builder household with
#1240's claimant and partner roles for the loaded model. Every v3 place
that sends a household now goes through it:

- useRequestedHouseholdRun reads the model information itself and sends
  every household this way, for the Household tab and the standalone
  household report alike, and compares the one on screen in that form.
  Its payloadOf option, which let the tab alone add the roles, is gone.
  The request keeps the household as sent (`sent`) beside the one the
  reader described.
- The standalone report's Reproduce in Python code reproduces the
  household as sent.
- SaveHouseholdForm stores the household as sent, and compares the one
  on screen, the saved one and the last saved one in that form.

The v2 report builder's own callers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n that arrives late

Two tests that fail until the next commit:
- the save form keeps saying "Saved", with nothing left to save, when
  UK model information loads after the save (it compared the household
  it saved as it was then, without roles, with the one on screen as it is
  sent now, with them);
- the standalone report waits for the model's variables, as the
  Household tab does, so on the v2 routes no household is described,
  sent or saved before the UK roles' variable is known.

Also, passing already: a UK household saved without its roles opens with
nothing to save; the Reproduce in Python test checks the parent's and
the child's roles; the save test uses the UK fixtures; and the
householdAsSent tests no longer use householdCreationPayload, which the
next commit removes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…today's form

- The standalone household report waits for the model's variables, as
  the Household tab does (V3VariablesGate): on the v2 routes they load
  in the background, and until they do a UK household would be described,
  sent and saved as if the model had no claimant and partner roles. On
  the v1 routes they are always ready, so nothing changes there.
- SaveHouseholdForm keeps the household its last save was given, and
  compares it as it is sent now, as it does the one on screen and the
  saved one, so UK model information that loads after a save leaves
  "Saved" showing and nothing to save.
- householdAsSent's module keeps only householdAsSent (the run hook
  builds the payload from the household as sent itself), and its
  comment names its callers and the v2 report builder flows that still
  call withSupportedBuilderClaimantRoles directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…real save paths

The report's loading test also checks, signed in, that neither the saved
households nor the save form show and that nothing is requested.
householdAsSent's comment names the Household tab's background save
(useSaveCalculatedHousehold), and SaveHouseholdForm's onSaved comment
says the page can also stop showing the form while the model's
variables load. Test and comments only: no behavior to fail first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 27, 2026
…-save API

#1392 now sends every v3 household as householdAsSent prepares it (UK
claimant and partner roles): useRequestedHouseholdRun applies it itself,
its payloadOf option is gone, and RequestedHousehold's payload is the
household as sent, which this branch's v2 run stores. #1392 also wraps
the standalone household report in V3VariablesGate, as this branch did.

Conflicts resolved:
- useFlagshipHousehold: #1392's arguments without payloadOf, with this
  branch's onCreated type.
- HouseholdReport.page: #1392's page (its wrapper is the same), with this
  branch's note on the v2 routes.

Tests adapted: the v2 hook test that passed payloadOf now has
householdAsSent prepare a household that differs from the one described,
and checks the v2 run is given that household's payload (it fails when
the run is given the described household's). This branch's test of the
report's loading placeholder is dropped, as #1392's page test covers it;
its tests of a failed load and of the builder panel stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
Preview – policyengine-calculator-next — f2544fdb Deployed Nov 27, 2026 by vercel[bot]
Preview – policyengine-website — f2544fdb Deployed Nov 27, 2026 by vercel[bot]
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.

v3: standalone household report and saved households, unreachable until v3 moves to the v2 routes

2 participants