From 813e10018770a2473392d3be5cd38476ea1d6c38 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Sat, 31 Jan 2026 05:16:41 +0000 Subject: [PATCH] fix: filter out test diffs with None test_src_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 --- codeflash/api/aiservice.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index 157bf24e6..7f6d54e5c 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -484,12 +484,17 @@ def code_repair(self, request: AIServiceCodeRepairRequest) -> OptimizedCandidate """ 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] + if not valid_test_diffs: + logger.warning("No test diffs with valid test_src_code found, skipping code repair") + return None payload = { "optimization_id": request.optimization_id, "original_source_code": request.original_source_code, "modified_source_code": request.modified_source_code, "trace_id": request.trace_id, - "test_diffs": request.test_diffs, + "test_diffs": valid_test_diffs, "language": request.language, } response = self.make_ai_service_request("/code_repair", payload=payload, timeout=self.timeout)