refactor(profiling): PNTS selections store null not false; routeToNextProfileQuestion skips after-field - #17
Conversation
…ON on null LA; add find-local-council link to SOMEWHERE_ELSE exit Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…tProfileQuestion skips after-field Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| expect(result.stateUpdates.currentGate).not.toBe('B5_PROFILE_CHILDREN'); | ||
| }); | ||
|
|
||
| test('PNTS through B5_PROFILE_CHILDREN does not re-trigger (regression)', () => { |
There was a problem hiding this comment.
Just noticed this new regression test looks like it's covering the same ground as the existing test at line 798 ("User who prefers not to say on children question progresses past the question"). Same session setup, same option selected, same assertion that the state doesn't come back to B5_PROFILE_CHILDREN.
Not a problem for correctness, but two identical tests means if the behaviour ever changes we'll get two failures for the same thing, and one of them will need updating anyway. Could we drop one? Either is fine, though I'd keep the new one if it has a clearer name tied to the fix in this PR.
| * Returns terminal output when all required fields are collected. | ||
| */ | ||
| function routeToNextProfileQuestion(session: SessionState): RoutingResult { | ||
| function routeToNextProfileQuestion(session: SessionState, after?: string): RoutingResult { |
There was a problem hiding this comment.
Not blocking, but worth considering: typing after as string | undefined means a typo at a call site (e.g. 'chilren') would silently do nothing and quietly re-introduce the bug this PR is fixing. If we constrain it to a union of the actual field names ('age' | 'gender' | 'lgbtq' | 'convictions' | 'nrpf' | 'children'), TypeScript will catch that at compile time.
Small change, and it protects the fix going forward. Up to you.
|
|
||
| const sessionWithGender = { ...session, gender: profGender }; | ||
| return routeToNextProfileQuestion(sessionWithGender); | ||
| return routeToNextProfileQuestion(sessionWithGender, 'gender'); |
There was a problem hiding this comment.
I might be missing something, but it looks like this handler returns routeToNextProfileQuestion() directly, so the value the user just gave for hasChildren doesn't end up in stateUpdates and gets lost when route.ts merges back into the session.
I can see from the PR description you're already tracking this as backlog item 59. Would mind adding the backlog to tracking and commit it with the next PR? It would be helpful for me to see what's known and what isn't.
Summary
Two coupled changes to fix how "Prefer not to say" selections are stored and routed in the profiling loop.
1. PNTS null storage fix
B5_PROFILE_LGBTQandB5_PROFILE_CHILDRENhandlers now storenull(notfalse) when the user selects "Prefer not to say". This distinguishes PNTS from an explicit "No" answer, matching thehousingOptionsInvolvementthree-way ternary pattern and theboolean | nulltype already declared on both fields.2.
afterparameter onrouteToNextProfileQuestionAdded an optional
afterparameter that tells the routing loop to skip the named field — preventing null PNTS values from re-triggering the question they just answered.B5_MAIN_SUPPORT_NEEDandB5A_ADVICE_TYPE) remain parameter-free'age','gender','lgbtq','convictions','nrpf','children'All 9 call sites were audited before building to confirm
session.localAuthorityis set at each point (guaranteed by the location gate move in PR #16).Test plan
B5_PROFILE_CHILDRENdoes not re-trigger the gatelgbtqstoresnull(wasfalse)Known issue: stateUpdates propagation (backlog item 59)
Identified during this build:
ageCategory,gender,criminalConvictions, andhasChildrenhandlers returnrouteToNextProfileQuestion()directly without wrappingstateUpdates, meaning the just-collected field is not propagated back viastateUpdates.lgbtq,lgbtqServicePreference,immigrationStatus, andpublicFundswrap correctly. No routing tests fail because of this, but it is a latent bug — the field is used for in-call routing decisions but lost whenroute.tsmergesstateUpdatesback into the session. Logged as item 59 in the backlog for a follow-up PR.🤖 Generated with Claude Code