Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Apr 18, 2025

Summary by CodeRabbit

  • New Features
    • Added enhanced validation for deployment, environment, and resource selectors in policy creation forms.
    • Introduced stricter checks for deployment version selectors when creating policy rules.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

## Walkthrough

This update introduces additional validation to policy-related schemas by incorporating specific refinement functions for deployment, environment, resource, and deployment version selectors. The changes ensure that if these selectors are provided (i.e., not null), they must pass their respective custom validation functions, adding stricter checks beyond basic type validation. The schema definitions themselves remain structurally unchanged, but now enforce these new validation constraints at insertion time. Additionally, the insertion logic for deployment version selectors in policy creation and update functions was simplified by spreading the selector object directly instead of explicit casting.

## Changes

| File(s)                                                                                  | Change Summary                                                                                                              |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| packages/db/src/schema/policy.ts                                                         | Enhanced `policyTargetInsertSchema` by adding `.refine()` calls with custom validation functions for deployment, environment, and resource selectors, enforcing stricter validation if selectors are present. |
| packages/db/src/schema/rules/deployment-selector.ts                                      | Updated `createPolicyRuleDeploymentVersionSelector` schema to include a required `deploymentVersionSelector` field with a refinement using `isValidDeploymentVersionCondition`.                   |
| packages/db/src/policies/create.ts, packages/db/src/policies/update.ts                   | Simplified insertion of deployment version selector by spreading the entire selector object with added `policyId` instead of explicit casting and nested assignment.                             |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Client
    participant Schema
    participant Validator

    Client->>Schema: Insert policy target with selectors
    Schema->>Validator: Validate deploymentSelector (if not null)
    Validator-->>Schema: Pass/Fail
    Schema->>Validator: Validate environmentSelector (if not null)
    Validator-->>Schema: Pass/Fail
    Schema->>Validator: Validate resourceSelector (if not null)
    Validator-->>Schema: Pass/Fail
    Schema-->>Client: Accept or reject based on validation

Possibly related PRs

  • policy selector #430: Refactors and adds stricter type-safe schema definitions for deploymentSelector and environmentSelector fields in the same policy schema file, closely related to the validation enhancements in this PR.
  • init filter rule #435: Introduces a new table and schema for deployment version selectors, related at the schema level but does not modify validation refinements or insertion logic.

Poem

A schema refined, with checks so neat,
Each selector now must pass the feat.
Validators watch with a keen rabbit eye,
Ensuring only the best data slips by.
With every hop, our rules grow strong—
Hooray for schemas that can't go wrong! 🐇✨


<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 1d3a3ca6c00082cbe3f48ea6073aae991708dd0f and 4e9a6d393f644819ba08512cd763b93a990f8d12.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `packages/db/src/policies/create.ts` (1 hunks)
* `packages/db/src/policies/update.ts` (1 hunks)
* `packages/db/src/schema/rules/deployment-selector.ts` (2 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* packages/db/src/schema/rules/deployment-selector.ts

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>📓 Path-based instructions (1)</summary>

<details>
<summary>`**/*.{ts,tsx}`: **Note on Error Handling:**
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...</summary>

> `**/*.{ts,tsx}`: **Note on Error Handling:**
> Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.
> 

- `packages/db/src/policies/create.ts`
- `packages/db/src/policies/update.ts`

</details>

</details>

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (6)</summary>

* GitHub Check: Typecheck
* GitHub Check: Lint
* GitHub Check: build (linux/amd64)
* GitHub Check: build (linux/amd64)
* GitHub Check: build (linux/amd64)
* GitHub Check: build (linux/amd64)

</details>

<details>
<summary>🔇 Additional comments (2)</summary><blockquote>

<details>
<summary>packages/db/src/policies/update.ts (1)</summary>

`76-76`: **Clean code simplification!**

The code is now more concise by directly spreading the `deploymentVersionSelector` with the `policyId` instead of using explicit casting. This approach is consistent with modern JavaScript/TypeScript patterns and reduces unnecessary complexity.

</details>
<details>
<summary>packages/db/src/policies/create.ts (1)</summary>

`100-100`: **Good simplification of deployment version selector handling**

You've simplified the code by directly spreading the deployment version selector object and adding the policy ID. This makes the code cleaner and more maintainable while maintaining the same functionality.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEejqANiS4AzeAA8uaWvQloL8WtXj4sBSIgkVmL4FMjwWIgMsCTMaIgGAHLYzAKUXAAsAJwA7AYAqoEUTrTqsmjR+Ni0sGgU8ABMAGxG+sbgUGT0+DY4BMRkyjT0TKzsXLz8wqLiUjLyTEpUqupaOm0mUHCoqJh9hKTkVMMKYxickFQA7gEpcRTycgpLKmqa2rpghu2mBtwVAGs0KREAB6WgCUGICgMKHRWJoUHcfAeBiyDS4RAcAwAIjxBgAxATIABBACSAyO1Dot1YdXkPUYtQwILMMRQzGRFFwAVw1LY52QNlCkCU3As+FkAtwABpIGQJPAKL5pXLMPQKNIqjCSAoMKVxL5IG4PF4CGFIFdKLqSPZ/vqaf4IgwLNVdUwKJrEMj9REiMb3J5vEabNgMGIfBgsZAAAZIABqgdoABESOLJdKAMK+A2RmNyuOIROmgCiGEVyowWZz6jzav1sYTSYASlrsDrs77DRgYxpIGS/OyY8jUbJoHVSLgB0VcABleFxGMBBdoUUkOwYWu+OW4dm7zW6wLBc3IAAUMbFEql7FnQRmoXzsYVSpVN7vIQoj/Vsa92oYJFvY8HwASkta1IGYRR4DsR18HQFxYw0TUNxIU9gKXBh3AsZBd2odBuHFeRd2kXUTSDbtIFDcNu0QPsSwqWAAnfc1LgRCJkAwbALAsFQrDlAQ8EgDB8BuZ1XSUZBV2QiJYnYSBcJ5MhEHbaQUF6YimKAvhUG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QIbXWujjaAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=ctrlplanedev/ctrlplane&utm_content=497):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@adityachoudhari26 adityachoudhari26 merged commit 622a891 into main Apr 18, 2025
9 of 10 checks passed
@adityachoudhari26 adityachoudhari26 deleted the validate-conditions-in-schemas branch April 18, 2025 17:09
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