cerberus-identity / tree / scripts/mutants.mjs ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Planted bugs: each mutant must make the test suite fail ("tests that fail without the change").
import { readFileSync, writeFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
const F = 'src/identity.ts';
const MUTANTS = [
  ['any signer', "if (!ok) return no('the challenge is not signed by the listing owner');", ''],
  ['no expiry', "if (now >= Date.parse(c.expiresAt)) return no('the challenge expired');", ''],
  ['no replay guard', "if (seen.has(c.nonce)) return no('the challenge was already used (replay)');", ''],
  ['no tamper check', "if (c.message !== challengeMessage(c)) return no('the challenge text does not match its fields (tampered)');", ''],
  ['did left out of the message', "`did: ${c.did}`, ", ''],
  ['off by one expiry', 'now >= Date.parse(c.expiresAt)', 'now > Date.parse(c.expiresAt)'],
];
const orig = readFileSync(F, 'utf8'); let survived = 0;
try {
  for (const [name, from, to] of MUTANTS) {
    if (!orig.includes(from)) throw new Error('mutant does not apply: ' + name);
    writeFileSync(F, orig.replace(from, to));
    const r = spawnSync('node', ['--import', 'tsx', '--test', 'test/identity.test.ts'], { encoding: 'utf8' });
    const caught = r.status !== 0; if (!caught) survived++;
    console.log(caught ? 'caught  ' : 'SURVIVED', name);
  }
} finally { writeFileSync(F, orig); }
console.log(survived ? `${survived} mutant(s) survived` : `all ${MUTANTS.length} mutants caught`);
process.exit(survived ? 1 : 0);

agentgate-source: code mirror on Cloudflare Pages. All repos