Skip to content

test: integration tests for Rego V1 dual-parse pipeline (Phase 1) #6318

@dakshhhhh16

Description

@dakshhhhh16

Part of #5262
Phase -1 Leftover part (Marking the end of phase 1)

Problem

The Phase 1 dual-parse infrastructure (DB migration, DetectRegoVersion(), service wiring, evaluator option, feature flag) was implemented but lacked integration tests verifying the full pipeline end-to-end:

  • No test verified that RegoVersion is correctly detected and passed to DB on CreateRuleType / UpdateRuleType
  • No test verified that V1 Rego policies evaluate correctly when WithRegoVersion(ast.RegoV1) is used
  • No edge-case tests for version detection (V0 function syntax, every keyword, comprehension-heavy policies, syntax errors)

Changes

pkg/ruletypes/service_test.go

  • Custom gomock.Matcher (regoVersionMatcher) that inspects the RegoVersion field in CreateRuleTypeParams / UpdateRuleTypeParams
  • withRegoEval(def) test helper to build rule types with Rego eval definitions
  • 5 new test scenarios:
    • CreateRuleType with V0 Rego → DB gets rego_version = "v0"
    • CreateRuleType with V1 Rego → DB gets rego_version = "v1"
    • CreateRuleType without Rego eval → DB gets rego_version = "v0"
    • UpdateRuleType with V0 Rego → DB gets rego_version = "v0"
    • UpdateRuleType with V1 Rego → DB gets rego_version = "v1"

internal/engine/eval/eval_test.go

  • 3 table-driven tests verifying WithRegoVersion option works through NewRuleEvaluator:
    • V1 deny-by-default policy evaluates with ast.RegoV1
    • V1 constraints policy evaluates with ast.RegoV1
    • V0 policy works with explicit ast.RegoV0 option (regression)
  • Dedicated test: V1 policy returns success when input matches

internal/engine/eval/rego/version_test.go

  • 5 new edge-case detection tests:
    • V0 function syntax (format_message(...) = msg { ... })
    • V1 function syntax (format_message(...) := msg if { ... })
    • V0 partial set with comprehensions
    • V1 every keyword
    • Syntax error falls back to V0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions