/** * Reads the `--seed` and `--to` options of a fuzz runner. * * Rejects a range that would scan no seed: an endpoint that is not a safe * integer (`--seed oops`, or `--to` with no value after it) or an end below * the start (`--seed 5 --to 4`). Without this check such a run printed * `FAILURES: 0` and exited with status 0, as if a sweep had passed. * * `--seed` defaults to 0 and `--to` to the start, so a runner given neither * scans seed 0 only. */ export function parseSeedRange(args: string[]): { seed: number; to: number } { const read = (name: string, fallback: number): number => { const index = args.indexOf(`--${name}`); if (index < 0) return fallback; const raw = args[index + 1]; const value = raw === undefined || raw.trim() === '' ? Number.NaN : Number(raw); if (!Number.isSafeInteger(value)) { throw new Error(`--${name} must be a safe integer, got ${raw === undefined ? 'no value' : `"${raw}"`}.`); } return value; }; const seed = read('seed', 0); const to = read('to', seed); if (to < seed) { throw new Error(`--to (${to}) must not be below --seed (${seed}).`); } return { seed, to }; }