Official Codebase of 3DCodeVerse
Python
repair: the error-matched cookbook section comes from prompts.sections — repair's own heading regex goes
gaoypeng73957e98169f
diff --git a/harness/codeverse3d/tracks/repair.py b/harness/codeverse3d/tracks/repair.pyindex e397eba1..d87a5541 100644--- a/harness/codeverse3d/tracks/repair.py+++ b/harness/codeverse3d/tracks/repair.py@@ -19,6 +19,7 @@ from pydantic import BaseModel, Fieldfrom codeverse3d.contracts.artifacts import BuildResult, GateReportfrom codeverse3d.contracts.common import Usagefrom codeverse3d.prompts import render+from codeverse3d.prompts.sections import split_sectionsfrom codeverse3d.tracks import skills_hookfrom codeverse3d.tracks.common import RunContext, generate_forfrom codeverse3d.tracks.generation import GenerationResult, GenerationTask@@ -85,7 +86,6 @@ def format_error_report(build: BuildResult, lint: GateReport, cookbook: str = ""return "\n".join(lines)-_HEADING = re.compile(r"^##+ .+$", re.M)_WORD = re.compile(r"[A-Za-z_][A-Za-z0-9_]{3,}")@@ -93,15 +93,10 @@ def relevant_cookbook_section(cookbook: str, error_text: str, *, max_chars: int"""Pick the cookbook ``##`` section sharing the most identifiers with the error."""if not cookbook or not error_text:return ""- heads = list(_HEADING.finditer(cookbook))- if not heads:- return ""err_words = {w.lower() for w in _WORD.findall(error_text)}err_words -= {"error", "line", "file", "traceback", "most", "recent", "call", "last", "module"}best, best_score = "", 0- for i, h in enumerate(heads):- end = heads[i + 1].start() if i + 1 < len(heads) else len(cookbook)- body = cookbook[h.start():end]+ for body in (s.body for s in split_sections(cookbook) if s.level >= 2):words = {w.lower() for w in _WORD.findall(body)}score = len(words & err_words)if score > best_score:diff --git a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py b/harness/tests/orchestrator_tracks/test_generation_planner_repair.pyindex 6ec857b6..d5662a38 100644--- a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py+++ b/harness/tests/orchestrator_tracks/test_generation_planner_repair.py@@ -259,6 +259,16 @@ def test_build_with_repair_single_shot_sends_file_contents_and_stops_at_max(tmp_++def test_repair_cookbook_sections_are_the_prompt_sections():+ """Repair splits the cookbook with ``prompts.sections`` (its own ``^##+`` regex went,+ identical on all 7 shipped cookbooks): a ``## `` comment inside a fence is code, not+ a heading that cuts the recipe in half."""+ cb = ("## Hinges\nhinge pivot axis revolute\n```python\n## pivot axis note\nhinge = 1\n```\n"+ "## Materials\nroughness metalness\n")+ got = relevant_cookbook_section(cb, "hinge pivot axis wrong")+ assert got.startswith("## Hinges") and "hinge = 1" in got and "Materials" not in got+def test_repair_rel_strips_a_prefix_not_a_character_set(tmp_ws):"""B14: ``lstrip("./")`` turned ``../x`` into ``x`` and ``.env.js`` into ``env.js``."""from types import SimpleNamespace