Skip to content

Fix parsing errors by fixing Matrix user input type #2775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Myranae
Copy link
Contributor

@Myranae Myranae commented Aug 7, 2025

Summary:

Matrix user input has always been received as array of string arrays. The type incorrectly defined it as numbers instead of strings, which caused parsing errors. This updates PerseusMatrixUserInput to reflect the actual type of user input, updates test files to show user input as strings,

Issue: LEMS-3342

Test plan:

  • Confirm all checks pass
  • Confirm Matrix still works as expected via Storybook
  • After deploying, confirm related parsing errors decrease

Myranae added 4 commits August 6, 2025 15:51
…to use string arrays

Refactors matrix-related types, parsers, and logic to represent user input as arrays of strings instead of numbers. Updates all relevant test cases, validation, scoring, and AI utility code to handle string-based matrix answers, ensuring consistent type usage throughout the codebase.
…ing error by updating matrix user input to an array of string arrays instead of number
@Myranae Myranae self-assigned this Aug 7, 2025
Copy link
Contributor

github-actions bot commented Aug 7, 2025

🗄️ Schema Change: No Changes ✅

Copy link
Contributor

github-actions bot commented Aug 7, 2025

Size Change: +18 B (0%)

Total Size: 496 kB

Filename Size Change
packages/perseus/dist/es/index.js 207 kB +18 B (+0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.7 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 12.9 kB
packages/perseus-core/dist/es/index.js 21.5 kB
packages/perseus-editor/dist/es/index.js 94.1 kB
packages/perseus-linter/dist/es/index.js 7.07 kB
packages/perseus-score/dist/es/index.js 9.34 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.56 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Aug 7, 2025

🛠️ Item Splitting: No Changes ✅

Copy link
Contributor

github-actions bot commented Aug 7, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (8f905b4) and published it to npm. You
can install it using the tag PR2775.

Example:

pnpm add @khanacademy/perseus@PR2775

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR2775

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR2775

Comment on lines 23 to 25
const supplied = userInput.answers;
const supplied = userInput.answers.map((row) =>
row.map((str) => Number(str)),
);
Copy link
Contributor Author

@Myranae Myranae Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMatrixSize says it requires array of array of numbers, but then the logic inside the function converts each number to a string. Maybe I should just update that function to take an array of arrays of strings and remove the .toString() call instead of converting here and then converting back there 🤔 Except we also call getMatrixSize with the solution, which is an array of arrays of numbers.

Copy link
Contributor

@handeyeco handeyeco Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make it take either string[][] | number[][] and convert it to string[][] in getMatrixSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as you suggested :)

Comment on lines 540 to 545
): PerseusMatrixUserInput {
): PerseusMatrixRubric {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this change. Going to double check how this function is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value has to be PerseusMatrixUserInput. getCorrectUserInput does what it says on the tin: it takes answerful widget options and returns the user input in the correct state.

The problem you're running into is that the type PerseusMatrixWidgetOptions stores the correct answer in (numbers) is different than the way PerseusMatrixUserInput stores user input (strings).

A quick fix: convert the numbers to strings in getCorrectUserInput. A more holistic (out of scope) fix is to make PerseusMatrixWidgetOptions and PerseusMatrixUserInput use the same type for user input and correct answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted return type and converted the numbers inside the function.

@Myranae Myranae marked this pull request as ready for review August 7, 2025 15:30
Myranae added 2 commits August 7, 2025 14:47
Adjust parameter for getMatrixSize to include 2D array of string, remove unneeded conversions, update getCorrectUserInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants