// 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/siws.ts';
const MUTANTS = [
['no domain check', "if (p.domain !== domain) return", "if (false) return"],
['no expiry', "if (now >= Date.parse(p.expirationTime)) return no('the message expired');", ''],
['no replay guard', "if (seen.has(p.nonce)) return", "if (false) return"],
['no allowlist', "if (!list.includes(address)) return", "if (false) return"],
['any signature', "if (!verifyEd25519(message, sig, address))", "if (false)"],
['nonce never recorded', "seen.add(p.nonce);", ''],
['address not bound to message', " || address !== p.address", ''],
];
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/siws.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