On this page

ADR-0310: Cross-Surface Differential Equivalence Oracle (app_test_parity / app_test.parity)

Context

derive AppSurface (ADR-0304) projects a single annotated action catalog onto multiple user and agent surfaces: direct ActionSession, dual-era MCP JSON-RPC 2.0 (2026-07-28 and 2025-11-25), CLI (app_surface.cli), loopback HTTP (app_surface.http_router), and TUI palette / tui.a11y triggers.

While each surface has its own unit tests, subtle cross-surface drift can occur whenever a surface adapter parses flags differently, omits expected_rev or approval_token, misclassifies an ActionErrorKind (e.g., returning InvalidArgs instead of UnknownAction or StaleRev), or serializes StateSnapshot JSON differently. Manually writing parallel test suites for all five surfaces does not scale and misses multi-step stateful interactions.

Decision

Introduce a pure (capabilities = []) differential equivalence oracle in plugins/app_test_parity/ (parity.tn, re-exported by lib.tn and exposed under app_test.parity at the Wave 4 barrier):

  1. Single Abstract Trace (vec<ParityStep>):
    • Each ParityStep encodes action_name, args_json, optional expected_rev, approval_token, presented_approval_id, optional human cli_argv, optional tui_trigger_id, and optional persisted_path.
    • The oracle executes the identical trace in parallel isolated instances across all 5 surfaces (6 concrete protocol lanes):
      1. direct: app_actions.session.execute + snapshot.
      2. mcp_2026_07_28: app_actions_mcp.bridge.serve_line modern JSON-RPC 2.0 (_meta protocol version 2026-07-28, app_act + app_state).
      3. mcp_2025_11_25: app_actions_mcp.bridge.serve_line legacy JSON-RPC 2.0 (initialize handshake + app_act + app_state).
      4. cli: app_surface.cli.dispatch_cli (act or human cli_argv + state JSON output).
      5. http: app_surface.http_router.handle_http loopback POST /act + GET /state.
      6. tui: app_surface.tui_palette.build_palette + tui.a11y (A11yNode button resolution and unclipped visibility check) mapped to ActionSession.
  2. Canonical Equivalence Checks:
    • Byte-identical StateSnapshot JSON: Both the underlying session snapshot and each surface's wire state payload (app_state, CLI state, HTTP GET /state) are normalized with state_delta.patch.canonicalize_value and compared byte-for-byte against the direct reference oracle.
    • Identical Error Classifications: Wire errors from JSON-RPC isError/payload, CLI exit codes + stderr, HTTP RFC-7807 problem titles, and TUI ActionSession outcomes are normalized to ActionErrorKind names (invalid_args, disabled_action, approval_required, stale_rev, unknown_action, policy_denied, execution_failed, circuit_broken, job_error).
    • Optional VirtualFs Persisted-Bytes Comparison: Pure in-memory VirtualFs records persisted state snapshots and fs.write effects per surface and asserts byte-identical persisted files across all surfaces without requiring ffi capabilities.
  3. Structured Pinpointing (ParityReport):
    • Returns ParityReport with ok, steps_executed, surfaces_checked, final_snapshot_json, final_rev, divergences, and first_divergence: option<ParityDivergence> pinpointing exact step_index, action_name, surface, DivergenceKind, expected_snapshot_json vs actual_snapshot_json, and expected_error vs actual_error.
    • Includes deterministic fault-injection hooks (ParityFault) so tests can prove single-surface divergences are caught and pinpointed on both native C and tenon interp.

Consequences