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

#267: Added intents depth and size limit #543

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

backsapc
Copy link
Contributor

@backsapc backsapc commented Jul 24, 2024

That's a simplest solution I came up with. I think we can discuss it. We actually can gather info about depth and anything else during Parsing phase, but I'm not sure about that.

#267

Summary by CodeRabbit

  • New Features

    • Introduced a function nesting analysis to evaluate and enforce a maximum nesting depth for function calls in expressions.
    • Added validation logic to the parsing process to check for adherence to specified nesting depth constraints.
    • Defined a maximum nesting depth constant to enhance parsing robustness.
  • Chores

    • Updated the CHANGELOG.md to reflect the new nesting depth constraint of 100 levels.
  • Tests

    • Implemented unit tests for the new validation and analysis functions to ensure correct behavior and coverage.

@backsapc backsapc requested a review from Pitasi July 24, 2024 07:24
@backsapc backsapc self-assigned this Jul 24, 2024
@backsapc backsapc linked an issue Jul 24, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Jul 24, 2024

Walkthrough

Walkthrough

The changes introduce a new mechanism for analyzing and validating the nesting depth of functions within an abstract syntax tree (AST). A dedicated validation function ensures that function calls do not exceed a specified maximum depth, significantly improving code robustness. This is complemented by a set of unit tests that verify the correct implementation of the analysis and validation processes.

Changes

Files Change Summary
shield/internal/validation/functions_nesting_analyzer.go, shield/internal/validation/validation.go, shield/internal/validation/validation_test.go Introduced functions for analyzing function nesting depth and a validation function to enforce a maximum depth limit. Added unit tests for these functionalities.
shield/shield.go Added a constant for maximum nesting depth and integrated validation into the parsing function to check AST depth constraints.
CHANGELOG.md Updated to include a new guideline indicating the maximum allowed nesting depth of 100 for functions, affecting code readability and maintainability.

Sequence Diagram(s)

sequenceDiagram
    participant Parser
    participant Validator
    participant Analyzer
    participant AST

    Parser->>AST: Generate AST
    Parser->>Validator: Validate(AST, MaxNestingDepth)
    Validator->>Analyzer: AnalyzeFunctionsNesting(AST)
    Analyzer-->>Validator: Return current nesting depth
    Validator->>Parser: Return validation result (error or success)
Loading

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

This comment has been minimized.

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

Outside diff range, codebase verification and nitpick comments (1)
shield/internal/validation/validation_test.go (1)

12-24: Enhance error message for better debugging.

Consider adding the input string to the error message for better debugging context.

-    require.FailNow(t, "Parser finished with errors", err)
+    require.FailNow(t, "Parser finished with errors for input: " + input, err)
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8414ec2 and d2a00b0.

Files selected for processing (4)
  • shield/internal/validation/functions_nesting_analyzer.go (1 hunks)
  • shield/internal/validation/validation.go (1 hunks)
  • shield/internal/validation/validation_test.go (1 hunks)
  • shield/shield.go (2 hunks)
Additional context used
Path-based instructions (4)
shield/internal/validation/validation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

shield/internal/validation/functions_nesting_analyzer.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

shield/shield.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

shield/internal/validation/validation_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (12)
shield/internal/validation/validation.go (1)

8-15: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to Validate match the new logic.

Verification successful

LGTM! The function usage in the codebase matches the new logic.

The code changes are approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `Validate` match the new logic.

# Test: Search for the function usage. Expect: Only occurances of the new logic.
rg --type go -A 5 $'Validate'

Length of output: 22689

shield/internal/validation/functions_nesting_analyzer.go (5)

7-22: LGTM!

The code changes are approved.


24-30: LGTM!

The code changes are approved.


33-35: LGTM!

The code changes are approved.


38-42: LGTM!

The code changes are approved.


45-46: LGTM!

The code changes are approved.

shield/shield.go (3)

14-14: LGTM!

The code changes are approved.


21-21: LGTM!

The code changes are approved.


33-35: LGTM!

The code changes are approved.

shield/internal/validation/validation_test.go (3)

26-43: LGTM!

The test cases cover various scenarios of function nesting and the function appears to be comprehensive.


45-61: LGTM!

The test cases cover various scenarios where the validation should fail and the function appears to be comprehensive.


63-81: LGTM!

The test cases cover various scenarios where the validation should succeed and the function appears to be comprehensive.

Copy link

vercel bot commented Jul 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
warden-help-center ⬜️ Ignored (Inspect) Jul 24, 2024 8:03am

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d2a00b0 and b72df77.

Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional context used
Path-based instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (1)
CHANGELOG.md (1)

45-46: Entry is clear and follows the changelog format.

The new entry under "Consensus Breaking Changes" is clear and adheres to the changelog format. No grammatical errors or ambiguities were found.

@Pitasi
Copy link
Contributor

Pitasi commented Jul 25, 2024

for me this doesn't really solve the first point described in #267

the solution would be to stop the parsing if we reach the max depth, while with this implementation does the parsing and then calculates the depth reached - still leading to potential heavyweight transactions

i'd put this issue on hold for a second, since Informal Systems is taking a look at our shield language right now, I'll give them a chance to say whether this is a problem and if they have suggestions :)

Copy link
Contributor

@Pitasi Pitasi left a comment

Choose a reason for hiding this comment

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

marking this as "request changes" to put this on hold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limit rule expressions depth and size
3 participants