Skip to content

Official Codebase of 3DCodeVerse

Python

repair: a failing-file path loses its './' prefix, not every leading '.' and '/' — '../x' was read as 'x' (B14)

gaoypengfeaaa7da38b8
diff --git a/harness/codeverse3d/tracks/repair.py b/harness/codeverse3d/tracks/repair.py
index a478616c..e397eba1 100644
--- a/harness/codeverse3d/tracks/repair.py
+++ b/harness/codeverse3d/tracks/repair.py
@@ -128,11 +128,15 @@ def files_for_repair(ctx: RunContext, build: BuildResult, lint: GateReport, file
def _rel(ctx: RunContext, path: str) -> str:
+ """``path`` relative to the workspace, or ``""`` when it points outside it (an absolute
+ path elsewhere, a ``..`` escape): never a file to inline. Was ``lstrip("./")``, which
+ strips a character SET — ``../x`` became ``x`` and ``.env.js`` became ``env.js`` (B14)."""
p = path.replace("\\", "/")
root = str(ctx.ws.root).replace("\\", "/").rstrip("/") + "/"
- if p.startswith(root):
- return p[len(root):]
- return p.lstrip("./")
+ p = p.removeprefix(root)
+ while p.startswith("./"):
+ p = p[2:]
+ return "" if p.startswith("/") or ".." in p.split("/") else p
def build_once(ctx: RunContext) -> tuple[BuildResult, GateReport]:
diff --git a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py b/harness/tests/orchestrator_tracks/test_generation_planner_repair.py
index c4a77dcc..6ec857b6 100644
--- a/harness/tests/orchestrator_tracks/test_generation_planner_repair.py
+++ b/harness/tests/orchestrator_tracks/test_generation_planner_repair.py
@@ -258,6 +258,19 @@ def test_build_with_repair_single_shot_sends_file_contents_and_stops_at_max(tmp_
assert out.usage.cost_usd == pytest.approx(0.004)
+
+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
+
+ from codeverse3d.tracks.repair import _rel
+
+ ctx = SimpleNamespace(ws=tmp_ws)
+ assert _rel(ctx, str(tmp_ws.root / "src" / "a.js")) == "src/a.js"
+ assert _rel(ctx, "./src/.env.js") == "src/.env.js"
+ assert _rel(ctx, "src/parts/seat.js") == "src/parts/seat.js"
+ assert _rel(ctx, "../outside.js") == "" and _rel(ctx, "/etc/passwd") == ""
+
def test_format_error_report_and_cookbook_section():
from codeverse3d.contracts.artifacts import BuildResult, GateFinding, GateReport, Severity