Bound and validate NodeRequirements.address_regex#145
Conversation
foxpatch-aleph
left a comment
There was a problem hiding this comment.
This PR correctly adds validation for the address_regex field by capping it at 256 characters and ensuring it compiles as a valid Python regex. The implementation is clean and follows existing patterns in the codebase. However, no tests are added for the new validation logic despite the PR description indicating tests were run. While existing tests pass, there's no coverage for the new validation behavior (invalid regex rejection, length limit enforcement).
aleph_message/models/execution/environment.py (line 195): Consider adding tests for this validator. The PR description mentions tests pass, but no new tests are added for the address_regex validation. Suggested test cases:
- Valid regex patterns should pass
- Invalid regex patterns (e.g., unclosed brackets, invalid escapes) should raise ValidationError
- Regex at exactly 256 characters should pass
- Regex over 256 characters should be rejected
- None value should pass through unchanged
This would follow the pattern of existing validation tests like test_validation_on_confidential_options.
aleph_message/models/execution/environment.py (line 200): Minor: Consider using a more specific exception type. re.error is caught correctly, but you could be explicit about what errors are expected (e.g., re.error is the correct choice here, so this is fine). The error message is clear and includes the underlying exception details, which is good for debugging.
Cap the field at 256 characters and reject values that don't compile as Python regular expressions. Catches malformed patterns at schema-validation time rather than at match time.
71c7a6d to
40d1284
Compare
Cover the four cases exercised by the new validator: - a valid regex is accepted, - an uncompilable pattern is rejected, - exactly MAX_ADDRESS_REGEX_LENGTH is accepted and one byte over is rejected, - None still passes through unchanged.
|
Thanks for the review.
|
foxpatch-aleph
left a comment
There was a problem hiding this comment.
This PR correctly adds validation for the address_regex field in NodeRequirements. It caps the field at 256 characters and validates that the value is a valid Python regular expression at schema-validation time. The implementation uses Pydantic's field_validator decorator properly, handles None correctly, and provides clear error messages. The test coverage is comprehensive, covering valid patterns, invalid patterns, length boundaries, and None values. No regressions in existing tests.
Cap the field at 256 characters and reject values that don't compile as Python regular expressions. Catches malformed patterns at schema-validation time rather than at match time.
Test plan
hatch -e testing run pytest(unchanged — same 4 pre-existing network-flaky tests fail on main)