fix: impl AsCelValue for FieldMask, Timestamp, Duration WKTs#6
Merged
Conversation
Field-level predefined CEL rules on `google.protobuf.FieldMask`,
`Timestamp`, and `Duration` failed to compile because the plugin emits
`AsCelValue::as_cel_value(inner)` for the field value but no
`AsCelValue` impl existed for those WKT structs.
Add the three impls in `protovalidate-buffa/src/cel.rs`:
- `FieldMask` -> CEL `Map { paths: List<String> }`, so expressions
like `this.paths.all(p, ...)` work.
- `Timestamp` -> native CEL `Timestamp` via `timestamp_from_secs_nanos`.
- `Duration` -> native CEL `Duration` via `duration_from_secs_nanos`.
Pulls `buffa-types = "0.5"` into the runtime crate for the WKT struct
definitions, and adds an integration test exercising each impl through
the real `CelConstraint::eval` path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Field-level predefined CEL rules on
google.protobuf.FieldMask,Timestamp, andDurationfailed to compile because the codegen plugin emits::protovalidate_buffa::cel::AsCelValue::as_cel_value(inner)for the field value, but noAsCelValueimpl existed for those WKT structs.For example a downstream proto like
failed with
the trait bound FieldMask: AsCelValue is not satisfied. Same shape for Timestamp- and Duration-typed fields.Fix
Three new
impl AsCelValueblocks inprotovalidate-buffa/src/cel.rs:FieldMask-> CELMap { paths: List<String> }, sothis.paths.all(p, ...),size(this.paths), etc. work.Timestamp-> native CELTimestampvia the existingtimestamp_from_secs_nanoshelper, sothis < timestamp(...),this < now,int(this)work.Duration-> native CELDurationvia the existingduration_from_secs_nanoshelper, sothis > duration('0s')works.Pulls
buffa-types = "0.5"into the runtime crate to reference the WKT struct definitions. No changes to the codegen plugin or to public API beyond the new impls.Test plan
cargo test -p protovalidate-buffa— newtests/wkt_cel.rsexercises each impl through the realCelConstraint::evalpath (this.paths.all(...),size(this.paths),this > duration('0s'),this < timestamp('9999-12-31T23:59:59Z'),this < now, sub-second nanos resolution).cargo test --workspace --all-targets— no regressions.cargo clippy --workspace --all-targets -- -D warnings— clean.cargo fmt --all -- --check— clean.update_maskCEL for a field-level predefined rule on agoogle.protobuf.FieldMaskfield, confirm it compiles.