fix per-module rego version lookup (#8799)

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
This commit is contained in:
Sebastian Spaink
2026-06-18 11:36:35 -05:00
committed by GitHub
parent 93d6984466
commit b0c824b1a9
2 changed files with 33 additions and 1 deletions
+1 -1
View File
@@ -780,7 +780,7 @@ func erasePolicies(ctx context.Context, store storage.Store, txn storage.Transac
}
getRegoVersion := func(modId string) (ast.RegoVersion, bool) {
info, ok := modulesInfo[modId]
info, ok := modulesInfo[strings.TrimPrefix(modId, "/")]
if !ok {
return ast.RegoUndefined, false
}
+32
View File
@@ -4278,6 +4278,38 @@ func TestActivate_DefaultRegoVersion(t *testing.T) {
}
}
// Regression test for https://github.com/open-policy-agent/opa/issues/8797.
func TestActivate_PreservesPerModuleRegoVersionWithLeadingSlashID(t *testing.T) {
ctx := t.Context()
store := mock.New()
v1Module := `package test
p contains 42`
policyID := "/test/policy.rego"
txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams)
if err := store.UpsertPolicy(ctx, txn, policyID, []byte(v1Module)); err != nil {
t.Fatalf("UpsertPolicy failed: %v", err)
}
if err := write(ctx, store, txn, moduleRegoVersionPath(policyID), int64(ast.RegoV1.Int())); err != nil {
t.Fatalf("writing rego_version failed: %v", err)
}
if err := store.Commit(ctx, txn); err != nil {
t.Fatalf("commit failed: %v", err)
}
mustActivate(t, store, &ActivateOpts{
Compiler: ast.NewCompiler().WithDefaultRegoVersion(ast.RegoV0CompatV1),
ParserOptions: ast.ParserOptions{RegoVersion: ast.RegoV0},
Bundles: map[string]*Bundle{
"other": {
Manifest: Manifest{Roots: &[]string{"other"}},
},
},
})
}
func TestDeactivate_DefaultRegoVersion(t *testing.T) {
tests := []struct {
note string