-
Notifications
You must be signed in to change notification settings - Fork 11
feat: external version dependencies #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThis set of changes introduces a DELETE operation for resource relationship rules in the API, updates the OpenAPI schema, and adds full end-to-end support and tests for managing resource relationship entities. The logic for evaluating release targets and dependencies is expanded to include child and parent resources, with corresponding updates in both the backend and test infrastructure. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant DB
Client->>API: DELETE /v1/resource-relationship-rules/{ruleId}
API->>DB: Query rule by ruleId
alt Rule not found
API-->>Client: 404 Not Found + error
else Rule found
API->>DB: Delete rule
API-->>Client: 200 OK + deleted rule object
end
sequenceDiagram
participant Worker
participant DB
Worker->>DB: getResourceChildren(resourceId)
Worker->>DB: getReleaseTargetsToEvaluate([resourceId, ...childIds], dependencies)
Note right of Worker: Evaluates release targets for resource and its children
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
openapi.v1.json (1)
3670-3732: Consider returning204 No Content(or allowing both 200 & 204) for DELETE.A successful DELETE typically responds with
204and an empty body.
Returning the deleted entity (200) is perfectly valid but may enlarge payloads and diverges from the consistency used for other DELETE endpoints in this spec (e.g./v1/resources/{resourceId}→ boolean success flag).Action (optional):
"responses": { - "200": { - "description": "The deleted resource relationship rule", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ResourceRelationshipRule" - } - } - } - }, + "204": { + "description": "Rule deleted successfully" + }, + "200": { # keep if consumers rely on the body + "description": "The deleted resource relationship rule", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ResourceRelationshipRule" + } + } + } + },Maintaining both keeps backward compatibility while aligning with REST conventions.
Also verify whether a soft-delete (deletedAt) is performed; if so, clarify this in the description.e2e/tests/api/version-dependency.spec.ts (2)
181-354: Well-structured helper functions for external resource testing.The helper functions follow a consistent pattern and properly assert response status codes. Each function has a clear single responsibility, making the test setup readable and maintainable.
Consider adding more descriptive error messages to the expect assertions for easier debugging when tests fail:
- expect(externalSystem.response.status).toBe(201); + expect(externalSystem.response.status).toBe(201, 'Failed to create external system');
356-404: Comprehensive test coverage for external parent resource dependencies.This test thoroughly exercises the new functionality by:
- Setting up a complete external system with all required components
- Testing both negative (dependency not satisfied) and positive (dependency satisfied) cases
- Demonstrating multi-agent support with agent-2
Consider consolidating the multiple
waitForTimeoutcalls into a reusable helper or using more deterministic waiting strategies:const waitForEventProcessing = async (page: Page, timeoutMs = 5000) => { await page.waitForTimeout(timeoutMs); }; // Or better, poll for a specific condition if possible const waitForReleaseCreation = async (api, releaseTargetId, versionTag, maxRetries = 10) => { for (let i = 0; i < maxRetries; i++) { const release = await getRelease(api, releaseTargetId, versionTag); if (release) return release; await new Promise(resolve => setTimeout(resolve, 1000)); } return undefined; };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
apps/event-worker/src/workers/job-update/trigger-dependent-targets.ts(4 hunks)apps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/openapi.ts(1 hunks)apps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.ts(2 hunks)apps/webservice/src/app/api/v1/resource-relationship-rules/openapi.ts(0 hunks)e2e/api/entities-builder.ts(2 hunks)e2e/api/entity-fixtures.ts(2 hunks)e2e/api/entity-refs.ts(3 hunks)e2e/api/schema.ts(3 hunks)e2e/tests/api/version-dependency.spec.ts(5 hunks)e2e/tests/api/version-dependency.spec.yaml(2 hunks)openapi.v1.json(2 hunks)packages/rule-engine/src/manager/version-manager-rules/version-dependency.ts(3 hunks)
💤 Files with no reviewable changes (1)
- apps/webservice/src/app/api/v1/resource-relationship-rules/openapi.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Formatting: Prettier is used with
@ctrlplane/prettier-config
Files:
e2e/tests/api/version-dependency.spec.yamlpackages/rule-engine/src/manager/version-manager-rules/version-dependency.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.tse2e/api/entity-fixtures.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/openapi.tsapps/event-worker/src/workers/job-update/trigger-dependent-targets.tse2e/api/entity-refs.tsopenapi.v1.jsone2e/api/entities-builder.tse2e/api/schema.tse2e/tests/api/version-dependency.spec.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (CLAUDE.md)
**/*.{ts,tsx}: Use TypeScript with explicit types (prefer interfaces for public APIs)
Import styles: Use named imports, group imports by source (std lib > external > internal)
Consistent type imports:import type { Type } from "module"
Prefer async/await over raw promises
Handle errors explicitly (use try/catch and typed error responses)
Files:
packages/rule-engine/src/manager/version-manager-rules/version-dependency.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.tse2e/api/entity-fixtures.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/openapi.tsapps/event-worker/src/workers/job-update/trigger-dependent-targets.tse2e/api/entity-refs.tse2e/api/entities-builder.tse2e/api/schema.tse2e/tests/api/version-dependency.spec.ts
⚙️ CodeRabbit Configuration File
**/*.{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.
Files:
packages/rule-engine/src/manager/version-manager-rules/version-dependency.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.tse2e/api/entity-fixtures.tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/openapi.tsapps/event-worker/src/workers/job-update/trigger-dependent-targets.tse2e/api/entity-refs.tse2e/api/entities-builder.tse2e/api/schema.tse2e/tests/api/version-dependency.spec.ts
🧠 Learnings (7)
📓 Common learnings
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#461
File: packages/job-dispatch/src/resource/handle-provider-scan.ts:48-49
Timestamp: 2025-04-09T17:14:38.947Z
Learning: The codebase implements soft deletes for resources by setting a `deletedAt` timestamp rather than physically removing records, which maintains referential integrity with foreign key constraints while allowing the application to filter out deleted resources as needed.
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#601
File: e2e/tests/api/policies/retry-policy.spec.ts:23-24
Timestamp: 2025-06-24T23:52:50.732Z
Learning: The user adityachoudhari26 prefers not to add null safety checks or defensive programming in test code, particularly in e2e tests, as they prioritize simplicity and focus on the main functionality being tested rather than comprehensive error handling within the test itself.
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#601
File: e2e/tests/api/policies/retry-policy.spec.ts:117-130
Timestamp: 2025-06-24T23:53:25.398Z
Learning: User adityachoudhari26 prefers to keep non-null assertions in e2e test code without extensive null safety checks, reasoning that test failures serve the same purpose of catching issues and the extra validation doesn't add much value in test contexts.
e2e/tests/api/version-dependency.spec.yaml (1)
Learnt from: adityachoudhari26
PR: #517
File: e2e/tests/api/deployment-variable.spec.ts:70-76
Timestamp: 2025-04-28T21:59:04.723Z
Learning: In the ctrlplane e2e tests, tests can be isolated between runs using prefixed systems with random IDs in YAML templates, but tests within the same file may still need to handle isolation between test cases if they operate on the same resources.
packages/rule-engine/src/manager/version-manager-rules/version-dependency.ts (12)
Learnt from: adityachoudhari26
PR: #604
File: packages/rule-engine/src/manager/version-manager.ts:124-139
Timestamp: 2025-06-30T21:19:43.866Z
Learning: In packages/rule-engine/src/manager/version-manager.ts, the findDesiredVersion method should use takeFirst (not takeFirstOrNull) because if a desiredVersionId is set but the query fails to find exactly one matching version, it indicates a data integrity or configuration issue that should fail loudly rather than be handled silently.
Learnt from: adityachoudhari26
PR: #181
File: packages/api/src/router/deployment.ts:116-131
Timestamp: 2024-10-29T02:04:50.312Z
Learning: In packages/api/src/router/deployment.ts, the list.byDeploymentId procedure requires multiple database queries due to limitations of the releaseMatchesCondition function.
Learnt from: adityachoudhari26
PR: #237
File: apps/webservice/src/app/[workspaceSlug]/(app)/_components/deployment-resource-drawer/DeploymentResourceDrawer.tsx:43-50
Timestamp: 2024-11-27T23:16:35.580Z
Learning: In DeploymentResourceDrawer.tsx, the isOpen variable already checks whether deploymentId, environmentId, and resourceId are non-null, so additional null checks in query enabled conditions are not necessary.
Learnt from: adityachoudhari26
PR: #579
File: packages/rule-engine/src/rules/concurrency-rule.ts:8-11
Timestamp: 2025-06-01T19:10:47.122Z
Learning: In packages/rule-engine/src/rules/concurrency-rule.ts, the ConcurrencyRule should remain simple without additional validation since database and Zod schemas already handle concurrency validation. The user prefers this rule to be "dumb" and just perform the comparison check rather than duplicating validation logic.
Learnt from: adityachoudhari26
PR: #627
File: apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts:0-0
Timestamp: 2025-07-23T22:42:20.903Z
Learning: In apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts, when implementing error handling for the triggerDependentTargets function, only a try-catch wrapper is needed around the entire function body. Additional null checks after takeFirst() calls are unnecessary since takeFirst throws an error if no record is found.
Learnt from: adityachoudhari26
PR: #395
File: packages/api/src/router/environment-page/resources/router.ts:40-45
Timestamp: 2025-03-24T18:46:38.894Z
Learning: The takeFirst utility function in the codebase (from @ctrlplane/db) throws an Error with message "Found non unique or inexistent value" if the result array doesn't contain exactly one element, making additional null/undefined checks unnecessary after its use.
Learnt from: adityachoudhari26
PR: #593
File: packages/rule-engine/src/manager/version-manager-rules/version-approval.ts:55-70
Timestamp: 2025-06-18T21:46:51.459Z
Learning: The takeFirst utility function from the database layer throws an error if no record is found, rather than returning undefined. This means functions using takeFirst already have error handling built-in and don't require additional null checks.
Learnt from: adityachoudhari26
PR: #579
File: packages/db/src/schema/rules/concurrency.ts:0-0
Timestamp: 2025-06-01T19:10:11.535Z
Learning: In the ctrlplane codebase, when defining database schemas with Drizzle ORM, it's an intentional pattern to spread base fields (like basePolicyRuleFields) and then redefine specific fields to add additional constraints (like unique constraints or foreign key references). The TypeScript field overwriting behavior is deliberately used to override base field definitions with more specific requirements.
Learnt from: adityachoudhari26
PR: #601
File: packages/job-dispatch/src/job-update.ts:264-270
Timestamp: 2025-06-24T23:56:54.799Z
Learning: In this codebase, the Tx type is just an alias for the database client type (Omit<typeof db, "$client">) and does not necessarily indicate an active transaction context. Functions like createReleaseJob need to be called within a transaction, which is why they are wrapped with db.transaction() even when the parameter is typed as Tx. Drizzle supports nested transactions via breakpoints, so additional transaction wrappers are safe even if already within a transaction.
Learnt from: adityachoudhari26
PR: #515
File: apps/event-worker/src/workers/compute-systems-release-targets.ts:86-110
Timestamp: 2025-04-28T18:38:21.163Z
Learning: In SQL queries that use inArray() with arrays like deploymentIds or environmentIds, if these arrays are empty, it will generate an invalid IN () clause that PostgreSQL rejects. Adding condition checks (e.g., if (array.length > 0)) before executing such queries prevents SQL syntax errors.
Learnt from: adityachoudhari26
PR: #188
File: packages/api/src/router/deployment.ts:144-161
Timestamp: 2024-11-01T02:37:25.510Z
Learning: In packages/api/src/router/deployment.ts, when using Drizzle ORM, there is a limitation when referencing the same table twice in a relational builder query (rbq), requiring separate queries to avoid issues.
Learnt from: adityachoudhari26
PR: #500
File: packages/db/src/schema/job.ts:117-120
Timestamp: 2025-04-21T18:34:54.764Z
Learning: In the system's job schema, the relationship between job and releaseJob is a true one-to-one relationship - a release job should only ever point to one job and vice versa. The implementation uses one(releaseJob, ...) in the jobRelations to reflect this business rule.
apps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.ts (6)
Learnt from: adityachoudhari26
PR: #579
File: packages/rule-engine/src/rules/concurrency-rule.ts:8-11
Timestamp: 2025-06-01T19:10:47.122Z
Learning: In packages/rule-engine/src/rules/concurrency-rule.ts, the ConcurrencyRule should remain simple without additional validation since database and Zod schemas already handle concurrency validation. The user prefers this rule to be "dumb" and just perform the comparison check rather than duplicating validation logic.
Learnt from: adityachoudhari26
PR: #395
File: packages/api/src/router/environment-page/resources/router.ts:40-45
Timestamp: 2025-03-24T18:46:38.894Z
Learning: The takeFirst utility function in the codebase (from @ctrlplane/db) throws an Error with message "Found non unique or inexistent value" if the result array doesn't contain exactly one element, making additional null/undefined checks unnecessary after its use.
Learnt from: adityachoudhari26
PR: #593
File: packages/rule-engine/src/manager/version-manager-rules/version-approval.ts:55-70
Timestamp: 2025-06-18T21:46:51.459Z
Learning: The takeFirst utility function from the database layer throws an error if no record is found, rather than returning undefined. This means functions using takeFirst already have error handling built-in and don't require additional null checks.
Learnt from: adityachoudhari26
PR: #604
File: packages/rule-engine/src/manager/version-manager.ts:124-139
Timestamp: 2025-06-30T21:19:43.866Z
Learning: In packages/rule-engine/src/manager/version-manager.ts, the findDesiredVersion method should use takeFirst (not takeFirstOrNull) because if a desiredVersionId is set but the query fails to find exactly one matching version, it indicates a data integrity or configuration issue that should fail loudly rather than be handled silently.
Learnt from: adityachoudhari26
PR: #183
File: apps/webservice/src/app/[workspaceSlug]/_components/environment-drawer/Overview.tsx:28-34
Timestamp: 2024-10-30T00:03:58.927Z
Learning: In the Ctrlplane project, error handling for API mutations in React components is not required unless specified by the user.
Learnt from: adityachoudhari26
PR: #579
File: packages/db/src/schema/rules/concurrency.ts:0-0
Timestamp: 2025-06-01T19:10:11.535Z
Learning: In the ctrlplane codebase, when defining database schemas with Drizzle ORM, it's an intentional pattern to spread base fields (like basePolicyRuleFields) and then redefine specific fields to add additional constraints (like unique constraints or foreign key references). The TypeScript field overwriting behavior is deliberately used to override base field definitions with more specific requirements.
apps/event-worker/src/workers/job-update/trigger-dependent-targets.ts (10)
Learnt from: adityachoudhari26
PR: #627
File: apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts:0-0
Timestamp: 2025-07-23T22:42:20.903Z
Learning: In apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts, when implementing error handling for the triggerDependentTargets function, only a try-catch wrapper is needed around the entire function body. Additional null checks after takeFirst() calls are unnecessary since takeFirst throws an error if no record is found.
Learnt from: adityachoudhari26
PR: #181
File: packages/api/src/router/deployment.ts:116-131
Timestamp: 2024-10-29T02:04:50.312Z
Learning: In packages/api/src/router/deployment.ts, the list.byDeploymentId procedure requires multiple database queries due to limitations of the releaseMatchesCondition function.
Learnt from: adityachoudhari26
PR: #515
File: apps/event-worker/src/workers/compute-systems-release-targets.ts:86-110
Timestamp: 2025-04-28T18:38:21.163Z
Learning: In SQL queries that use inArray() with arrays like deploymentIds or environmentIds, if these arrays are empty, it will generate an invalid IN () clause that PostgreSQL rejects. Adding condition checks (e.g., if (array.length > 0)) before executing such queries prevents SQL syntax errors.
Learnt from: adityachoudhari26
PR: #237
File: packages/api/src/router/job.ts:362-365
Timestamp: 2024-11-27T23:18:42.055Z
Learning: In the file packages/api/src/router/job.ts, the function releaseMatchesCondition returns undefined if the filter parameter is null. This behavior ensures that when constructing the query with and(...), the condition is omitted, allowing the query to function correctly even if there is no release channel associated with the environment.
Learnt from: adityachoudhari26
PR: #237
File: apps/webservice/src/app/[workspaceSlug]/(app)/_components/deployment-resource-drawer/DeploymentResourceDrawer.tsx:43-50
Timestamp: 2024-11-27T23:16:35.580Z
Learning: In DeploymentResourceDrawer.tsx, the isOpen variable already checks whether deploymentId, environmentId, and resourceId are non-null, so additional null checks in query enabled conditions are not necessary.
Learnt from: adityachoudhari26
PR: #188
File: apps/webservice/src/app/[workspaceSlug]/_components/release-channel-drawer/Usage.tsx:42-44
Timestamp: 2024-11-01T02:35:07.352Z
Learning: In apps/webservice/src/app/[workspaceSlug]/_components/release-channel-drawer/Usage.tsx, within the Usage component, the arrays used for filtering inherited environments are expected to remain small. Therefore, performance optimizations for this filtering logic are not necessary.
Learnt from: adityachoudhari26
PR: #395
File: packages/api/src/router/environment-page/resources/router.ts:40-45
Timestamp: 2025-03-24T18:46:38.894Z
Learning: The takeFirst utility function in the codebase (from @ctrlplane/db) throws an Error with message "Found non unique or inexistent value" if the result array doesn't contain exactly one element, making additional null/undefined checks unnecessary after its use.
Learnt from: adityachoudhari26
PR: #593
File: packages/rule-engine/src/manager/version-manager-rules/version-approval.ts:55-70
Timestamp: 2025-06-18T21:46:51.459Z
Learning: The takeFirst utility function from the database layer throws an error if no record is found, rather than returning undefined. This means functions using takeFirst already have error handling built-in and don't require additional null checks.
Learnt from: adityachoudhari26
PR: #601
File: packages/job-dispatch/src/job-update.ts:264-270
Timestamp: 2025-06-24T23:56:54.799Z
Learning: In this codebase, the Tx type is just an alias for the database client type (Omit<typeof db, "$client">) and does not necessarily indicate an active transaction context. Functions like createReleaseJob need to be called within a transaction, which is why they are wrapped with db.transaction() even when the parameter is typed as Tx. Drizzle supports nested transactions via breakpoints, so additional transaction wrappers are safe even if already within a transaction.
Learnt from: adityachoudhari26
PR: #500
File: packages/db/src/schema/job.ts:117-120
Timestamp: 2025-04-21T18:34:54.764Z
Learning: In the system's job schema, the relationship between job and releaseJob is a true one-to-one relationship - a release job should only ever point to one job and vice versa. The implementation uses one(releaseJob, ...) in the jobRelations to reflect this business rule.
e2e/api/entity-refs.ts (1)
Learnt from: adityachoudhari26
PR: #515
File: apps/webservice/src/app/api/v1/release-targets/[releaseTargetId]/releases/route.ts:103-108
Timestamp: 2025-04-28T18:41:58.813Z
Learning: In this project, full records from the deployment and deployment_version tables are considered safe for public API consumption, and there's no need to create restricted DTOs for them.
e2e/tests/api/version-dependency.spec.ts (7)
Learnt from: adityachoudhari26
PR: #181
File: packages/api/src/router/deployment.ts:116-131
Timestamp: 2024-10-29T02:04:50.312Z
Learning: In packages/api/src/router/deployment.ts, the list.byDeploymentId procedure requires multiple database queries due to limitations of the releaseMatchesCondition function.
Learnt from: adityachoudhari26
PR: #187
File: apps/jobs/src/ephemeral-env-checker/index.ts:57-0
Timestamp: 2024-10-30T23:10:58.869Z
Learning: In the codebase, deployments are decoupled from environments. When deleting environments (e.g., in apps/jobs/src/ephemeral-env-checker/index.ts), associated deployments should not be deleted.
Learnt from: adityachoudhari26
PR: #627
File: apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts:0-0
Timestamp: 2025-07-23T22:42:20.903Z
Learning: In apps/event-worker/src/workers/job-update/trigger-dependendent-targets.ts, when implementing error handling for the triggerDependentTargets function, only a try-catch wrapper is needed around the entire function body. Additional null checks after takeFirst() calls are unnecessary since takeFirst throws an error if no record is found.
Learnt from: zacharyblasczyk
PR: #382
File: apps/webservice/src/app/api/v1/deployments/[deploymentId]/route.ts:82-88
Timestamp: 2025-03-16T19:41:44.129Z
Learning: In Next.js 15, dynamic route parameters (params) return Promises instead of direct values in async contexts. When accessing properties like params.deploymentId in an async function, use (await params).deploymentId to avoid the "params should be awaited before using its properties" error. This applies to API routes, page components, and other async contexts.
Learnt from: zacharyblasczyk
PR: #382
File: apps/webservice/src/app/api/v1/deployments/[deploymentId]/route.ts:82-88
Timestamp: 2025-03-16T19:41:44.129Z
Learning: In Next.js 15, params in dynamic routes must be awaited before accessing their properties in async contexts. For example, params.deploymentId should be accessed as (await params).deploymentId in async functions.
Learnt from: adityachoudhari26
PR: #287
File: packages/validators/src/jobs/conditions/status-condition.ts:4-4
Timestamp: 2025-01-21T19:52:22.838Z
Learning: In apps/webservice/src/app/api/github/webhook/workflow/handler.ts, the external "completed" status is intentionally mapped to JobStatus.Successful to handle GitHub workflow status conversions.
Learnt from: adityachoudhari26
PR: #517
File: e2e/tests/api/deployment-variable.spec.ts:70-76
Timestamp: 2025-04-28T21:59:04.723Z
Learning: In the ctrlplane e2e tests, tests can be isolated between runs using prefixed systems with random IDs in YAML templates, but tests within the same file may still need to handle isolation between test cases if they operate on the same resources.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: build (linux/amd64)
- GitHub Check: Typecheck
- GitHub Check: Lint
- GitHub Check: build (linux/amd64)
🔇 Additional comments (24)
e2e/tests/api/version-dependency.spec.yaml (2)
13-14: LGTM!Adding the
e2e: "true"metadata field is a good practice for identifying test resources and enabling proper filtering in test scenarios.
37-40: LGTM!The addition of two agents with consistent naming convention supports the expanded test scenarios that require multiple agents. This aligns well with the test updates that explicitly specify agent names when marking jobs as successful.
packages/rule-engine/src/manager/version-manager-rules/version-dependency.ts (2)
36-40: LGTM!The logic to include parent resources in dependency satisfaction checks is well-implemented. The approach of fetching parent relationships and extracting their IDs to create a comprehensive list of resources to check is sound.
65-65: Verify consistent inArray usage patterns.The change from
eqtoinArrayfor resource ID checking is correct and aligns with the expanded scope to include parent resources. TheresourceIdsToCheckarray will always contain at least one element (the original resource ID), so no empty array issues.Let me verify that similar patterns are used consistently across the codebase:
#!/bin/bash # Description: Check for consistent inArray usage patterns with resource IDs # Search for other inArray usage with resourceId to ensure consistency rg -A 3 -B 3 "inArray.*resourceId" --type tse2e/api/entity-fixtures.ts (2)
102-117: LGTM!The
ResourceRelationshipFixtureschema is well-designed with appropriate required and optional fields. The structure supports flexible resource relationship definitions while ensuring essential fields likesource,dependencyType, andreferenceare mandatory.
171-171: LGTM!The integration of the new
resourceRelationshipsfield into theEntityFixturesschema maintains consistency with the existing optional array pattern used for other entity types.apps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/openapi.ts (1)
107-155: LGTM!The DELETE operation specification is well-structured and follows established patterns from the existing PATCH operation. The response codes (200, 404, 500) appropriately cover all expected scenarios, and the schema references are consistent with the existing API design.
apps/event-worker/src/workers/job-update/trigger-dependent-targets.ts (3)
72-72: LGTM!The function signature change to accept an array of resource IDs appropriately supports the expanded evaluation scope to include child resources.
107-112: LGTM!The logic to include child resources in dependency evaluation is well-implemented. The approach mirrors the parent resource inclusion in the version-dependency rule, providing comprehensive hierarchical dependency resolution.
92-92: Verify empty array handling is consistent.The change from
eqtoinArrayis correct. TheresourceIdsarray will always contain at least the originalresourceId, so no empty array issues should occur.Based on previous learnings about inArray and empty arrays, let me verify this pattern is handled consistently:
#!/bin/bash # Description: Check for inArray usage patterns and potential empty array handling # Search for inArray usage to ensure consistent patterns rg -A 2 -B 2 "inArray.*resourceId" --type ts # Check if there are any array length checks before inArray usage rg -A 5 -B 5 "\.length.*>.*0.*inArray" --type tsapps/webservice/src/app/api/v1/resource-relationship-rules/[ruleId]/route.ts (2)
7-7: LGTM: Import addition is appropriate.The addition of
takeFirstOrNullimport is necessary for the new DELETE handler's existence check.
176-217: LGTM: Well-implemented DELETE handler.The DELETE handler follows established patterns with proper:
- Authentication and authorization checks
- Use of
takeFirstOrNullfor existence verification (appropriate for nullable case)- Use of
takeFirstfor deletion (safe after existence confirmation)- Error handling with appropriate HTTP status codes
- Consistent structure with the existing PATCH handler
e2e/api/entities-builder.ts (2)
169-220: LGTM: Consistent resource relationship fixture handling.The
upsertResourceRelationshipsFixturesmethod follows the established pattern of other fixture methods with proper:
- Error handling for missing fixtures
- Request body construction with workspace ID
- API endpoint usage
- Reference tracking with conditional target handling
- Consistent logging and result collection
708-715: LGTM: Proper cleanup implementation.The resource relationship cleanup follows the same pattern as other entity cleanups, using the appropriate DELETE endpoint and maintaining consistency with the existing cleanup logic.
e2e/api/entity-refs.ts (3)
67-79: LGTM: Well-defined interface for resource relationships.The
ResourceRelationshipRefinterface is properly structured with:
- Clear field definitions
- Appropriate optional target fields for flexibility
- Consistent typing with other reference interfaces
97-97: LGTM: Consistent array property addition.The
resourceRelationshipsarray property follows the established naming convention and pattern used by other entity types.
140-156: LGTM: Consistent method implementations.The resource relationship methods follow the established patterns:
takeResourceRelationshipsandoneResourceRelationshipuse the existingtakeRandomutilitygetResourceRelationshipByReferenceproperly usesexactlyOnefor exact matching- All methods maintain consistency with other entity type methods
e2e/api/schema.ts (3)
659-660: LGTM! DELETE operation addition follows established patterns.The DELETE operation for resource relationship rules is properly integrated into the paths interface with appropriate documentation and operation reference.
3913-3956: Well-structured operation definition with appropriate responses.The
deleteResourceRelationshipRuleoperation follows OpenAPI best practices with:
- Proper path parameter definition for
ruleId- Comprehensive response codes (200, 404, 500)
- Consistent error response structure
- Returns the deleted resource in the success response
1557-1557: Verify the schema change from enum to string type.The
ResourceRelationshipRuleDependencyTypehas been changed from a specific enum with defined string literals to a plainstringtype. This reduces type safety and compile-time validation.Please confirm this change aligns with the intended API design. If dynamic dependency types are needed, consider documenting the expected values or using a union type with an extensible pattern.
#!/bin/bash # Verify if this schema change is consistent across the codebase echo "Searching for ResourceRelationshipRuleDependencyType usage..." rg -A 3 -B 3 "ResourceRelationshipRuleDependencyType" echo -e "\nChecking for dependency type constants or enums..." rg -A 5 -B 5 "(depends_on|depends_indirectly_on|uses_at_runtime|created_after|provisioned_in|inherits_from)"e2e/tests/api/version-dependency.spec.ts (4)
69-73: Good refactoring to improve encapsulation.The function now internally derives the
deploymentIdfrom the builder's references, eliminating the need for callers to pass redundant information. This makes the API cleaner and reduces the chance of mismatched parameters.
113-117: Excellent enhancement to support multi-agent scenarios.The explicit
agentNameparameter enables testing with different agents, which is essential for the new external dependency test cases. The implementation correctly retrieves the agent and uses its ID.
176-179: Clear and explicit test assertions.The simplified flow with explicit assertions makes the test's expectations more obvious. Good practice to verify the release is defined after marking the job as successful.
249-249: Verify the expected status code for environment creation.This function expects status 200 for a POST request, while other creation endpoints expect 201. Please verify if this is intentional.
#!/bin/bash # Description: Check the OpenAPI spec for the expected status code for POST /v1/environments # Search for the environments endpoint definition in OpenAPI specs fd -e yaml -e yml -e json | xargs rg -A 10 "\/v1\/environments.*post" -i # Also check for any existing tests that create environments rg -A 5 "POST.*\/v1\/environments" --type ts
| "type": "string" | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the enum weakens validation – restore or document allowed values.
ResourceRelationshipRuleDependencyType is now a free-form string.
Previously enumerated values (“depends_on”, “requires”, …) provided compile-time validation to clients and server code-gen. Eliminating them:
- Allows invalid / miss-spelled values to slip through.
- Is a breaking change for generated SDKs that expect an enum.
Unless an open set of values is truly required, re-introduce the enum (or extend it) and update backend validation accordingly.
"ResourceRelationshipRuleDependencyType": {
"type": "string",
+ "enum": [
+ "depends_on",
+ "uses",
+ "owned_by"
+ ]
}If openness is required, add a description explaining expected semantics and a pattern so automated tooling still benefits from schema-level checks.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "type": "string" | |
| }, | |
| "ResourceRelationshipRuleDependencyType": { | |
| "type": "string", | |
| "enum": [ | |
| "depends_on", | |
| "uses", | |
| "owned_by" | |
| ] | |
| } |
🤖 Prompt for AI Agents
In openapi.v1.json around lines 6845 to 6846, the removal of the enum from
ResourceRelationshipRuleDependencyType weakens validation and breaks SDK
compatibility. To fix this, restore the enum with the previously defined allowed
values or extend it if needed, and update backend validation accordingly. If a
fully open string is required, add a descriptive explanation and a pattern
property to enforce schema-level validation for tooling support.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
Chores