Sign in

    MoonReduce

    Deterministic failure-preserving testcase reduction for MoonBit projects

    testing
    reducer
    delta-debugging
    cli
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    last month
    Downloads
    29

    #MoonReduce

    A MoonBit testcase reducer and native CLI. It removes irrelevant project files, declarations, statements and tokens in independent copies while preserving a user-defined failure predicate.

    #Quick start

    Use the pinned MoonBit toolchain and a native C compiler. The native runtime uses moonbitlang/async 0.20.4.

    moon update moon run cmd/main -- reduce --project --config testdata/final/compile_diagnostic/predicate.json --workspace testdata/final/compile_diagnostic/input --output ./compile-result moon run cmd/main -- replay ./compile-result/report.json

    Use a fresh output directory outside the input, with an existing parent. Replay checks SHA-256 and executes uncached final trials in new copies.

    moon build --target native --release cmd/main moon install ./cmd/main --bin ./local-bin moon run examples/custom_pass --target native

    #Features

    • Single-file and multi-file reduction, protected glob selection and package edits.
    • Text/token passes and 16 structured families with conservative syntax fallback.
    • Exit/timeout/output predicates, bounded regex, diagnostic fingerprints, wrappers, differential commands, repeated quorum and inconclusive decisions.
    • Deterministic candidate batches with configurable workers and strict scoring.
    • Checkpoints, resume, run-scoped cache, budgets and uncached final verification.
    • Checksummed evidence bundles, environment summaries, diff and standalone replay.
    • Pure evaluator/pass/event extension contracts and check/reduce library facade.

    Commands: check, reduce, resume, replay, diff, explain, passes, config validate, cache stats and cache clean. Run --help for all options. JSON defaults are validated and overridden by CLI arguments. The twelve examples in examples/ include a runnable custom library extension.

    #Verification and boundaries

    Run scripts/verify.ps1, scripts/benchmark-final.ps1 and scripts/determinism-final.ps1 from PowerShell. Pure packages support native, JavaScript and wasm-gc; process/workspace/CLI packages require native. See testing, benchmarks, compatibility and the acceptance record.

    Only trusted commands/projects are supported. Copies are not a sandbox. The scanner is not a complete MoonBit parser. Snapshot limits are 1000 files/16 MiB, 1 MiB per file and 64 KiB per MoonBit source. Private checkpoints retain explicit environment overrides; ordinary reports omit values. Do not put secrets in argv or share private checkpoints. SHA-256 detects corruption, not a malicious author. See security and limitations.

    Apache-2.0. Dependencies and owned fixture provenance are in THIRD_PARTY.md and each fixture's LICENSE.

    CandidateEvaluator

    pub(open) trait CandidateEvaluator {
    fn evaluate(Self,
    Snapshot
    ) -> Result[
    Decision
    , String]
    }

    Synchronous pure-driver evaluation contract. Each call is one uncached trial. Return Unresolved for inconclusive observations, Err for execution failures.

    EventSink

    pub(open) trait EventSink {
    fn emit(Self, Event) -> Unit
    }

    Event delivery is synchronous; sinks may record evidence or update a UI.

    Event

    pub(all) struct Event {
    schema_version : Int
    candidate_id : Int
    phase : String
    trial : Int
    decision :
    Decision

    } derive(ToJson)

    Immutable versioned observation delivered in deterministic candidate order.

    ReduceConfig

    pub(all) struct ReduceConfig {
    max_tests : Int
    repeat : Int
    quorum : Int
    consecutive : Bool
    final_repeat : Int
    final_quorum : Int
    score : String
    includes : Array[String]
    protects : Array[String]
    ignores : Array[String]
    pass_include : Array[String]
    pass_exclude : Array[String]
    extra_passes : Array[&
    ReductionPass
    ]
    }

    Pure reduction options. Native CLI time/process controls belong to app.Config.

    check

    Validate only the baseline; no pass runs and no original data is changed.

    default_config

    fn default_config() -> ReduceConfig

    Defaults match the deterministic project engine: 2 baseline, 3 final trials.

    default_passes

    Built-in pure passes, in the same order as the native project CLI.

    reduce

    Reduce immutable input using the same cached deterministic engine as the CLI. Baseline and final trials always bypass the candidate cache.