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

👍 rejects if the plugin name is invalid #418

Merged
merged 3 commits into from
Sep 16, 2024
Merged

👍 rejects if the plugin name is invalid #418

merged 3 commits into from
Sep 16, 2024

Conversation

Milly
Copy link
Contributor

@Milly Milly commented Sep 14, 2024

Fixes part of #415.

Summary by CodeRabbit

  • New Features

    • Introduced validation for plugin names, ensuring only valid names are processed, enhancing overall system robustness.
    • Added a constant for invalid plugin names to improve validation and error handling.
  • Bug Fixes

    • Improved error handling for various plugin operations when invalid names are used.
  • Tests

    • Expanded test coverage for handling invalid plugin names across multiple functions, ensuring robust error detection and handling.
  • Documentation

    • Added comments to clarify relationships between constants and improve code understanding.

Copy link

coderabbitai bot commented Sep 14, 2024

Walkthrough

The changes encompass the addition of validation for plugin names across several files in the Denops framework. A new function, assertValidPluginName, is introduced to ensure plugin names conform to a specified pattern. Tests are expanded to cover various methods and scenarios, verifying the handling of both valid and invalid plugin names. Additionally, a new test data file is created to store invalid plugin names, enhancing the robustness and maintainability of the codebase.

Changes

Files Change Summary
autoload/denops/_internal/plugin.vim Added a comment linking s:VALID_NAME_PATTERN to a constant in service.ts.
denops/@denops-private/service.ts Introduced assertValidPluginName for plugin name validation; modified waitLoaded to async syntax.
denops/@denops-private/service_test.ts Added tests for invalid plugin names across multiple service methods.
tests/denops/runtime/functions/denops/notify_test.ts Implemented tests for denops#notify() function handling invalid plugin names.
tests/denops/runtime/functions/denops/request_async_test.ts Added tests for denops#request_async() function with invalid plugin names.
tests/denops/runtime/functions/denops/request_test.ts Expanded tests for denops#request() function to handle invalid plugin names.
tests/denops/runtime/functions/plugin/check_type_test.ts Enhanced test to validate multiple invalid plugin names.
tests/denops/runtime/functions/plugin/is_loaded_test.ts Expanded test coverage for invalid plugin names in is_loaded.
tests/denops/runtime/functions/plugin/load_test.ts Improved test for load function to check multiple invalid names.
tests/denops/runtime/functions/plugin/reload_test.ts Enhanced test for reload function to cover multiple invalid plugin names.
tests/denops/runtime/functions/plugin/unload_test.ts Expanded test for unload function to validate multiple invalid names.
tests/denops/runtime/functions/plugin/wait_async_test.ts Improved test for wait_async function with multiple invalid names.
tests/denops/runtime/functions/plugin/wait_test.ts Enhanced test for wait function to cover multiple invalid names.
tests/denops/testdata/invalid_plugin_names.ts Introduced a new file containing an array of invalid plugin names for testing.

Possibly related PRs

Poem

🐰 In the garden of code, we hop and play,
Validating names in a bright new way.
With tests that cover each nook and each cranny,
Ensuring our plugins are valid and zany!
So let’s celebrate with a joyful cheer,
For clean, robust code is finally here! 🌼

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 Sep 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.96%. Comparing base (aed70a1) to head (908c59e).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #418      +/-   ##
==========================================
+ Coverage   95.90%   95.96%   +0.05%     
==========================================
  Files          24       25       +1     
  Lines        1393     1412      +19     
  Branches      174      179       +5     
==========================================
+ Hits         1336     1355      +19     
  Misses         55       55              
  Partials        2        2              

☔ 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aed70a1 and 908c59e.

Files selected for processing (14)
  • autoload/denops/_internal/plugin.vim (1 hunks)
  • denops/@denops-private/service.ts (5 hunks)
  • denops/@denops-private/service_test.ts (9 hunks)
  • tests/denops/runtime/functions/denops/notify_test.ts (1 hunks)
  • tests/denops/runtime/functions/denops/request_async_test.ts (1 hunks)
  • tests/denops/runtime/functions/denops/request_test.ts (1 hunks)
  • tests/denops/runtime/functions/plugin/check_type_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/is_loaded_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/load_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/reload_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/unload_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/wait_async_test.ts (2 hunks)
  • tests/denops/runtime/functions/plugin/wait_test.ts (2 hunks)
  • tests/denops/testdata/invalid_plugin_names.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • autoload/denops/_internal/plugin.vim
Additional comments not posted (32)
tests/denops/testdata/invalid_plugin_names.ts (1)

1-6: LGTM!

The INVALID_PLUGIN_NAMES constant provides a clear and concise reference for identifying invalid plugin names. The use of tuples with descriptive labels enhances the readability and maintainability of the test data.

The use of readonly is a good practice to ensure the integrity of the test data.

Overall, this addition aligns well with the PR objective of improving the validation of plugin names.

tests/denops/runtime/functions/denops/request_test.ts (3)

1-25: LGTM!

The test setup is comprehensive and follows best practices:

  • Imports necessary dependencies
  • Sets up the test environment using testHost
  • Initializes variables to capture error outputs
  • Waits for the Denops server to be running
  • Sets up an autocommand to capture plugin events

26-36: LGTM!

The test case for invalid plugin names is well-structured and comprehensive:

  • Iterates over a predefined list of invalid plugin names
  • Asserts that calling denops#request with each invalid name throws an appropriate error
  • Ensures comprehensive coverage of invalid plugin name scenarios

38-55: LGTM!

The test case for a valid plugin is well-structured and comprehensive:

  • Loads a valid plugin and waits for it to be initialized
  • Verifies that the plugin is loaded by checking the captured plugin events
  • Calls denops#request with valid parameters once the plugin is loaded
  • Asserts that the output includes the expected confirmation message, indicating successful execution of the request
tests/denops/runtime/functions/denops/notify_test.ts (1)

12-61: LGTM!

The testHost function is well-structured and follows best practices for testing Denops plugins. It sets up a test environment using the testHost utility, tests the behavior of denops#notify() with invalid plugin names using the INVALID_PLUGIN_NAMES constant, resolves the path to a valid plugin script using the resolveTestDataPath utility, waits for asynchronous operations to complete using the wait utility, introduces a delay in the tests using the delay utility, and makes assertions using the assertEquals and assertStringIncludes utilities.

The function is testing the behavior of denops#notify() under various conditions, including invalid plugin names and a valid plugin, which is a good practice for ensuring the robustness of the code.

Overall, the function is well-written and enhances the reliability of the Denops framework by ensuring that the notification system behaves correctly under both valid and invalid conditions.

tests/denops/runtime/functions/denops/request_async_test.ts (3)

1-9: Imports are well-structured and promote code reusability.

The imports are organized and follow a clear naming convention. The use of separate test data and utility files enhances code reusability and maintainability.


13-116: Comprehensive test suite with clear structure and assertions.

The test suite for denops#request_async() is well-designed and covers both valid and invalid scenarios. The tests are structured logically and use clear assertions to verify the expected behavior. The use of async/await and utility functions enhances the readability and reliability of the tests.


36-71: Thorough testing of invalid plugin name handling.

The tests comprehensively cover the handling of invalid plugin names by iterating over a list of invalid names and verifying the expected behavior. The use of a loop reduces code duplication and improves maintainability. The assertions are clear and accurately verify the invocation of the failure callback with the expected error message.

tests/denops/runtime/functions/plugin/check_type_test.ts (1)

80-90: LGTM!

The test case is well-structured, comprehensive, and follows the existing test case structure. It covers all the invalid plugin names provided in the INVALID_PLUGIN_NAMES array and uses the assertRejects function to check if the denops#plugin#check_type function throws an error with the appropriate message.

denops/@denops-private/service.ts (5)

48-48: LGTM!

The addition of plugin name validation using the assertValidPluginName function is a good improvement. It ensures that only valid plugin names are loaded, enhancing the robustness of the system.


83-83: LGTM!

The addition of plugin name validation using the assertValidPluginName function is a good improvement. It ensures that only valid plugin names are unloaded, enhancing the robustness of the system.


88-88: LGTM!

The addition of plugin name validation using the assertValidPluginName function is a good improvement. It ensures that only valid plugin names are reloaded, enhancing the robustness of the system.


95-100: LGTM!

The addition of plugin name validation using the assertValidPluginName function is a good improvement. It ensures that only valid plugin names are waited for, enhancing the robustness of the system.

The modification to use async/await syntax also improves readability and consistency in handling asynchronous operations.


118-118: LGTM!

The addition of plugin name validation using the assertValidPluginName function is a good improvement. It ensures that only valid plugin names are dispatched to, enhancing the robustness of the system.

tests/denops/runtime/functions/plugin/is_loaded_test.ts (2)

3-3: LGTM!

The import statement is correctly formatted and follows the existing import style in the file.


34-44: Excellent test case!

The new test case is well-structured, follows the existing test style, and improves the robustness of the tests by ensuring that multiple invalid inputs are validated. The use of assertRejects, for...of loop, and template literals is spot-on.

tests/denops/runtime/functions/plugin/wait_async_test.ts (2)

8-8: LGTM!

Importing the invalid plugin names from an external file is a good practice for maintainability and reusability.


33-46: LGTM!

The test case correctly loops over the array of invalid plugin names and asserts that calling denops#plugin#wait_async() with each invalid name throws an error with the expected message. Including the invalid plugin name in the error message is helpful for debugging.

tests/denops/runtime/functions/plugin/unload_test.ts (2)

7-7: LGTM!

Importing the invalid plugin names from an external file is a good practice for maintainability and reusability of test data.


36-46: Great job enhancing the test coverage!

The new test case iterates over multiple invalid plugin names and verifies that the unload method throws an error with the expected message for each invalid name. This improves the robustness of the test suite by ensuring that the error handling is tested for a broader range of invalid inputs.

The test case is well-structured and follows the existing test suite pattern, making it easy to understand and maintain.

tests/denops/runtime/functions/plugin/reload_test.ts (2)

7-7: LGTM!

The import statement is correctly written and the imported data is used in the tests.


36-46: Great job enhancing the test coverage!

The changes introduce a loop that iterates over multiple invalid plugin names imported from an external file. For each invalid plugin name, the test dynamically generates a step that checks if calling denops#plugin#reload with that name throws an error with the expected message. This improves the robustness of the tests by covering multiple invalid cases rather than a single hardcoded instance.

tests/denops/runtime/functions/plugin/load_test.ts (2)

7-7: LGTM!

The import statement is correct and the imported data is likely used to enhance the tests for invalid plugin names.


35-45: Excellent enhancement to the invalid plugin name test!

The introduction of the test loop that iterates over INVALID_PLUGIN_NAMES significantly improves the robustness and coverage of the test. By dynamically checking each invalid plugin name and generating a specific error message, the test ensures that multiple invalid cases are covered and provides clear feedback on failures.

This change broadens the scope of the test and eliminates the reliance on a single hardcoded case, making it more comprehensive and maintainable.

tests/denops/runtime/functions/plugin/wait_test.ts (2)

10-10: LGTM!

Importing test data from a separate file is a good practice for maintainability and reusability.


39-49: LGTM!

The loop is correctly implemented and improves the test coverage by testing the denops#plugin#wait function with multiple invalid plugin names. Using the assertRejects function to check if the function call throws an error with the expected error message is a good practice.

denops/@denops-private/service_test.ts (6)

446-464: LGTM!

The test case for .load() with invalid plugin names is implemented correctly. It properly asserts that service.load() rejects with a TypeError containing the invalid plugin name and verifies that no calls are made to the host.


787-805: LGTM!

The test case for .unload() with invalid plugin names is implemented correctly. It properly asserts that service.unload() rejects with a TypeError containing the invalid plugin name and verifies that no calls are made to the host.


1106-1124: LGTM!

The test case for .reload() with invalid plugin names is implemented correctly. It properly asserts that service.reload() rejects with a TypeError containing the invalid plugin name and verifies that no calls are made to the host.


1222-1235: LGTM!

The test case for .waitLoaded() with invalid plugin names is implemented correctly. It properly asserts that service.waitLoaded() rejects with a TypeError containing the invalid plugin name.


1379-1392: LGTM!

The test case for .dispatch() with invalid plugin names is implemented correctly. It properly asserts that service.dispatch() rejects with a string error containing the invalid plugin name.


1620-1652: LGTM!

The test case for .dispatchAsync() with invalid plugin names is implemented correctly. It properly asserts that service.dispatchAsync() resolves but calls the failure callback with an error object containing the invalid plugin name.

@lambdalisue lambdalisue merged commit d0718c2 into main Sep 16, 2024
9 checks passed
@lambdalisue lambdalisue deleted the plugin-name branch September 16, 2024 09:05
Milly added a commit that referenced this pull request Sep 17, 2024
This is a regression due to #418 and discovered by #419.
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