Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Mar 21, 2025

fixes #1984

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

📝 Walkthrough

Walkthrough

This pull request refactors the function invocation validation logic and expands its functionality. In the language server package, two new private methods—getExpressionContext and isStaticFunctionCall—are introduced to modularize context determination and static function call validation. Additionally, the SDK package now exports the isValidationAttribute function, and a new regression test suite has been added to verify access control and model validation behavior related to function execution in policies.

Changes

File(s) Change Summary
packages/schema/.../function-invocation-validator.ts Refactored the FunctionInvocationValidator class by adding private methods getExpressionContext and isStaticFunctionCall to improve expression context determination and validate static function calls.
packages/sdk/validation.ts Changed isValidationAttribute from a private function to an exported function without altering its logic.
tests/regression/.../issue-1984.test.ts Added a new regression test suite with three test cases to verify access control policies and model validation rules, particularly for disallowing function execution in specific contexts.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Validator
    Client->>Validator: Invoke function validation
    Validator->>Validator: getExpressionContext(containerAttribute)
    Validator-->>Validator: Return expression context
    alt Context Check
        Validator->>Validator: Evaluate if context is valid (considering funcAllowedContext length)
        Note over Validator: Enhance error message with context details
    end
    alt Static Function Call Detection
        Validator->>Validator: isStaticFunctionCall(expression)
        Validator-->>Validator: Return static check result
    end
    Validator-->>Client: Return validation outcome
Loading

Assessment against linked issues

Objective Addressed Explanation
Functions do not support execution of functions as input [#1984]

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57c6120 and b3cc9a6.

📒 Files selected for processing (3)
  • packages/schema/src/language-server/validator/function-invocation-validator.ts (5 hunks)
  • packages/sdk/src/validation.ts (1 hunks)
  • tests/regression/tests/issue-1984.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/schema/src/language-server/validator/function-invocation-validator.ts (2)
packages/sdk/src/utils.ts (1) (1)
  • getFunctionExpressionContext (429-443)
packages/sdk/src/validation.ts (1) (1)
  • isValidationAttribute (10-12)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
🔇 Additional comments (10)
packages/sdk/src/validation.ts (1)

10-10: Good adjustment of function visibility

Making isValidationAttribute accessible by exporting it allows for better code organization and reuse, supporting the refactoring in the function invocation validator.

tests/regression/tests/issue-1984.test.ts (3)

3-29: Well-designed test case for access policy rules

Good implementation of regression tests for using currentModel() and currentOperation() in access policies. The test thoroughly verifies different access scenarios:

  • Rejection when auth access doesn't match the model or operation
  • Success when auth access includes the model name
  • Success when auth access includes the operation name (create)
  • Rejection when auth access only includes a different operation (read)

This effectively tests the core functionality introduced by this PR.


31-43: Good validation test for currentModel in model rules

This test case properly verifies that using currentModel() in validation rules (@Validate) is correctly rejected with an appropriate error message.


45-56: Good validation test for currentModel in field constraints

This test case verifies that using currentModel() in field constraints is correctly rejected with an appropriate error message, providing complete coverage of the validation logic.

packages/schema/src/language-server/validator/function-invocation-validator.ts (6)

14-14: Good import additions

Adding imports for isInvocationExpr and isValidationAttribute supports the new functionality for validating static function calls and determining expression context.

Also applies to: 25-25


75-75: Good extraction of context determination logic

Replacing inline context determination with a call to the new getExpressionContext method improves code organization and maintainability.


80-89: Enhanced validation logic with improved error messages

The validation condition has been improved to be more robust by explicitly checking for the presence of funcAllowedContext. The error message now includes the context type when available, which will be helpful for debugging.


127-128: Key functionality addition for static function calls

This change implements the core fix for issue #1984 by allowing static function calls like currentModel and currentOperation to be used as the second argument in policy rules.


156-168: Well-structured context determination method

The new getExpressionContext method centralizes the logic for determining expression context from container attributes. It handles validation attributes and uses pattern matching for clear, maintainable code.


170-172: Clean implementation of static function call detection

The new isStaticFunctionCall method provides a clear way to identify invocations of currentModel and currentOperation functions, supporting the core functionality of this PR.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

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.

@ymc9 ymc9 merged commit 1369f9e into dev Mar 21, 2025
11 checks passed
@ymc9 ymc9 deleted the fix/issue-1984 branch March 21, 2025 01:05
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