Skip to content

Conversation

@misrasaurabh1
Copy link
Contributor

Summary

  • Filter out test diffs where test_src_code is None before calling the code_repair API endpoint
  • Return early with a warning log if no valid test diffs remain after filtering

Problem

When running codeflash on JavaScript/TypeScript files, the code_repair API call fails with:

ERROR    Error generating optimized candidates: 422 - {"detail": [{"type":      
         "string_type", "loc": ["body", "data", "test_diffs", 0,                
         "test_src_code"], "msg": "Input should be a valid string"}]}

This happens because:

  1. The CLI's TestDiff.test_src_code is Optional[str] = None
  2. The get_src_code() method returns None when it can't find/parse the test source
  3. The aiservice expects test_src_code: str (non-nullable)

Test plan

  • Manual testing with codeflash on appsmith TypeScript codebase
  • Unit test to verify filtering logic works correctly

🤖 Generated with Claude Code

When calling the code_repair API endpoint, test diffs with None
test_src_code cause a 422 validation error since aiservice expects
test_src_code to be a string. This filters out invalid test diffs
before making the API call.

The test_src_code can be None when get_src_code() cannot find or
parse the test source file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
console.rule()
try:
# Filter out test diffs where test_src_code is None since aiservice requires it to be a string
valid_test_diffs = [diff for diff in request.test_diffs if diff.test_src_code is not None]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aseembits93 can you review this? why would this be None? is there a root cause fix for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@misrasaurabh1 this is the expected schema on the backend


class TestDiff(Schema):
    test_src_code: str

this is the schema on cli

@dataclass
class TestDiff:
    test_src_code: Optional[str] = None

i'll fix it on the backend, we can close this one

@aseembits93 aseembits93 closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants