On this page

ADR-0309: Automatic ActionApp Property & Fuzz Explorer (app_test & tenon test --explore)

Context

Hand-written unit tests for ActionApp implementations rarely cover the combinatorial state-space bugs that emerge in real agentic and interactive sessions: unredacted secret leaks triggered only after specific state transitions, destructive actions that lose requires_approval: true in alternate modes, dry_run previews that diverge from execute, malformed RFC-6901 state_delta patches, corrupted undo()/rollback_to_rev history, and TUI layout/contrast regressions on narrow or wide viewports.

Following ADR-0291 ("Freeze Rust, Grow in Tenon"), we want a pure, deterministic, zero-capability Tenon plugin (plugins/app_test/) that automatically explores any ActionApp (and optional tui.runtime.App) directly from its live ActionSpec.input_schema_json, verifies 7 universal oracles on every transition with zero user-written assertions, and shrinks any failing trace into a minimal copy-pasteable .tn regression test, paired with thin tenon test --explore CLI support.

Decision

  1. New Pure Library Plugin plugins/app_test/ (capabilities = [])

    • Depends strictly on json, app_actions, state_delta, tui, and tui_lint.
    • Deterministic Seeded PRNG & Schema Synthesizer (explore.tn):
      • Implements an overflow-free Park-Miller PRNG (Rng) that produces identical sequences on both native C and tenon interp.
      • Synthesizes schema-valid JSON payloads directly from live ActionSpec.input_schema_json (synthesize_args), exercising boundary values ("", minLength, maxLength, minimum, maximum, 0, -1, 1), Unicode/CJK/emoji strings (日本語テスト, 🚀✨🎉, café naïve 界), the canary secret (sk-live-CANARY-9f8e7d6c5b4a), enums, booleans, nested arrays, and nested objects.
    • 7 Universal Oracles (explore_action_app & explore_harness):
      1. Zero Runtime Traps: actions, project_state, state_summary, apply, and optional TUI view (80x24, 48x16, 160x50) execute without trapping.
      2. Dry-Run Parity: dry_run matches execute (rev, WireUpdate, actions_changed, effects, note, and error classification) without mutating prior state.
      3. RFC-6901 Delta Exactness: state_delta.apply.apply_delta(prev, ops) equals next StateSnapshot.state, and recomputed diff_values round-trips identically.
      4. Undo / Rollback Restoration: undo() restores the exact prior StateSnapshot.state and restored_from_rev after every state-mutating transition.
      5. Canary Secret Redaction: canary_secret never appears unredacted in project_state, state_summary, or StateSnapshot.
      6. ADR-0225 Approval Enforcement: Every enabled ActionRisk.Destructive action must declare requires_approval: true, and every requires_approval: true action must fail closed (ApprovalRequired / PolicyDenied) when called without a matching presented approval token.
      7. TUI Lint Invariants: tui_lint.lib.audit_screen passes across sampled viewports (80x24, 48x16, 160x50).
    • Delta-Debugging Trace Shrinking & Regression Generation (shrink_trace, format_regression_tn):
      • Deterministically minimizes failing traces in-memory (< 50 ms) via binary chunk removal followed by a 1-minimal pass, preserving the exact target OracleKind.
      • Formats the minimized trace into a standalone .tn test regression_<app>_<oracle> { ... } snippet and structured JSON report (report_to_json).
  2. CLI Support in crates/tenon/src/app_test/

    • Extends tenon test with --explore [--seeds N] [--depth N] (bounded seeds in 1..=10000, default 32; depth in 1..=256, default 12; rejecting --seeds/--depth without --explore).
    • In --explore mode, discovers and runs explore_* unit tests (falling back to package unit tests when no explore_* filter match exists) and reports exploration metadata (explore: seeds=N depth=N in human output; "explore":{"seeds":N,"depth":N} in --json output) while leaving non-explore tenon test output byte-for-byte unchanged.

Consequences