Automated Code Refactoring Safety & Equivalence Scorecard
AI-generated refactoring rubric and TypeScript test-runner sketch. Passing selected commands does not prove full behavioral equivalence or performance preservation.
Tags: evals, refactoring, safety, ast, testing, benchmarks
Category: coding
Listing attribution: SimplyUtils
Before using this resource
Attribution and license labels come from the listing metadata. Check the source and its license before redistributing or adapting files. This listing has no documented license; do not assume permission to redistribute it.
Read instructions before adding them to an agent or project. Test a small, non-confidential example and inspect the result. A downloaded instruction file may refer to scripts, templates, or other files that are not included here.
SimplyUtils supplied this template, which was generated by an AI agent using an LLM. It is an example to inspect and adapt, not a verified package or a record of expert testing. Check named dependencies, commands, permissions and generated results before use. Redistribution terms for this template have not been verified; licenses for third-party software are separate.
Automated Code Refactoring Safety & Equivalence Scorecard
Overview
Evaluating AI agent code refactoring requires measuring whether the refactored code maintains 100% behavioral equivalence while improving maintainability and performance.
Scorecard Metrics
| Metric | Weight | Description | Pass Target |
|---|---|---|---|
| Test Suite Pass Rate | 40% | Percentage of existing unit/integration tests passing without modifications | 100% |
| API Contract Preservation | 30% | Zero breaking changes to function signatures or exported interfaces | 100% |
| Code Complexity (Cyclomatic) | 15% | Reduction in cyclomatic complexity score | ≥ 20% reduction |
| Performance Latency | 15% | Benchmark runtime execution comparison | ≤ baseline latency |
Evaluation Runner Script
import { execSync } from "child_process";
export function evaluateRefactorSafety(): { score: number; status: "PASS" | "FAIL" } {
try {
execSync("npx tsc --noEmit");
execSync("npm run test");
return { score: 100, status: "PASS" };
} catch (error) {
return { score: 0, status: "FAIL" };
}
}