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

fix(sozo): return error if inspect doesn't find resource #2920

Merged
merged 3 commits into from
Jan 18, 2025

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Jan 17, 2025

If sozo inspect doesn't find a resource, it returns an error. Also, if the provider is not healthy, sozo inspect checks only the local resources.

This is a good way to check if some external contracts have been correctly added to the Scarb.toml.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for additional external contracts in the build process.
    • Introduced a new test function for dungeon feature testing.
  • CI/CD Updates

    • Renamed GitHub workflow job for improved clarity.
    • Enhanced CI workflow with additional build and inspection commands.
  • Technical Improvements

    • Updated error handling and logging strategies in command utilities.
    • Modified resource inspection to better propagate errors.
    • Adjusted test expectations to reflect increased model counts.

Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

Ohayo, sensei! This pull request introduces enhancements to the Dojo project's CI workflow, modifies the sozo command functionality, and expands the spawn-and-move example. Key changes include updating the CI configuration with new commands, improving error handling in the inspect command, adjusting logging levels in utility functions, and extending the list of external contracts in the Scarb.toml file. Additionally, a new test function for the dungeon feature has been added to enhance testing capabilities.

Changes

File Change Summary
.github/workflows/ci.yml Renamed job from dojo-spawn-and-move-example-test to dojo-examples-test and added new sozo build and inspect commands targeting specific namespaces.
bin/sozo/src/commands/inspect.rs Updated inspect_resource function to return Result<()> for better error propagation.
bin/sozo/src/utils.rs Changed logging from error to warn and simplified provider health check error handling.
examples/spawn-and-move/Scarb.toml Extended build-external-contracts to include armory::m_Flatbow and bestiary::m_RiverSkale.
examples/spawn-and-move/src/actions.cairo Added new test_feature_dungeon test function with dungeon namespace resources.
crates/dojo/bindgen/src/lib.rs Updated test assertion in gather_data_ok to expect 8 models instead of 6.
crates/torii/indexer/src/test.rs Modified assertion in test_load_from_remote to expect 10 models instead of 8.

Sequence Diagram

sequenceDiagram
    participant CI as GitHub Actions
    participant Sozo as Sozo Binary
    participant Build as Build Process
    participant Test as Test Execution

    CI->>Sozo: Run build command
    Sozo->>Build: Build external contracts
    Build-->>Sozo: Build complete
    Sozo->>Sozo: Inspect resources
    Sozo->>Test: Execute tests
    Test-->>CI: Report results
Loading

Possibly related PRs

Suggested labels

sozo, contributor


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2a1c30 and f191927.

⛔ Files ignored due to path filters (1)
  • examples/game-lib/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/dojo/bindgen/src/lib.rs (1 hunks)
  • crates/torii/indexer/src/test.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ensure-wasm
  • GitHub Check: clippy
  • GitHub Check: docs
🔇 Additional comments (2)
crates/dojo/bindgen/src/lib.rs (1)

265-265: Ohayo sensei! Verify the updated model count assertion.

The test now expects 8 models instead of the previous 6. Please ensure this change aligns with the actual number of models in the spawn-and-move example.

crates/torii/indexer/src/test.rs (1)

143-143: Ohayo sensei! Verify the updated database model count.

The test now expects 10 models in the database instead of 8. This change should be validated against the actual number of models being created during the test setup.

✅ Verification successful

Ohayo sensei! The model count update is valid.

The test creates a fresh database and bootstraps it with world data. The change from 8 to 10 models reflects the current state of model initialization in the test environment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the total number of models in the database schema
# Expected: Should find 10 model-related tables or definitions

# Search for model-related database operations in the migrations
rg -A 5 "CREATE TABLE.*model" "../migrations/"

Length of output: 101


Script:

#!/bin/bash
# Find migrations directory
fd -t d migrations

# Examine the test file for model setup
rg -B 5 -A 5 "assert_eq.*models\.len\(\)" "crates/torii/indexer/src/test.rs"

# Look for model creation or setup code
ast-grep --pattern 'fn test_load_from_remote() {
  $$$
}'

Length of output: 668


Script:

#!/bin/bash
# Check migrations for model table definition
rg -A 5 "CREATE TABLE" "crates/torii/migrations/"

# Look for model initialization or setup in test file
rg -B 10 "bootstrap_engine" "crates/torii/indexer/src/test.rs"

# Check world reader setup which might contain model definitions
ast-grep --pattern 'let world_reader = $_'

Length of output: 16811


🪧 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. (Beta)
  • @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.

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

🧹 Nitpick comments (2)
examples/spawn-and-move/src/actions.cairo (1)

323-355: Ohayo sensei! Let's make this test more robust!

While the test setup is well-structured, it could benefit from additional verifications:

  1. Add assertions to verify the state after entering the dungeon
  2. Consider testing error scenarios (e.g., invalid dungeon address)

Here's a suggested enhancement:

 actions_system.enter_dungeon(dungeon_addr);
+
+// Verify Flatbow was created correctly
+let flatbow: armory::Flatbow = world.read_model(1);
+assert(flatbow.atk_speek == 2, 'wrong flatbow attack speed');
+assert(flatbow.range == 1, 'wrong flatbow range');
+
+// Verify RiverSkale was created correctly
+let river_skale: bestiary::RiverSkale = world.read_model(1);
+assert(river_skale.health == 5, 'wrong river_skale health');
+assert(river_skale.armor == 3, 'wrong river_skale armor');
+assert(river_skale.attack == 2, 'wrong river_skale attack');
+
+// Add error case
+let invalid_dungeon = starknet::contract_address_const::<0x0>();
+should_panic(
+    || { actions_system.enter_dungeon(invalid_dungeon); },
+    'should fail with invalid dungeon'
+);
bin/sozo/src/utils.rs (1)

120-126: Ohayo sensei! Nice improvement to error handling!

The change from error to warning level is appropriate here since the code gracefully falls back to local inspection. The message is also more informative about the implications.

Consider adding a trace log with the actual error from the health check for debugging purposes:

 if (provider_utils::health_check_provider(provider.clone()).await).is_err() {
+    trace!(target: LOG_TARGET, "Provider health check failed with error: {:?}", err);
     warn!(target: LOG_TARGET, "Provider health check failed during sozo inspect, inspecting locally and all resources will appeared as `Created`. Remote resources will not be fetched.");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 051e2e8 and 89d9f15.

⛔ Files ignored due to path filters (3)
  • bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock is excluded by !**/*.lock
  • crates/dojo/core-cairo-test/Scarb.lock is excluded by !**/*.lock
  • examples/spawn-and-move/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .github/workflows/ci.yml (2 hunks)
  • bin/sozo/src/commands/inspect.rs (4 hunks)
  • bin/sozo/src/utils.rs (2 hunks)
  • examples/spawn-and-move/Scarb.toml (1 hunks)
  • examples/spawn-and-move/src/actions.cairo (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (4)
examples/spawn-and-move/src/actions.cairo (1)

231-231: Ohayo! Import looks good, sensei!

The dungeon module import is properly placed and follows the crate's module structure.

bin/sozo/src/commands/inspect.rs (2)

169-169: Ohayo sensei! Great improvement to error handling!

Converting the function to return Result<()> and propagating the error is a much better approach than just printing a message. This allows callers to handle the "resource not found" case appropriately.

Also applies to: 178-178


245-245: Clean implementation of the success case!

The addition of Ok(()) properly completes the Result return type implementation.

.github/workflows/ci.yml (1)

153-155: Ohayo sensei! CI changes look solid!

The addition of sozo build and sozo inspect commands for the new namespaces ensures proper testing of both the external contracts and the enhanced inspect functionality.

@@ -10,7 +10,7 @@ edition = "2024_07"
sierra-replace-ids = true

[[target.starknet-contract]]
build-external-contracts = [ "dojo::world::world_contract::world" ]
build-external-contracts = [ "dojo::world::world_contract::world", "armory::m_Flatbow", "bestiary::m_RiverSkale" ]
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Ohayo sensei! We've got some missing contracts!

The external contracts armory::m_Flatbow and bestiary::m_RiverSkale referenced in build-external-contracts don't exist in the repository. Please ensure:

  • The contract files are implemented and added to the repository
  • The module names are correct
  • Any required dependencies are properly set up
🔗 Analysis chain

Ohayo sensei! External contracts addition looks good!

The new external contracts armory::m_Flatbow and bestiary::m_RiverSkale are properly added and align with the declared dependencies.

Let's verify that these modules exist in the referenced paths:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the external contract modules exist
fd -t f "m_Flatbow.cairo$" "../game-lib/armory"
fd -t f "m_RiverSkale.cairo$" "../game-lib/bestiary"

Length of output: 314


Script:

#!/bin/bash
# Search for the contract files in the repository
fd -t f "m_Flatbow.cairo$"
fd -t f "m_RiverSkale.cairo$"

# Also check if these are referenced in any other configuration files
rg "m_Flatbow|m_RiverSkale" -t toml

Length of output: 248

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.

Project coverage is 55.91%. Comparing base (30e574c) to head (f191927).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
bin/sozo/src/utils.rs 0.00% 5 Missing ⚠️
bin/sozo/src/commands/inspect.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2920   +/-   ##
=======================================
  Coverage   55.90%   55.91%           
=======================================
  Files         443      443           
  Lines       57190    57192    +2     
=======================================
+ Hits        31973    31978    +5     
+ Misses      25217    25214    -3     

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

@glihm glihm merged commit 74ccf13 into main Jan 18, 2025
14 of 15 checks passed
@glihm glihm deleted the sozo/test-cairo-feature branch January 18, 2025 04:30
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