#!/usr/bin/env node

import fs from 'node:fs';
import vm from 'node:vm';
import process from 'node:process';

const PAGE = new URL('../../public/strata/conway-base-13/index.html', import.meta.url);
const html = fs.readFileSync(PAGE, 'utf8');

let assertions = 0;
let failures = 0;

function show(value) {
  if (typeof value === 'bigint') return value.toString();
  if (typeof value === 'string') return value;
  try { return JSON.stringify(value, (_, item) => typeof item === 'bigint' ? item.toString() : item); }
  catch { return String(value); }
}

function check(name, condition, detail = '') {
  assertions += 1;
  if (condition) console.log(`PASS ${String(assertions).padStart(3, '0')}  ${name}${detail ? `  [${show(detail)}]` : ''}`);
  else {
    failures += 1;
    console.error(`FAIL ${String(assertions).padStart(3, '0')}  ${name}${detail ? `  [${show(detail)}]` : ''}`);
  }
  return Boolean(condition);
}

function mustThrow(fn) {
  try { fn(); return false; } catch { return true; }
}

const R = 13n;
const A = 10;
const B = 11;
const C = 12;

function oAbs(n) { return n < 0n ? -n : n; }
function oGcd(a, b) {
  a = oAbs(a); b = oAbs(b);
  while (b !== 0n) [a, b] = [b, a % b];
  return a || 1n;
}
function oRat(n, d = 1n, reduce = true) {
  if (d === 0n) throw new Error('zero denominator');
  if (d < 0n) { n = -n; d = -d; }
  if (!reduce) return { n, d };
  const g = oGcd(n, d);
  return { n: n / g, d: d / g };
}
function oCmp(x, y) {
  const v = x.n * y.d - y.n * x.d;
  return v < 0n ? -1 : v > 0n ? 1 : 0;
}
function oEqual(x, y) { return oCmp(x, y) === 0; }
function oNeg(x) { return { n: -x.n, d: x.d }; }
function oSub(x, y) { return oRat(x.n * y.d - y.n * x.d, x.d * y.d); }
function oPow(base, exponent) {
  let answer = 1n;
  for (let i = 0; i < exponent; i += 1) answer *= BigInt(base);
  return answer;
}
function oFloor(x) {
  return x.n >= 0n ? x.n / x.d : -((-x.n + x.d - 1n) / x.d);
}
function oParse(text) {
  let source = String(text).trim();
  if (!source || source.length > 256 || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(source)) throw new Error('invalid decimal');
  let sign = 1n;
  if (source[0] === '+' || source[0] === '-') {
    if (source[0] === '-') sign = -1n;
    source = source.slice(1);
  }
  const [whole = '0', fraction = ''] = source.split('.');
  return oRat(sign * BigInt(`${whole || '0'}${fraction}`), oPow(10n, fraction.length));
}
function oParts(text) {
  const value = oParse(text);
  let source = String(text).trim().replace(/^[+-]/, '');
  const pieces = source.split('.');
  const whole = (pieces[0] || '0').replace(/^0+(?=\d)/, '') || '0';
  const fraction = (pieces[1] || '').replace(/0+$/, '');
  return { negative: value.n < 0n, whole, fraction, value };
}
function oEncode(text, markers = { plus: A, minus: B, point: C }) {
  const parts = oParts(text);
  return [parts.negative ? markers.minus : markers.plus]
    .concat([...parts.whole].map(Number), markers.point, [...parts.fraction].map(Number));
}
function oDigitValue(digits, radix = R) {
  return digits.reduce((value, digit) => value * radix + BigInt(digit), 0n);
}
function oDecode(payload) {
  if (!Array.isArray(payload) || ![A, B].includes(payload[0])) throw new Error('bad sign marker');
  const point = payload.indexOf(C, 1);
  if (point < 2 || payload.indexOf(C, point + 1) !== -1) throw new Error('bad point marker');
  const other = payload.filter((_, i) => i !== 0 && i !== point);
  if (other.some(digit => digit < 0 || digit > 9)) throw new Error('bad decimal digit');
  const whole = payload.slice(1, point).join('');
  const fraction = payload.slice(point + 1).join('');
  const magnitude = BigInt(`${whole}${fraction}` || '0');
  return oRat((payload[0] === B ? -1n : 1n) * magnitude, oPow(10n, fraction.length));
}
function oSlice(a, b) {
  if (oCmp(a, b) >= 0) throw new Error('unordered interval');
  const zero = oRat(0n);
  let sign, low, high;
  if (oCmp(b, zero) > 0) {
    sign = 1n; low = oCmp(a, zero) > 0 ? a : zero; high = b;
  } else {
    sign = -1n; low = oNeg(b); high = oNeg(a);
  }
  const shell = oFloor(low);
  const cap = oRat(shell + 1n);
  const upper = oCmp(high, cap) < 0 ? high : cap;
  return { sign, shell, lo: oSub(low, oRat(shell)), hi: oSub(upper, oRat(shell)) };
}
function oCylinder(lo, hi, radix = R) {
  let denominator = 1n;
  for (let k = 0; k < 4096; k += 1) {
    const p = (lo.n * denominator + lo.d - 1n) / lo.d;
    if (lo.n * denominator <= p * lo.d && (p + 1n) * hi.d <= hi.n * denominator) return { p, k, denominator };
    denominator *= radix;
  }
  throw new Error('no cylinder');
}
function oFixed(n, length) {
  const digits = Array(length).fill(0);
  let value = n;
  for (let i = length - 1; i >= 0; i -= 1) { digits[i] = Number(value % R); value /= R; }
  if (value !== 0n) throw new Error('overflow');
  return digits;
}
function oConstruct(leftText, rightText, targetText, deeperIndex = 0, deeperDigits = 0) {
  const a = oParse(leftText);
  const b = oParse(rightText);
  const slice = oSlice(a, b);
  const cylinder = oCylinder(slice.lo, slice.hi);
  const capacity = oPow(R, deeperDigits);
  const prefixInteger = cylinder.p * capacity + BigInt(deeperIndex);
  if (BigInt(deeperIndex) < 0n || BigInt(deeperIndex) >= capacity) throw new Error('bad deeper index');
  const prefixLength = cylinder.k + deeperDigits;
  const payload = oEncode(targetText);
  const payloadInteger = oDigitValue(payload);
  const denominator = oPow(R, prefixLength + payload.length);
  const fractionalNumerator = prefixInteger * oPow(R, payload.length) + payloadInteger;
  const numerator = slice.sign * (slice.shell * denominator + fractionalNumerator);
  return {
    a, b, target: oParse(targetText), x: oRat(numerator, denominator, false), slice, cylinder,
    prefixInteger, prefixLength, prefix: oFixed(prefixInteger, prefixLength), payload, payloadInteger
  };
}
function oDepth(n, radix = 13n, branches = 10n) {
  const allowed = oPow(branches, n);
  const total = oPow(radix, n);
  return {
    allowed, total,
    ratio: Number(allowed) / Number(total),
    dimension: Math.log(Number(allowed)) / Math.log(Number(total))
  };
}
function oFormatRat(x) { return x.d === 1n ? String(x.n) : `${x.n}/${x.d}`; }
function oBaseDigits(value) {
  let denominator = value.d;
  let exponent = 0;
  while (denominator > 1n && denominator % R === 0n) { denominator /= R; exponent += 1; }
  if (denominator !== 1n) throw new Error('not terminating base thirteen');
  const n = oAbs(value.n);
  let whole = n / value.d;
  let remainder = n % value.d;
  const integer = [];
  if (whole === 0n) integer.push(0);
  while (whole > 0n) { integer.unshift(Number(whole % R)); whole /= R; }
  const fraction = [];
  for (let i = 0; i < exponent; i += 1) {
    remainder *= R;
    fraction.push(Number(remainder / value.d));
    remainder %= value.d;
  }
  return integer.concat(fraction);
}
function oDecodeTail(digits) {
  for (let i = digits.length - 1; i >= 0; i -= 1) {
    if (![A, B].includes(digits[i])) continue;
    try { return oDecode(digits.slice(i)); } catch { /* keep looking */ }
  }
  return oRat(0n);
}
function oEvaluate(value) { return oDecodeTail(oBaseDigits(value)); }

console.log('\nINDEPENDENT ARITHMETIC');

check('decimal zero parses exactly', oEqual(oParse('0'), oRat(0n)));
check('signed zero normalizes exactly', oEqual(oParse('-0.000'), oRat(0n)));
check('leading-dot decimal parses exactly', oEqual(oParse('.125'), oRat(1n, 8n)));
check('trailing-dot integer parses exactly', oEqual(oParse('17.'), oRat(17n)));
check('leading zeros normalize', oEqual(oParse('+0012.3400'), oRat(617n, 50n)));
check('negative decimal reduces', oEqual(oParse('-3.14'), oRat(-157n, 50n)));
check('fraction syntax is rejected', mustThrow(() => oParse('1/3')));
check('scientific notation is rejected', mustThrow(() => oParse('1e-3')));
check('non-numeric text is rejected', mustThrow(() => oParse('thirteen')));
check('blank input is rejected', mustThrow(() => oParse('')));

check('positive payload has declared controls', show(oEncode('12.34')) === show([10, 1, 2, 12, 3, 4]), oEncode('12.34'));
check('negative payload has declared controls', show(oEncode('-3.14')) === show([11, 3, 12, 1, 4]), oEncode('-3.14'));
check('integer payload retains point marker', show(oEncode('8')) === show([10, 8, 12]), oEncode('8'));
check('trailing decimal zeros are canonicalized', show(oEncode('2.5000')) === show([10, 2, 12, 5]), oEncode('2.5000'));
check('positive payload decodes exactly', oEqual(oDecode(oEncode('12.34')), oRat(617n, 50n)));
check('negative payload decodes exactly', oEqual(oDecode(oEncode('-3.14')), oRat(-157n, 50n)));
check('zero payload decodes exactly', oEqual(oDecode(oEncode('-0.000')), oRat(0n)));
check('payload without point marker is rejected', mustThrow(() => oDecode([10, 1, 2, 3])));
check('payload with a second control is rejected', mustThrow(() => oDecode([10, 1, 12, 2, 11])));

check('first radix power is exact', oPow(13n, 1) === 13n);
check('second radix power is exact', oPow(13n, 2) === 169n);
check('third radix power is exact', oPow(13n, 3) === 2197n);
check('fiftieth ordinary branch count is exact length', oPow(10n, 50).toString().length === 51);
check('fiftieth total count is exact', oPow(13n, 50) === 49792922297912707801714181535533618316401192004725734249n);

const defaultOracle = oConstruct('0.2', '0.21', '-3.14');
check('default cylinder left endpoint fits', defaultOracle.slice.lo.n * defaultOracle.cylinder.denominator <= defaultOracle.cylinder.p * defaultOracle.slice.lo.d);
check('default cylinder right endpoint fits', (defaultOracle.cylinder.p + 1n) * defaultOracle.slice.hi.d <= defaultOracle.slice.hi.n * defaultOracle.cylinder.denominator);
check('default witness is strictly right of a', oCmp(defaultOracle.a, defaultOracle.x) < 0, oFormatRat(defaultOracle.x));
check('default witness is strictly left of b', oCmp(defaultOracle.x, defaultOracle.b) < 0, oFormatRat(defaultOracle.x));
check('default witness decodes to target', oEqual(oEvaluate(defaultOracle.x), defaultOracle.target));
check('default prefix length is minimal', defaultOracle.prefixLength === 2, defaultOracle.prefixLength);
check('default leftmost prefix is exact', defaultOracle.prefixInteger === 34n, defaultOracle.prefixInteger);
check('default payload integer is exact', defaultOracle.payloadInteger === 322807n, defaultOracle.payloadInteger);

const constructionCases = [
  ['0', '1', '0'],
  ['-1.2', '-1.1', '2.5'],
  ['-0.01', '0.01', '999.001'],
  ['13', '13.0001', '-0.125'],
  ['999999999999999999999.9', '1000000000000000000000.1', '42'],
  ['-1000000000000000000000.1', '-999999999999999999999.9', '-42'],
  ['.333', '.333000000000000000001', '7.75']
];

for (const [left, right, target] of constructionCases) {
  const result = oConstruct(left, right, target);
  check(`oracle containment for (${left}, ${right})`, oCmp(result.a, result.x) < 0 && oCmp(result.x, result.b) < 0, oFormatRat(result.x));
  check(`oracle decoding for target ${target}`, oEqual(oEvaluate(result.x), result.target), oFormatRat(oEvaluate(result.x)));
}

const manyOracle = Array.from({ length: 24 }, (_, index) => oConstruct('0.2', '0.21', '-3.14', index, 2));
check('twenty-four oracle witnesses are distinct', new Set(manyOracle.map(item => oFormatRat(item.x))).size === 24);
check('every repeated witness remains in the interval', manyOracle.every(item => oCmp(item.a, item.x) < 0 && oCmp(item.x, item.b) < 0));
check('every repeated witness has the same target', manyOracle.every(item => oEqual(oEvaluate(item.x), item.target)));

const d1 = oDepth(1);
const d2 = oDepth(2);
const d30 = oDepth(30);
const d50 = oDepth(50);
check('depth one exact counts', d1.allowed === 10n && d1.total === 13n);
check('depth two exact counts', d2.allowed === 100n && d2.total === 169n);
check('depth thirty numerator is exact', d30.allowed === 1000000000000000000000000000000n);
check('depth thirty denominator is exact', d30.total === 2619995643649944960380551432833049n);
check('depth thirty displayed fraction rounds correctly', d30.ratio.toFixed(15) === '0.000381680023943', d30.ratio.toFixed(15));
check('dimension display rounds correctly', d30.dimension.toFixed(12) === '0.897711717503', d30.dimension.toFixed(12));
check('dimension is depth invariant within floating tolerance', Math.abs(d1.dimension - d50.dimension) < 2e-16);
check('surviving fractions strictly decrease', d2.ratio < d1.ratio && d30.ratio < d2.ratio && d50.ratio < d30.ratio);
check('depth fifty exact numerator', d50.allowed === 10n ** 50n);
check('depth fifty exact denominator', d50.total === 13n ** 50n);

const scaleBase = oConstruct('0.2', '0.21', '-3.14').x;
check('oracle scale invariance up one radix power', oEqual(oEvaluate(oRat(scaleBase.n * R, scaleBase.d, false)), oParse('-3.14')));
check('oracle scale invariance down one radix power', oEqual(oEvaluate(oRat(scaleBase.n, scaleBase.d * R, false)), oParse('-3.14')));
check('oracle scale invariance up four radix powers', oEqual(oEvaluate(oRat(scaleBase.n * oPow(R, 4), scaleBase.d, false)), oParse('-3.14')));
check('oracle scale invariance down four radix powers', oEqual(oEvaluate(oRat(scaleBase.n, scaleBase.d * oPow(R, 4), false)), oParse('-3.14')));

console.log('\nPAGE STRUCTURE AND SOURCE RECORD');

check('page has canonical URL', html.includes('<link rel="canonical" href="https://artwaste.land/strata/conway-base-13/"'));
// The deployed copy carries Cloudflare's analytics beacon, which worker.js injects into
// every HTML response (oversight/requests/008); a reader who downloads the page gets it.
// The claim is about the page as authored, so the injected tag is set aside first
// (found 2026-10-30, when this check failed for a reader running it from /checks/).
const authored = html.replace(/<script defer src="https:\/\/static\.cloudflareinsights\.com\/beacon\.min\.js" data-cf-beacon='[^']*'><\/script>/g, '');
check('page loads only local executable script resources', !/<script[^>]+src=["']https?:\/\//i.test(authored));
check('page loads only local stylesheet resources', !/<link[^>]+rel=["']stylesheet["'][^>]+href=["']https?:\/\//i.test(html));
check('page has no em dash character', !html.includes(String.fromCodePoint(0x2014)));
check('page ends with load-bearing closing tags', /<\/script>\s*<\/body>\s*<\/html>\s*$/.test(html));
check('layer one precedes layer two', html.indexOf('id="layer-one"') < html.indexOf('id="layer-two"'));
check('layer two precedes layer three', html.indexOf('id="layer-two"') < html.indexOf('id="layer-three"'));
check('the check panel is visible in document flow', html.indexOf('class="check-panel"') > html.indexOf('id="layer-three"'));
check('reduced-motion guard is present', html.includes('@media (prefers-reduced-motion:reduce)'));
check('focus-visible style is present', html.includes(':focus-visible'));
check('aria-live readouts are present', (html.match(/aria-live="polite"/g) || []).length >= 6);
check('Darboux source record is present', html.includes('10.24033/asens.122') && html.includes('57-112'));
check('Oman source record is present', html.includes('10.35834/mjms/1418931955') && html.includes('134-150'));
check('Boylan source record is present', html.includes('arXiv:2103.10249'));
check('Hutchinson source record is present', html.includes('10.1512/iumj.1981.30.30055') && html.includes('713-747'));
check('historical cutoff is stated', html.includes('data-source="cutoff-date">2026-08-01'));
check('arbitrary real evaluation hazard is named', html.includes('No arbitrary-real evaluator is claimed'));
check('marker convention uncertainty is named', html.includes('Marker assignments are a declared convention') || html.includes('marker assignments are a declared convention'));

console.log('\nPAGE COUPLING');

const engineMatch = html.match(/<script id="conway-engine" data-engine>([\s\S]*?)<\/script>/);
check('shipped page engine can be extracted', Boolean(engineMatch));

let Page;
if (engineMatch) {
  const context = vm.createContext({ console });
  try {
    vm.runInContext(engineMatch[1], context, { filename: 'conway-page-engine.js', timeout: 3000 });
    Page = context.ConwayEngine;
  } catch (error) {
    console.error(error);
  }
}
check('shipped page engine executes in node:vm', Boolean(Page));
check('page engine exports radix thirteen', Page?.RADIX === 13n);
check('page engine exports ten ordinary branches', Page?.ORDINARY === 10n);
check('page engine exports the marker assignment', Page?.PLUS === 10 && Page?.MINUS === 11 && Page?.POINT === 12);

if (Page) {
  const parseCases = ['0', '-0.000', '.125', '17.', '+0012.3400', '-3.14', '999999999999999999999.0001'];
  for (const text of parseCases) {
    const expected = oParse(text);
    const actual = Page.parseDecimal(text);
    check(`page parser matches oracle for ${text}`, actual.n === expected.n && actual.d === expected.d, `${actual.n}/${actual.d}`);
  }

  const payloadCases = ['0', '-0', '8', '2.5000', '12.34', '-3.14', '999.001'];
  for (const text of payloadCases) {
    const actual = Array.from(Page.encodeDecimal(text).symbols);
    check(`page payload matches oracle for ${text}`, show(actual) === show(oEncode(text)), actual);
    const decoded = Page.decodePayload(actual);
    check(`page payload decodes independently for ${text}`, oEqual({ n: decoded.n, d: decoded.d }, oParse(text)), `${decoded.n}/${decoded.d}`);
  }

  for (const [left, right, target] of constructionCases.concat([['0.2', '0.21', '-3.14']])) {
    const expected = oConstruct(left, right, target);
    const actual = Page.construct(left, right, target, 0, 0);
    check(`page numerator matches oracle in (${left}, ${right})`, actual.x.n === expected.x.n, actual.x.n);
    check(`page denominator matches oracle in (${left}, ${right})`, actual.x.d === expected.x.d, actual.x.d);
    check(`page prefix matches oracle in (${left}, ${right})`, actual.prefixInteger === expected.prefixInteger && actual.prefixLength === expected.prefixLength);
    check(`page result lies strictly inside (${left}, ${right})`, Page.cmp(actual.a, actual.x) < 0 && Page.cmp(actual.x, actual.b) < 0);
    check(`page result decodes to ${target}`, Page.equal(actual.decoded, actual.target));
  }

  for (const n of [1, 2, 3, 7, 15, 30, 41, 50]) {
    const expected = oDepth(n);
    const actual = Page.depthStats(n);
    check(`page exact allowed count at depth ${n}`, actual.allowed === expected.allowed, actual.allowed);
    check(`page exact total count at depth ${n}`, actual.total === expected.total, actual.total);
    check(`page ratio at depth ${n}`, Math.abs(actual.ratio - expected.ratio) <= Number.EPSILON * expected.ratio);
    check(`page dimension at depth ${n}`, Math.abs(actual.dimension - expected.dimension) < 2e-15);
  }

  const actualMany = Array.from(Page.constructMany('0.2', '0.21', '-3.14', 24));
  check('page produces requested witness count', actualMany.length === 24);
  check('page repeated witnesses are distinct', new Set(actualMany.map(item => `${item.x.n}/${item.x.d}`)).size === 24);
  check('page repeated witnesses stay inside interval', actualMany.every(item => Page.cmp(item.a, item.x) < 0 && Page.cmp(item.x, item.b) < 0));
  check('page repeated witnesses decode correctly', actualMany.every(item => Page.equal(item.decoded, item.target)));

  const pageDefault = Page.construct('0.2', '0.21', '-3.14', 0, 0);
  const up = Page.rawRat(pageDefault.x.n * 13n, pageDefault.x.d);
  const down = Page.rawRat(pageDefault.x.n, pageDefault.x.d * 13n);
  check('page engine reproduces scale invariance upward', Page.equal(Page.decodeBase13Rational(up), pageDefault.target));
  check('page engine reproduces scale invariance downward', Page.equal(Page.decodeBase13Rational(down), pageDefault.target));
  check('page depth-thirty display matches checked anchor', Page.formatRatio(Page.depthStats(30).ratio) === '0.000381680023943');
  check('page dimension display matches checked anchor', Page.formatDimension(Page.depthStats(30).dimension) === '0.897711717503');
}

console.log('\nMUTATION SWEEP');

const mutations = [];
function mutation(name, caught) { mutations.push({ name, caught: Boolean(caught) }); check(`mutation caught: ${name}`, caught); }

mutation('radix changed from thirteen to twelve', oDepth(30, 12n, 10n).total !== d30.total);
mutation('ordinary branch count changed from ten to nine', oDepth(30, 13n, 9n).allowed !== d30.allowed);
mutation('positive marker swapped', show(oEncode('12.34', { plus: 11, minus: 11, point: 12 })) !== show(oEncode('12.34')));
mutation('negative marker swapped', show(oEncode('-3.14', { plus: 10, minus: 10, point: 12 })) !== show(oEncode('-3.14')));
mutation('decimal marker changed', show(oEncode('12.34', { plus: 10, minus: 11, point: 11 })) !== show(oEncode('12.34')));
mutation('payload final digit deleted', !oEqual(oDecode(oEncode('-3.14').slice(0, -1)), oParse('-3.14')));
mutation('payload target sign reversed', !oEqual(oDecode(oEncode('3.14')), oParse('-3.14')));
mutation('dimension uses radix twelve', Math.abs(Math.log(10) / Math.log(12) - d30.dimension) > 1e-3);
mutation('dimension uses nine branches', Math.abs(Math.log(9) / Math.log(13) - d30.dimension) > 1e-3);
mutation('survivor exponent reduced by one', oPow(10n, 29) !== d30.allowed);
mutation('total exponent reduced by one', oPow(13n, 29) !== d30.total);
mutation('ratio inverted', (d30.total / d30.allowed) !== 0n && Number(d30.total) / Number(d30.allowed) !== d30.ratio);

const pMinus = defaultOracle.cylinder.p - 1n;
mutation('cylinder rounded left instead of up', defaultOracle.slice.lo.n * defaultOracle.cylinder.denominator > pMinus * defaultOracle.slice.lo.d);
const pPlus = defaultOracle.cylinder.p + 1n;
mutation('cylinder shifted right', (pPlus + 1n) * defaultOracle.slice.hi.d > defaultOracle.slice.hi.n * defaultOracle.cylinder.denominator);

const shortDen = oPow(R, defaultOracle.prefixLength + defaultOracle.payload.length - 1);
const shortX = oRat(defaultOracle.x.n, shortDen, false);
mutation('construction denominator loses one radix power', !oEqual(shortX, defaultOracle.x));
const wrongPayloadValue = defaultOracle.payloadInteger + 1n;
mutation('payload integer incremented', wrongPayloadValue !== defaultOracle.payloadInteger);
mutation('strict left containment weakened to equality', oCmp(defaultOracle.a, defaultOracle.x) !== 0);
mutation('strict right containment weakened to equality', oCmp(defaultOracle.x, defaultOracle.b) !== 0);
mutation('twenty-four witnesses all reuse one prefix', new Set(Array(24).fill(oFormatRat(defaultOracle.x))).size !== 24);
mutation('scale shift uses twelve', !oEqual(oEvaluate(oRat(scaleBase.n * 12n, scaleBase.d, false)), oParse('-3.14')));

const caughtMutations = mutations.filter(item => item.caught).length;
console.log(`\nMUTATIONS CAUGHT ${caughtMutations} / ${mutations.length}`);
check('every attempted mutation was caught', caughtMutations === mutations.length);

console.log(`\nSUMMARY ${assertions - failures} passed, ${failures} failed, ${assertions} assertions total`);
if (assertions < 40) {
  console.error('FAIL verifier contains fewer than forty assertions');
  process.exitCode = 1;
} else if (failures > 0) {
  process.exitCode = 1;
} else {
  console.log('ALL CHECKS PASS');
}
