feat(yaml): support ref targets, scope-refs, and ref data - #390
Conversation
Add `ref: <Entity>` and `scope-ref: <Entity>` type forms, each with an optional `data:` payload. `ref` lowers to an `EntityRef` carrying the ref-target constraint; `scope-ref` additionally adds the ref-tree marker. Validation resolves targets and tree shape via the constraint tuple. Demonstrate both forms in the instrumentation-build example: a Server entity, a scope-ref from Connection to it, and a data-carrying ref. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
83a2bc7 to
5d9e9b4
Compare
Generate a zero-size marker per entity and parameterize `EntityRef<E, T>` by it, so a reference's target entity is checked at compile time. The codegen reads the ref-target constraint to pick the marker, falling back to the `AnyEntity` marker for untargeted references. Each handle gains `as_entity_ref`/`as_entity_ref_with` (typed) and `as_any_entity_ref`/ `as_any_entity_ref_with` (unrestricted target), each capturing its own id. A handle can no longer stand in for a reference to a different entity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: QUIET Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe YAML schema adds ChangesTyped entity references
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/instrumentation-build/src/data_type.rs`:
- Around line 59-84: Add a test covering EntityRef target-marker generation with
a quent.ref-target annotation, using a target such as Cluster and asserting the
generated type includes EntityRef<Cluster, ...>. Keep the existing
default-annotation test for the AnyEntity fallback, and place the new coverage
alongside tests for map_data_type or ref_target_marker.
In `@crates/yaml/Cargo.toml`:
- Around line 10-11: Add quent-ref-target and quent-ref-tree to the root
[workspace.dependencies], then update crates/yaml/Cargo.toml lines 10-11 to use
workspace-managed declarations with workspace = true instead of local path
dependencies. Apply the same workspace dependency change to quent-ref-target in
crates/instrumentation-build/Cargo.toml line 12; do not introduce git
dependencies.
In `@crates/yaml/src/lower.rs`:
- Around line 213-219: Update the docstring for the entity-reference helper near
the targeted/tree-forming reference construction to describe only the returned
reference type and its optional data/tree-forming behavior. Remove details about
ref-target/ref-tree constraint storage and validation responsibilities, keeping
the documentation focused on the helper’s public contract.
In `@crates/yaml/tests/references.rs`:
- Around line 97-116: Extend scope_emits_target_and_tree by adding a data
payload to the scope-ref for Cluster, then assert the resulting EntityRef data
type through the returned annotations. Preserve the existing target and tree
assertions while covering the advertised scope-ref data path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: QUIET
Plan: Enterprise
Run ID: 2bf72a3c-6eb4-44b7-8753-bb0e8ca8bdc5
⛔ Files ignored due to path filters (2)
Cargo.lockis excluded by!**/*.lock,!Cargo.lockcrates/instrumentation-build/example/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (14)
crates/instrumentation-build/Cargo.tomlcrates/instrumentation-build/example/model.yamlcrates/instrumentation-build/example/src/main.rscrates/instrumentation-build/src/data_type.rscrates/instrumentation-build/src/events.rscrates/instrumentation-build/src/runtime/handle.rscrates/instrumentation-build/src/runtime/mod.rscrates/instrumentation/src/entity_ref.rscrates/instrumentation/src/lib.rscrates/yaml/Cargo.tomlcrates/yaml/src/ast.rscrates/yaml/src/lib.rscrates/yaml/src/lower.rscrates/yaml/tests/references.rs
Add a data_type test asserting a ref-target annotation lowers to `EntityRef<Cluster, ..>`, and extend the scope-ref test with a `data:` payload so the scope-ref data path is exercised. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
/merge |
Description
Adds entity references to the YAML DSL, and makes their target type-safe in the generated instrumentation.
The DSL gains
ref: <Entity>andscope-ref: <Entity>type forms, each with an optionaldata:payload.refemits thequent.ref-targetconstraint;scope-refalso emitsquent.ref-tree. Targets and tree shape are validated at load time.In the generated instrumentation,
EntityRef<E, T>is now parameterized by a per-entity marker, so a reference's target entity is checked at compile time. Each handle produces its own references viaas_entity_ref/as_entity_ref_with(andas_any_entity_refvariants for untargeted fields).The instrumentation-build example shows both forms end to end.
Related Issues
Part of #355
🤖 Generated with Claude Code