Skip to content

Commit 03a9952

Browse files
committed
Add REGO debugger to Mindev.
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.
1 parent 0068f4d commit 03a9952

File tree

6 files changed

+740
-13
lines changed

6 files changed

+740
-13
lines changed

cmd/dev/app/rule_type/rttst.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func CmdTest() *cobra.Command {
6767
testCmd.Flags().StringP("token", "t", "", "token to authenticate to the provider."+
6868
"Can also be set via the TEST_AUTH_TOKEN environment variable.")
6969
testCmd.Flags().StringArrayP("data-source", "d", []string{}, "YAML file containing the data source to test the rule with")
70+
testCmd.Flags().BoolP("debug", "", false, "Start REGO debugger (only works for REGO-based rules types)")
7071

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

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

198200
// TODO: use cobra context here
199201
ctx := context.Background()
200-
eng, err := rtengine.NewRuleTypeEngine(ctx, ruletype, prov, nil /*experiments*/, options.WithDataSources(dsRegistry))
202+
eng, err := rtengine.NewRuleTypeEngine(ctx, ruletype, prov, nil, /*experiments*/
203+
options.WithDataSources(dsRegistry),
204+
options.WithDebugger(debug),
205+
)
201206
if err != nil {
202207
return fmt.Errorf("cannot create rule type engine: %w", err)
203208
}

0 commit comments

Comments
 (0)