Skip to content
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

Rename widget validators to use scoring phrasing #1848

Merged
merged 40 commits into from
Nov 13, 2024

Conversation

Myranae
Copy link
Contributor

@Myranae Myranae commented Nov 13, 2024

Summary:

In preparation of splitting out the valid/invalid logic from the scoring logic, this renames the widget validator functions and related code to use phrasing related to scoring instead of validation. The goal is to prevent confusion when we add actual validation logic to validate a user's input before sending to the server and right before scoring on the server.

Issue: LEMS-2593

Test plan:

  • Confirm all checks pass
  • Confirm all widgets still work as expected via Storybook

@Myranae Myranae self-assigned this Nov 13, 2024
Copy link
Contributor

github-actions bot commented Nov 13, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1848

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1848

Copy link
Contributor

github-actions bot commented Nov 13, 2024

Size Change: +21 B (0%)

Total Size: 866 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 283 kB -11 B (0%)
packages/perseus/dist/es/index.js 417 kB +32 B (+0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.8 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.8 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.54 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

export function csProgramValidator(
state: PerseusCSProgramUserInput,
): PerseusScore {
export function scoreCSProgram(state: PerseusCSProgramUserInput): PerseusScore {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this scoring file doesn't do the export default at the bottom. Should I update it to export like the others?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, please. We mix between export default and exporting named functions in Perseus, but we should at least be consistent across the scoring function/files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Jeremy and I disagree; I think export function is better and he advocates for having it at the end. I think it's best to be consistent more than anything.

@Myranae Myranae marked this pull request as ready for review November 13, 2024 17:58
@khan-actions-bot khan-actions-bot requested a review from a team November 13, 2024 17:58
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Nov 13, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .eslintrc.js, .changeset/nice-cars-itch.md, config/test/custom-matchers.ts, packages/perseus/src/renderer-util.ts, packages/perseus/src/types.ts, packages/perseus/src/widgets.ts, packages/perseus/src/widgets/interactive-graph.tsx, packages/perseus/src/widgets/__shared__/score-noop.test.ts, packages/perseus/src/widgets/__shared__/score-noop.ts, packages/perseus/src/widgets/categorizer/categorizer.tsx, packages/perseus/src/widgets/categorizer/score-categorizer.test.ts, packages/perseus/src/widgets/categorizer/score-categorizer.ts, packages/perseus/src/widgets/cs-program/cs-program.tsx, packages/perseus/src/widgets/cs-program/score-cs-program.test.ts, packages/perseus/src/widgets/cs-program/score-cs-program.ts, packages/perseus/src/widgets/definition/definition.tsx, packages/perseus/src/widgets/deprecated-standin/deprecated-standin.tsx, packages/perseus/src/widgets/dropdown/dropdown.tsx, packages/perseus/src/widgets/dropdown/score-dropdown.test.ts, packages/perseus/src/widgets/dropdown/score-dropdown.ts, packages/perseus/src/widgets/explanation/explanation.test.ts, packages/perseus/src/widgets/explanation/explanation.tsx, packages/perseus/src/widgets/expression/expression.tsx, packages/perseus/src/widgets/expression/score-expression.test.ts, packages/perseus/src/widgets/expression/score-expression.ts, packages/perseus/src/widgets/grapher/grapher.tsx, packages/perseus/src/widgets/grapher/score-grapher.test.ts, packages/perseus/src/widgets/grapher/score-grapher.ts, packages/perseus/src/widgets/iframe/iframe.tsx, packages/perseus/src/widgets/iframe/score-iframe.test.ts, packages/perseus/src/widgets/iframe/score-iframe.ts, packages/perseus/src/widgets/image/image.tsx, packages/perseus/src/widgets/input-number/input-number.test.ts, packages/perseus/src/widgets/input-number/input-number.tsx, packages/perseus/src/widgets/input-number/score-input-number.test.ts, packages/perseus/src/widgets/input-number/score-input-number.ts, packages/perseus/src/widgets/interaction/interaction.tsx, packages/perseus/src/widgets/interactive-graphs/score-interactive-graph.test.ts, packages/perseus/src/widgets/interactive-graphs/score-interactive-graph.ts, packages/perseus/src/widgets/label-image/label-image.tsx, packages/perseus/src/widgets/label-image/score-label-image.test.ts, packages/perseus/src/widgets/label-image/score-label-image.ts, packages/perseus/src/widgets/matcher/matcher.tsx, packages/perseus/src/widgets/matcher/score-matcher.test.ts, packages/perseus/src/widgets/matcher/score-matcher.ts, packages/perseus/src/widgets/matrix/matrix.tsx, packages/perseus/src/widgets/matrix/score-matrix.test.ts, packages/perseus/src/widgets/matrix/score-matrix.ts, packages/perseus/src/widgets/measurer/measurer.tsx, packages/perseus/src/widgets/molecule/molecule.tsx, packages/perseus/src/widgets/number-line/number-line.tsx, packages/perseus/src/widgets/number-line/score-number-line.test.ts, packages/perseus/src/widgets/number-line/score-number-line.ts, packages/perseus/src/widgets/numeric-input/numeric-input.tsx, packages/perseus/src/widgets/numeric-input/score-numeric-input.test.ts, packages/perseus/src/widgets/numeric-input/score-numeric-input.ts, packages/perseus/src/widgets/orderer/orderer.tsx, packages/perseus/src/widgets/orderer/score-orderer.test.ts, packages/perseus/src/widgets/orderer/score-orderer.ts, packages/perseus/src/widgets/passage/passage.tsx, packages/perseus/src/widgets/passage-ref/passage-ref.tsx, packages/perseus/src/widgets/passage-ref-target/passage-ref-target.tsx, packages/perseus/src/widgets/plotter/plotter.tsx, packages/perseus/src/widgets/plotter/score-plotter.test.ts, packages/perseus/src/widgets/plotter/score-plotter.ts, packages/perseus/src/widgets/radio/radio-component.tsx, packages/perseus/src/widgets/radio/radio.ts, packages/perseus/src/widgets/radio/score-radio.test.ts, packages/perseus/src/widgets/radio/score-radio.ts, packages/perseus/src/widgets/sorter/score-sorter.test.ts, packages/perseus/src/widgets/sorter/score-sorter.ts, packages/perseus/src/widgets/sorter/sorter.tsx, packages/perseus/src/widgets/table/score-table.test.ts, packages/perseus/src/widgets/table/score-table.ts, packages/perseus/src/widgets/table/table.tsx, packages/perseus/src/widgets/video/video.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/interactive-graph-editor.tsx, packages/perseus/src/widgets/radio/__tests__/radio.test.ts

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

Thanks for slogging through this rename! :)

.eslintrc.js Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing the linting also!

export function csProgramValidator(
state: PerseusCSProgramUserInput,
): PerseusScore {
export function scoreCSProgram(state: PerseusCSProgramUserInput): PerseusScore {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, please. We mix between export default and exporting named functions in Perseus, but we should at least be consistent across the scoring function/files.

@@ -28,13 +28,12 @@ import type {
* - For each answer:
* ~ Try to validate the user's input against the answer. The answer is
* expected to parse.
* ~ If the user's input validates (the validator judges it "correct"), we've
* matched and can stop considering answers.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you delete this line by accident?

Copy link
Contributor Author

@Myranae Myranae Nov 13, 2024

Choose a reason for hiding this comment

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

Yep, I accidentally modified this comment before realizing it was related to khanAnswerType instead of the SSS validators. Returning it now! Thanks for pointing it out!!

it("returns a pointless object", () => {
const result = noopValidator();
const result = scoreNoop();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: score[Widget] makes sense, but I don't think scoreNoop really makes sense. I think noopScorer is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I was going for consistency with the naming of the scoring related functions, but that seems fine with me. Might be a good idea to keep the file name the way it is to conform to the eslint rules though. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We talked in messages and decided to leave it as is so it is consistent and conforms to the eslint rules.

export function csProgramValidator(
state: PerseusCSProgramUserInput,
): PerseusScore {
export function scoreCSProgram(state: PerseusCSProgramUserInput): PerseusScore {
Copy link
Contributor

Choose a reason for hiding this comment

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

Jeremy and I disagree; I think export function is better and he advocates for having it at the end. I think it's best to be consistent more than anything.

@@ -28,13 +28,12 @@ import type {
* - For each answer:
* ~ Try to validate the user's input against the answer. The answer is
* expected to parse.
* ~ If the user's input validates (the validator judges it "correct"), we've
* matched and can stop considering answers.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to delete this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, definitely was unintended. I accidentally modified this comment before realizing it was related to khanAnswerType instead of the SSS validators. Returning it now! Thanks for pointing it out!!

@Myranae Myranae merged commit 55371de into main Nov 13, 2024
9 checks passed
@Myranae Myranae deleted the tb/LEMS-2593/rename-validate-to-score branch November 13, 2024 21:14
Myranae pushed a commit that referenced this pull request Nov 14, 2024
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @khanacademy/perseus@41.3.0

### Minor Changes

-   [#1848](#1848) [`55371ded7`](55371de) Thanks [@Myranae](https://github.com/Myranae)! - Rename all validator functions and related code to reference scoring instead


-   [#1754](#1754) [`77f1bf98f`](77f1bf9) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Adds the getPromptJSON utility method to the renderer and every widget. It can be used to get a JSON representation of the exercise to pass to an LLM.

### Patch Changes

-   [#1844](#1844) [`092c81f6c`](092c81f) Thanks [@Myranae](https://github.com/Myranae)! - Update Radio's userInput and rubric objects and types


-   [#1837](#1837) [`80f0480e6`](80f0480) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Type widget exports using 'satisfies' keyword instead of 'as'


-   [#1785](#1785) [`32b27322c`](32b2732) Thanks [@benchristel](https://github.com/benchristel)! - Internal: add a parsing layer to typecheck PerseusItem data at runtime (ADR #773). The parsing code is not used yet.


-   [#1838](#1838) [`08fa66103`](08fa661) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Introduce a PerseusArticle type


-   [#1825](#1825) [`3dd1fa5ce`](3dd1fa5) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Adding stronger typing to expression editor issues.


-   [#1847](#1847) [`dcb4b27b3`](dcb4b27) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Allow the usage of `{$}` to denote actual dollar signs within locked label TeX


-   [#1850](#1850) [`61dbd4a2c`](61dbd4a) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Export WidgetPromptJSON type so it is accessible


-   [#1842](#1842) [`cf2ea471e`](cf2ea47) Thanks [@MikeKlemarewski](https://github.com/MikeKlemarewski)! - Fix function signature of getUserInputFromProps for radio widget

## @khanacademy/perseus-editor@14.11.1

### Patch Changes

-   [#1825](#1825) [`3dd1fa5ce`](3dd1fa5) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Adding stronger typing to expression editor issues.


-   [#1847](#1847) [`dcb4b27b3`](dcb4b27) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels] Allow the usage of `{$}` to denote actual dollar signs within locked label TeX

-   Updated dependencies \[[`092c81f6c`](092c81f), [`80f0480e6`](80f0480), [`32b27322c`](32b2732), [`08fa66103`](08fa661), [`55371ded7`](55371de), [`3dd1fa5ce`](3dd1fa5), [`dcb4b27b3`](dcb4b27), [`61dbd4a2c`](61dbd4a), [`77f1bf98f`](77f1bf9), [`cf2ea471e`](cf2ea47)]:
    -   @khanacademy/perseus@41.3.0

Author: khan-actions-bot

Reviewers: Myranae

Required Reviewers:

Approved By: Myranae

Checks: ⏭️  Publish npm snapshot, ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x)

Pull Request URL: #1840
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.

4 participants