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

Export setup module under test-utils feature #2247

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Conversation

kariy
Copy link
Member

@kariy kariy commented Aug 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced conditional instantiation of services based on feature flags, enhancing configuration flexibility.
    • Added a new test_utils module to improve testing capabilities with utility functions.
    • Created a public setup module for streamlined test setups.
  • Bug Fixes

    • Improved organization of import statements across test files for better readability and maintainability.
  • Chores

    • Refactored import statements for cleaner code and reduced redundancy in test files.
    • Adjusted module visibility for better encapsulation of test modules.

Copy link

coderabbitai bot commented Aug 1, 2024

Walkthrough

Ohayo, sensei! The recent changes enhance the configurability and modularity of the codebase. Key modifications include the conditional instantiation of the NodeService, new testing utilities within sozo, and a reorganization of import statements in various test files. These adjustments improve clarity, reduce redundancy, and facilitate better testing practices, ultimately streamlining the development process.

Changes

Files Change Summary
crates/katana/node/src/lib.rs Modified NodeService instantiation to conditionally include the messaging parameter based on a feature flag.
crates/sozo/ops/Cargo.toml Added new dependencies (dojo-test-utils, katana-runner) and defined test-utils feature for modular testing.
crates/sozo/ops/src/lib.rs Introduced a new test_utils module, conditionally compiled for enhanced testing capabilities.
crates/sozo/ops/src/test_utils/mod.rs Added setup module within test_utils for encapsulating setup functionality in tests.
crates/sozo/ops/src/tests/auth.rs Cleaned up import statements for improved readability without changing functionality.
crates/sozo/ops/src/tests/call.rs Streamlined imports and reformatted assertions for clarity while maintaining logic.
crates/sozo/ops/src/tests/migration.rs Reorganized imports and refined assertion syntax without altering test logic.
crates/sozo/ops/src/tests/mod.rs Changed visibility of multiple test modules from public to private, enhancing encapsulation.
crates/sozo/ops/src/tests/model.rs Adjusted import structure, adding setup from crate::test_utils for better organization.
crates/sozo/ops/src/tests/utils.rs Modified imports to streamline dependencies without affecting functionality.

Sequence Diagram(s)

sequenceDiagram
    participant A as Client
    participant B as NodeService
    participant C as Messaging

    A->>B: Start NodeService
    alt Messaging Enabled
        A->>B: Create with Messaging
        B->>C: Initialize Messaging
    else Messaging Disabled
        A->>B: Create without Messaging
    end
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 60e3b68 and 7540dae.

Files selected for processing (5)
  • crates/sozo/ops/src/tests/auth.rs (1 hunks)
  • crates/sozo/ops/src/tests/call.rs (1 hunks)
  • crates/sozo/ops/src/tests/migration.rs (1 hunks)
  • crates/sozo/ops/src/tests/model.rs (1 hunks)
  • crates/sozo/ops/src/tests/utils.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • crates/sozo/ops/src/tests/model.rs
  • crates/sozo/ops/src/tests/utils.rs
Files skipped from review as they are similar to previous changes (3)
  • crates/sozo/ops/src/tests/auth.rs
  • crates/sozo/ops/src/tests/call.rs
  • crates/sozo/ops/src/tests/migration.rs

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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@kariy kariy requested a review from glihm August 1, 2024 16:57
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, codebase verification and nitpick comments (5)
crates/sozo/ops/src/tests/mod.rs (5)

1-1: Ohayo sensei! The auth module cannot be made private.

The auth module is used in multiple locations outside of crates/sozo/ops/src/tests/mod.rs, including:

  • crates/sozo/ops/src/migration/migrate.rs
  • crates/sozo/ops/src/migration/auto_auth.rs
  • crates/sozo/ops/src/migration/utils.rs
  • bin/sozo/src/commands/mod.rs
  • bin/sozo/src/commands/auth.rs

Making the auth module private will break these references.

Analysis chain

Verify the impact of making auth module private.

The auth module is now private to the current module. Ensure that no external code relies on this module being public.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no external code relies on the `auth` module being public.

# Test: Search for external usage of the `auth` module. Expect: No occurrences of external usage.
rg --type rust 'auth::' --glob '!crates/sozo/ops/src/tests/mod.rs'

Length of output: 3818


5-5: Ohayo, sensei!

The setup module is still being used extensively across multiple test files. Removing the setup module declaration without addressing its usage will break these tests.

  • Files impacted:
    • crates/sozo/ops/src/tests/auth.rs
    • crates/sozo/ops/src/tests/migration.rs
    • crates/sozo/ops/src/tests/utils.rs
    • crates/sozo/ops/src/tests/model.rs
    • crates/sozo/ops/src/tests/call.rs

Please ensure to either reintroduce the setup module or refactor the tests to remove dependencies on it.

Analysis chain

Verify the impact of removing the setup module declaration.

The setup module declaration has been removed. Ensure that no external code relies on this module.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no external code relies on the `setup` module.

# Test: Search for external usage of the `setup` module. Expect: No occurrences of external usage.
rg --type rust 'setup::'

Length of output: 3377


4-4: Ohayo, sensei!

The model module is being used in various places outside of crates/sozo/ops/src/tests/mod.rs. Making this module private will break these dependencies. Please consider making the model module public again or refactor the code to avoid external dependencies on this module.

  • External usages found:
    • crates/torii/libp2p/src/tests.rs
    • crates/torii/graphql/src/tests/mod.rs
    • crates/torii/graphql/src/schema.rs
    • crates/sozo/ops/src/auth.rs
    • crates/sozo/ops/src/register.rs
    • crates/dojo-world/src/manifest/mod.rs
    • crates/dojo-world/src/contracts/world.rs
    • crates/dojo-world/src/contracts/model.rs
    • crates/dojo-world/src/contracts/abi/model.rs
    • crates/dojo-lang/src/introspect/ty.rs
    • crates/dojo-lang/src/introspect/mod.rs
    • crates/dojo-lang/src/introspect/layout.rs
    • crates/dojo-lang/src/introspect/size.rs
    • crates/dojo-bindgen/src/lib.rs
    • crates/dojo-lang/src/plugin.rs
    • crates/dojo-lang/src/model.rs
    • crates/dojo-lang/src/event.rs
    • bin/sozo/src/commands/model.rs
    • bin/sozo/src/commands/mod.rs
Analysis chain

Verify the impact of making model module private.

The model module is now private to the current module. Ensure that no external code relies on this module being public.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no external code relies on the `model` module being public.

# Test: Search for external usage of the `model` module. Expect: No occurrences of external usage.
rg --type rust 'model::' --glob '!crates/sozo/ops/src/tests/mod.rs'

Length of output: 21129


2-2: Ohayo sensei,

Making the call module private will break external references.

The call module is used in:

  • bin/sozo/src/commands/call.rs for invoking the call function.
  • bin/sozo/src/commands/mod.rs for importing CallArgs.

Making this module private will disrupt these references and break the functionality.

Analysis chain

Verify the impact of making call module private.

The call module is now private to the current module. Ensure that no external code relies on this module being public.


Ohayo sensei,

Verify the impact of making call module private.

The call module is referenced in bin/sozo/src/commands. We need to ensure that making it private won't break functionality. Let's gather more information about the context of these references.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no external code relies on the `call` module being public.

# Test: Search for external usage of the `call` module. Expect: No occurrences of external usage.
rg --type rust 'call::' --glob '!crates/sozo/ops/src/tests/mod.rs'

Length of output: 600


Script:

#!/bin/bash
# Description: Gather more detailed information about the usage context of `call` in `bin/sozo/src/commands`.

# Display the lines around the usage of `call` in `bin/sozo/src/commands/mod.rs` and `bin/sozo/src/commands/call.rs`.
rg --type rust -A 5 -B 5 'call::' bin/sozo/src/commands/mod.rs bin/sozo/src/commands/call.rs

Length of output: 1355


3-3: Ohayo, sensei!

The removal of the pub keyword from the migration module declaration has caused issues. There are multiple external references to migration::, which rely on the module being public. Here are some of the affected files:

  • crates/torii/grpc/src/server/tests/entities_test.rs
  • crates/torii/graphql/src/tests/mod.rs
  • crates/torii/core/src/sql_test.rs
  • crates/dojo-world/src/utils.rs
  • crates/sozo/ops/src/tests/model.rs
  • crates/sozo/ops/src/tests/migration.rs
  • crates/sozo/ops/src/test_utils/setup.rs
  • crates/sozo/ops/src/tests/auth.rs
  • crates/sozo/ops/src/utils.rs
  • crates/sozo/ops/src/register.rs
  • crates/dojo-world/src/contracts/world_test.rs
  • crates/sozo/ops/src/migration/auto_auth.rs
  • crates/sozo/ops/src/migration/utils.rs
  • crates/sozo/ops/src/migration/migrate.rs
  • crates/sozo/ops/src/migration/mod.rs
  • crates/saya/core/src/dojo_os/mod.rs
  • crates/sozo/ops/src/execute.rs
  • crates/sozo/ops/src/auth.rs
  • crates/sozo/ops/src/account.rs
  • crates/saya/core/src/verifier/starknet.rs
  • crates/dojo-test-utils/src/migration.rs
  • crates/dojo-world/src/manifest/manifest_test.rs
  • bin/sozo/tests/register_test.rs
  • bin/sozo/src/commands/migrate.rs
  • bin/sozo/src/commands/options/transaction.rs
  • bin/sozo/src/commands/options/account/controller.rs

You might want to reconsider making the migration module public again to avoid these issues.

Analysis chain

Verify the impact of making migration module private.

The migration module is now private to the current module. Ensure that no external code relies on this module being public.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no external code relies on the `migration` module being public.

# Test: Search for external usage of the `migration` module. Expect: No occurrences of external usage.
rg --type rust 'migration::' --glob '!crates/sozo/ops/src/tests/mod.rs'

Length of output: 4619

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

fmt and then let's merge, thanks for the refactoring here.
In-fine we will surely move the setup part into dojo-test-utils actually. As this may be re-used elsewhere too, wdyt? This also avoids the feature here and we will only use the dev dependencies without loading the final binary with test related stuff.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.18%. Comparing base (566ad6c) to head (60e3b68).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2247      +/-   ##
==========================================
+ Coverage   70.14%   70.18%   +0.03%     
==========================================
  Files         343      344       +1     
  Lines       45199    45250      +51     
==========================================
+ Hits        31707    31760      +53     
+ Misses      13492    13490       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy
Copy link
Member Author

kariy commented Aug 1, 2024

In-fine we will surely move the setup part into dojo-test-utils actually. As this may be re-used elsewhere too, wdyt? This also avoids the feature here and we will only use the dev dependencies without loading the final binary with test related stuff.

yeah, good point.

@kariy kariy merged commit 9d694e8 into main Aug 1, 2024
13 checks passed
@kariy kariy deleted the sozo/ops-testutils branch August 1, 2024 18:20
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