Skip to content

Governance-as-operator testing infrastructure: mock engine and cross-zome tests #45

@Soushi888

Description

@Soushi888

Summary

Build the testing infrastructure needed to verify the governance-as-operator pattern: a mock governance engine for isolated resource zome testing, and cross-zome integration tests for the full Request-Evaluate-Apply flow.

Context

The governance-as-operator pattern introduces cross-zome dependencies that require new testing approaches:

  • Resource zome tests need to mock governance decisions to test in isolation
  • Integration tests need to verify the full cross-zome flow
  • The pure-function GovernanceEngine needs comprehensive unit tests

Technical Implementation

1. Mock Governance Engine

pub struct MockGovernanceEngine {
    approval_mode: ApprovalMode,
}

pub enum ApprovalMode {
    ApproveAll,
    RejectAll,
    RoleBased(Vec<String>),
    Conditional(Box<dyn Fn(&GovernanceTransitionRequest) -> bool>),
}

This enables resource zome tests to:

  • Test approved transitions without real governance logic
  • Test rejection handling without complex rule setup
  • Test specific role-based scenarios

2. Unit Tests for GovernanceEngine

Test the pure-function evaluation logic:

  • Permission checks (authorized, unauthorized, various roles)
  • Rule evaluation (access requirements, usage limits, transfer conditions)
  • State transition validation (valid/invalid action-state combinations)
  • Edge cases (empty rules, multiple failures, boundary conditions)

3. Cross-Zome Integration Tests (Tryorama)

End-to-end scenarios:

  • Resource creation → use request → governance approval → state change → event generated
  • Transfer request → permission check → custody change → PPR generation
  • Unauthorized action → governance rejection → no state change → rejection logged
  • Multi-agent scenarios with different roles requesting different actions

4. Test Helpers

  • Factory functions for creating test resources, specs, agents with roles
  • Assertion helpers for verifying governance results
  • Test fixtures for common governance rule configurations

Acceptance Criteria

  • MockGovernanceEngine with ApproveAll, RejectAll, RoleBased, Conditional modes
  • Unit tests for GovernanceEngine::evaluate_transition pure function
  • Unit tests cover: approvals, permission denials, rule violations, invalid states
  • Cross-zome integration tests using Tryorama for full flow
  • Integration tests cover: approved transfers, rejected actions, multi-agent scenarios
  • Test helpers and factory functions for common setup
  • All tests pass with bun run tests

Dependencies

Definition of Done

  • Mock engine implemented
  • Unit test suite comprehensive
  • Integration tests pass
  • Test helpers documented
  • Code review completed

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-highHigh priority - important for milestone completioncross-zomeCross-zome integration and coordinationphase-2-governancePhase 2 - Enhanced governance & process integration (current)testingTest infrastructure, scenarios, integration testszome-governanceGovernance zome - validation, economic events, commitments

    Type

    No type

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions