Skip to content

fix(validation): unique id per question for multi-question steps (#2514) - #2519

Merged
jung-thomas merged 1 commit into
DEVfrom
fix/multi-validate-per-step-2514
Sep 27, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
fix/multi-validate-per-step-2514

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Fixes #2514.

Problem

An author can put several [VALIDATE_N] blocks in a single step (the number keys the step, not the question). The parser already accumulates them into one array and Validation.vue already renders N questions per step — but every question was assigned the same id validate-${stepNum} (scripts/parsers/rules.ts:277,301).

Because the client keys answer state and per-question verdicts by q.id, three questions with identical ids collided onto one slot:

  • couldn't validate the questions (shared answer + all-or-nothing grader failed the step),
  • MCQ selections appeared stuck/unchangeable,
  • the parser's own sibling maps (${stepNum}:${q.id}) overwrote each other, collapsing AI-graded specs to one row per step.

Fix

Thread an ordinal (the count already in the step's array) into parseBlock and assign:

  • first question in a step → validate-N (unchanged — single-question steps and all published content are byte-for-byte identical),
  • each subsequent question → validate-N-<ordinal>.

The id and the sibling-map keys are computed in one place so they stay consistent. No frontend change needed — Validation.vue/grading.ts already key by id.

Tests

New scripts/parsers/__tests__/rules-multi-question-per-step.test.ts:

  • three blocks accumulate into one step,
  • distinct id per question + first keeps legacy validate-N,
  • single-question step regression,
  • sibling map keeps a distinct entry per question (no AI-graded overwrite).

Full parser + validation suites green (227 tests): npx vitest run scripts/parsers/ hugo-apps/src/validation/.

Authors can put multiple [VALIDATE_N] blocks in one step (the number keys
the STEP, not the question) and the parser already accumulated them into
one array. But every question was assigned the same `validate-${stepNum}`
id, so client-side answer/verdict state (keyed by id) collided across the
questions: only one could hold an answer, MCQ selections appeared stuck,
and the all-or-nothing grader failed the step. The parser's own sibling
maps (`${stepNum}:${q.id}`) also overwrote each other, collapsing AI-graded
specs to one row per step.

Assign `validate-N` to the first question in a step and
`validate-N-<ordinal>` to each subsequent one. First-question id is
unchanged, so single-question steps and all published content are
byte-for-byte identical. The Validation.vue component and grading already
key everything by id and need no change.

Adds rules-multi-question-per-step.test.ts covering distinct ids,
backward-compat, and no sibling-map overwrite for AI-graded blocks.
@jung-thomas
jung-thomas merged commit 53fe30a into DEV Sep 27, 2026
4 checks passed
@jung-thomas
jung-thomas deleted the fix/multi-validate-per-step-2514 branch September 27, 2026 13:36
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