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): model get not using prefixes #2867

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

emarc99
Copy link

@emarc99 emarc99 commented Jan 6, 2025

Description

Related issue

Closes #2835

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Enhanced key input flexibility for model retrieval
    • Added support for short string and hexadecimal key formats
    • Improved key decoding functionality
  • Documentation

    • Updated help descriptions for model commands
    • Clarified accepted key input formats
  • Tests

    • Added unit tests for key decoding functionality

Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

Ohayo, sensei! The pull request introduces enhancements to the sozo model get command, focusing on improving key input flexibility. The changes primarily modify the ModelCommand::Get command to support more versatile key input formats, including short string prefixes and decoding mechanisms. The modifications aim to make key input more user-friendly and robust.

Changes

File Change Summary
bin/sozo/src/commands/model.rs - Updated Get command's keys argument type from Vec<Felt> to String
- Added key decoding using calldata_decoder::decode_calldata
- Introduced support for sstr: prefix for short strings
bin/sozo/src/commands/mod.rs - Reformatted Migrate command documentation string to multi-line format
bin/sozo/src/commands/auth.rs - Refactored code structure in clone_permissions function for improved readability

Assessment against linked issues

Objective Addressed Explanation
Support prefix parsing for sozo model get
Handle short string inputs with sstr: prefix

The changes directly address the requirements outlined in issue #2835, implementing prefix parsing and decoding for the model get command.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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

🧹 Nitpick comments (2)
bin/sozo/src/commands/model.rs (2)

113-116: Ohayo sensei! Nice usage of multi-line help docs.
This enhanced help text clearly explains how to supply comma-separated values with various prefixes. The additional detail helps users form correct input on the command line.


214-215: Sensei, consider robust error handling.
You raise an error if decode_calldata fails. That's good. If you anticipate user mistakes frequently, you might provide a more descriptive error or usage example upon failure.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ddee9e and 69d83d0.

📒 Files selected for processing (3)
  • bin/sozo/src/commands/auth.rs (3 hunks)
  • bin/sozo/src/commands/mod.rs (1 hunks)
  • bin/sozo/src/commands/model.rs (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • bin/sozo/src/commands/mod.rs
🔇 Additional comments (8)
bin/sozo/src/commands/model.rs (4)

3-3: Ohayo sensei! Great addition for the decoder import.
The import of calldata_decoder sets the foundation for decoding user input with flexible prefixes. This is useful for supporting short-string notation and conventional felts.


117-117: Sensei, verify the impact of switching from Vec to String.
Swapping from Vec<Felt> to String is beneficial for user-friendly input, but ensure that usage sites (including tests and other commands) are updated accordingly.


126-128: Ohayo sensei! Thorough documentation for the block argument.
No issues spotted; the docstring clarifies the usage of a block number or a pending block. Looks good to merge.


233-264: Ohayo sensei! Impressive test coverage for short strings and hex validation.
Testing both short-string prefixes and hex-to-decimal conversions is crucial. The tests confirm that your new input format is working as intended.

bin/sozo/src/commands/auth.rs (4)

245-249: Sensei, good clarity in the resource filtering condition.
The explicit if checks improve readability compared to a one-liner.


258-262: Ohayo sensei! Consistent approach for filtering owners.
Following the same pattern for owners and writers helps maintain a uniform code style.


314-320: Sensei, verifying name resolution for external writers.
You map resource selectors to hex strings or “World” if they match WORLD. This is clear. Make sure there’s no confusion about which resources are truly global.


321-327: Ohayo sensei! Good consistency in naming for external owners.
Repeating the same logic for owners ensures symmetrical permission logic for resource tagging.

@emarc99 emarc99 marked this pull request as draft January 6, 2025 09:07
@emarc99 emarc99 marked this pull request as ready for review January 6, 2025 09:35
@emarc99 emarc99 marked this pull request as draft January 6, 2025 13:39
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.

Thank you for taking the time on this @emarc99!

Some comments, please don't hesitate if you have any questions.

Comment on lines +113 to +116
#[arg(help = "Comma separated values e.g., \
0x12345,0x69420,sstr:\"hello\",sstr:\"misty\". Supported prefixes:\n \
- sstr: A cairo short string\n \
- no prefix: A cairo felt")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the case of the keys, only one felt long serialized type are supported (everything that can fit in one felt).

That's great you've only put the sstr which is the only one supported actually.

Suggested change
#[arg(help = "Comma separated values e.g., \
0x12345,0x69420,sstr:\"hello\",sstr:\"misty\". Supported prefixes:\n \
- sstr: A cairo short string\n \
- no prefix: A cairo felt")]
#[arg(help = "Comma separated values e.g., \
0x12345,0x69420,sstr:\"hello\". Supported prefixes:\n \
- sstr: A cairo short string\n \
- no prefix: A cairo felt")]

Copy link
Collaborator

Choose a reason for hiding this comment

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

We may add a check that only this prefix is actually used, wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, the check will be quite useful. I'll add it.

@@ -222,3 +230,35 @@ impl ModelArgs {
})
}
}

#[cfg(test)]
mod tests {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for thinking about tests.

In the current context, this test should already be covered into the calldata_decoder file. We can remove this one. 👍

You could write a test on the argument though.

Copy link
Author

Choose a reason for hiding this comment

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

Awesome, that'll be the better option. These tests were meant to go away eventually.

@glihm
Copy link
Collaborator

glihm commented Jan 8, 2025

Don't forget to run the scripts/ for the linter. They are in the repository scripts/ folder.

@emarc99
Copy link
Author

emarc99 commented Jan 8, 2025

Don't forget to run the scripts/ for the linter. They are in the repository scripts/ folder.

Noted, sir.

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.

[BUG] Sozo model get is not using prefixes
2 participants