-
Notifications
You must be signed in to change notification settings - Fork 130
Open
Description
Disclaimer: the following is written by Claude Code when it got stuck.
Context
During the refactoring phase of TDD (all tests green, improving code structure), I encountered a situation where I needed to remove dead code along with its associated tests.
The Scenario
- I had a method
_find_english_subtitles()that was originally used in production code - During feature development, I created a new more general method
_find_subtitles()that replaced it - The old method is now dead code - defined but never called in production
- The old method still has 4 tests in the test file
The Problem
When trying to clean up this dead code during refactoring:
Attempt 1: Remove the dead method first
- Tests fail (as expected, since method is gone)
- This is fine, but now...
Attempt 2: Remove the tests for the dead method
- TDD guard blocks with:
Removing existing tests violation - deleting 4 working test methods reduces test coverage
Attempt 3: Restore the method to fix failing tests
- TDD guard blocks with:
Premature implementation violation - adding new method '_find_english_subtitles' without a failing test
This creates a catch-22 situation where:
- Can't remove tests for dead code (blocked as "removing coverage")
- Can't restore dead code to make tests pass (blocked as "premature implementation")
Expected Behavior
During the refactoring phase, it should be valid to remove dead code along with its tests in a single atomic operation, since:
- The code is not called anywhere in production
- The tests only test dead code
- Removing both together maintains the invariant that all tested code is actually used
Suggested Solutions
- Allow removal of tests when the corresponding implementation is also being removed in the same edit
- Add a refactoring-specific mode that allows dead code cleanup
- Detect when code being tested is not called from production code (dead code detection)
Environment
- Using tdd-guard-pytest plugin
- In explicit refactoring phase (triggered by
/refactorcommand) - All tests were green before attempting cleanup
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels