Skip to content

Commit cd3341e

Browse files
committed
fix: align builtin aggregate template with runtime input shape
Addresses codex-review feedback: bundled aggregate_report rules are evaluated with entries under input.aggregates_internal["cat/name"], not the custom-rule compatibility shape input.aggregate. The prior builtin template would produce a rule whose scaffolded test passed (because it injected input.aggregate directly) but which never emitted violations during normal linting. Switch the builtin template to read from input.aggregates_internal keyed by "{{.Category}}/{{.NameOriginal}}" and update the generated test to exercise the same shape via util.with_source_files.
1 parent cc5d20e commit cd3341e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

internal/embeds/templates/builtin/builtin_aggregate.rego.tpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ aggregate contains entry if {
2525
# schemas:
2626
# - input: schema.regal.aggregate
2727
aggregate_report contains violation if {
28-
# Correlate the collected entries across modules and emit a violation.
28+
# Built-in aggregate rules read the collected entries from
29+
# input.aggregates_internal, keyed by "category/name".
2930
# Replace this example with your own cross-module condition.
30-
some entry in input.aggregate
31+
some entry in input.aggregates_internal["{{.Category}}/{{.NameOriginal}}"][_]
3132

3233
violation := result.fail(rego.metadata.chain(), entry.aggregate_source)
3334
}

internal/embeds/templates/builtin/builtin_aggregate_test.rego.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package regal.rules.{{.Category}}{{.NameTest}}
22

33
import data.regal.ast
4+
import data.regal.util
45

56
import data.regal.rules.{{.Category}}{{.Name}} as rule
67

78
# Example test, replace with your own
89
test_aggregate_reports_violation if {
910
agg := rule.aggregate with input as ast.policy("foo := true")
1011

11-
r := rule.aggregate_report with input.aggregate as agg
12+
r := rule.aggregate_report with input.aggregates_internal as util.with_source_files(
13+
"{{.Category}}/{{.NameOriginal}}",
14+
[agg],
15+
)
1216

1317
# Use print(r) here to see the report. Great for development!
1418

0 commit comments

Comments
 (0)