Skip to content
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

Property schema edge case tests+fixes #370

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Southclaws
Copy link
Owner

No description provided.

Copy link

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
storyden ⬜️ Ignored (Inspect) Visit Preview Mar 11, 2025 10:20pm
storyden-homepage ⬜️ Ignored (Inspect) Visit Preview Mar 11, 2025 10:20pm

Copy link

coderabbitai bot commented Mar 11, 2025

📝 Walkthrough

Walkthrough

This pull request includes multiple updates to improve schema update and node property handling. The changes refine query construction in schema updates, enhance error wrapping for constraint violations, and update the handling of the ParentNodeID field by switching from value to pointer types. Additionally, the HTTP serialization logic is modified, and new tests have been introduced to validate property schema updates. These modifications ensure that nil values are correctly handled and that updates to node properties are more robust.

Changes

File(s) Change Summary
app/resources/.../node_properties/writer.go
app/transports/.../bindings/nodes.go
In writer.go, updated UpdateSiblings to use a dynamic predicate array and enhanced error wrapping in doSchemaUpdates. In nodes.go, replaced the serialization call to output a revised property schema list.
internal/ent/mutation.go
internal/ent/node.go
internal/ent/node_create.go
internal/ent/node_query.go
internal/ent/schema/node.go
Changed handling of the ParentNodeID field from a value to a pointer across multiple modules. Updates include modifications in method return types, scan/assign logic, nil checks, and field schema definition to allow nil values.
tests/library/properties/property_schema_test.go Added two new tests to verify property schema updates for root-level nodes and to enforce proper handling of various invalid states.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SchemaWriter
    participant Database

    Client->>SchemaWriter: Request schema update
    SchemaWriter->>SchemaWriter: Build dynamic predicate array
    SchemaWriter->>Database: Execute update query with predicates
    Database-->>SchemaWriter: Return result or error
    alt Constraint Error
        SchemaWriter->>SchemaWriter: Wrap error with fault tag
    end
    SchemaWriter-->>Client: Return update response
Loading
sequenceDiagram
    participant HTTPClient
    participant NodesHandler
    participant SchemaService

    HTTPClient->>NodesHandler: NodeUpdatePropertySchema request
    NodesHandler->>SchemaService: Process property schema update
    SchemaService-->>NodesHandler: Return updated schema list
    NodesHandler-->>HTTPClient: Respond with serialized schema list
Loading

Possibly related PRs

  • Node properties #364: Modifies aspects of the SchemaWriter, specifically related to the MapNode function and the introduction of a new SchemaWriter, which is directly connected to the updates in query construction and error handling.

Poem

Hop along the code trail in delight,
I’m a rabbit celebrating changes bright.
Parent pointers now softly point with care,
Schema errors wrapped with a thoughtful stare.
With tests that pat and ensure no plight,
This bunny hops on, coding through the night!

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

also fix ent schema not having parent node ID as nullable
@Southclaws Southclaws force-pushed the property-schema-edge-case-tests branch from e79a9f9 to 383b57c Compare March 11, 2025 22:19
Copy link

@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)
internal/ent/node.go (2)

300-304: Consider resetting the pointer to nil in the else branch.

When value.Valid is false, the code currently leaves ParentNodeID untouched if it was previously non-nil. Consider explicitly setting n.ParentNodeID = nil to avoid stale values in re-used structs.


474-477: Provide a placeholder or explanatory text when ParentNodeID is nil.

Currently, the parent_node_id is simply omitted from the output if it's nil. You could add a lightweight placeholder for clarity when the ID is undefined, though this is purely cosmetic.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e79a9f9 and 383b57c.

📒 Files selected for processing (8)
  • app/resources/library/node_properties/writer.go (3 hunks)
  • app/transports/http/bindings/nodes.go (1 hunks)
  • internal/ent/mutation.go (1 hunks)
  • internal/ent/node.go (4 hunks)
  • internal/ent/node_create.go (1 hunks)
  • internal/ent/node_query.go (2 hunks)
  • internal/ent/schema/node.go (1 hunks)
  • tests/library/properties/property_schema_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • internal/ent/schema/node.go
  • internal/ent/mutation.go
  • app/resources/library/node_properties/writer.go
  • app/transports/http/bindings/nodes.go
  • internal/ent/node_create.go
  • internal/ent/node_query.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: backend-test
🔇 Additional comments (9)
internal/ent/node.go (2)

43-43: Ensure pointer usage remains consistent throughout the codebase.

Converting ParentNodeID to a pointer allows representing a nil parent node, which appears correct. However, please verify all internal logic and related references to confirm they're updated accordingly to handle a pointer-based ID.


216-216: Appropriate use of sql.NullScanner for nullable fields.

The scanning logic correctly accounts for fields that may be null in the database. This change aligns well with moving to a pointer-based field for parent_node_id.

tests/library/properties/property_schema_test.go (7)

5-5: Good addition of net/http import for status code checks

Adding the net/http import allows for clear HTTP status code validation in the new tests, making the assertions more readable with explicit status code constants.


123-175: Well-structured test for root-level node property schema updates

This test effectively validates that property schema updates correctly propagate between sibling nodes at the root level. The test creates two independent root nodes and verifies that updating one node's schema properly affects its sibling.

Good use of assertion helpers and HTTP status verification to ensure the expected behavior.


153-172: Thorough validation of schema propagation between siblings

The assertion logic properly verifies that:

  1. The schema update returns the expected response
  2. The updated node has the correct schema properties
  3. The sibling node also receives the same property schema

This effectively tests the sibling update functionality mentioned in the PR summary.


177-272: Comprehensive testing of invalid property schema update scenarios

This test function thoroughly covers edge cases and error handling for property schema updates with three well-designed test cases:

  1. Duplicate property definitions in a single request
  2. Conflicting property types in a single request
  3. Conflicting property type updates in separate requests

Each test properly verifies both the error response (400 Bad Request) and that the transaction is rolled back, preserving data integrity.


191-214: Good validation of duplicate property handling

This test correctly verifies that when the same property is defined multiple times in a request, the API returns a 400 Bad Request and the transaction is rolled back, leaving the node's properties unchanged.


216-239: Effective test for type conflict handling in single request

This test case properly verifies the API's response when properties have the same name but different types in a single request. The assertion of the node's unchanged state confirms proper transaction rollback.


241-269: Good testing of sequential conflicting updates

This test effectively validates that when a property schema is already defined with one type, attempting to update it with a conflicting type fails appropriately with a 400 Bad Request, while preserving the original property configuration.

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.

1 participant