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

Fix entity find path #2541

Merged
merged 8 commits into from
Feb 7, 2025
Merged

Fix entity find path #2541

merged 8 commits into from
Feb 7, 2025

Conversation

GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Feb 6, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Summary by CodeRabbit

  • New Features
    • Introduced a more flexible, path-based entity search allowing users to navigate complex hierarchical structures with improved accuracy.
  • Bug Fixes
    • Added validation to prevent unnecessary processing for empty path segments in entity searches.
  • Refactor
    • Streamlined the underlying search logic to better handle edge cases, ensuring smoother and more reliable search results.
  • Tests
    • Enhanced test coverage for the entity search functionality, including edge cases and clarifications for existing tests.

@GuoLei1990 GuoLei1990 added the bug Something isn't working label Feb 6, 2025
Copy link

coderabbitai bot commented Feb 6, 2025

Warning

Rate limit exceeded

@GuoLei1990 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8c68ce2 and b87f266.

📒 Files selected for processing (1)
  • tests/src/core/Entity.test.ts (2 hunks)

Walkthrough

The changes refactor the entity search functionality by enhancing the recursive lookup mechanism. The _findChildByName method in the Entity class now uses additional parameters for recursive traversal through a hierarchy defined by path segments. The findByPath method has been adjusted to preprocess the input path and delegate to the new recursive method. In the Scene class, the findEntityByPath method now checks for empty paths and employs the updated recursive helper, streamlining its logic and control flow.

Changes

File Path Change Summary
packages/core/src/Entity.ts Modified _findChildByName to accept (entity, childIndex, paths, pathIndex) and perform a recursive search through entity hierarchies. Updated findByPath to split the input path and filter empty segments before calling the new helper.
packages/core/src/Scene.ts Updated findEntityByPath to validate non-empty path segments and use Entity._findChildByName for entity lookup instead of iterating through the list of roots, enhancing clarity and robustness.
tests/src/core/Entity.test.ts Added test cases for findEntityByPath to cover scenarios with empty paths and new path strings, ensuring correct behavior. Renamed variable child2 to child for clarity and introduced child3 for additional testing.

Possibly related PRs

  • Replace Transform #2464: The changes in the main PR are related to the modifications in the Entity class, specifically the _findChildByName method, which is invoked in the findEntityByPath method of the retrieved PR, indicating a direct connection in functionality.

Suggested labels

ignore for release

Poem

I'm a bouncy rabbit in a land of code,
Hopping through paths on the entity road.
I found my way with recursion so neat,
Now each entity lookup is a rhythmic beat.
With a twitch and a hop, my heart sings in glee,
Celebrating these changes—set my code free!
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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.

@GuoLei1990 GuoLei1990 linked an issue Feb 6, 2025 that may be closed by this pull request
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: 1

🧹 Nitpick comments (1)
packages/core/src/Scene.ts (1)

421-423: Align empty path handling in findEntityByPath with Entity.findByPath

When the input path is empty, findEntityByPath returns null, whereas Entity.findByPath returns the current entity. For consistency and intuitive API behavior, consider returning null or the root entity consistently in both methods.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 494b7a1 and 6aa622f.

📒 Files selected for processing (2)
  • packages/core/src/Entity.ts (2 hunks)
  • packages/core/src/Scene.ts (1 hunks)
🔇 Additional comments (3)
packages/core/src/Entity.ts (2)

406-408: Ensure findByPath correctly handles empty paths

The findByPath method now returns this when the input path is empty, which correctly allows an empty path to refer to the current entity.


37-39: Review the recursive call logic in _findChildByName

The recursive call at lines 37-39 may lead to infinite recursion or incorrect traversal due to the adjustment of pathIndex and childIndex. Verify that decrementing pathIndex and incrementing siblingIndex in the recursive call correctly backtracks to search sibling entities at higher levels.

Run the following script to test the method with various entity hierarchies and paths:

packages/core/src/Scene.ts (1)

426-429: Confirm the usage of _findChildByName in findEntityByPath

The method now uses Entity._findChildByName for searching entities by path. Ensure that this change integrates well with the overall entity hierarchy traversal and that access to the _findChildByName method (which is marked as internal) is appropriate.

Review the access modifiers and consider whether _findChildByName should remain internal or be exposed more appropriately for use in Scene.

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 85.29412% with 5 lines in your changes missing coverage. Please review.

Project coverage is 68.52%. Comparing base (ed9c82f) to head (b87f266).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/src/Entity.ts 75.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2541      +/-   ##
==========================================
+ Coverage   68.47%   68.52%   +0.04%     
==========================================
  Files         961      961              
  Lines      100221   100233      +12     
  Branches     8559     8576      +17     
==========================================
+ Hits        68630    68685      +55     
+ Misses      31331    31288      -43     
  Partials      260      260              
Flag Coverage Δ
unittests 68.52% <85.29%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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)
tests/src/core/Entity.test.ts (2)

297-309: Enhance test coverage with additional scenarios.

While the current test cases verify basic functionality, consider adding tests for:

  1. Case sensitivity in path segments
  2. Invalid paths (e.g., non-existent segments)
  3. Path segments with special characters

Example test cases to add:

 expect(parent.findByPath("/child")).eq(child);
 expect(parent.findByPath("child/grandson")).eq(grandson2);
+// Case sensitivity
+expect(parent.findByPath("CHILD/grandson")).eq(null);
+// Invalid paths
+expect(parent.findByPath("child/nonexistent")).eq(null);
+expect(parent.findByPath("child//grandson")).eq(null);
+// Special characters
+expect(parent.findByPath("child/../child/grandson")).eq(null);
🧰 Tools
🪛 ESLint

[error] 305-306: Delete

(prettier/prettier)


23-24: Fix formatting: Remove extra empty lines.

Remove the extra empty lines to comply with the project's formatting rules.

Also applies to: 30-33, 305-306

🧰 Tools
🪛 ESLint

[error] 23-24: Delete

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4532dbf and dd4a609.

📒 Files selected for processing (2)
  • packages/core/src/Scene.ts (1 hunks)
  • tests/src/core/Entity.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/Scene.ts
🧰 Additional context used
🪛 ESLint
tests/src/core/Entity.test.ts

[error] 23-24: Delete

(prettier/prettier)


[error] 30-33: Delete ⏎⏎⏎

(prettier/prettier)


[error] 305-306: Delete

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (22.x, windows-latest)
  • GitHub Check: codecov
  • GitHub Check: e2e (22.x)
🔇 Additional comments (1)
tests/src/core/Entity.test.ts (1)

24-26: LGTM! Good test coverage for edge cases.

The new test cases effectively verify the behavior of findEntityByPath for empty paths and root paths.

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: 1

🧹 Nitpick comments (3)
tests/src/core/Entity.test.ts (3)

17-24: Consider using unique names for test entities.

Having multiple entities named "parent" (parentX, parent, parentY) could lead to ambiguous test results and make debugging more difficult.

Consider using more descriptive names that reflect their role in the test:

-const parentX = new Entity(engine, "parent");
-const parent = new Entity(engine, "parent");
-const parentY = new Entity(engine, "parent");
+const firstParent = new Entity(engine, "first_parent");
+const middleParent = new Entity(engine, "middle_parent");
+const lastParent = new Entity(engine, "last_parent");

309-318: Improve test clarity with unique entity names and descriptive comments.

Having multiple entities named "child" makes the test harder to understand. Consider using unique names that describe the entity's role in the test hierarchy.

-const child2 = new Entity(engine, "child");
-const child3 = new Entity(engine, "child");
+const secondChild = new Entity(engine, "second_child");
+const thirdChild = new Entity(engine, "third_child");

-const grandson = new Entity(engine, "grandsonX");
-const grandson2 = new Entity(engine, "grandson");
+const firstGrandson = new Entity(engine, "first_grandson");
+const secondGrandson = new Entity(engine, "second_grandson");

// Add descriptive comments
// Test hierarchy:
// - parent
//   - child
//     - firstGrandson
//   - secondChild
//     - secondGrandson
//   - thirdChild

33-33: Fix formatting issue.

Remove the extra whitespace on this empty line to comply with the project's formatting rules.

-     
+
🧰 Tools
🪛 ESLint

[error] 33-34: Delete ⏎·····

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3d9f6d and 8c68ce2.

📒 Files selected for processing (1)
  • tests/src/core/Entity.test.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
tests/src/core/Entity.test.ts

[error] 45-45: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

🪛 ESLint
tests/src/core/Entity.test.ts

[error] 33-34: Delete ⏎·····

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: codecov
  • GitHub Check: e2e (22.x)

@GuoLei1990 GuoLei1990 merged commit ad832b3 into galacean:main Feb 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

findbypath can't find the right result because of same name
2 participants