Skip to content

Conversation

@hardbyte
Copy link
Owner

@hardbyte hardbyte commented Aug 7, 2025

Update CEL crate to v0.11.0 and enhance documentation validation

Summary

This PR updates the underlying CEL implementation from v0.10.0 to v0.11.0 and improves our documentation testing to ensure all examples are properly validated.

CEL v0.11.0 Update

Breaking Changes

  • Crate renamed: cel-interpretercel
  • Function registration system: Updated to new IntoFunction trait
  • Python function integration: Now uses Arguments extractor for variadic arguments
  • Import changes: All cel_interpreter:: imports updated to ::cel::

API Compatibility

  • No breaking changes to Python API - all existing code continues to work
  • Full backward compatibility maintained for users
  • Performance improvements from new extractors system
  • Better error handling in function registration

Documentation Validation Enhancements

Problem Identified

  • mktestdocs was only testing Python syntax, not whether CEL expressions actually worked correctly
  • 12 functions across cookbook documentation had no actual test validation
  • Documentation examples could contain semantic bugs while still "passing" tests

Solution Implemented

  • Comprehensive test validation: Added realistic business logic test cases to all previously untested functions
  • Semantic bug fixes: Corrected role hierarchy logic, seasonal discount calculations, and CEL syntax issues
  • Context-aware testing: Each test now validates actual CEL expression behavior with proper business contexts
  • Sub-agent verification: Used distributed verification to systematically review all cookbook examples

Files Enhanced

  • docs/how-to-guides/access-control-policies.md - Added hierarchical, time-based, and resource-specific access control validation
  • docs/how-to-guides/business-logic-data-transformation.md - Added comprehensive business rule validation with proper contexts
  • docs/how-to-guides/error-handling.md - Added security validation for safe expression evaluation
  • docs/how-to-guides/production-patterns-best-practices.md - Added performance monitoring and complex expression validation

Key Fixes

  • Role hierarchy bug: Fixed required_level: 1required_level: 0 to allow guest access to public resources
  • CEL syntax corrections: Fixed has('string')has(field) macro usage
  • Python vs CEL syntax: Changed Python ternary to CEL conditional operators
  • Business logic validation: Replaced trivial 1 + 1 == 2 tests with meaningful business rule validation

Testing Status

  • All 18 documentation files pass integrated mktestdocs validation via pytest
  • 315 tests pass with updated CEL v0.11.0 integration
  • All cookbook examples now test actual CEL expression behavior
  • Business logic validation ensures educational value of documentation tests

Migration Impact

For Users

  • Zero breaking changes - existing Python code works unchanged
  • Better performance from new CEL v0.11.0 optimizations
  • More reliable documentation with validated examples

For Developers

  • Updated dependencies: PyO3 0.25.0 → 0.25.1, pyo3-log 0.12.1 → 0.12.4
  • New internal APIs: IntoFunction trait system (internal only)
  • Enhanced documentation: All examples now properly tested and validated

Future Compatibility

Analysis of upcoming cel-rust developments shows:

  • Enhanced type system infrastructure for better introspection
  • Foundation for type() function (missing from current CEL spec compliance)
  • Optional value infrastructure for safer null handling
  • Maintained backward compatibility with our wrapper design

Verification

# Run comprehensive test suite (includes mktestdocs validation)
uv run pytest --log-cli-level=debug

# Run just documentation validation tests
uv run pytest tests/test_docs.py -v

# Build and formatting checks
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo build --workspace

Note: Warning messages in test output are expected and intentional - they test error conditions, security validation, and exception handling to ensure robust error handling works correctly.

This update maintains full backward compatibility while providing significant improvements to both the underlying CEL engine and our documentation quality assurance.

- Added test cases to 12 previously untested functions in documentation
- Fixed role hierarchy bug in access control (required_level: 0 vs 1)
- Corrected Python if-else syntax to CEL ternary operators
- Fixed invalid has() usage with string literals vs field references
- Enhanced business logic tests with proper validation contexts
- Added comprehensive batch processing and rule composition validation
- Updated all cookbook examples to verify CEL expressions actually work
- Ensured mktestdocs tests validate business logic accuracy, not just syntax
- Document breaking changes from cel-interpreter to cel crate
- Added comprehensive notes on API compatibility maintenance
- Updated dependency versions and migration details
@hardbyte hardbyte force-pushed the update/cel-interpreter branch from c4a5b1d to 2469587 Compare August 7, 2025 10:41
@hardbyte hardbyte merged commit d27116a into main Aug 7, 2025
16 checks passed
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