Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Enable test framework to test rego-format ruletypes - #6639

#6639
Open
evankanderson wants to merge 4 commits into
mindersec:mainmindersec/minder:mainfrom
evankanderson:rego-test-frameworkevankanderson/minder:rego-test-frameworkCopy head branch name to clipboard
Open

Enable test framework to test rego-format ruletypes#6639
evankanderson wants to merge 4 commits into
mindersec:mainmindersec/minder:mainfrom
evankanderson:rego-test-frameworkevankanderson/minder:rego-test-frameworkCopy head branch name to clipboard

Conversation

@evankanderson

Copy link
Copy Markdown
Member

Summary

Enables the mindev test command to discover and load ruletypes stored as .rego files in addition to the existing support for .yaml files.

Testing

Updated the existing tests to migrate one (of two) ruletype definitions from .yaml to .rego.

@evankanderson
evankanderson requested a review from a team as a code owner July 29, 2026 01:48
@evankanderson

Copy link
Copy Markdown
Member Author

I'd like to get this in alongside #6637 for a v0.3.0 client tools release (which would include the exit-code updates for mindev test as well as official support for .rego-format ruletypes).

@coveralls

coveralls commented Jul 29, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 61.541% (+0.007%) from 61.534% — evankanderson:rego-test-framework into mindersec:main

@krrish175-byte krrish175-byte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One required change (stale doc comment) and one worth discussing (silent rego parse errors). Everything else is minor polish.

Comment thread pkg/ruletest/runner.go
if err != nil {
return nil, fmt.Errorf("globbing rego files: %w", err)
}
ruleFiles := append(yamlFiles, regoFiles...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit: append(yamlFiles, regoFiles...) may reuse yamlFiles's backing array if it has excess capacity, silently clobbering it. filepath.Glob returns a tightly-sized slice in practice so this is safe today, but it's a fragile assumption. Consider:

ruleFiles := make([]string, 0, len(yamlFiles)+len(regoFiles))
ruleFiles = append(ruleFiles, yamlFiles...)
ruleFiles = append(ruleFiles, regoFiles...)

Comment thread pkg/ruletest/runner.go
for _, yf := range ruleFiles {
rt, err := loadSingleRule(yf)
if err != nil {
continue // skip files that aren't valid rule types

@krrish175-byte krrish175-byte Jul 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This silent continue was fine for YAML (where non-ruletype YAML files legitimately live in directories). For .rego files the assumption is much stronger -- any .rego file in a testdata directory is almost certainly meant to be a ruletype, so swallowing the parse error gives no signal when metadata is malformed. At minimum a log.Printf or zerolog warn here would save a lot of head-scratching.

Comment thread pkg/ruletest/runner.go
rt.Context = &minderv1.Context{}
}
if rt.Context.GetProject() == "" {
rt.Context.Project = ptr.Ptr(uuid.UUID{}.String())

@krrish175-byte krrish175-byte Jul 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The zero UUID is a fine sentinel, but uuid.UUID{}.String() is a somewhat roundabout way to write it. It constructs a value type just to call String(). The literal "00000000-0000-0000-0000-000000000000" (used in the deleted YAML file) is clearer and avoids the uuid import entirely:

rt.Context.Project = ptr.Ptr("00000000-0000-0000-0000-000000000000")

Comment thread pkg/ruletest/runner.go
}
// Ensure that ruletypes have a project context; the Minder CLI + API tooling
// will automatically apply the "current project" when creating a ruletype.
if rt.Context == nil {

@krrish175-byte krrish175-byte Jul 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The previous code guarded this with if rt != nil. ReadResourceTyped can't actually return (nil, nil) today (it always returns a pointer), so removing the guard is technically correct -- but it's a non-obvious invariant. A short comment here would prevent someone from reflexively restoring the guard in a future cleanup:

// rt is never nil when err is nil; ReadResource always returns a pointer value.

# SPDX-License-Identifier: Apache-2.0

# METADATA
#

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Trailing space on a blank comment line (# instead of #). The parser handles it fine, but OPA convention (and most editors) use a bare # for blank comment lines. Worth trimming.

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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.