Skip to content

Commit

Permalink
Add REGO debugger to Mindev.
Browse files Browse the repository at this point in the history
This change adds the possibility to start evaluate a REGO-based rule
type in a debugger.

The debugger allows setting breakpoints, stepping, printing source,
and a few other simple utilities.

The debugger is currently very, very, VERY rough around the edges and
could use some love, especially in the reception of events from the
debuggee, which is done inline and not asynchronously.
  • Loading branch information
blkt committed Dec 20, 2024
1 parent 0068f4d commit 03a9952
Show file tree
Hide file tree
Showing 6 changed files with 740 additions and 13 deletions.
7 changes: 6 additions & 1 deletion cmd/dev/app/rule_type/rttst.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func CmdTest() *cobra.Command {
testCmd.Flags().StringP("token", "t", "", "token to authenticate to the provider."+
"Can also be set via the TEST_AUTH_TOKEN environment variable.")
testCmd.Flags().StringArrayP("data-source", "d", []string{}, "YAML file containing the data source to test the rule with")
testCmd.Flags().BoolP("debug", "", false, "Start REGO debugger (only works for REGO-based rules types)")

if err := testCmd.MarkFlagRequired("rule-type"); err != nil {
fmt.Fprintf(os.Stderr, "Error marking flag as required: %s\n", err)
Expand Down Expand Up @@ -98,6 +99,7 @@ func testCmdRun(cmd *cobra.Command, _ []string) error {
token := viper.GetString("test.auth.token")
providerclass := cmd.Flag("provider")
providerconfig := cmd.Flag("provider-config")
debug := cmd.Flag("debug").Value.String() == "true"

dataSourceFileStrings, err := cmd.Flags().GetStringArray("data-source")
if err != nil {
Expand Down Expand Up @@ -197,7 +199,10 @@ func testCmdRun(cmd *cobra.Command, _ []string) error {

// TODO: use cobra context here
ctx := context.Background()
eng, err := rtengine.NewRuleTypeEngine(ctx, ruletype, prov, nil /*experiments*/, options.WithDataSources(dsRegistry))
eng, err := rtengine.NewRuleTypeEngine(ctx, ruletype, prov, nil, /*experiments*/
options.WithDataSources(dsRegistry),
options.WithDebugger(debug),
)
if err != nil {
return fmt.Errorf("cannot create rule type engine: %w", err)
}
Expand Down
Loading

0 comments on commit 03a9952

Please sign in to comment.