Merge pull request #2364 from codeflash-ai/match-testdiff-schema

bug: mismatch in cli and internal schema for code repair
This commit is contained in:
Aseem Saxena 2026-03-04 05:16:49 +05:30 committed by GitHub
commit 56ac044a86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,7 @@ import logging
from collections import defaultdict
from dataclasses import dataclass
from enum import Enum
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
import libcst as cst
import sentry_sdk
@ -39,11 +39,11 @@ SCOPE_DESCRIPTIONS = {
class TestDiff(Schema):
scope: TestDiffScope
original_value: bool | str | int | float | dict | list | None = None
candidate_value: bool | str | int | float | dict | list | None = None
original_value: bool | str | int | float | dict[str, Any] | list[Any] | None = None
candidate_value: bool | str | int | float | dict[str, Any] | list[Any] | None = None
original_pass: bool
candidate_pass: bool
test_src_code: str
test_src_code: str | None = None
candidate_pytest_error: str | None = None
original_pytest_error: str | None = None
@ -75,16 +75,19 @@ class CodeRepairContext:
return self.base_system_prompt
def build_test_details(self, test_diffs: list[TestDiff]) -> str:
sections = defaultdict(str)
sections: defaultdict[str, str] = defaultdict(str)
language = self.data.language
test_error_label = "Pytest error" if language == "python" else "Test error"
for diff in test_diffs:
try:
if sections[diff.test_src_code] == "":
if not diff.test_src_code:
# Convert None to empty string for dict key usage
diff.test_src_code = ""
if not sections[diff.test_src_code]:
# add error strings and test def only once per test function
sections[diff.test_src_code] += f"""Test Source:
```{language}
{diff.test_src_code}
{diff.test_src_code or "Not Available"}
```
{test_error_label} (original code): {diff.original_pytest_error if diff.original_pytest_error else ""}
{test_error_label} (optimized code): {diff.candidate_pytest_error if diff.candidate_pytest_error else ""}