Skip to content

feat(resource): validator, builder, and tests for the resource constraint - #387

Merged
rapids-bot[bot] merged 11 commits into
rapidsai:mainfrom
johanpel:resource-constraint
Jul 20, 2026
Merged

feat(resource): validator, builder, and tests for the resource constraint#387
rapids-bot[bot] merged 11 commits into
rapidsai:mainfrom
johanpel:resource-constraint

Conversation

@johanpel

@johanpel johanpel commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

Implements the quent.resource.v0.1.0 constraint in the existing quent-resource crate.

Adds validation for resource declarations, capacity claims, bounds coverage, FSM usage lifetimes, record references, and annotation placement. Refines the resource metadata types and adds a fallible ResourceBuilder that produces the definition, usage record, and optional bounds record.

Related Issues

Solves #196
Part of #191

🤖 Generated with Claude Code
🤖 Generated by OpenAI Codex.

johanpel and others added 2 commits July 16, 2026 09:19
…aint

Implement the quent.resource.v1 constraint: the Resource/Capacity
metadata types, a Visitor validating the eight requirements plus role
placement, and a ResourceBuilder that emits the usage and bounds record
types and the definition for a caller to compose the entity from. Add a
focused test per requirement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Capacities alias is private, so linking it from the public
ResourceConstraint doc produced rustdoc private-intra-doc-link warnings.
Refer to the capacities in plain prose; the public Capacity type stays
linked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@johanpel
johanpel force-pushed the resource-constraint branch from 80f0cb4 to 1b40c07 Compare July 16, 2026 09:06
@johanpel
johanpel marked this pull request as ready for review July 20, 2026 12:17
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a ResourceBuilder for generating resource definitions and records, and implements ResourceConstraint validation for resource declarations, capacities, usage, bounds, FSM users, and annotation placement.

Changes

Resource constraint

Layer / File(s) Summary
Resource model and builder API
crates/resource/Cargo.toml, crates/resource/src/builder.rs, crates/resource/src/lib.rs
Adds resource builder types and errors, updates capacity identifiers to map keys, and generates usage and optional bounds records.
Resource constraint validation
crates/resource/src/lib.rs, crates/resource/tests/resource-constraint.rs
Collects and decodes resource annotations, validates capacity and record relationships, enforces FSM and placement rules, and adds coverage for valid and invalid schemas.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: feature request

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: the resource constraint validator, builder, and tests.
Description check ✅ Passed The description covers the change and related issues, but it omits the Testing section and Screenshots from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (1)
crates/resource/src/lib.rs-296-312 (1)

296-312: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Misleading diagnostic text for a usage record without an enclosing entity.

When entity is None here, on_entity_ref was already confirmed true above (the check that would've continued otherwise). So the actual failure is "no enclosing entity", not "a non-entity reference" — the element label describes the wrong condition and will mislead anyone debugging this error.

🐛 Proposed fix
     None => errors.push(ResourceError::MisplacedRole {
         location: location.clone(),
         role: "usage",
-        element: "a non-entity reference",
+        element: "a record with no enclosing entity",
     }),
🤖 Prompt for 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.

In `@crates/resource/src/lib.rs` around lines 296 - 312, Update the `None` branch
of the `match entity` handling in `on_entity_ref` so
`ResourceError::MisplacedRole` reports the missing enclosing entity accurately;
change only the `element` diagnostic label from the misleading non-entity
reference wording while preserving the existing location, role, and error flow.
🧹 Nitpick comments (2)
crates/resource/src/builder.rs (1)

159-160: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider bullet_list for BuildError::Multiple for consistency.

ResourceError::Multiple (in lib.rs) renders its aggregated errors via bullet_list(.0); this variant instead dumps raw {0:?}. Aligning the two would give a more readable multi-error message here too.

♻️ Proposed fix
-    #[error("multiple resource builder errors: {0:?}")]
+    #[error("multiple resource builder errors:\n{}", quent_constraints::utils::bullet_list(.0))]
     Multiple(Vec<BuildError>),
🤖 Prompt for 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.

In `@crates/resource/src/builder.rs` around lines 159 - 160, Update the
BuildError::Multiple display annotation to use the existing bullet_list
formatter on its contained errors, matching ResourceError::Multiple in lib.rs
instead of rendering the vector with raw debug formatting.
crates/resource/src/lib.rs (1)

147-387: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider splitting finish() into per-requirement helpers.

The method spans ~140 lines and interleaves four distinct validation passes (usage/capacity, FSM+reference+bounds-ownership, bounds coverage, missing-bounds). Extracting each pass into a private helper taking the relevant collections would improve readability/testability without changing behavior.

🤖 Prompt for 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.

In `@crates/resource/src/lib.rs` around lines 147 - 387, Split
ResourceConstraint::finish into private helpers for the four validation passes:
usage/capacity validation, reference and bounds ownership validation, bounds
coverage validation, and missing-bounds validation. Have each helper receive
only the relevant collections and append to the shared errors collection, while
preserving the existing validation order and final error aggregation behavior.
🤖 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/resource/Cargo.toml`:
- Around line 8-10: Update the resource crate’s quent-schema, quent-constraints,
and quent-fsm entries in both [dependencies] and [dev-dependencies] to use
workspace-managed declarations with workspace = true instead of direct paths.
Add matching path-based entries for these three crates to the workspace root’s
[workspace.dependencies], preserving the repository’s existing dependency
configuration style.

---

Other comments:
In `@crates/resource/src/lib.rs`:
- Around line 296-312: Update the `None` branch of the `match entity` handling
in `on_entity_ref` so `ResourceError::MisplacedRole` reports the missing
enclosing entity accurately; change only the `element` diagnostic label from the
misleading non-entity reference wording while preserving the existing location,
role, and error flow.

---

Nitpick comments:
In `@crates/resource/src/builder.rs`:
- Around line 159-160: Update the BuildError::Multiple display annotation to use
the existing bullet_list formatter on its contained errors, matching
ResourceError::Multiple in lib.rs instead of rendering the vector with raw debug
formatting.

In `@crates/resource/src/lib.rs`:
- Around line 147-387: Split ResourceConstraint::finish into private helpers for
the four validation passes: usage/capacity validation, reference and bounds
ownership validation, bounds coverage validation, and missing-bounds validation.
Have each helper receive only the relevant collections and append to the shared
errors collection, while preserving the existing validation order and final
error aggregation behavior.
🪄 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: 2a834ab7-073c-4ae5-9650-afc2031957c9

📥 Commits

Reviewing files that changed from the base of the PR and between 32f072f and e78d65a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (4)
  • crates/resource/Cargo.toml
  • crates/resource/src/builder.rs
  • crates/resource/src/lib.rs
  • crates/resource/tests/resource-constraint.rs

Comment on lines +8 to +10
quent-schema = { path = "../schema", features = ["serde", "visitor"] }
quent-constraints = { path = "../constraints" }
quent-fsm = { path = "../fsm" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Route internal crate deps through [workspace.dependencies].

quent-schema, quent-constraints, and quent-fsm are declared with direct path = "..." in both [dependencies] (Lines 8-10) and [dev-dependencies] (Line 18), bypassing workspace = true used consistently by every other dependency in this file (Lines 11-15).

🔧 Proposed fix
-quent-schema = { path = "../schema", features = ["serde", "visitor"] }
-quent-constraints = { path = "../constraints" }
-quent-fsm = { path = "../fsm" }
+quent-schema = { workspace = true, features = ["serde", "visitor"] }
+quent-constraints = { workspace = true }
+quent-fsm = { workspace = true }

and add corresponding entries to the workspace root's [workspace.dependencies].

As per path instructions, "Dependencies come from [workspace.dependencies] via workspace = true; no git deps."

Also applies to: 17-18

🤖 Prompt for 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.

In `@crates/resource/Cargo.toml` around lines 8 - 10, Update the resource crate’s
quent-schema, quent-constraints, and quent-fsm entries in both [dependencies]
and [dev-dependencies] to use workspace-managed declarations with workspace =
true instead of direct paths. Add matching path-based entries for these three
crates to the workspace root’s [workspace.dependencies], preserving the
repository’s existing dependency configuration style.

Source: Path instructions

@johanpel

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit bcbbc74 into rapidsai:main Jul 20, 2026
11 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