Claude should verify business code first when unit tests fail

Resolved 💬 3 comments Opened Dec 16, 2025 by Wubabalala Closed Dec 19, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a unit test fails, Claude directly fixes the test code without first verifying whether the business code has the same vulnerability.

What Should Happen?

  1. First check the actual business code (PaymentService.generateOrderNo())
  2. Verify if business code has the same issue
  3. Found business code uses UUID - no issue exists
  4. Then align test code with business logic

Error Messages/Logs

Steps to Reproduce

  1. Have a test file with a helper method that generates IDs using only timestamp:

```java
// Test helper
order.setOrderNo("TEST_ORDER_" + System.currentTimeMillis());

  1. Run a test that calls this helper twice in quick succession (same millisecond), causing duplicate key error
  2. Ask Claude to run all unit tests
  3. Observe: Claude immediately adds AtomicLong counter to fix the test, without checking business code
  4. Expected: Claude should first check PaymentService.generateOrderNo() to see if business code has the same vulnerability
  5. Upon checking, Claude would find business code uses UUID - no issue exists:

// Business code (already safe)
return String.format("ORDER_%d_%d_%s",
System.currentTimeMillis(),
userId,
UUID.randomUUID().toString().substring(0, 8));

  1. Correct fix: Align test code with business logic (use UUID), not invent a different solution (AtomicLong)

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.70 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗