Skip to content

cli: Add new swift-opa test command. - #189

Open
philipaconrad wants to merge 1 commit into
open-policy-agent:mainfrom
philipaconrad:philip/add-opa-test-ir
Open

cli: Add new swift-opa test command.#189
philipaconrad wants to merge 1 commit into
open-policy-agent:mainfrom
philipaconrad:philip/add-opa-test-ir

Conversation

@philipaconrad

@philipaconrad philipaconrad commented Jul 15, 2026

Copy link
Copy Markdown
Member

What code changed, and why?

This commit includes the CLI interface and machinery required to implement a basic subset of opa test's functionality for IR policies. We can now run tests on compiled IR bundles!

The core idea is that we generate wrapper IR plans for any test_* rules that are present in the bundle, replacing any IR plans that may already have been present. This results in consistent execution of tests.

The wrapper plans are then executed one-by-one, and the results are aggregated and reported in similar style to opa test's output format.

The most reliable way to ensure the tests are included in the IR plan outputs is to mark the test package(s) as entrypoints, like: opa build -b <dir> -t plan -e <test-package>

Resolves: #182

How to test

  • Try running it yourself! 😄
% swift run swift-opa-cli test Tests/TestRunnerTests/Fixtures/example-bundle 
[1/1] Planning build
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build of product 'swift-opa-cli' complete! (0.80s)
example_test.rego:13:
data.example_test.test_fail: FAIL (617.916μs)
example_test.rego:17:
data.example_test.todo_test_skip: SKIPPED
--------------------------------------------------------------------------------
PASS: 2/4
FAIL: 1/4
SKIPPED: 1/4

Related Resources

@philipaconrad philipaconrad self-assigned this Jul 15, 2026
@philipaconrad philipaconrad added the new-feature New feature or request label Jul 15, 2026
This commit includes the CLI interface and plumbing required to implement a
minimal subset of `opa test`'s functionality for IR policies. We can now
run tests on compiled IR bundles!

The core idea is that we generate wrapper plans for any `test_*` rules that
are present in the bundle, replacing any plans that may already have been
present. This results in consistent execution of tests.

The wrapper plans are then executed one-by-one, and the results are
aggregated and reporting in similar style to `opa test`'s output format.

Resolves: open-policy-agent#182

Signed-off-by: Philip Conrad <philip_conrad@apple.com>
@philipaconrad
philipaconrad force-pushed the philip/add-opa-test-ir branch from ce23258 to 2fb78ad Compare July 15, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Improve testing of IR bundles with something like opa test

1 participant