Skip to content

Fault Localization

chimera.training.fault_localization ranks code locations by suspiciousness using test failure analysis. It parses pytest output, extracts traceback references, and scores locations that appear more frequently in failing tests using an Ochiai-inspired approach.


Dataclass representing a code location ranked by suspiciousness.

FieldTypeDescription
filestrSource file path
functionstr | NoneEnclosing function name (if identified)
lineintLine number in the source file
scorefloat0.0 (not suspicious) to 1.0 (very suspicious)
reasonstrHuman-readable explanation of the score

Parses test output and ranks suspicious locations. Filters out test files so only production code is reported.

Key methods:

  • localize(test_output) -> list[SuspiciousLocation] — parse and rank
  • augment_prompt(prompt, locations, max_locations) -> str — append suspected bug locations to an agent prompt
from chimera.training.fault_localization import FaultLocalizer
localizer = FaultLocalizer()
# Parse pytest output
test_output = env.run_tests().output
locations = localizer.localize(test_output)
for loc in locations[:3]:
print(f"{loc.file}:{loc.line}{loc.score:.0%} suspicious")
print(f" {loc.reason}")
# Augment an agent prompt with fault info
prompt = localizer.augment_prompt(
"Fix the failing tests in the calculator module.",
locations,
max_locations=3,
)
result = agent.run(prompt, env=env)