Skip to content

E2E: Allow yaml-entity creation order to be explicit #576

Merged
jsbroks merged 9 commits intoctrlplanedev:mainfrom
wandb:j7m4/e2e-overhaul
May 29, 2025
Merged

E2E: Allow yaml-entity creation order to be explicit #576
jsbroks merged 9 commits intoctrlplanedev:mainfrom
wandb:j7m4/e2e-overhaul

Conversation

@j7m4
Copy link
Copy Markdown
Contributor

@j7m4 j7m4 commented May 27, 2025

In order to test different orderings of entity creation, the yaml-entity loader:

  • now requires a separate call for each type of entity created: createSystem, createResources, createDeployments, createDeploymentVariables, etc.
  • will be expanded to include many more creation options in the future.

Summary by CodeRabbit

  • Refactor

    • Introduced a new stepwise builder pattern for test entity setup with the EntitiesBuilder class.
    • Updated all test suites to use the builder for creating and managing test entities instead of the previous import function.
    • Enhanced test initialization and cleanup consistency.
    • Improved code readability with minor formatting adjustments.
  • Chores

    • Removed unused YAML keys and unnecessary imports in test specifications.
  • New Features

    • Added structured entity fixture definitions and validation for test data.
    • Provided a cleanup function to remove created test entities in a controlled order.
    • Added a new end-to-end test suite verifying deployment version creation via job agent queue.
  • Bug Fixes

    • Adjusted API schema types for improved consistency in request and response payloads.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 27, 2025

Walkthrough

The codebase refactors YAML entity import logic from a single asynchronous function into a modular EntitiesBuilder class, which manages stepwise creation of entities and maintains state throughout the process. All related end-to-end tests are updated to use this builder pattern for setup and teardown, replacing previous flat import approaches. Additionally, API schema types for policy approvals and deployment variable values were simplified from arrays to single objects or simpler arrays.

Changes

File(s) Change Summary
e2e/api/yaml-loader.ts Refactored import logic into EntitiesBuilder class; removed function; updated types and signatures.
e2e/api/entities-builder.ts Added new EntitiesBuilder class and EntitiesCache interface for modular entity creation and cleanup; includes stepwise async creation methods and cleanup function.
e2e/api/entity-fixtures.ts Added schemas and types for entity fixtures using zod; implemented YAML import with templating and validation.
e2e/api/index.ts Changed re-export from "./yaml-loader" to "./entities-builder".
e2e/api/schema.ts Simplified API schema types: changed some array properties to single objects and adjusted nested types for policy approvals and deployment variable values.
e2e/tests/api/deployment-remove-event.spec.ts
e2e/tests/api/deployment-variable.spec.ts
e2e/tests/api/deployment-version.spec.ts
e2e/tests/api/deployments.spec.ts
e2e/tests/api/environments.spec.ts
e2e/tests/api/job-agents.spec.ts
e2e/tests/api/release-targets.spec.ts
e2e/tests/api/release.spec.ts
e2e/tests/api/resource-grouping.spec.ts
e2e/tests/api/resource-relationships.spec.ts
e2e/tests/api/resource-variables.spec.ts
e2e/tests/api/resources.spec.ts
e2e/tests/api/yaml-import.spec.ts
e2e/tests/api/policies/matched-release-targets.spec.ts
Updated test setup and teardown to use EntitiesBuilder; replaced all references to old import function and types with builder.cache; minor formatting adjustments.
e2e/tests/api/resource-grouping.spec.yaml Removed empty top-level keys (environments, deployments, policies) from YAML file.
e2e/tests/api/resource-relationships.spec.yaml Added config: { enabled: true } to resource definitions.
e2e/tests/api/workspace.spec.ts Removed unused import and YAML path declaration.
e2e/tests/api/yaml-import.spec.yaml Changed versionAnyApprovals from a map to a single-item list containing a map.
e2e/tests/api/jobs/job-flow-1.spec.ts Added new test suite for Deployment Versions API using EntitiesBuilder for setup and cleanup.
e2e/tests/api/jobs/job-flow-entities.spec.yaml Added new YAML test spec defining system, resource, deployment, environment, and agent entities for job flow testing.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant EntitiesBuilder
    participant ApiClient
    participant WorkspaceFixture

    TestSuite->>EntitiesBuilder: new EntitiesBuilder(api, workspace, yamlPath)
    loop For each creation step
        TestSuite->>EntitiesBuilder: createSystem()/createResources()/createEnvironments()/...
        EntitiesBuilder->>ApiClient: POST entity creation request
        ApiClient-->>EntitiesBuilder: Entity created response
        EntitiesBuilder-->>EntitiesBuilder: Store created entity in cache
    end
    TestSuite->>EntitiesBuilder: Access builder.cache for entities
    TestSuite->>EntitiesBuilder: cleanupImportedEntities(api, builder.cache, workspaceId)
Loading

Possibly related PRs

  • ctrlplanedev/ctrlplane#571: Updates API schema for versionAnyApprovals from an array to a single object, consistent with the schema changes in this PR.

Poem

A builder now hops where imports once lay,
Stepwise it crafts, in a modular way.
Entities bloom from YAML with care,
Test rabbits rejoice—no more import despair!
With each method call, the test garden grows,
And cleanup is simple, as everybun knows.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fcc2dd5 and e5409ff.

📒 Files selected for processing (4)
  • e2e/api/entities-builder.ts (1 hunks)
  • e2e/api/entity-fixtures.ts (1 hunks)
  • e2e/tests/api/deployment-remove-event.spec.ts (5 hunks)
  • e2e/tests/api/jobs/job-flow-1.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • e2e/tests/api/deployment-remove-event.spec.ts
  • e2e/tests/api/jobs/job-flow-1.spec.ts
  • e2e/api/entity-fixtures.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • e2e/api/entities-builder.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
🔇 Additional comments (9)
e2e/api/entities-builder.ts (9)

8-63: Well-designed interface structure for entity caching.

The EntitiesCache interface provides comprehensive typing for tracking created entities with proper optional fields and nested structures. The design supports the incremental entity creation pattern effectively.


76-97: Constructor properly handles cache initialization and fixture loading.

The constructor correctly handles both new cache creation and existing cache reuse, with appropriate random prefix generation using faker for isolation between test runs.


99-123: System creation method follows proper API patterns.

The method correctly validates the 201 status code for resource creation and properly updates the cache with both API response data and original fixture names.


160-199: Environment creation with proper dependency validation.

The method correctly validates that the system exists before creating environments and handles the API responses appropriately. The TODO comment suggests future enhancement for resource selector updates.


201-231: Deployment creation follows consistent patterns.

The method properly validates status codes, updates cache with complete deployment structure including initialized arrays for versions and variables.


233-281: Deployment version creation with proper parent lookup.

The method correctly finds parent deployments in the cache and validates API responses. The status fallback to "ready" is a reasonable default.


334-363: Policy creation method is well-implemented.

The method follows the established pattern with proper workspace ID inclusion and appropriate status code validation.


365-393: Agent creation uses appropriate PATCH method.

The use of PATCH for agent creation and 200 status code validation is correct for an update/upsert operation pattern.


401-449: Cleanup function implements proper reverse deletion order.

The function correctly deletes entities in reverse dependency order (policies → deployments → environments → system → resources) to avoid constraint violations. Error logging for resource deletion failures is helpful for debugging.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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 for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
e2e/api/yaml-loader.ts (1)

244-246: Address the TODO comment for resource selector.

There's a TODO comment about updating the resource selector that should be addressed. If this functionality is needed, it should be implemented. Otherwise, consider removing the comment.

Would you like me to open an issue to track the implementation of resource selector updates for environments?

e2e/tests/api/deployment-variable.spec.ts (1)

207-207: Minor typo in test name.

There's a typo: "shoudl" should be "should". This appears to be pre-existing code not introduced by this PR.

-  test("shoudl fail if more than one default value is provided", async ({ api }) => {
+  test("should fail if more than one default value is provided", async ({ api }) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b28f702 and f27bd52.

📒 Files selected for processing (15)
  • e2e/api/yaml-loader.ts (11 hunks)
  • e2e/tests/api/deployment-remove-event.spec.ts (5 hunks)
  • e2e/tests/api/deployment-variable.spec.ts (4 hunks)
  • e2e/tests/api/deployment-version.spec.ts (10 hunks)
  • e2e/tests/api/deployments.spec.ts (15 hunks)
  • e2e/tests/api/environments.spec.ts (16 hunks)
  • e2e/tests/api/job-agents.spec.ts (2 hunks)
  • e2e/tests/api/release-targets.spec.ts (2 hunks)
  • e2e/tests/api/release.spec.ts (12 hunks)
  • e2e/tests/api/resource-grouping.spec.ts (1 hunks)
  • e2e/tests/api/resource-grouping.spec.yaml (0 hunks)
  • e2e/tests/api/resource-relationships.spec.ts (13 hunks)
  • e2e/tests/api/resource-variables.spec.ts (10 hunks)
  • e2e/tests/api/resources.spec.ts (10 hunks)
  • e2e/tests/api/yaml-import.spec.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • e2e/tests/api/resource-grouping.spec.yaml
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • e2e/tests/api/resources.spec.ts
  • e2e/tests/api/job-agents.spec.ts
  • e2e/tests/api/resource-grouping.spec.ts
  • e2e/tests/api/release-targets.spec.ts
  • e2e/tests/api/deployment-version.spec.ts
  • e2e/tests/api/yaml-import.spec.ts
  • e2e/tests/api/environments.spec.ts
  • e2e/tests/api/deployments.spec.ts
  • e2e/tests/api/deployment-variable.spec.ts
  • e2e/tests/api/resource-relationships.spec.ts
  • e2e/tests/api/deployment-remove-event.spec.ts
  • e2e/tests/api/release.spec.ts
  • e2e/tests/api/resource-variables.spec.ts
  • e2e/api/yaml-loader.ts
🧬 Code Graph Analysis (6)
e2e/tests/api/resource-grouping.spec.ts (2)
e2e/tests/fixtures.ts (1)
  • test (11-26)
e2e/api/yaml-loader.ts (1)
  • EntitiesBuilder (128-435)
e2e/tests/api/environments.spec.ts (5)
e2e/tests/fixtures.ts (1)
  • test (11-26)
e2e/api/yaml-loader.ts (2)
  • EntitiesBuilder (128-435)
  • cleanupImportedEntities (442-490)
packages/db/src/schema/workspace.ts (1)
  • workspace (18-27)
packages/db/src/schema/environment.ts (1)
  • environment (59-84)
packages/db/src/schema/release.ts (1)
  • releaseTarget (20-42)
e2e/tests/api/resource-relationships.spec.ts (3)
e2e/tests/fixtures.ts (1)
  • test (11-26)
e2e/api/yaml-loader.ts (2)
  • EntitiesBuilder (128-435)
  • cleanupImportedEntities (442-490)
packages/db/src/schema/workspace.ts (1)
  • workspace (18-27)
e2e/tests/api/deployment-remove-event.spec.ts (1)
e2e/api/yaml-loader.ts (2)
  • EntitiesBuilder (128-435)
  • cleanupImportedEntities (442-490)
e2e/tests/api/resource-variables.spec.ts (3)
e2e/tests/fixtures.ts (1)
  • test (11-26)
e2e/api/yaml-loader.ts (2)
  • EntitiesBuilder (128-435)
  • cleanupImportedEntities (442-490)
packages/db/src/schema/workspace.ts (1)
  • workspace (18-27)
e2e/api/yaml-loader.ts (2)
e2e/api/index.ts (1)
  • ApiClient (23-23)
e2e/tests/auth.setup.ts (1)
  • WorkspaceFixture (15-20)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
🔇 Additional comments (35)
e2e/api/yaml-loader.ts (4)

50-50: LGTM! Good addition of valueType field.

The addition of the optional valueType field to support "direct" or "reference" values provides better type safety and clarity for deployment variable values.

Also applies to: 114-114


128-168: Well-designed class structure for explicit entity creation order.

The EntitiesBuilder class effectively addresses the PR objective by providing explicit control over entity creation order through separate methods. The constructor properly handles both new and existing entity scenarios, and the use of readonly properties ensures immutability of core data.


235-239: Excellent defensive programming with clear error messages.

The validation check for system ID before creating environments prevents runtime errors and provides clear guidance to users about the required creation order.


212-218:

Details

✅ Verification successful

Verify the expected status code for resource creation.

The status check expects 200 for resource creation, while other entity creations like system (line 181) and deployments (line 282) expect 201. Please verify this is correct according to your API specification.


🏁 Script executed:

#!/bin/bash
# Search for other POST requests to /v1/resources to verify expected status codes
rg -A 5 'POST.*"/v1/resources".*response\.status' --type ts

Length of output: 61


To locate all usages and verify the expected status code, let’s search for every reference to /v1/resources and how resourceResponse is handled:


🏁 Script executed:

#!/bin/bash
# Locate any endpoint definitions or calls for /v1/resources
rg -n '/v1/resources' --type ts

# Find where resourceResponse is used to inspect status checks
rg -n 'resourceResponse' --type ts

# Find any .post(...) invocations related to resources
rg -n '\.post.*resources' --type ts

Length of output: 12001


Let’s inspect all POST calls and their corresponding status checks in e2e/api/yaml-loader.ts to confirm which endpoints expect 200 vs. 201:

#!/bin/bash
# Show POST calls with a few lines of context to capture status checks
rg -n 'this\.api\.POST' -A4 e2e/api/yaml-loader.ts

Resource creation endpoint correctly returns 200

Verified that all existing end-to-end tests for POST /v1/resources assert a 200 status (e.g. e2e/tests/api/resources.spec.ts:299). The YAML loader’s check for status !== 200 aligns with the API’s behavior—no change needed.

e2e/tests/api/job-agents.spec.ts (1)

11-22: Proper implementation of the EntitiesBuilder pattern.

The test setup correctly uses the new EntitiesBuilder class with appropriate entity creation order (system → environments → deployments) and includes proper cleanup. This is a good example of the refactored pattern.

e2e/tests/api/release-targets.spec.ts (2)

4-22: LGTM! Clean refactor to builder pattern.

The migration from importEntitiesFromYaml to EntitiesBuilder is well-executed. The explicit stepwise creation methods (createSystem(), createResources(), createEnvironments(), createDeployments()) provide the desired control over entity creation order as outlined in the PR objectives.


24-73: Entity access properly updated to use builder pattern.

All references to entities have been correctly updated to use builder.result instead of the previous importedEntities approach. The test logic remains unchanged while benefiting from the improved entity management.

e2e/tests/api/deployment-version.spec.ts (2)

5-21: Excellent refactor with consistent builder pattern implementation.

The explicit creation sequence (createSystem()createDeployments()) allows for testing different entity creation orders. The refactor maintains test functionality while improving organization.


137-139: Good formatting improvement for error handling.

Adding braces around single-line conditional throws improves code consistency and readability.

Also applies to: 180-182, 221-223

e2e/tests/api/deployments.spec.ts (2)

5-22: Comprehensive refactor demonstrates creation order flexibility.

The explicit sequence (createSystem()createEnvironments()createResources()) shows how the builder pattern enables different entity creation orders, fulfilling the PR's goal of explicit control over E2E test setup.


24-531: All entity references properly migrated to builder pattern.

The systematic update of all importedEntities references to builder.result is thorough and maintains test functionality. The formatting improvements with braces enhance code consistency.

e2e/tests/api/resources.spec.ts (3)

5-22: Consistent builder pattern completes comprehensive refactor.

The creation sequence (createSystem()createEnvironments()createDeployments()) maintains consistency with the other test files while providing the flexibility to test different entity creation orders.


284-286: Nice formatting improvement for multiline string interpolation.

The formatting of the multiline string interpolation improves readability.


24-419: Entity management thoroughly migrated to builder pattern.

All entity references have been systematically updated to use builder.result, maintaining test functionality while benefiting from the improved entity management approach.

e2e/tests/api/resource-relationships.spec.ts (2)

5-5: Excellent refactoring to the new EntitiesBuilder pattern!

The migration from importEntitiesFromYaml to EntitiesBuilder is well-executed and provides explicit control over entity creation order as intended. The setup now clearly separates system and resource creation steps.

Also applies to: 11-11, 14-16, 20-20


24-27: Consistent entity access pattern updates.

All references to importedEntities.prefix have been properly updated to builder.result.prefix. The variable naming and logic remain clear and functional.

Also applies to: 37-40, 59-59, 72-72

e2e/tests/api/release.spec.ts (2)

5-5: Consistent EntitiesBuilder implementation.

The refactoring follows the same systematic pattern with proper setup of system, resources, and environments. The explicit creation order provides better control over test entity dependencies.

Also applies to: 11-11, 14-17, 22-22


26-26: Proper entity access pattern migration.

All references to the created entities have been correctly updated to use builder.result, maintaining the same test logic while using the new infrastructure.

Also applies to: 32-32, 48-48

e2e/tests/api/deployment-variable.spec.ts (2)

5-5: Well-executed EntitiesBuilder integration.

The refactoring to use EntitiesBuilder with explicit createSystem() and createDeployments() calls provides clear control over the test setup process.

Also applies to: 11-11, 14-16, 21-21


126-131: Improved formatting for variable value extraction.

The reformatting of the ternary operators for variable value extraction improves readability while maintaining the same logic. The conditional handling of valueType === "direct" is preserved correctly.

Also applies to: 191-196, 200-202

e2e/tests/api/deployment-remove-event.spec.ts (2)

5-5: Appropriate selective use of EntitiesBuilder.

The implementation correctly uses only createSystem() since this test suite only requires system entities. This demonstrates the flexibility and efficiency of the new approach.

Also applies to: 11-11, 14-15, 19-19


23-23: Consistent system entity access updates.

All references to the system entity have been properly updated from importedEntities.system to builder.result.system. The system access pattern is consistent across all test cases.

Also applies to: 105-105, 189-189, 274-274, 356-356

e2e/tests/api/environments.spec.ts (4)

5-5: LGTM! Import statement correctly updated for new EntitiesBuilder pattern.

The import has been properly updated to include both EntitiesBuilder and cleanupImportedEntities from the refactored API.


11-22: Excellent refactoring to EntitiesBuilder pattern.

The migration from importEntitiesFromYaml to the explicit EntitiesBuilder approach is well-executed:

  • Proper instantiation of EntitiesBuilder with required parameters
  • Explicit creation methods called in logical order: createSystem()createResources()createDeployments()
  • Cleanup properly updated to use builder.result

This aligns perfectly with the PR objective of providing explicit control over entity creation order.


29-29: Entity references correctly updated to use builder pattern.

All references to system entities have been properly migrated from the old imported entities to builder.result.system, maintaining the same functionality while using the new API.

Also applies to: 39-39, 43-43


378-385: Improved code formatting with proper brace usage.

The formatting has been improved by adding braces around the single-line if statement, which enhances code readability and follows JavaScript best practices.

e2e/tests/api/yaml-import.spec.ts (4)

6-6: Import correctly updated for EntitiesBuilder pattern.

The import statement has been properly updated to include EntitiesBuilder alongside the existing cleanupImportedEntities function.


13-26: Comprehensive and well-structured entity creation process.

This represents the most complete usage of the EntitiesBuilder pattern in the codebase:

  • Creates all entity types: system, resources, environments, deployments, deployment variables, and policies
  • Follows logical creation order with proper dependencies
  • Includes appropriate timing delay for resource processing
  • Demonstrates the full capabilities of the new explicit creation approach

This perfectly showcases the PR's objective of providing granular control over entity creation order.


30-32: Good defensive programming with conditional cleanup check.

The addition of the conditional check if (builder.result) before cleanup is a good defensive programming practice, ensuring cleanup only occurs when entities were successfully created.


38-38: All entity references properly migrated to builder pattern.

All references to imported entities have been consistently updated to use builder.result, maintaining the same test logic while leveraging the new EntitiesBuilder API.

Also applies to: 71-71, 74-74, 90-90, 92-92

e2e/tests/api/resource-variables.spec.ts (5)

5-5: Import statement correctly updated.

The import has been properly updated to include both EntitiesBuilder and cleanupImportedEntities from the refactored API.


14-18: Thoughtful selective entity creation for test requirements.

The builder appropriately creates only the necessary baseline entities (createSystem(), createEnvironments(), createDeployments()) while intentionally omitting createResources(). This is well-suited for this test suite since it creates resources dynamically within individual tests, demonstrating flexible usage of the EntitiesBuilder pattern.


21-21: Cleanup properly updated to use builder result.

The cleanup logic has been correctly migrated to use builder.result with the cleanupImportedEntities function.


25-25: Consistent entity reference updates across all test functions.

All references to system entities have been systematically updated from the old imported entities to builder.result.system, maintaining consistent access patterns throughout the test suite.

Also applies to: 80-80, 138-138, 168-170, 261-263, 412-414, 586-588


320-320: Deployment references correctly updated.

References to deployment entities have been properly migrated to use builder.result.deployments[0], maintaining the same test logic while using the new builder pattern.

Also applies to: 474-474, 647-647

Comment on lines 9 to 16
test.describe("Resource Provider API", () => {
let importedEntities: ImportedEntities;
let builder: EntitiesBuilder;
test.beforeAll(async ({ api, workspace }) => {
importedEntities = await importEntitiesFromYaml(
api,
workspace.id,
yamlPath,
);
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding cleanup to prevent test data accumulation.

This test suite creates entities but doesn't clean them up in an afterAll hook, unlike other test files in this PR. This could lead to test data accumulation.

Add cleanup after the tests:

 test.describe("Resource Provider API", () => {
   let builder: EntitiesBuilder;
   test.beforeAll(async ({ api, workspace }) => {
     builder = new EntitiesBuilder(api, workspace, yamlPath);
     await builder.createSystem();
     await builder.createResources();
   });
+
+  test.afterAll(async ({ api, workspace }) => {
+    await cleanupImportedEntities(api, builder.result, workspace.id);
+  });

Don't forget to import cleanupImportedEntities:

-import { EntitiesBuilder } from "../../api";
+import { cleanupImportedEntities, EntitiesBuilder } from "../../api";
📝 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.

Suggested change
test.describe("Resource Provider API", () => {
let importedEntities: ImportedEntities;
let builder: EntitiesBuilder;
test.beforeAll(async ({ api, workspace }) => {
importedEntities = await importEntitiesFromYaml(
api,
workspace.id,
yamlPath,
);
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
});
// Update import to include the cleanup helper
-import { EntitiesBuilder } from "../../api";
+import { cleanupImportedEntities, EntitiesBuilder } from "../../api";
test.describe("Resource Provider API", () => {
let builder: EntitiesBuilder;
test.beforeAll(async ({ api, workspace }) => {
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
});
+ // Ensure we clean up created entities after all tests run
+ test.afterAll(async ({ api, workspace }) => {
+ await cleanupImportedEntities(api, builder.result, workspace.id);
+ });
🤖 Prompt for AI Agents
In e2e/tests/api/resource-grouping.spec.ts around lines 9 to 16, the test suite
creates entities but lacks an afterAll hook to clean them up, which can cause
test data accumulation. Add an afterAll hook that calls cleanupImportedEntities
to remove the created entities after tests complete. Also, ensure you import
cleanupImportedEntities at the top of the file to enable this cleanup
functionality.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
e2e/api/yaml-loader.ts (2)

195-228: Consider making error handling more consistent.

The method checks for both existence and length of resources array, but some other methods only check for existence. Consider standardizing this pattern across all creation methods.

-    if (!this.data.resources || this.data.resources.length === 0) {
+    if (!this.data.resources?.length) {

This approach is more concise and handles both null/undefined and empty array cases consistently.


244-245: TODO comment indicates incomplete feature.

The commented code suggests that resource selector handling is planned but not yet implemented. Consider tracking this as a separate task.

Would you like me to create an issue to track the resource selector implementation for environments?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f27bd52 and 69309c7.

📒 Files selected for processing (13)
  • e2e/api/yaml-loader.ts (11 hunks)
  • e2e/tests/api/deployment-remove-event.spec.ts (5 hunks)
  • e2e/tests/api/deployment-variable.spec.ts (4 hunks)
  • e2e/tests/api/deployment-version.spec.ts (11 hunks)
  • e2e/tests/api/deployments.spec.ts (17 hunks)
  • e2e/tests/api/environments.spec.ts (18 hunks)
  • e2e/tests/api/job-agents.spec.ts (2 hunks)
  • e2e/tests/api/release-targets.spec.ts (3 hunks)
  • e2e/tests/api/release.spec.ts (11 hunks)
  • e2e/tests/api/resource-relationships.spec.ts (13 hunks)
  • e2e/tests/api/resource-variables.spec.ts (10 hunks)
  • e2e/tests/api/resources.spec.ts (10 hunks)
  • e2e/tests/api/yaml-import.spec.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (12)
  • e2e/tests/api/job-agents.spec.ts
  • e2e/tests/api/resource-variables.spec.ts
  • e2e/tests/api/release.spec.ts
  • e2e/tests/api/deployment-remove-event.spec.ts
  • e2e/tests/api/deployment-variable.spec.ts
  • e2e/tests/api/yaml-import.spec.ts
  • e2e/tests/api/deployments.spec.ts
  • e2e/tests/api/environments.spec.ts
  • e2e/tests/api/deployment-version.spec.ts
  • e2e/tests/api/release-targets.spec.ts
  • e2e/tests/api/resource-relationships.spec.ts
  • e2e/tests/api/resources.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • e2e/api/yaml-loader.ts
🔇 Additional comments (7)
e2e/api/yaml-loader.ts (7)

50-50: LGTM: Added optional valueType field for better type safety.

The addition of the optional valueType field to both interfaces enhances type safety and aligns with the modular entity creation approach.

Also applies to: 114-114


128-167: Well-structured constructor with proper initialization.

The constructor properly handles file loading, templating with Handlebars, and initialization logic. The path resolution for both absolute and relative paths is handled correctly.


169-193: System creation method looks solid.

The method properly validates the API response status (201) and updates the result object with the created system data including the original name for tracking.


235-239: Excellent dependency validation.

The check for system ID before creating environments is a good defensive programming practice that ensures proper creation order dependencies.


312-317: Good defensive programming for deployment lookups.

The methods properly validate that deployments exist in the result before adding versions/variables, preventing runtime errors.

Also applies to: 362-367


438-441: Updated function signature maintains backward compatibility.

The cleanup function signature correctly uses the new TestEntities type, maintaining consistency with the refactored builder pattern.


212-218:

Details

❓ Verification inconclusive

Inconsistent HTTP status code expectations.

The creation methods expect different status codes for success:

  • System: 201
  • Resources: 200
  • Environments: 200
  • Deployments: 201
  • Deployment versions: 201
  • Deployment variables: 201
  • Policies: 200

Please verify that these status code expectations align with your API design. If they should be consistent, consider standardizing them.

Also applies to: 254-258, 282-288, 330-336, 380-386, 418-422


🏁 Script executed:

#!/bin/bash
# Search for API endpoint definitions to verify expected status codes
rg -A 5 "POST.*/(systems|resources|environments|deployments|policies)" --type ts

Length of output: 45314


🏁 Script executed:

#!/bin/bash
# Extract status checks for each POST in yaml-loader.ts
rg -n -C3 "systemResponse\.response\.status" -C3 e2e/api/yaml-loader.ts
rg -n -C3 "resourceResponse\.response\.status" -C3 e2e/api/yaml-loader.ts
rg -n -C3 "envResponse\.response\.status" -C3 e2e/api/yaml-loader.ts
rg -n -C3 "deploymentResponse\.response\.status" -C3 e2e/api/yaml-loader.ts
rg -n -C3 "variableResponse\.response\.status" -C3 e2e/api/yaml-loader.ts
rg -n -C3 "policyResponse\.response\.status" -C3 e2e/api/yaml-loader.ts

Length of output: 1786


Standardize Create Endpoint Status Codes

We’ve confirmed the following expectations in e2e/api/yaml-loader.ts:

  • POST /v1/systems → expects 201 (line 181)
  • POST /v1/resources → expects 200 (line 212)
  • POST /v1/environments → expects 200 (line 254)
  • POST /v1/deployments → expects 201 (line 282)
  • POST /v1/deployments/{id}/variables → expects 201 (line 380)
  • POST /v1/policies → expects 200 (line 418)

Please verify these align with your API specification. If all “create” calls should return the same status (e.g., 201), consider updating the 200 checks to 201 for consistency.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
e2e/tests/api/policies/matched-release-targets.spec.ts (1)

452-452: ⚠️ Potential issue

Fix remaining references to undefined importedEntities variable.

Multiple lines still reference the old importedEntities variable which is no longer defined after the migration to EntitiesBuilder. These will cause runtime errors.

All references to importedEntities should be updated to use builder.cache:

-    const systemPrefix = importedEntities.system.slug.split("-")[0]!;
+    const systemPrefix = builder.cache.system.slug.split("-")[0]!;

-        systemId: importedEntities.system.id,
+        systemId: builder.cache.system.id,

These changes need to be applied to lines: 452, 510, 586, 593, 664, 747, 853, 936, 1042, 1125, 1231, and 1359.

Also applies to: 510-510, 586-586, 593-593, 664-664, 747-747, 853-853, 936-936, 1042-1042, 1125-1125, 1231-1231, 1359-1359

🧹 Nitpick comments (2)
e2e/api/entities-builder.ts (2)

172-174: Address TODO for resource selector updates.

There's an unimplemented TODO for updating resource selectors. This might be important for proper environment configuration.

Would you like me to help implement the resource selector update logic or create an issue to track this task?


366-414: Well-structured cleanup function with proper deletion order.

The function correctly deletes entities in reverse dependency order and handles errors appropriately. Good use of optional chaining for defensive programming.

Consider making the error handling consistent by either throwing or logging for all deletion failures:

     if (response.response.status !== 200) {
-      console.error(
+      throw new Error(
         `Failed to delete resource: ${JSON.stringify(response.error)}`,
       );
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 69309c7 and 66e82f0.

📒 Files selected for processing (20)
  • e2e/api/entities-builder.ts (1 hunks)
  • e2e/api/entity-fixtures.ts (1 hunks)
  • e2e/api/index.ts (1 hunks)
  • e2e/api/schema.ts (3 hunks)
  • e2e/tests/api/deployment-remove-event.spec.ts (5 hunks)
  • e2e/tests/api/deployment-variable.spec.ts (4 hunks)
  • e2e/tests/api/deployment-version.spec.ts (11 hunks)
  • e2e/tests/api/deployments.spec.ts (17 hunks)
  • e2e/tests/api/environments.spec.ts (17 hunks)
  • e2e/tests/api/job-agents.spec.ts (2 hunks)
  • e2e/tests/api/policies/matched-release-targets.spec.ts (7 hunks)
  • e2e/tests/api/release-targets.spec.ts (3 hunks)
  • e2e/tests/api/release.spec.ts (11 hunks)
  • e2e/tests/api/resource-relationships.spec.ts (13 hunks)
  • e2e/tests/api/resource-relationships.spec.yaml (3 hunks)
  • e2e/tests/api/resource-variables.spec.ts (10 hunks)
  • e2e/tests/api/resources.spec.ts (10 hunks)
  • e2e/tests/api/workspace.spec.ts (0 hunks)
  • e2e/tests/api/yaml-import.spec.ts (3 hunks)
  • e2e/tests/api/yaml-import.spec.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • e2e/tests/api/workspace.spec.ts
✅ Files skipped from review due to trivial changes (3)
  • e2e/api/index.ts
  • e2e/tests/api/resource-relationships.spec.yaml
  • e2e/tests/api/job-agents.spec.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • e2e/tests/api/release.spec.ts
  • e2e/tests/api/yaml-import.spec.ts
  • e2e/tests/api/deployment-version.spec.ts
  • e2e/tests/api/release-targets.spec.ts
  • e2e/tests/api/resources.spec.ts
  • e2e/tests/api/resource-relationships.spec.ts
  • e2e/tests/api/deployment-remove-event.spec.ts
  • e2e/tests/api/deployment-variable.spec.ts
  • e2e/tests/api/deployments.spec.ts
  • e2e/tests/api/environments.spec.ts
  • e2e/tests/api/resource-variables.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • e2e/tests/api/policies/matched-release-targets.spec.ts
  • e2e/api/entities-builder.ts
  • e2e/api/entity-fixtures.ts
  • e2e/api/schema.ts
🧬 Code Graph Analysis (1)
e2e/tests/api/policies/matched-release-targets.spec.ts (1)
e2e/api/entities-builder.ts (2)
  • EntitiesBuilder (61-359)
  • cleanupImportedEntities (366-414)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint
🔇 Additional comments (6)
e2e/api/entity-fixtures.ts (1)

1-130: Excellent implementation of entity fixture schemas and import functionality.

This new module provides a robust foundation for entity fixture handling with:

  • Comprehensive type-safe schemas using zod
  • Proper path resolution for both absolute and relative paths
  • Handlebars templating support with prefix parameter
  • Good error handling using safeParse with descriptive error messages
  • Clean separation of concerns between schema definition and import logic
e2e/tests/api/yaml-import.spec.yaml (1)

111-113: YAML structure change aligns with schema requirements.

The modification of versionAnyApprovals from a single object to an array containing one object is consistent with the PolicyFixture schema in entity-fixtures.ts, which defines this field as z.array(...). This change properly supports multiple approval configurations.

e2e/api/schema.ts (2)

1-4: Auto-generated file changes look appropriate.

These schema modifications align with the PR's goal of modularizing entity creation. The simplification from arrays to single objects suggests a more streamlined API contract.


1307-1307:

Details

✅ Verification successful

Verify API contract changes are intentional.

The schema changes from arrays to single objects/simplified arrays should be validated against the source OpenAPI specification to ensure they're intentional and won't break existing integrations.

Run the following script to check if these schema changes are reflected in the OpenAPI spec file:

Also applies to: 1996-1996, 2724-2724, 2726-2726


🏁 Script executed:

#!/bin/bash
# Description: Look for OpenAPI spec files and check for the schema definitions

# Find OpenAPI spec files
fd -e yaml -e yml -e json openapi api swagger spec | head -10

# Search for policy and deployment variable schema definitions
rg -A 10 "versionAnyApprovals|createDeploymentVariable" --type yaml --type json

Length of output: 2655


🏁 Script executed:

#!/bin/bash
python3 << 'EOF'
import json
from collections import Counter

# Load the OpenAPI spec
with open("openapi.v1.json") as f:
    spec = json.load(f)

# Print the component schema for VersionAnyApproval
comp = spec.get("components", {}).get("schemas", {}).get("VersionAnyApproval")
print("\ncomponents/schemas/VersionAnyApproval:")
print(json.dumps(comp, indent=2))

# Traverse the spec to count occurrences of versionAnyApprovals
counts = Counter()
locations = []
def traverse(obj, path):
    if isinstance(obj, dict):
        for k, v in obj.items():
            if k == "versionAnyApprovals":
                if isinstance(v, dict) and v.get("type") == "array":
                    counts["array"] += 1
                elif isinstance(v, dict) and v.get("$ref"):
                    counts["ref"] += 1
                else:
                    counts["other"] += 1
                locations.append((path + [k], v))
            traverse(v, path + [k])
    elif isinstance(obj, list):
        for idx, item in enumerate(obj):
            traverse(item, path + [str(idx)])

traverse(spec, [])
print("\nOccurrence counts for 'versionAnyApprovals':")
for key, cnt in counts.items():
    print(f"  {key}: {cnt}")

print("\nDetailed locations for each occurrence:")
for loc, v in locations:
    print("  Path:", "/".join(loc), "Definition:", "array" if v.get("type")=="array" else ("$ref" if v.get("$ref") else "other"))
EOF

Length of output: 657


API component schema matches the OpenAPI spec

I’ve verified that components.schemas.VersionAnyApproval is defined as an object (with a single required requiredApprovalsCount property) in openapi.v1.json, and that the two $ref usages of versionAnyApprovals in the components match this. The lone inline array definition appears only in the PATCH request body (not in the shared schema), so the change in e2e/api/schema.ts to use the object type is intentional and correct—there is no breaking change to the component schema.

No action required.

e2e/api/entities-builder.ts (2)

8-59: Well-structured cache interface.

The EntitiesCache interface provides a clear and comprehensive structure for tracking created entities with appropriate type definitions and optional properties.


72-92: Good constructor implementation with cache reuse support.

The constructor properly handles both new entity creation and building from existing cache, which supports the PR's goal of allowing explicit control over entity creation order.

Comment on lines +17 to +20
builder.createSystem();
builder.createResources();
builder.createEnvironments();
builder.createDeployments();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing await keywords for async method calls.

The entity creation methods are async but not being awaited, which will cause the entities to not be fully created before the tests run.

Apply this diff to fix the async calls:

-    builder.createSystem();
-    builder.createResources();
-    builder.createEnvironments();
-    builder.createDeployments();
+    await builder.createSystem();
+    await builder.createResources();
+    await builder.createEnvironments();
+    await builder.createDeployments();
📝 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.

Suggested change
builder.createSystem();
builder.createResources();
builder.createEnvironments();
builder.createDeployments();
await builder.createSystem();
await builder.createResources();
await builder.createEnvironments();
await builder.createDeployments();
🤖 Prompt for AI Agents
In e2e/tests/api/policies/matched-release-targets.spec.ts around lines 17 to 20,
the async methods builder.createSystem(), builder.createResources(),
builder.createEnvironments(), and builder.createDeployments() are called without
await, causing potential race conditions. Fix this by adding the await keyword
before each of these method calls to ensure they complete before proceeding with
the tests.

body: {
...resource,
workspaceId,
config: resource.config as Record<string, never>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect type casting for resource config.

The type cast as Record<string, never> represents an empty object type that cannot have any properties. This seems incorrect for a config object that likely contains configuration data.

Consider using a more appropriate type:

-          config: resource.config as Record<string, never>,
+          config: resource.config as Record<string, unknown>,
📝 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.

Suggested change
config: resource.config as Record<string, never>,
config: resource.config as Record<string, unknown>,
🤖 Prompt for AI Agents
In e2e/api/entities-builder.ts at line 133, the type cast 'as Record<string,
never>' is incorrect because it represents an empty object type, which is
unsuitable for a config object that should contain configuration data. Replace
this with a more appropriate type such as 'Record<string, any>' or a specific
interface/type that accurately reflects the structure of the config object to
ensure proper typing and avoid runtime issues.

},
);

if (variableResponse.response.status !== 201) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect status code check for deployment variable creation.

According to the OpenAPI schema, the createDeploymentVariable operation returns status 200 on success, not 201.

Update the status code check:

-          if (variableResponse.response.status !== 201) {
+          if (variableResponse.response.status !== 200) {
📝 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.

Suggested change
if (variableResponse.response.status !== 201) {
if (variableResponse.response.status !== 200) {
🤖 Prompt for AI Agents
In e2e/api/entities-builder.ts at line 308, the status code check for the
createDeploymentVariable response incorrectly expects 201, but the OpenAPI
schema specifies 200 on success. Change the condition to check if
variableResponse.response.status is not equal to 200 instead of 201 to correctly
handle success responses.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66e82f0 and fcc2dd5.

📒 Files selected for processing (5)
  • e2e/api/entities-builder.ts (1 hunks)
  • e2e/api/entity-fixtures.ts (1 hunks)
  • e2e/tests/api/deployment-remove-event.spec.ts (5 hunks)
  • e2e/tests/api/jobs/job-flow-1.spec.ts (1 hunks)
  • e2e/tests/api/jobs/job-flow-entities.spec.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • e2e/tests/api/jobs/job-flow-entities.spec.yaml
🚧 Files skipped from review as they are similar to previous changes (3)
  • e2e/tests/api/deployment-remove-event.spec.ts
  • e2e/api/entities-builder.ts
  • e2e/api/entity-fixtures.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • e2e/tests/api/jobs/job-flow-1.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint
🔇 Additional comments (2)
e2e/tests/api/jobs/job-flow-1.spec.ts (2)

1-8: LGTM! Clean imports and path setup.

The imports correctly use the new EntitiesBuilder pattern and the path setup follows standard practices.


23-25: LGTM! Proper cleanup implementation.

The cleanup using the builder's cache and workspace ID follows the new pattern correctly.

Comment on lines +12 to +21
test.beforeAll(async ({ api, workspace }) => {
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
await builder.createEnvironments();
await builder.createDeployments();
await builder.createAgents();
await builder.createDeploymentVersions();
await new Promise((resolve) => setTimeout(resolve, 5000));
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider replacing hardcoded delay with proper readiness checks.

The explicit entity creation order aligns well with the PR objectives. However, the hardcoded 5-second delay could lead to flaky tests.

Consider replacing the arbitrary timeout with proper readiness checks:

-    await new Promise((resolve) => setTimeout(resolve, 5000));
+    // Wait for entities to be properly initialized
+    await builder.waitForReadiness();

Alternatively, implement polling for specific conditions rather than a fixed delay.

📝 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.

Suggested change
test.beforeAll(async ({ api, workspace }) => {
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
await builder.createEnvironments();
await builder.createDeployments();
await builder.createAgents();
await builder.createDeploymentVersions();
await new Promise((resolve) => setTimeout(resolve, 5000));
});
test.beforeAll(async ({ api, workspace }) => {
builder = new EntitiesBuilder(api, workspace, yamlPath);
await builder.createSystem();
await builder.createResources();
await builder.createEnvironments();
await builder.createDeployments();
await builder.createAgents();
await builder.createDeploymentVersions();
// Wait for entities to be properly initialized
await builder.waitForReadiness();
});
🤖 Prompt for AI Agents
In e2e/tests/api/jobs/job-flow-1.spec.ts around lines 12 to 21, replace the
hardcoded 5-second delay after entity creation with a readiness check or polling
mechanism. Instead of waiting a fixed time, implement logic to verify that the
created entities or system components are fully ready or available before
proceeding, such as checking API responses or status flags in a loop with a
timeout. This will make the tests more reliable and reduce flakiness.

@j7m4 j7m4 closed this May 29, 2025
@j7m4 j7m4 deleted the j7m4/e2e-overhaul branch May 29, 2025 03:18
@j7m4 j7m4 restored the j7m4/e2e-overhaul branch May 29, 2025 14:12
@j7m4 j7m4 reopened this May 29, 2025
@jsbroks jsbroks merged commit deac9ae into ctrlplanedev:main May 29, 2025
5 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