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

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

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 an asynchronous test function to verify the problems method of the DotrainAddOrderLsp struct. The test asserts that the method correctly identifies various syntax and semantic issues in the sample document. The test is 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, a helper function, and an async test for the problems method.

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

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 890c189 and 6d68f99.

📒 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: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (3)
crates/common/src/dotrain_add_order_lsp.rs (3)

128-206: LGTM! Comprehensive test document structure.

The test document includes a good variety of valid and invalid constructs to test error detection, including tokens, orders, scenarios, deployments, and invalid Rainlang expressions.


208-215: LGTM! Well-implemented helper function.

The get_text_document() function properly initializes a TextDocumentItem with the test document, making the test setup clean and reusable.


217-219: LGTM! Clear test setup.

Good use of the tokio test harness for async testing and clean instantiation of the DotrainAddOrderLsp with empty bindings.

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

Comment on lines 217 to 222
#[tokio::test]
#[cfg(not(target_family = "wasm"))] // Keep cfg consistent with the problems function
async fn test_problems() {
let lsp = DotrainAddOrderLsp::new(get_text_document(), HashMap::new());
let problems = lsp.problems("https://rpc.com", None, None).await;

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider using a mock or configurable RPC URL.

While the test correctly exercises the problems method, using a hardcoded URL "https://rpc.com" might be problematic if the code actually tries to connect to it.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[tokio::test]
#[cfg(not(target_family = "wasm"))] // Keep cfg consistent with the problems function
async fn test_problems() {
let lsp = DotrainAddOrderLsp::new(get_text_document(), HashMap::new());
let problems = lsp.problems("https://rpc.com", None, None).await;
#[tokio::test]
#[cfg(not(target_family = "wasm"))] // Keep cfg consistent with the problems function
async fn test_problems() {
let lsp = DotrainAddOrderLsp::new(get_text_document(), HashMap::new());
// Use a clearly fake URL or environment variable for testing
let problems = lsp.problems("http://localhost:invalid-test-url", None, None).await;

Comment on lines +223 to +237
let expected_msgs = vec![
"invalid reference to binding: raindex-subparser, only literal bindings can be referenced",
"invalid expression line",
"invalid expression line",
"invalid word pattern: ABC",
"elided binding 'fixed-io-output-token': The output token that the fixed io is for. If this doesn't match the runtime output then the fixed-io will be inverted.",
"elided binding 'fixed-io': The io ratio for the limit order.",
"undefined word: test",
"unexpected token",
];
let actual_msgs: Vec<String> = problems.iter().map(|p| p.msg.clone()).collect();

assert_eq!(problems.len(), 8);
assert_eq!(actual_msgs, expected_msgs, "Mismatch in problem messages");
}
Copy link
Contributor

@coderabbitai coderabbitai bot May 1, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Thorough validation of problem detection.

The test effectively validates both the number of problems and their specific messages, which is excellent for ensuring the error detection logic works correctly. Consider extending it to also check problem positions and error codes for more complete validation.

 assert_eq!(problems.len(), 8);
 assert_eq!(actual_msgs, expected_msgs, "Mismatch in problem messages");
+
+ // Also validate positions and error codes for complete testing
+ let expected_codes = vec![
+     /* Add expected error codes here */
+ ];
+ let actual_codes: Vec<_> = problems.iter().map(|p| p.code).collect();
+ assert_eq!(actual_codes, expected_codes, "Mismatch in error codes");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let expected_msgs = vec![
"invalid reference to binding: raindex-subparser, only literal bindings can be referenced",
"invalid expression line",
"invalid expression line",
"invalid word pattern: ABC",
"elided binding 'fixed-io-output-token': The output token that the fixed io is for. If this doesn't match the runtime output then the fixed-io will be inverted.",
"elided binding 'fixed-io': The io ratio for the limit order.",
"undefined word: test",
"unexpected token",
];
let actual_msgs: Vec<String> = problems.iter().map(|p| p.msg.clone()).collect();
assert_eq!(problems.len(), 8);
assert_eq!(actual_msgs, expected_msgs, "Mismatch in problem messages");
}
assert_eq!(problems.len(), 8);
assert_eq!(actual_msgs, expected_msgs, "Mismatch in problem messages");
// Also validate positions and error codes for complete testing
let expected_codes = vec![
/* Add expected error codes here */
];
let actual_codes: Vec<_> = problems.iter().map(|p| p.code).collect();
assert_eq!(actual_codes, expected_codes, "Mismatch in error codes");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need to do this

Copy link
Contributor

Choose a reason for hiding this comment

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

@findolor Understood, no problem! The existing validation in your test is already thorough in checking both the number and content of error messages.

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