Skip to content

Range surveys: require integers and improve validation#1102

Open
mkbehr wants to merge 5 commits into
PAIR-code:mainfrom
mkbehr:survey-validation-enhancements
Open

Range surveys: require integers and improve validation#1102
mkbehr wants to merge 5 commits into
PAIR-code:mainfrom
mkbehr:survey-validation-enhancements

Conversation

@mkbehr
Copy link
Copy Markdown
Collaborator

@mkbehr mkbehr commented May 1, 2026

Description

  • Potentially breaking change: require numbers in range-type surveys to be integers

    • From manual testing, this already wasn't supported (at least for the web editor), so make that explicit.
  • Check range-type survey stages for various requirements:

    • min < max
    • step size > 0
    • step size | max - min
    • all numbers are integers
  • Require survey stages to contain at least one question

  • Validate experiments in edit mode as well as creation mode

  • Change response code for bad experiment config from 400 to 422 (more specific)

  • Documentation updated as needed


Verification

  • Screenshots or videos included (if applicable)
  • Clear reproduction steps provided to invoke the feature (if applicable)
  • All tests pass (if applicable)
Screenshot 2026-05-01 at 3 59 48 PM

Related issues

This PR fixes: #1098


mkbehr added 3 commits May 1, 2026 15:33
…P error statuses

- Add Scale range divisibility and integer constraints validation for Survey questions
- Restrict survey stages to contain at least one question
- Surface active config errors Lit Header UI editor edit mode and create mode
- Support entering floats in frontend UI scale number form fields to trigger float validations
- Return HTTP 422 Unprocessable Entity for REST cloud function experiment rejections
- Add Jest unit and Express integrations tests covering positive/negative validation scenarios
…P error statuses

- Add Scale range divisibility and integer constraints validation for Survey questions
- Restrict survey stages to contain at least one question
- Surface active config errors Lit Header UI editor edit mode and create mode
- Support entering floats in frontend UI scale number form fields to trigger float validations
- Return HTTP 422 Unprocessable Entity for REST cloud function experiment rejections
- Add Jest unit and Express integrations tests covering positive/negative validation scenarios
…P error statuses

- Add Scale range divisibility and integer constraints validation for Survey questions
- Restrict survey stages to contain at least one question
- Surface active config errors Lit Header UI editor edit mode and create mode
- Support entering floats in frontend UI scale number form fields to trigger float validations
- Return HTTP 422 Unprocessable Entity for REST cloud function experiment rejections
- Add Jest unit and Express integrations tests covering positive/negative validation scenarios
@mkbehr mkbehr changed the title feat: Improve survey validation Range surveys: require integers and improve validation May 1, 2026
mkbehr added 2 commits May 1, 2026 16:02
…P error statuses

- Add Scale range divisibility and integer constraints validation for Survey questions
- Restrict survey stages to contain at least one question
- Surface active config errors Lit Header UI editor edit mode and create mode
- Support entering floats in frontend UI scale number form fields to trigger float validations
- Return HTTP 422 Unprocessable Entity for REST cloud function experiment rejections
- Add Jest unit and Express integrations tests covering positive/negative validation scenarios
…P error statuses

- Add Scale range divisibility and integer constraints validation for Survey questions
- Restrict survey stages to contain at least one question
- Surface active config errors Lit Header UI editor edit mode and create mode
- Support entering floats in frontend UI scale number form fields to trigger float validations
- Return HTTP 422 Unprocessable Entity for REST cloud function experiment rejections
- Add Jest unit and Express integrations tests covering positive/negative validation scenarios
@mkbehr mkbehr marked this pull request as ready for review May 1, 2026 21:04
@mkbehr mkbehr requested a review from jimbojw May 1, 2026 21:04
msg.includes('Invalid stage configuration') ||
msg.includes('Invalid variable configuration') ||
msg.includes('Duplicate cohort alias found');
throw createHttpError(isValidationError ? 422 : 500, msg);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for upgrading from 400 to more specific HTTP error codes. 🙏

`${stage.name} question ${index + 1} ("${question.questionTitle}"): values must be integers`,
);
}
if (question.lowerValue >= question.upperValue) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My main nit is that here and elsewhere, you assert a condition that would make the comparison potentially unspecified.

For example, earlier, you check !Number.isInteger(question.lowerValue) and if so, you append to the errors array. This is good. But in that case, when we get to this line, there are several possibilities, only some of which make sense. E.g., it could be that lowerValue is, say a float like 3.5, or even a string like "456". Those are legal values for this JavaScript >= comparison against upperValue, but they would have been flagged already as being illegal (non-integer).

Anyway, if the code works and the tests pass, it's good enough for me. Just flagging that it's strange to me to see later comparisons using potentially bad values that were checked earlier.

`${stage.name} question ${index + 1} ("${question.questionTitle}"): step size must be greater than 0`,
);
}
if (range % step !== 0) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here. Above we check that step is positive. But here, we're outside that check. So we could be comparing a negative step number's modulus against the range. It's strange to me to allow these potentially weird comparisons, given that earlier validation checks aim to ensure correct types and values.

);
}
}
if (question.kind === 'mc') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Is there a static variable for the string 'mc' we could use instead of the literal, such as an Enum value?

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.

Add additional validation on creating an experiment with bad multiple choice values

2 participants