auth-yes/.forum/poc-g2/mutation_poc.ts

69 lines
2.3 KiB
TypeScript

import { assert } from "https://deno.land/std@0.224.0/testing/asserts.ts";
/**
* Proof of Concept: Mutation Testing Scores (Gen 2)
*
* Demonstrates the Adversary enforcing edge-case quality by consuming structured
* mutation score data generated from a (simulated) external tool, forcing the Coder
* agent to rewrite tests if a threshold is not met.
*/
// Simulated output that would normally be generated by a mutation framework like Stryker
// We simulate loading it from a file
async function generateAndLoadMutationReport(filePath: string) {
await Deno.writeTextFile(filePath, JSON.stringify({
mutationScore: 65.4,
threshold: 80.0,
survivingMutants: [
{
file: "src/auth.ts",
line: 42,
mutator: "ConditionalExpression",
status: "Survived"
}
]
}));
return JSON.parse(await Deno.readTextFile(filePath));
}
function verifyQualityGate(report: any): { pass: boolean; feedback: string[] } {
const feedback = [];
if (report.mutationScore < report.threshold) {
feedback.push(`Mutation score ${report.mutationScore}% is below threshold ${report.threshold}%`);
}
report.survivingMutants.forEach((mutant: any) => {
if (mutant.status === "Survived") {
feedback.push(`Mutant survived in ${mutant.file}:${mutant.line} via ${mutant.mutator}. Add edge-case test.`);
}
});
return {
pass: feedback.length === 0,
feedback
};
}
if (import.meta.main) {
console.log("Running Mutation Testing PoC (Gen 2) tests...");
try {
const tempReport = await Deno.makeTempFile({ suffix: ".json" });
const report = await generateAndLoadMutationReport(tempReport);
const gate = verifyQualityGate(report);
assert(gate.pass === false, "Expected quality gate to fail due to low mutation score");
assert(gate.feedback.length === 2, "Expected 2 pieces of critical feedback");
console.log("Adversary Agent Feedback generated from real File I/O mutation report:");
gate.feedback.forEach(f => console.log(` - ${f}`));
await Deno.remove(tempReport);
console.log("✅ Mutation Testing PoC (Gen 2) successful: Enforced strict quality gate via structured report data.");
} catch (err) {
console.error("❌ Mutation Testing PoC (Gen 2) failed:", err);
Deno.exit(1);
}
}