feat(variant): Phase 2 — thread fields_per_variant through validate (#287)#298
Open
avrabe wants to merge 1 commit into
Open
feat(variant): Phase 2 — thread fields_per_variant through validate (#287)#298avrabe wants to merge 1 commit into
avrabe wants to merge 1 commit into
Conversation
…287) Closes #287. v0.10.0 (PR #285) shipped `Artifact::fields_per_variant` and the `fields_for_variant(Option<&str>) -> Cow<'_, BTreeMap<...>>` resolver as a building block but nothing consumed variant overlays during validate. This PR wires the resolver through the validation engine. **rivet-core/src/schema.rs** — variant-aware helpers (additive): - `get_field_value_for_variant(artifact, field, variant)` resolves through `Artifact::fields_for_variant` when `variant` is `Some(_)`, delegates to the existing borrowed-Cow path when `None` (zero allocations on the no-variant path). - `Condition::matches_artifact_for_variant_with(...)`. - `Requirement::check_for_variant(...)` for `RequiredFields`. Per design §6 Phase 2 scope ("fields only"), `RequiredLinks` stays variant-flat — links aren't overlayed. **rivet-core/src/validate.rs** — additive wrappers + threading: - New public APIs: `validate_with_variant`, `validate_with_externals_and_variant`, `validate_structural_with_variant`, `validate_structural_with_externals_and_variant`. - Existing `validate*` functions thin-wrap the variant-aware version with `variant: None`. No breaking signature changes. - Required-fields and allowed-values reads now go through `artifact.fields_for_variant(variant)` (resolved once per artifact as `effective_fields`). - Conditional rules (phase 8) use `cond.matches_artifact_for_variant_with` + `rule.then.check_for_variant`. **rivet-cli/src/main.rs cmd_validate** — threads the active variant: - When `--variant <name>` is set, falls through to the direct path (salsa doesn't yet take variant as a tracked input) and calls `validate_with_externals_and_variant(..., active_variant)`. - Baseline-only / no-variant / `--direct` paths preserved. Tests added (rivet-core/src/validate.rs, mod tests): 1. `conditional_rule_respects_variant_field_overlay` — artifact has `fields.priority=must` and `fields-per-variant.automotive.priority= should`. Conditional rule fires on `priority==must`. Without variant: rule fires. With `Some("automotive")`: doesn't fire. With unknown variant: behaves like no variant (1 diag). 2. `required_field_satisfied_by_variant_overlay` — required field `asil` absent from `fields` but present in `fields-per-variant.automotive.asil=D`. Without variant: 1 required-field error. With `Some("automotive")`: 0 errors. NOT in this PR (deliberately): - `rivet list --variant <name>` filtering. - `rivet coverage --variant <name>` scoping. - Variant-aware s-expr validation rules (phase 9 in validate.rs). - Salsa-tracked variant input (direct-path fallback for now). - Cross-product multi-axis variants. - `when:` clause on external-anchor. Implements: REQ-004, REQ-007 Refs: FEAT-001, #287 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
11a4d84 to
58295cb
Compare
📐 Rivet artifact deltaNo artifact changes in this PR. Code-only changes (renderer, CLI wiring, tests) don't touch the artifact graph. |
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
Closes #287. v0.10.0 shipped `Artifact::fields_per_variant` + the `fields_for_variant` resolver as a building block but nothing consumed variant overlays during validate. This PR wires the resolver through the validation engine.
What ships
rivet-core/src/schema.rs — variant-aware helpers (additive):
rivet-core/src/validate.rs — additive wrappers + threading:
rivet-cli/src/main.rs — `--variant ` flag now actually flows through to the validate engine. Salsa doesn't yet take variant as a tracked input, so variant-active falls through to the direct path.
Tests
Both pass:
Full suite: 996 lib tests + 2 new = green. Clippy clean. Format clean.
NOT in this PR
Test plan
🤖 Generated with Claude Code