Skip to content

Fix scenario blocks field parsing bug#1646

Merged
hardyjosh merged 4 commits intomainfrom
2025-04-10-scenario-block-parsing-yaml
Apr 10, 2025
Merged

Fix scenario blocks field parsing bug#1646
hardyjosh merged 4 commits intomainfrom
2025-04-10-scenario-block-parsing-yaml

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Apr 10, 2025

Motivation

See issue: #1644

Solution

  • Properly parse blocks field and use validate_blocks function to get correct BlockCfg value
  • Add tests

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 #1644

Summary by CodeRabbit

  • New Features

    • Enhanced block configuration flexibility, allowing users to specify block settings using both string and hash formats.
  • Refactor

    • Updated field visibility for improved access to block range settings.
  • Tests

    • Introduced new tests to validate the parsing of diverse block configuration scenarios.

@findolor findolor added bug Something isn't working rust Related to rust crates labels Apr 10, 2025
@findolor findolor requested a review from hardyjosh April 10, 2025 11:03
@findolor findolor self-assigned this Apr 10, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2025

Walkthrough

The pull request modifies block configuration processing in two ways. In crates/settings/src/blocks.rs, the BlockRangeCfg struct now exposes its start and end fields publicly, enabling external access. In crates/settings/src/scenario.rs, the handling of blocks in ScenarioCfg is enhanced to accept both string and hash formats. This change includes error handling for missing keys (range and interval) and a new test to validate various YAML configurations.

Changes

File(s) Change Summary
crates/settings/src/blocks.rs Updated BlockRangeCfg: made start and end fields public.
crates/settings/src/scenario.rs Enhanced ScenarioCfg: enabled blocks field to accept string and hash formats, added error handling for missing range/interval, and added test.

Sequence Diagram(s)

sequenceDiagram
    participant YAML
    participant Parser
    participant Validator

    YAML->>Parser: Provide YAML scenario config with blocks field
    alt blocks provided as string
        Parser->>Validator: Validate blocks string format
    else blocks provided as hash
        Parser->>Parser: Extract "range" and "interval" using get_hash_value
        Parser->>Validator: Validate constructed blocks string
    end
    Validator-->>Parser: Return validation result
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct parsing of block field in scenario YAML (#1644)

📜 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 e61a33f and ed7a56d.

📒 Files selected for processing (1)
  • crates/settings/src/scenario.rs (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1646
File: crates/settings/src/blocks.rs:34-35
Timestamp: 2025-04-10T11:08:26.317Z
Learning: The `start` and `end` fields in the `BlockRangeCfg` struct should be public as this is necessary for proper scenario blocks field parsing functionality.
crates/settings/src/scenario.rs (1)
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1646
File: crates/settings/src/scenario.rs:1-1
Timestamp: 2025-04-10T11:08:33.383Z
Learning: Wildcard imports (using `*`) are acceptable in the rain.orderbook codebase, as per the author's preference.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: Deploy-Preview
🔇 Additional comments (1)
crates/settings/src/scenario.rs (1)

114-137: Well-implemented fix for block configuration parsing.

The implementation now correctly handles both string and hash formats for the blocks field, addressing the parsing bug. The code extracts range and interval values from hash configurations and properly formats them for validation, with appropriate error handling for missing keys.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown
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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b05823 and e61a33f.

📒 Files selected for processing (2)
  • crates/settings/src/blocks.rs (1 hunks)
  • crates/settings/src/scenario.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean
🔇 Additional comments (1)
crates/settings/src/scenario.rs (1)

560-563: These imports appear valid and are used in subsequent tests.
No issues noted; the added imports for BlockCfg, BlockRangeCfg, and mock_deployer are appropriate for the tested functionality.

Comment thread crates/settings/src/blocks.rs
Comment thread crates/settings/src/scenario.rs
Comment thread crates/settings/src/scenario.rs Outdated
Comment thread crates/settings/src/scenario.rs
@hardyjosh hardyjosh enabled auto-merge April 10, 2025 15:00
@hardyjosh hardyjosh merged commit 826ef8a into main Apr 10, 2025
17 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 rust Related to rust crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect parsing of block field in scenario yaml

2 participants