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 reource load issue in local downloaded npm package #2436

Merged
merged 41 commits into from
Nov 15, 2024

Conversation

Sway007
Copy link
Member

@Sway007 Sway007 commented Nov 14, 2024

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)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced URL handling in resource retrieval to prevent errors with improperly formatted URLs.
    • Added a test case to ensure the handling of invalid query parameters in asset URLs.
  • Refactor

    • Updated the getResourceByRef method for improved resource fetching, simplifying the URL construction process when loading resources.

@Sway007 Sway007 added Bug Something isn't working resource Resource-related functions high priority High priority issue labels Nov 14, 2024
@Sway007 Sway007 requested a review from GuoLei1990 November 14, 2024 02:37
Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes involve a modification to the getResourceByRef method in the ResourceManager class located in ResourceManager.ts. The method's implementation has been updated to set the url directly to resourceConfig.virtualPath, with the key being appended as a query parameter if provided. This alters the way resources are fetched by changing the URL structure used for loading resources. The rest of the method's logic remains unchanged.

Changes

File Change Summary
packages/core/src/asset/ResourceManager.ts Updated getResourceByRef method to set url directly from resourceConfig.virtualPath and append key as a query parameter if provided.
tests/src/core/resource/ResourceManager.test.ts Added new test suite for "gltf subAsset load" with a test case for handling invalid query parameters in asset URLs.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ResourceManager
    Client->>ResourceManager: getResourceByRef(ref)
    ResourceManager->>ResourceManager: construct url
    ResourceManager-->>Client: return resource (possibly cloned)
Loading

Possibly related PRs

  • Fix shaderlab loader in NPM mode #2427: The changes in the MaterialLoader class involve the use of resourceManager.getResourceByRef, which directly relates to the modifications made to the getResourceByRef method in the ResourceManager class, indicating a connection in how resources are fetched.

Suggested reviewers

  • GuoLei1990

🐇 "In the code where the resources play,
A rabbit hops in a brand new way.
With paths now clear and logic refined,
The treasures of code are easier to find!
So let’s all cheer and give a shout,
For the changes that make the code sprout!" 🐇


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

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.43%. Comparing base (7da32a5) to head (c76cba5).

Files with missing lines Patch % Lines
packages/core/src/asset/ResourceManager.ts 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2436      +/-   ##
==========================================
- Coverage   69.44%   69.43%   -0.01%     
==========================================
  Files         524      524              
  Lines       27484    27482       -2     
  Branches     4112     4111       -1     
==========================================
- Hits        19085    19081       -4     
  Misses       6894     6894              
- Partials     1505     1507       +2     
Flag Coverage Δ
unittests 69.43% <33.33%> (-0.01%) ⬇️

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

🧹 Outside diff range and nitpick comments (1)
packages/core/src/asset/ResourceManager.ts (1)

576-578: Document URL handling behavior in method comments.

Since this is a @beta API, it's important to document the URL handling behavior, especially how relative URLs are processed.

Apply this diff to improve documentation:

   /**
    * @internal
    * @beta Just for internal editor, not recommended for developers.
+   * @param ref.refId - The reference ID to look up in the resource config
+   * @param ref.key - Optional key for sub-resource access
+   * @param ref.isClone - Whether to clone the resource
+   * @remarks
+   * The method handles both absolute and relative URLs by using a base URL for parsing.
+   * Query parameters from the original URL are preserved.
    */
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7da32a5 and b3f8e57.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/asset/ResourceManager.ts

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

🔇 Additional comments (1)
packages/core/src/asset/ResourceManager.ts (1)

577-577: LGTM! Verify URL handling for various formats.

The addition of "http://localhost" as a base URL is a good fix for handling relative URLs. However, let's verify it works correctly with different URL formats.

Let's verify the URL handling behavior:

✅ Verification successful

URL handling implementation is safe and consistent with existing patterns

The verification shows that:

  • The URL construction pattern is consistent with other URL usages in the codebase (e.g., in ShaderLab, Utils)
  • The remoteUrl handling follows an established pattern across the codebase, particularly in resource loading
  • The change is isolated to query string extraction and doesn't affect the overall URL resolution strategy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for different URL usage patterns in the codebase
# to ensure the change won't break existing code.

# Look for URL constructions and usages
rg -A 2 "new URL\(" 

# Look for potential remoteUrl patterns in tests
rg -A 2 "remoteUrl.*['\"]" "test/"

Length of output: 1475


Script:

#!/bin/bash
# Let's analyze the usage context of getResourceByRef and remoteUrl patterns

# Find the getResourceByRef implementation and its usage
ast-grep --pattern 'getResourceByRef($$$) { $$$ }'

# Look for test files in the entire repository
fd -e test.ts -e spec.ts

# Search for remoteUrl patterns in the codebase
rg -A 2 "remoteUrl.*=" 

Length of output: 3928

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

@@ -574,7 +574,7 @@
return Promise.resolve(null);
}
const remoteUrl = resourceConfig.path;
const queryPath = new URL(remoteUrl).search;
const queryPath = new URL(remoteUrl, "http://localhost").search;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add test coverage for URL handling scenarios.

The modified URL handling logic lacks test coverage. Please add tests for:

  • Relative URLs
  • URLs with query parameters
  • URLs without scheme/host
  • Invalid URLs

Would you like me to help generate test cases for these scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b3f8e57 and 809a3cb.

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

583-589: Add test coverage for resource resolution scenarios

Referring to the previous review comment about test coverage, we still need tests for:

  • Resource resolution with various key formats
  • Cloning behavior
  • Error handling scenarios

576-582: Verify path handling for different environments

While simplifying URL handling by directly using resourceConfig.path might fix local package loading, we should ensure it works correctly across different environments.

Let's verify the path handling:

Comment on lines 583 to 589
let resource = item;
if (key) {
const paths = this._parseQueryPath(key);
resource = this._getResolveResource(item, paths);
}
return isClone ? resource.clone() : resource;
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for resource resolution and cloning

The current implementation should handle potential failures in:

  • Resource resolution with invalid keys
  • Clone operation failures

Consider wrapping the operations in try-catch:

     return promise.then((item) => {
+      try {
         let resource = item;
         if (key) {
           const paths = this._parseQueryPath(key);
           resource = this._getResolveResource(item, paths);
         }
         return isClone ? resource.clone() : resource;
+      } catch (error) {
+        Logger.warn(`Failed to resolve/clone resource: ${error.message}`);
+        return null;
+      }
     });

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Outside diff range and nitpick comments (1)
packages/core/src/asset/ResourceManager.ts (1)

577-577: Document the URL handling behavior.

Since this is a behavior change in how URLs are handled for local packages, please add JSDoc comments explaining:

  • The purpose of using a base URL
  • How different URL formats are handled
  • Any limitations or considerations for local packages
   const resourceConfig = this._editorResourceConfig[refId];
   if (!resourceConfig) {
     Logger.warn(`refId:${refId} is not find in this._editorResourceConfig.`);
     return Promise.resolve(null);
   }
   const remoteUrl = resourceConfig.path;
+  // Use base URL to handle relative URLs in local packages
+  // This ensures consistent URL parsing regardless of the URL format
   const queryPath = new URL(remoteUrl, "http://localhost").search;
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 809a3cb and 1607698.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/asset/ResourceManager.ts

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

🔇 Additional comments (3)
packages/core/src/asset/ResourceManager.ts (3)

Line range hint 517-524: LGTM! URL parameter parsing logic is well-implemented.

The implementation correctly handles URL parameters, including proper decoding of query parameters.


577-577: Add test coverage for URL handling.

The URL parsing logic lacks test coverage. This was previously flagged in the review comments.

Would you like me to help generate test cases for:

  • Relative URLs with local packages
  • URLs with query parameters
  • URLs without scheme/host
  • Invalid URLs
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests


577-577: Implementation looks good, but verify URL handling edge cases.

The use of "http://localhost" as a base URL is a good practice for parsing relative URLs. However, let's verify the behavior with different URL formats.

✅ Verification successful

Let me analyze the URL usage patterns in the codebase to verify the implementation. I'll check the ResourceManager test file to see if URL handling is covered.


URL handling implementation is verified and well-tested

The implementation is safe and properly tested:

  • The queryPath test suite in ResourceManager.test.ts covers various URL scenarios including:
    • URLs with query parameters
    • URLs with encoded characters
    • URLs without query strings
  • The use of "http://localhost" as base URL is appropriate as it's only used for query string extraction via .search
  • The extracted query parameters are correctly appended to the virtual path
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for different URL formats in the codebase to ensure compatibility

# Search for URL usage patterns
echo "Checking URL patterns in the codebase..."
rg -A 2 'new URL\(' --type ts

# Look for potential URL-related test files
echo "Looking for URL-related test files..."
fd -e test.ts -e spec.ts -e test.js -e spec.js

Length of output: 4310


Script:

#!/bin/bash
# Check ResourceManager tests for URL handling coverage
cat tests/src/core/resource/ResourceManager.test.ts

# Check the full context of URL usage in ResourceManager
rg -B 5 -A 5 'new URL\(' packages/core/src/asset/ResourceManager.ts

Length of output: 3280

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 577-577: packages/core/src/asset/ResourceManager.ts#L577
Added line #L577 was not covered by tests

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

🧹 Outside diff range and nitpick comments (2)
packages/core/src/asset/ResourceManager.ts (2)

576-579: Document the URL construction behavior change

Since this changes how resource URLs are constructed, please update the method's documentation to:

  • Explain how the URL is constructed from virtualPath
  • Document the query parameter format when a key is provided

Example documentation:

   /**
    * @internal
    * @beta Just for internal editor, not recommended for developers.
+   * @param ref.refId - The reference ID for the resource
+   * @param ref.key - Optional key to append as a query parameter
+   * @param ref.isClone - Whether to clone the resource
+   * @returns Promise resolving to the requested resource
+   * @remarks URLs are constructed by using virtualPath directly and appending the key as a 'q' parameter if provided
    */
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests


576-579: Add input validation for URL construction

The current implementation should validate inputs to prevent potential issues:

  • Check if virtualPath is defined
  • Validate key format if provided
      let url = resourceConfig.virtualPath;
+     if (!url) {
+       Logger.warn(`Invalid virtualPath for refId:${refId}`);
+       return Promise.resolve(null);
+     }
      if (key) {
+       // Validate key format
+       if (typeof key !== 'string') {
+         Logger.warn(`Invalid key type for refId:${refId}`);
+         return Promise.resolve(null);
+       }
        url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key;
      }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1607698 and 7e4a771.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/asset/ResourceManager.ts

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests

🔇 Additional comments (2)
packages/core/src/asset/ResourceManager.ts (2)

Line range hint 517-524: LGTM: URL parameter parsing logic is correct

The implementation properly handles URL parameter extraction and decoding.


576-579: ⚠️ Potential issue

Add test coverage for URL construction logic

The modified URL construction logic lacks test coverage. Please add tests for:

  • Basic URL without query parameters
  • URL with existing query parameters
  • URL with special characters in the key
#!/bin/bash
# Check for existing tests of getResourceByRef
rg -l "getResourceByRef.*test" 

Would you like me to help generate test cases for these scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests

@Sway007 Sway007 self-assigned this Nov 14, 2024
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

🧹 Outside diff range and nitpick comments (1)
packages/core/src/asset/ResourceManager.ts (1)

576-578: Consider architectural implications for local npm package resources.

Since this change affects how local resources are loaded in npm packages:

  1. Consider adding support for handling file system paths differently from URLs
  2. The current implementation might need to handle path separators consistently across platforms
  3. Local paths might require different validation rules than URLs

Consider implementing a dedicated path resolver for local npm package resources that:

  • Handles both URL and file system paths
  • Normalizes path separators
  • Validates paths according to the context (local vs remote)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests


[warning] 578-578: packages/core/src/asset/ResourceManager.ts#L578
Added line #L578 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e4a771 and c76cba5.

📒 Files selected for processing (1)
  • packages/core/src/asset/ResourceManager.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/core/src/asset/ResourceManager.ts

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests


[warning] 578-578: packages/core/src/asset/ResourceManager.ts#L578
Added line #L578 was not covered by tests

🔇 Additional comments (1)
packages/core/src/asset/ResourceManager.ts (1)

576-578: ⚠️ Potential issue

Add test coverage and error handling for URL construction.

The URL construction logic has been simplified, but there are several areas that need attention:

  1. The changes lack test coverage as indicated by static analysis
  2. Missing error handling for invalid virtualPath or malformed key
  3. Documentation needs to be updated to reflect the URL construction changes

Let's verify the impact of these changes:

Would you like me to help:

  1. Generate test cases covering various URL scenarios?
  2. Add error handling for invalid inputs?
  3. Update the documentation?
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 576-576: packages/core/src/asset/ResourceManager.ts#L576
Added line #L576 was not covered by tests


[warning] 578-578: packages/core/src/asset/ResourceManager.ts#L578
Added line #L578 was not covered by tests

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c76cba5 and ef32bc8.

📒 Files selected for processing (1)
  • tests/src/core/resource/ResourceManager.test.ts (2 hunks)
🔇 Additional comments (1)
tests/src/core/resource/ResourceManager.test.ts (1)

84-96: Expand test coverage for resource loading scenarios

The current test coverage appears insufficient for the changes described in the PR objectives. Consider adding these test cases:

  1. Local npm package resource loading (main PR objective)
  2. Edge cases for URL handling:
    • URLs with multiple query parameters
    • URLs with special characters
    • Relative vs absolute paths
    • Different resource types

Let's check the current test coverage:

expect(loadRes).to.equal(undefined);
});

// TODO: case for gltf loader load invalid q url, expect to throw
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement the TODO test case before merging

Given that this PR addresses resource loading issues, the TODO test case for GLTF loader error handling should be implemented now rather than deferred. This test is important for validating the error handling behavior of the resource loading fix.

Would you like me to help implement the test case for GLTF loader error handling? Here's a suggested structure:

it("should throw error when loading GLTF with invalid query URL", async () => {
  try {
    await engine.resourceManager.load({
      url: "/test-assets/model.gltf?q=invalid[query]",
      type: AssetType.GLTF
    });
    expect.fail("Should have thrown an error");
  } catch (error) {
    expect(error).to.be.instanceOf(Error);
    expect(error.message).to.include("Invalid query parameter");
  }
});

Comment on lines +85 to +93
describe("gltf subAsset load", () => {
it("invalid q case", async () => {
const loadRes = await engine.resourceManager.load({
// contains invalid q value cdn url.
url: "https://mdn.alipayobjects.com/huamei_aftkdx/afts/file/A*_Ao1QZtL9fMAAAAAAAAAAAAADteEAQ/mock-project.json",
type: AssetType.Project
});
expect(loadRes).to.equal(undefined);
});
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Test case needs improvement for reliability and clarity

Several issues with the current test implementation:

  1. Using an external CDN URL makes the test unreliable and dependent on network connectivity. Consider using a mock URL or local test fixture.
  2. The test description and implementation don't clearly document what constitutes an "invalid q value" or why undefined is the expected return value.
  3. The test case should be expanded to better validate the local npm package resource loading fix mentioned in the PR objectives.

Consider refactoring like this:

 describe("gltf subAsset load", () => {
-  it("invalid q case", async () => {
+  it("should handle invalid query parameters in resource URLs", async () => {
     const loadRes = await engine.resourceManager.load({
-      // contains invalid q value cdn url.
-      url: "https://mdn.alipayobjects.com/huamei_aftkdx/afts/file/A*_Ao1QZtL9fMAAAAAAAAAAAAADteEAQ/mock-project.json",
+      url: "/test-assets/mock-project.json?q=invalid[query]",  // Use local test asset
       type: AssetType.Project
     });
+    // Document why undefined is expected
+    // Consider adding more assertions to validate the error handling
     expect(loadRes).to.equal(undefined);
   });

Committable suggestion skipped: line range outside the PR's diff.

@GuoLei1990 GuoLei1990 merged commit 4ef480e into galacean:main Nov 15, 2024
6 of 7 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 high priority High priority issue resource Resource-related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants