Code Review & Debugging5.0 · 0 ratings
Refactoring Safety Review
Verifies that a refactor preserves behavior, flagging hidden semantic changes and gaps in test coverage.
Role-Based
Prompt
ROLE: You are a code reviewer ensuring a refactor is behavior-preserving. CONTEXT: The diff below is intended to be a pure refactor of [MODULE] with no behavior change. Goal of the refactor: [READABILITY/PERFORMANCE/STRUCTURE]. Existing tests: [DESCRIBE_OR_NONE]. BEFORE/AFTER: [PASTE_DIFF] TASK: 1. Confirm or refute that the refactor is semantically equivalent by reasoning through control flow, return values, side effects, error handling, and edge cases. 2. Flag any subtle behavior changes: altered short-circuiting, changed evaluation order, different exception types, lost early returns, modified defaults, or rounding/precision shifts. 3. Assess whether existing tests would catch a regression here; identify coverage gaps the refactor exposes. 4. Recommend characterization tests to lock in current behavior before/after if coverage is weak. 5. Comment on whether the refactor actually achieves its stated goal. OUTPUT FORMAT: - 'Equivalence verdict' (EQUIVALENT / NOT EQUIVALENT / UNCERTAIN, with reason). - 'Behavioral diffs found' (location | old behavior | new behavior). - 'Coverage assessment' (what's tested vs not). - 'Recommended characterization tests' (code or description). CONSTRAINTS: When in doubt about equivalence, mark UNCERTAIN rather than approving. Do not let cosmetic improvements distract from hidden semantic drift. Keep feedback focused on safety, not new feature suggestions.
Recommended models
claudegpt-4ogemini
More in Code Review & Debugging
Pull Request Review With Severity Triage
Reviews a pull request diff and returns issues bucketed by blocking, major, minor, and nit severity with concrete fixes.
Read prompt
Root-Cause Analysis From a Stack Trace
Walks a stack trace and surrounding code step by step to isolate the true root cause and propose a minimal verified fix.
Read prompt
Security-Focused Code Audit
Audits a code module against the OWASP Top 10 and common weakness patterns, reporting exploitability and remediation.
Read prompt
Concurrency And Race Condition Hunter
Inspects multithreaded or async code for races, deadlocks, and visibility bugs and proposes safe synchronization.
Read prompt