feat(studio): add guardrail-checks SDK for entity-store-backed test cases#829
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
📝 WalkthroughWalkthroughGuardrail-check API support is added with typed entity contracts, parent-scoped CRUD, execution and run persistence, concurrent batch processing, React Query hooks, cache invalidation, and public exports. ChangesGuardrail Checks
Sequence Diagram(s)sequenceDiagram
participant Client
participant ReactQuery
participant GuardrailChecksAPI
participant EntityStore
participant GuardrailsEndpoint
Client->>ReactQuery: request guardrail checks
ReactQuery->>GuardrailChecksAPI: list or fetch check
GuardrailChecksAPI->>EntityStore: query scoped entities
EntityStore-->>GuardrailChecksAPI: return check entities
GuardrailChecksAPI-->>ReactQuery: return page or entity
Client->>ReactQuery: run guardrail check
ReactQuery->>GuardrailChecksAPI: run check
GuardrailChecksAPI->>EntityStore: load parent config
GuardrailChecksAPI->>GuardrailsEndpoint: execute /checks request
GuardrailsEndpoint-->>GuardrailChecksAPI: return check response
GuardrailChecksAPI->>EntityStore: append persisted run
ReactQuery->>ReactQuery: invalidate affected caches
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@web/packages/studio/src/api/guardrail-checks/guardrailChecks.ts`:
- Around line 71-86: Make the parent parameter required in getGuardrailCheck and
deleteGuardrailCheck, matching createGuardrailCheck. Remove the optional
fallback so both name lookups and deletions always pass parent as the required
scope, and update affected callers or types accordingly.
- Line 1: Update the imports in guardrailChecks.ts and hooks.ts to use type-only
specifiers for the listed TypeScript types while keeping
GUARDRAIL_CHECKS_ENTITY_TYPE as a runtime import. In hooks.ts, mark the React
Query option types as type-only and move the `@tanstack/react-query` import into
the external-library import group.
- Line 1: Require a parent scope for all name-based guardrail check operations:
update getGuardrailCheck and deleteGuardrailCheck to require or reject missing
parent before resolving the entity, and extend UseDeleteGuardrailCheckOptions
mutation variables to include parent and pass it through to
deleteGuardrailCheck. Preserve the existing scoped behavior while preventing
unscoped lookup or deletion.
🪄 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: CHILL
Plan: Enterprise
Run ID: ad136db7-9590-4974-aaf9-113856ec0df9
📒 Files selected for processing (5)
web/packages/studio/src/api/guardrail-checks/guardrailChecks.tsweb/packages/studio/src/api/guardrail-checks/hooks.tsweb/packages/studio/src/api/guardrail-checks/index.tsweb/packages/studio/src/api/guardrail-checks/invalidateGuardrailChecksCaches.tsweb/packages/studio/src/api/guardrail-checks/types.ts
…ases Signed-off-by: Alex Ray <alray@nvidia.com>
34a76bf to
a6b221b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
web/packages/studio/src/api/guardrail-checks/hooks.ts (2)
19-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGroup external imports before internal aliases.
Move
@tanstack/react-queryabove the@studio/*imports.As per coding guidelines, “Group imports: external libraries, internal modules, relative imports in TypeScript.”
🤖 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 `@web/packages/studio/src/api/guardrail-checks/hooks.ts` around lines 19 - 27, Reorder the imports in the guardrail-checks hooks module so the external `@tanstack/react-query` import block appears before the internal `@studio/api` imports, preserving the imported symbols and existing grouping style.Source: Coding guidelines
36-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDeclare explicit return types for exported APIs.
These public query and mutation helpers currently expose inferred React Query types.
As per coding guidelines, “Use explicit return types for public APIs and complex functions in TypeScript.”
Also applies to: 48-52, 55-65, 68-78, 84-89, 105-114, 126-135, 146-155, 167-176, 188-197
🤖 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 `@web/packages/studio/src/api/guardrail-checks/hooks.ts` around lines 36 - 45, Declare explicit return types for all exported query and mutation helpers in this module, including getGuardrailChecksQueryOptions and the additional ranges identified in the review. Use the appropriate React Query option type matching each helper’s query or mutation configuration, while preserving the existing keys, functions, and options behavior.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@web/packages/studio/src/api/guardrail-checks/hooks.ts`:
- Around line 19-27: Reorder the imports in the guardrail-checks hooks module so
the external `@tanstack/react-query` import block appears before the internal
`@studio/api` imports, preserving the imported symbols and existing grouping
style.
- Around line 36-45: Declare explicit return types for all exported query and
mutation helpers in this module, including getGuardrailChecksQueryOptions and
the additional ranges identified in the review. Use the appropriate React Query
option type matching each helper’s query or mutation configuration, while
preserving the existing keys, functions, and options behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 8d321de8-5d71-4b59-876c-20105ca1e07d
📒 Files selected for processing (5)
web/packages/studio/src/api/guardrail-checks/guardrailChecks.tsweb/packages/studio/src/api/guardrail-checks/hooks.tsweb/packages/studio/src/api/guardrail-checks/index.tsweb/packages/studio/src/api/guardrail-checks/invalidateGuardrailChecksCaches.tsweb/packages/studio/src/api/guardrail-checks/types.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- web/packages/studio/src/api/guardrail-checks/index.ts
- web/packages/studio/src/api/guardrail-checks/invalidateGuardrailChecksCaches.ts
- web/packages/studio/src/api/guardrail-checks/types.ts
- web/packages/studio/src/api/guardrail-checks/guardrailChecks.ts
…ases (NVIDIA-NeMo#829) Signed-off-by: Alex Ray <alray@nvidia.com>
Signed-off-by: Alex Ray alray@nvidia.com
Summary by CodeRabbit