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

feat(sozo): ensure sozo errors with dojo-core version mismatch #2364

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Aug 29, 2024

Description

When the toolchain version changed (dojoup -v 1.0.0-alpha.8), the dependency on dojo inside the Scarb.toml must also change. To avoid weird error messages, sozo is now throwing an error if the dojo-core version mismatches the dependency version set by the user in Scarb.toml.

Summary by CodeRabbit

  • New Features
    • Introduced a version validation check for the "dojo" dependency across packages during build and test processes, enhancing package management robustness.
  • Bug Fixes
    • Improved error handling for version mismatches, providing clearer feedback on expected versions and paths to package manifests.
  • Chores
    • Updated the version of the dojo_examples package from "1.0.0-alpha.4" to "1.0.0-alpha.8".

Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

Ohayo, sensei! The changes introduce a new function, check_package_dojo_version, which verifies the version of the "dojo" dependency in specified packages. This function is integrated into both the build and test processes, enhancing the validation of package versions before proceeding with further operations. The implementation ensures that version mismatches are identified early, improving the overall reliability of package management.

Changes

Files Change Summary
bin/sozo/src/commands/build.rs Added a call to check_package_dojo_version in the BuildArgs implementation to validate package versions.
bin/sozo/src/commands/mod.rs Introduced check_package_dojo_version function to verify "dojo" dependency versions in packages.
bin/sozo/src/commands/test.rs Added a call to check_package_dojo_version in the TestArgs implementation for package validation.
examples/spawn-and-move/Scarb.toml Updated version number from "1.0.0-alpha.4" to "1.0.0-alpha.8" for the dojo_examples package.

Sequence Diagram(s)

sequenceDiagram
    participant Workspace
    participant Package
    participant BuildArgs
    participant TestArgs
    participant check_package_dojo_version

    Workspace->>+BuildArgs: Iterates over packages
    BuildArgs->>+check_package_dojo_version: Call to check version
    check_package_dojo_version->>Package: Verify "dojo" version
    Package-->>-check_package_dojo_version: Return version status
    check_package_dojo_version-->>-BuildArgs: Return validation result
    BuildArgs-->>-Workspace: Proceed with build

    Workspace->>+TestArgs: Iterates over packages
    TestArgs->>+check_package_dojo_version: Call to check version
    check_package_dojo_version->>Package: Verify "dojo" version
    Package-->>-check_package_dojo_version: Return version status
    check_package_dojo_version-->>-TestArgs: Return validation result
    TestArgs-->>-Workspace: Proceed with tests
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e59aa57 and f1041ba.

Files ignored due to path filters (1)
  • examples/spawn-and-move/Scarb.lock is excluded by !**/*.lock
Files selected for processing (2)
  • bin/sozo/src/commands/mod.rs (2 hunks)
  • examples/spawn-and-move/Scarb.toml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bin/sozo/src/commands/mod.rs
Additional comments not posted (1)
examples/spawn-and-move/Scarb.toml (1)

4-4: Ohayo, sensei! Version update looks good.

The version number has been updated to "1.0.0-alpha.8". Ensure that this version update is consistent with the changes in the codebase and that no other dependencies are affected.


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.

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.

@glihm glihm changed the title feat: ensure sozo errors with dojo-core version mismatch feat(sozo): ensure sozo errors with dojo-core version mismatch Aug 29, 2024
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: 3

Comment on lines 137 to 167
pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyhow::Result<()> {
if let Some(dojo_dep) =
package.manifest.summary.dependencies.iter().find(|dep| dep.name.as_str() == "dojo")
{
let dojo_version = env!("CARGO_PKG_VERSION");

if !dojo_dep.to_string().contains(dojo_version) {
if let Ok(cp) = ws.current_package() {
let path =
if cp.id == package.id { package.manifest_path() } else { ws.manifest_path() };

anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
path
)
} else {
// Virtual workspace.
anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
ws.manifest_path()
)
}
}
}

Ok(())
}
Copy link

Choose a reason for hiding this comment

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

Refactor for readability and enhance error message.

The function is well-structured but can be optimized by reducing the number of nested if statements. Additionally, the error message can be more descriptive.

Apply this diff to refactor the function and enhance the error message:

pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyhow::Result<()> {
    if let Some(dojo_dep) = package.manifest.summary.dependencies.iter().find(|dep| dep.name.as_str() == "dojo") {
        let dojo_version = env!("CARGO_PKG_VERSION");

        if !dojo_dep.to_string().contains(dojo_version) {
            let path = match ws.current_package() {
                Ok(cp) if cp.id == package.id => package.manifest_path(),
                _ => ws.manifest_path(),
            };

            anyhow::bail!(
                "Found dojo-core version mismatch: expected version {}. Please verify your dojo dependency in {}",
                dojo_version,
                path
            );
        }
    }

    Ok(())
}
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
pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyhow::Result<()> {
if let Some(dojo_dep) =
package.manifest.summary.dependencies.iter().find(|dep| dep.name.as_str() == "dojo")
{
let dojo_version = env!("CARGO_PKG_VERSION");
if !dojo_dep.to_string().contains(dojo_version) {
if let Ok(cp) = ws.current_package() {
let path =
if cp.id == package.id { package.manifest_path() } else { ws.manifest_path() };
anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
path
)
} else {
// Virtual workspace.
anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
ws.manifest_path()
)
}
}
}
Ok(())
}
pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyhow::Result<()> {
if let Some(dojo_dep) = package.manifest.summary.dependencies.iter().find(|dep| dep.name.as_str() == "dojo") {
let dojo_version = env!("CARGO_PKG_VERSION");
if !dojo_dep.to_string().contains(dojo_version) {
let path = match ws.current_package() {
Ok(cp) if cp.id == package.id => package.manifest_path(),
_ => ws.manifest_path(),
};
anyhow::bail!(
"Found dojo-core version mismatch: expected version {}. Please verify your dojo dependency in {}",
dojo_version,
path
);
}
}
Ok(())
}

Comment on lines +86 to +88
for p in &packages {
check_package_dojo_version(&ws, p)?;
}
Copy link

Choose a reason for hiding this comment

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

Add logging for better traceability.

The function call to check_package_dojo_version is correctly placed. However, adding a log statement to indicate the package being checked would improve traceability.

Apply this diff to add a log statement:

for p in &packages {
+    tracing::info!("Checking dojo version for package: {}", p.name);
    check_package_dojo_version(&ws, p)?;
}
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
for p in &packages {
check_package_dojo_version(&ws, p)?;
}
for p in &packages {
tracing::info!("Checking dojo version for package: {}", p.name);
check_package_dojo_version(&ws, p)?;
}

Comment on lines +62 to +64
for p in &packages {
check_package_dojo_version(&ws, p)?;
}
Copy link

Choose a reason for hiding this comment

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

Add logging for better traceability.

The function call to check_package_dojo_version is correctly placed. However, adding a log statement to indicate the package being checked would improve traceability.

Apply this diff to add a log statement:

for p in &packages {
+    tracing::info!("Checking dojo version for package: {}", p.name);
    check_package_dojo_version(&ws, p)?;
}
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
for p in &packages {
check_package_dojo_version(&ws, p)?;
}
for p in &packages {
tracing::info!("Checking dojo version for package: {}", p.name);
check_package_dojo_version(&ws, p)?;
}

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 45.94595% with 20 lines in your changes missing coverage. Please review.

Project coverage is 67.47%. Comparing base (13cee86) to head (f1041ba).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
bin/sozo/src/commands/mod.rs 45.45% 18 Missing ⚠️
bin/sozo/src/commands/test.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2364      +/-   ##
==========================================
- Coverage   67.49%   67.47%   -0.03%     
==========================================
  Files         359      359              
  Lines       46971    47002      +31     
==========================================
+ Hits        31704    31715      +11     
- Misses      15267    15287      +20     

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

@glihm glihm merged commit 1d32ab1 into dojoengine:main Aug 29, 2024
13 of 15 checks passed
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.

1 participant