Skip to content

Support rules with a script node interior type.#29

Closed
scunningham wants to merge 1 commit intomainfrom
script
Closed

Support rules with a script node interior type.#29
scunningham wants to merge 1 commit intomainfrom
script

Conversation

@scunningham
Copy link
Contributor

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for script nodes as an interior node type in the rule parsing and AST building system. Script nodes allow embedding Lua scripts that process inputs from sequences, sets, or PromQL queries.

Changes:

  • Added NodeTypeScript to the schema and parser/AST infrastructure
  • Implemented script node parsing with validation for Lua code and input requirements
  • Added test cases for script nodes as children of sequences and sets, plus failure cases for scripts at root level and scripts without inputs

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/schema/schema.go Added NodeTypeScript constant to the node type enumeration
pkg/parser/parse.go Added ParseScriptT struct; removed JSON tags from several structs (breaking change); refactored variable declarations
pkg/parser/tree.go Added script node parsing logic, error definitions, LuaValidator hook, and IsScriptNode() method
pkg/testdata/rules.go Added test data for script nodes including success and failure cases
pkg/parser/parse_test.go Added test cases for script node parsing
pkg/ast/ast_script.go New file implementing AST building for script nodes
pkg/ast/ast_machine.go Added script node case in buildMachineNode (unreachable code)
pkg/ast/ast.go Refactored child building logic to support script nodes; added buildChildrenNodes and buildLeafChild helper functions
pkg/ast/ast_test.go Added recursive gathering of node addresses; added test cases for script nodes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +265 to +267
// Expect first child to be a script definition and second child to be undefined term.
_, ok := node.Children[0].(*ScriptT)

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The comment in IsScriptNode is inaccurate/misleading: the second child is expected to be the script input node (a *NodeT), not an “undefined term”. Consider updating the comment and (optionally) tightening the check to also validate node.Children[1] is a *NodeT to avoid false positives if the structure changes.

Suggested change
// Expect first child to be a script definition and second child to be undefined term.
_, ok := node.Children[0].(*ScriptT)
// Expect first child to be a script definition and second child to be the script input node.
if _, ok := node.Children[0].(*ScriptT); !ok {
return false
}
_, ok := node.Children[1].(*NodeT)

Copilot uses AI. Check for mistakes.
Comment on lines 790 to 797
switch term.Script.Language {
case "", "lua":
if err := LuaValidator(term.Script.Code); err != nil {
return nil, err
}
default:
return nil, ErrScriptLanguage
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

ErrScriptLanguage is returned directly (not pqerr-wrapped), so callers won’t get rule metadata / YAML position via pqerr.PosOf. Since parse errors elsewhere are generally wrapped, consider creating the script node (or otherwise capturing yn.Line/Column + rule metadata) before language validation and returning a wrapped error (e.g. node.WrapError(ErrScriptLanguage) / pqerr.Wrap(...)).

Copilot uses AI. Check for mistakes.
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