Skip to content

wizard: detect the demographics block by qwac id, not by name (#47) - #48

Merged
jstet merged 1 commit into
mainfrom
issue-47-demographics-section
Sep 25, 2026
Merged

jstet merged 1 commit into
mainfrom
issue-47-demographics-section

Conversation

@jstet

@jstet jstet commented Sep 25, 2026

Copy link
Copy Markdown
Member

The survey preview used name in selectedDemographics && !rationale to spot the appended demographics. A model question about age that happened to be called age (and dropped its rationale) was mistaken for the first demographic, and everything after it — including the real appended demographics — ended up under the "automatically added" divider.

Why id is the right key. Demographics carry their qwac question_id (constants.ts); model output goes through question_parser.ts with a synthetic q_${index} id by default. So id-based detection is unambiguous; the rationale check stays as a belt-and-braces guard against a model that ever copies a qwac id verbatim.

  • Extract detectDemographicsStart into a pure helper in src/lib/components/surveyView.ts so it's unit-testable.
  • SurveyView prop: demographicNames → demographicIds.
  • Page maps the wizard's selected names to ids via the constants.
  • New surveyView.test.ts with five cases, including the exact failure from the issue.

Regression check. Temporarily reverted the helper to the old name-based logic and confirmed the new test fails (expected -1 to be 3 — the divider landed on the model's age question instead of the real age demographic). With the fix restored, all five pass.

Verified: npm run test:unit (87 pass, +5), npm run test:e2e (45 pass), npm run check, npm run lint.

Closes #47.

The survey preview used `name in selectedDemographics && !rationale` to
spot the appended demographics, and a model question about age that
happened to be called 'age' (and dropped its rationale) would be
mistaken for the first demographic. Everything after it — including the
real appended demographics — ended up under the 'automatically added'
divider.

Demographics carry their qwac question_id (constants.ts); model output
goes through question_parser with a synthetic 'q_${index}' id by
default. Switching the check to id-based makes the boundary
unambiguous, and the rationale check stays as a belt-and-braces guard
against a model that ever copies a qwac id verbatim.

* Extract `detectDemographicsStart` into a pure helper in
  `src/lib/components/surveyView.ts` so it can be unit-tested.
* SurveyView prop: `demographicNames` -> `demographicIds`.
* Page maps the wizard's selected names to ids via the constants.
* New `surveyView.test.ts` with five cases, including the exact
  failure from the issue (regression). Verified that the regression
  test fails on the old name-based logic and passes on the fix.
@jstet
jstet merged commit ad71196 into main Sep 25, 2026
1 check passed
@jstet
jstet deleted the issue-47-demographics-section branch September 25, 2026 12:46
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.

generated questions ended up in automatically added section

1 participant