Skip to content

Bound and validate NodeRequirements.address_regex#145

Merged
odesenfans merged 2 commits into
mainfrom
feat/validate-address-regex
Apr 21, 2026
Merged

Bound and validate NodeRequirements.address_regex#145
odesenfans merged 2 commits into
mainfrom
feat/validate-address-regex

Conversation

@odesenfans
Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown

@foxpatch-aleph foxpatch-aleph left a comment

Choose a reason for hiding this comment

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

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.
@odesenfans odesenfans force-pushed the feat/validate-address-regex branch from 71c7a6d to 40d1284 Compare April 21, 2026 21:44
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.
@odesenfans
Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  • Tests for the validator — fair point, the "tests pass" line in
    the description was about regression coverage only; there was no
    positive coverage for the new validator. Added in 5e3dd66: four
    focused tests on `NodeRequirements` directly (valid pattern,
    uncompilable pattern, the 256/257 length boundary, and the None
    passthrough), using the `MAX_ADDRESS_REGEX_LENGTH` constant so the
    boundary test stays honest if the cap ever moves. All four pass
    locally; CI should pick them up on the next run.
  • `re.error` note — agreed, no change needed. It is the right
    exception class for `re.compile` failures and the wrapped message
    already includes the underlying cause.

Copy link
Copy Markdown

@foxpatch-aleph foxpatch-aleph left a comment

Choose a reason for hiding this comment

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

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.

@odesenfans odesenfans merged commit ff21b17 into main Apr 21, 2026
10 checks passed
@odesenfans odesenfans deleted the feat/validate-address-regex branch April 21, 2026 22:02
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.

2 participants