Skip to Content

Test a Rust integration

veriproof-sdk includes VeriproofTestHarness, a deterministic runtime that exercises the real client without an account or network. Use it in unit tests for the code that calls govern.

Run one governed action

use veriproof_sdk::{GovernOptions, TestPolicyDecision, VeriproofTestHarness}; let harness = VeriproofTestHarness::new(); harness.respond_with([TestPolicyDecision::deny()]); let result = harness .veriproof() .govern("payments.submit", payment, submit_payment, GovernOptions::default()) .await; assert!(!result.completed()); assert!(result.value.is_none());

harness.veriproof() returns a client bound to the in-memory runtime. Queue decisions in evaluation order: the first decision answers the input check, the next answers the output check.

Queue decisions

ConstructorResult
TestPolicyDecision::allow()The action runs and its value is released
TestPolicyDecision::warn()The action runs and the result is CompletedWithWarning
TestPolicyDecision::deny()Blocked; the action does not run when queued for the input check
TestPolicyDecision::review_required()ReviewRequired with a checkpoint
TestPolicyDecision::transform(replacement)The replacement is used and the result is Transformed
TestPolicyDecision::fail_closed()Failed with a degraded decision
TestPolicyDecision::review_context_required()ReviewContextRequired; the call carried no review options

Each decision exposes message, reason_code, replacement, and degraded if a test needs to adjust them.

Prove the field contract and Stop

require_fields installs an application field contract so a test can prove that a missing or mistyped required field fails closed before the action runs:

use veriproof_sdk::TestPolicyField; harness.require_fields(vec![TestPolicyField { canonical_path: "input.snapshot.facts.payment_amount".to_owned(), data_type: "number".to_owned(), required: true, allowed_values: vec![], }]);

issue_stop delivers a Stop directive to the next governed run. Assert that the action observes throw_if_stopped and that the result reports CancelledByDirective.

requests() returns the policy requests the runtime accepted, so a test can assert on the facts and industry values the SDK sent.

Keep the harness in tests

The harness holds state in memory and loses it when the process ends. It does not qualify transport, Edge Gateway, or callback hosting. Use SqliteReviewStore and a real endpoint for those checks. Your deployed application must supply persistent storage for review checkpoints and directive state.