MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / runFuzz

Function runFuzz

packages/testkit/src/fuzz.ts:136–175  ·  view source on GitHub ↗
(options: FuzzRunOptions, body: FuzzBody)

Source from the content-addressed store, hash-verified

134}
135
136export async function runFuzz(options: FuzzRunOptions, body: FuzzBody): Promise<FuzzRunSummary> {
137 const label = options.label ?? "fuzz";
138 assertUInt32("seed", options.seed);
139 assertPositiveInteger("iterations", options.iterations);
140
141 for (let iteration = 0; iteration < options.iterations; iteration++) {
142 const caseSeed = deriveFuzzCaseSeed(options.seed, iteration);
143 const notes: string[] = [];
144 const ctx: FuzzIterationContext = Object.freeze({
145 label,
146 seed: options.seed >>> 0,
147 iteration,
148 caseSeed,
149 rng: createRng(caseSeed),
150 note(message: string): void {
151 notes.push(message);
152 },
153 fail(message: string, cause?: unknown): never {
154 throw new FuzzFailureError(
155 { label, seed: options.seed >>> 0, iteration, caseSeed },
156 cause === undefined ? new Error(message) : new Error(message, { cause }),
157 notes,
158 );
159 },
160 });
161
162 try {
163 await body(ctx);
164 } catch (cause: unknown) {
165 if (cause instanceof FuzzFailureError) throw cause;
166 throw new FuzzFailureError(ctx, cause, notes);
167 }
168 }
169
170 return Object.freeze({
171 label,
172 seed: options.seed >>> 0,
173 iterations: options.iterations,
174 });
175}
176
177export function fuzzTest(name: string, options: FuzzRunOptions, body: FuzzBody): void {
178 const label = options.label ?? name;

Calls 4

assertPositiveIntegerFunction · 0.85
deriveFuzzCaseSeedFunction · 0.85
assertUInt32Function · 0.70
createRngFunction · 0.70

Tested by

no test coverage detected