Official Codebase of 3DCodeVerse
Python
generation: a model-written path is normalised before the harness-owned / read-only / edit_only checks (B1)
gaoypeng99309456f8e4
diff --git a/harness/codeverse3d/tracks/generation.py b/harness/codeverse3d/tracks/generation.pyindex a2ff70da..d160e3f7 100644--- a/harness/codeverse3d/tracks/generation.py+++ b/harness/codeverse3d/tracks/generation.py@@ -36,7 +36,7 @@ import loggingimport reimport shutilfrom collections.abc import Callable, Collection-from pathlib import Path+from pathlib import Path, PurePosixPathfrom typing import Anyfrom pydantic import BaseModel, Field@@ -135,10 +135,13 @@ def _strip_envelope_header(body: str) -> str:def _clean_path(p: str) -> str:- p = p.strip().strip("`'\"").replace("\\", "/")- while p.startswith("./"):- p = p[2:]- return p.lstrip("/")+ """Normalised (``//`` and ``./`` collapsed — ``src//lib/x.js`` IS ``src/lib/x.js``, so it must+ meet the harness-owned / scope checks as that), relative; a trailing ``/`` is kept."""+ p = p.strip().strip("`'\"").replace("\\", "/").lstrip("/")+ if not p:+ return p+ norm = PurePosixPath(p).as_posix().lstrip("/")+ return f"{norm}/" if p.endswith("/") and norm != "." else normdef _strip_fence(body: str) -> str:diff --git a/harness/tests/orchestrator_tracks/test_write_scope.py b/harness/tests/orchestrator_tracks/test_write_scope.pyindex d9e4479e..261811a0 100644--- a/harness/tests/orchestrator_tracks/test_write_scope.py+++ b/harness/tests/orchestrator_tracks/test_write_scope.py@@ -52,6 +52,26 @@ def test_write_files_only_skips_existing_out_of_scope_paths(tmp_ws: Workspace):assert [c.path for c in write_files(tmp_ws, {"src/zones/q.js": "// new q"})] == ["src/zones/q.js"]+def test_write_files_normalises_a_path_before_the_owned_and_scope_checks(tmp_ws: Workspace):+ """B1: `src//lib/x.js`, `src/./lib/x.js` and `src//recipes.glsl` ARE the harness-owned files —+ un-normalised they slipped past `is_harness_owned` and the edit_only scope and were written."""+ (tmp_ws.src / "lib").mkdir(parents=True, exist_ok=True)+ (tmp_ws.src / "lib" / "x.js").write_text("// owned\n")+ (tmp_ws.src / "recipes.glsl").write_text("// owned\n")+ (tmp_ws.src / "zones").mkdir(parents=True, exist_ok=True)+ (tmp_ws.src / "zones" / "q.js").write_text("// old q\n")+ skipped: list[str] = []+ files = {"src//lib/x.js": "// pwned", "src/./lib/x.js": "// pwned", "src//recipes.glsl": "// pwned",+ "src//zones/q.js": "// out of scope", "src/./parts/a.js": "// mine"}+ changes = write_files(tmp_ws, files, only={"src/parts/a.js"}, frozen=("src/lib/", "src/recipes.glsl"),+ on_skip=lambda p, r: skipped.append(p))+ assert [c.path for c in changes] == ["src/parts/a.js"]+ assert sorted(skipped) == sorted(set(files) - {"src/./parts/a.js"})+ assert (tmp_ws.src / "lib" / "x.js").read_text() == "// owned\n"+ assert (tmp_ws.src / "recipes.glsl").read_text() == "// owned\n"+ assert (tmp_ws.src / "zones" / "q.js").read_text() == "// old q\n"++class ScriptedModel:"""Yields ``(text, finish_reason)`` pairs in order (same as test_fix_generation)."""