Skip to content

Add tests for dotrain add order lsp file #1719

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

Merged
merged 6 commits into from
May 12, 2025
Merged

Conversation

findolor
Copy link
Collaborator

@findolor findolor commented May 1, 2025

Motivation

See issue: #1625

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • [ ] included screenshots (if this involves a front-end change)

fix #1625

Summary by CodeRabbit

  • Tests
    • Added comprehensive tests to verify detection of syntax and semantic issues in Rainlang documents, including handling of invalid references, expressions, and unexpected tokens.

@findolor findolor added test test code rust Related to rust crates labels May 1, 2025
@findolor findolor added this to the Test coverage, tech debt milestone May 1, 2025
@findolor findolor requested a review from hardyjosh May 1, 2025 09:36
@findolor findolor self-assigned this May 1, 2025
Copy link
Contributor

coderabbitai bot commented May 1, 2025

"""

Walkthrough

A new test module was introduced to the dotrain_add_order_lsp.rs file under a conditional compilation flag. This module defines a multiline Rainlang document as a constant, provides a helper function to create a test TextDocumentItem, and adds two asynchronous test functions to verify the problems method of the DotrainAddOrderLsp struct. The tests assert that the method correctly identifies various syntax and semantic issues in the sample document and confirms no problems for a minimal valid input. The tests are configured to run only in non-WASM environments.

Changes

File(s) Change Summary
crates/common/src/dotrain_add_order_lsp.rs Added a test module with a sample Rainlang document constant, a helper function, and two async tests verifying the problems method behavior for valid and invalid Rainlang inputs.

Sequence Diagram(s)

sequenceDiagram
    participant Test as test_problems()
    participant Doc as TextDocumentItem
    participant LSP as DotrainAddOrderLsp

    Test->>Doc: Create TextDocumentItem with test Rainlang text
    Test->>LSP: Instantiate DotrainAddOrderLsp with Doc
    Test->>LSP: Call problems()
    LSP-->>Test: Return list of problems (diagnostics)
    Test->>Test: Assert problems match expected diagnostics
Loading

Assessment against linked issues

Objective Addressed Explanation
Add missing tests for dotrain_add_order_lsp.rs (Issue #1625)

Suggested reviewers

  • hardyjosh
    """

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

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

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.

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.

@findolor
Copy link
Collaborator Author

findolor commented May 1, 2025

@hardyjosh I didn't add any tests for hover and completion functions because they aren't used anywhere in both webapp and tauri app. I could not figure out how they are used so if you have any input on this, that would be awesome.

Copy link
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 UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c4c519 and 890c189.

📒 Files selected for processing (1)
  • crates/common/src/dotrain_add_order_lsp.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
🔇 Additional comments (3)
crates/common/src/dotrain_add_order_lsp.rs (3)

123-126: Appropriate test module setup and imports.

The test module is correctly set up with the #[cfg(test)] attribute and imports the necessary components. This is a good practice for isolating test code.


128-206: Well-structured test data with appropriate test cases.

The TEXT constant provides comprehensive test coverage with various sections (tokens, orders, scenarios, deployments) and intentionally includes different kinds of errors to test problem detection. This approach ensures thorough testing of the LSP functionality.


208-215: Clean helper function implementation.

The get_text_document helper function is well-implemented, making the test more readable by encapsulating the creation of the test document.

Copy link
Collaborator

@0xgleb 0xgleb left a comment

Choose a reason for hiding this comment

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

Should we have a test case with no problems?

@hardyjosh
Copy link
Contributor

@hardyjosh I didn't add any tests for hover and completion functions because they aren't used anywhere in both webapp and tauri app. I could not figure out how they are used so if you have any input on this, that would be awesome.

right, the front end work was something we decided to deprioritise. for the same reason i agree it wouldn't be a good use of time to write tests for it right now.

Copy link
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

♻️ Duplicate comments (1)
crates/common/src/dotrain_add_order_lsp.rs (1)

241-241: 🧹 Nitpick (assertive)

Consider using a mock or configurable RPC URL.

While the test is using a different URL from a previous review comment, it's still using a hardcoded URL which could be problematic if tests run in environments with different configurations. Consider using a clearly fake URL pattern or an environment variable.

- let problems = lsp.problems("https://some-rpc-url.com", None, None).await;
+ // Use a clearly fake URL or environment variable for testing
+ let problems = lsp.problems("http://invalid-test-url", None, None).await;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc6aa54 and 82d0fa9.

📒 Files selected for processing (1)
  • crates/common/src/dotrain_add_order_lsp.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: git-clean
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (3)
crates/common/src/dotrain_add_order_lsp.rs (3)

218-236: Good job on the test_no_problems implementation.

The test correctly sets up a LocalEvm instance and tests the "happy path" by verifying that a valid document produces no problems. Using a real deployer address from the local EVM provides better test coverage than a dummy value.


257-259: Effective implementation of message comparison.

This implementation addresses the nitpick from a previous reviewer about displaying mismatches more clearly by comparing messages pairwise rather than comparing entire vectors.


238-256: Comprehensive problem detection test.

The test effectively validates that the problems method correctly identifies all expected issues in an invalid document. The assertions check both the number of problems and their specific messages, which provides good coverage of the error detection logic.

@hardyjosh hardyjosh enabled auto-merge May 11, 2025 08:53
@hardyjosh hardyjosh merged commit ba1ecbb into main May 12, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Related to rust crates test test code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing test - Common crate - dotrain_add_order_lsp.rs
3 participants