veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

testing/fuzz

lib/testing/fuzz.vk

lib/testing/fuzz.vk Deterministic seedable fuzzing and counterexample shrinking harness (SplitMix64). Zero host capabilities required: runs identically across ORO VM, Wasm 3.0, and Native AOT.

FuzzConfig struct
signature
FuzzConfig = struct { seed i64 = ..., runs i64 = ..., max_len i64 = ... }

Configuration for a deterministic fuzzing campaign.

FuzzResult struct
signature
FuzzResult = struct { ok bool = ..., runs i64 = ..., seed i64 = ..., failing_input any = ..., shrunk_input any = ..., shrink_steps i64 = ..., failure_msg str = ... }

Outcome of a fuzzing run, including the minimal delta-debugged counterexample on failure.

signature
next-u64 = fn [state i64] StepU64

Advances a 64-bit SplitMix64 state and returns StepU64 { state, val }.

signature
fuzz-bytes = fn [cfg FuzzConfig, prop fn[bytes->any]] FuzzResult

Fuzzes prop over boundary byte vectors and cfg.runs pseudo-random bytes slices, shrinking any failing input to its minimal reproducing byte sequence.

Executable Example
veko
use [fz = testing/fuzz]
cfg = fz/FuzzConfig { seed = 42, runs = 80, max_len = 32 }
ok_res = fz/fuzz-bytes cfg fn [b bytes] any [ (len b) <= 32 ]
if not ok_res.ok [ return (err 'expected ok_res to pass') ]
// Plant a bug triggered whenever consecutive bytes [0xfe 0xff] or byte >= 200 appear
bad = fz/fuzz-bytes cfg fn [b bytes] any [
    mut i = 0
    while i < (len b) [
        if b[i] >= 200 [ return (err 'high byte boom') ]
        i = i + 1
    ]
    true
]
if bad.ok or (len bad.shrunk_input) != 1 [ err 'expected shrunk 1-byte reproducer' ] else [ .ok ]
signature
fuzz-str = fn [cfg FuzzConfig, prop fn[str->any]] FuzzResult

Fuzzes prop over boundary strings and cfg.runs valid UTF-8 / delimiter strings, shrinking any failure down to the minimal failing UTF-8 string.

signature
fuzz-block = fn [cfg FuzzConfig, prop fn[block->any]] FuzzResult

Fuzzes prop over structured homoiconic Veko blocks (i64, str, bool, .enum, and nested [ ... ] sub-blocks) and shrinks any failure to the minimal failing block.

Executable Example
veko
use [fz = testing/fuzz]
cfg = fz/FuzzConfig { seed = 99, runs = 80, max_len = 8 }
res = fz/fuzz-block cfg fn [xs block] any [
    mut i = 0
    while i < (len xs) [
        if (type-of xs[i]) == .enum_sym and xs[i] == .eof [ return false ]
        i = i + 1
    ]
    true
]
if res.ok or res.shrunk_input != [.eof] [ err 'expected shrunk [.eof]' ] else [ .ok ]
signature
assert-fuzz = fn [res FuzzResult, label str] any

Returns .ok if res.ok == true, or a formatted err describing the seed and minimal counterexample.