runok test
runok test runs test cases defined in your runok.yml and reports whether each command produces the expected decision (allow, ask, or deny). Use it to verify that your rules work as intended before deploying configuration changes.
runok test [options]--config, -c <path>
Section titled “--config, -c <path>”Path to the configuration file to test. When omitted, runok looks for runok.yml (or runok.yaml) in the current directory.
runok test -c ./path/to/runok.ymlDefining test cases
Section titled “Defining test cases”Test cases can be defined in two places:
Inline tests (per-rule)
Section titled “Inline tests (per-rule)”Add a tests list to any rule entry. Each entry specifies the expected decision (allow, ask, or deny) and the command to evaluate:
rules: - allow: 'git status' tests: - allow: 'git status' - allow: 'git status --short'
- deny: 'git push -f|--force *' tests: - deny: 'git push --force origin main' - deny: 'git push -f origin main'Top-level tests
Section titled “Top-level tests”For cross-rule tests or tests that need additional configuration, use the top-level tests section:
rules: - allow: 'git *' - deny: 'git push -f|--force *'
tests: cases: - allow: 'git push origin main' - deny: 'git push --force origin main'tests.extends
Section titled “tests.extends”Load additional configuration files only during test execution. This is useful for testing rules that depend on shared presets without affecting production configuration:
tests: extends: - ./test-fixtures/readonly-unix.yml cases: - allow: 'cat /etc/hosts' - deny: 'rm -rf /'Test environment
Section titled “Test environment”runok test runs in an isolated environment:
- Global configuration is excluded. The global
~/.config/runok/runok.ymlis not loaded. Only the target configuration file and itsextendsare used. - All test cases run. The runner does not stop on the first failure — it executes every test case and reports all results.
Output
Section titled “Output”Each test case produces a PASS or FAIL line:
PASS: git status => allowPASS: git push --force origin main => denyFAIL: git push origin main => expected allow, got askAfter all tests, a summary is printed:
2 passed, 1 failed, 3 totalExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 | All tests passed. |
1 | One or more tests failed. |
2 | An error occurred before tests could run (config error, no tests, etc.). |
Examples
Section titled “Examples”Run tests in the current directory:
runok testRun tests for a specific config file:
runok test -c ./presets/my-preset.yml