Deterministic order of rules for optimized bundles

Before this fix, an optimized bundle would get
non-deterministic order of the support rules.

One example use case where it is necessary for the optimized
bundle to be deterministic is when a hash of the bundle is
used for version tag.

Fixes: #3453

Signed-off-by: Andre Håland <andre.haland@gmail.com>
This commit is contained in:
Andre Håland
2021-05-14 15:43:29 +02:00
committed by Torin Sandall
parent ee115dba41
commit 4b5f53b548
3 changed files with 57 additions and 7 deletions
+5 -4
View File
@@ -350,9 +350,9 @@ func TestCompilerOptimizationL1(t *testing.T) {
optimizedExp := ast.MustParseModule(`
package test
q { input.x = 1 }
p { data.test.q = X; X }
default p = false
p { data.test.q = X; X }
q { input.x = 1 }
`)
// NOTE(tsandall): PE generates vars with wildcard prefix. Instead of
@@ -409,8 +409,8 @@ func TestCompilerOptimizationL2(t *testing.T) {
optimizedExp := ast.MustParseModule(`
package test
p { input.x = 1 }
default p = false
p { input.x = 1 }
`)
if len(compiler.bundle.Modules) != 2 {
@@ -872,10 +872,11 @@ func TestOptimizerOutput(t *testing.T) {
"optimized/test.rego": `
package test
default p = false
p = true { 1 = input.x }
p = true { 2 = input.x }
default p = false
`,
"test.rego": `
package test