Skip to content

Fix: guard mcq migrations against components without _items (fixes #263)#264

Closed
swashbuck wants to merge 1 commit into
masterfrom
issue/263
Closed

Fix: guard mcq migrations against components without _items (fixes #263)#264
swashbuck wants to merge 1 commit into
masterfrom
issue/263

Conversation

@swashbuck

Copy link
Copy Markdown
Contributor

Fixes #263

Fix

  • The v4.1.0 > v4.2.0 mutates ("add item _isPartlyCorrect", "add item _score") and the v7.3.11 > v7.4.0 mutate ("add altText to _items") accessed MCQ._items.forEach(...) directly, throwing TypeError: Cannot read properties of undefined (reading 'forEach') when an mcq has no _items. The v4.2.0 testSuccessWhere (which includes itemless mcqs) already failed because of this.
  • Use MCQ._items?.forEach(...) in the mutates and (MCQ._items ?? []).every(...) in the matching checks so an absent _items array is handled gracefully (matching the pattern used by other components such as accordion).

Testing

  1. grunt migration:test --file=adapt-contrib-mcq
  2. All scenarios pass, including the itemless-mcq testSuccessWhere fixtures.

The v4.1.0 > v4.2.0 mutates ("add item _isPartlyCorrect", "add item
_score") and the v7.3.11 > v7.4.0 mutate ("add altText to _items")
accessed MCQ._items.forEach(...) with no guard, throwing
"TypeError: Cannot read properties of undefined (reading 'forEach')"
for an mcq with no _items. The v4.2.0 testSuccessWhere (itemless mcq)
already failed because of this.

Use MCQ._items?.forEach(...) in the mutates and (MCQ._items ?? []).every(...)
in the matching checks so an absent _items array is handled gracefully.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@swashbuck

Copy link
Copy Markdown
Contributor Author

Closing this. On review, the failure originates from the migration's own testSuccessWhere fixtures, which include mcqs with no _items. In practice an mcq always has _items; an itemless one would indicate something else has gone wrong upstream, where a loud failure during migration is arguably correct rather than something to silently tolerate. Not pursuing a migration change. If the failing test scenario is itself considered invalid, the fixture could be amended instead.

@swashbuck swashbuck closed this Jun 22, 2026
@swashbuck
swashbuck deleted the issue/263 branch June 22, 2026 14:09
@github-project-automation github-project-automation Bot moved this from Needs Reviewing to Recently Released in adapt_framework: The TODO Board Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix mcq v4.2.0 migration throws on components without _items

2 participants