Skip to content

Official Codebase of 3DCodeVerse

Python

languages, texturing: delete test-only and write-only code — lint_text, lint_blender_file, load_manifest, the ZoneProbeReport tuple, rubric_hint and the build.json keys nothing reads

gaoypeng593b9c1f1dc0
diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.py
index e808c163..50a5c6a4 100644
--- a/harness/codeverse3d/languages/blender/__init__.py
+++ b/harness/codeverse3d/languages/blender/__init__.py
@@ -292,12 +292,6 @@ def lint_blender_source(
return GateReport.of(GATE, findings, duration_ms=int((time.monotonic() - t0) * 1000))
-def lint_blender_file(path: Path, *, target: str = "src/model.py") -> GateReport:
- if not path.is_file():
- return GateReport(gate=GATE, passed=False, findings=[_f(Severity.ERROR, f"{target} is missing", None, "create src/model.py (see the skeleton)", target)])
- return lint_blender_source(path.read_text(), target=target)
-
-
# ===================================================================== layout
ENTRY_REL = ENTRY_FILE[Language.BLENDER] # "src/model.py"
PARTS_DIR = "parts"
diff --git a/harness/codeverse3d/languages/glsl_shader/__init__.py b/harness/codeverse3d/languages/glsl_shader/__init__.py
index 7b9638c7..7590d98c 100644
--- a/harness/codeverse3d/languages/glsl_shader/__init__.py
+++ b/harness/codeverse3d/languages/glsl_shader/__init__.py
@@ -266,19 +266,6 @@ def lint_workspace(ws: Workspace) -> GateReport:
return GateReport.of(GATE, findings)
-def lint_text(shader_src: str, common_src: str | None = None, buffer_a_src: str | None = None, *,
- recipes_src: str | None = None) -> list[GateFinding]:
- """Lint in-memory sources (tools / tests); ``recipes_src`` is the harness-owned recipe file whose
- names the agent files may not redefine (it is not linted itself)."""
- reserved = frozenset(defined_functions(recipes_src)) if recipes_src else frozenset()
- out = _check_file(SHADER, shader_src, role="shader", recipe_names=reserved)
- if common_src is not None:
- out += _check_file(COMMON, common_src, role="common", recipe_names=reserved)
- if buffer_a_src is not None:
- out += _check_file(BUFFER_A, buffer_a_src, role="buffer_a", recipe_names=reserved)
- return out
-
-
# ===================================================================== skeleton
COMMON_GLSL = """// src/common.glsl — helpers pasted above shader.frag by the harness (no #include needed).
// Keep ONLY functions / constants here; no main(), no uniforms, no #version.
diff --git a/harness/codeverse3d/languages/scene_threejs/__init__.py b/harness/codeverse3d/languages/scene_threejs/__init__.py
index 6697e18c..e5b18e2a 100644
--- a/harness/codeverse3d/languages/scene_threejs/__init__.py
+++ b/harness/codeverse3d/languages/scene_threejs/__init__.py
@@ -392,8 +392,7 @@ class ZoneProbe(BaseModel):
class ZoneProbeReport(BaseModel):
- """``probe_zone_modules`` outcome. Unpacks as ``probes, census, other = ...``
- (historical 3-tuple); ``camera_specs`` carries the driver-fitted cameras
+ """``probe_zone_modules`` outcome; ``camera_specs`` carries the driver-fitted cameras
(``{azimuth, overview, zones:[{group, position, lookAt, fov}]}``)."""
probes: dict[str, ZoneProbe] = Field(default_factory=dict)
@@ -401,11 +400,6 @@ class ZoneProbeReport(BaseModel):
other_errors: list[str] = Field(default_factory=list)
camera_specs: dict[str, Any] = Field(default_factory=dict)
- def __iter__(self): # type: ignore[override]
- yield self.probes
- yield self.census
- yield self.other_errors
-
class AssembleResult(BaseModel):
scene_path: str
@@ -530,8 +524,8 @@ export async function createScene({{ renderer, loaders }}) {{
def probe_zone_modules(ws: Workspace, *, timeout_s: float = 90.0, sun_azimuth_deg: float | None = None) -> ZoneProbeReport:
"""Probe env + every zone module independently in the browser host.
- Returns a :class:`ZoneProbeReport` (unpacks as the historical 3-tuple of
- zone probes by snake name, census, other console errors). When
+ Returns a :class:`ZoneProbeReport` (zone probes by snake name, census, other
+ console errors). When
``sun_azimuth_deg`` is given the driver also fits overview + per-group
cameras from the measured bboxes (``camera_specs``).
"""
diff --git a/harness/codeverse3d/languages/wrappers/_wrapper_common.py b/harness/codeverse3d/languages/wrappers/_wrapper_common.py
index 43aa779e..c417ff24 100644
--- a/harness/codeverse3d/languages/wrappers/_wrapper_common.py
+++ b/harness/codeverse3d/languages/wrappers/_wrapper_common.py
@@ -31,17 +31,18 @@ def wrapper_argv() -> list[str]:
return sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else sys.argv[1:]
-def new_report(language: str, rlimit_gb: float, **extra: Any) -> dict[str, Any]:
- """The build.json skeleton; applies the memory cap (RLIMIT_AS, so a geometry bomb dies
- in-process) and says whether it took."""
- return {"ok": False, "language": language, "error_type": "", "error_message": "", "error_file": "",
- "error_line": None, "error_source": "", "traceback": "", "warnings": [], "exported": {},
- "rlimit": _apply_rlimit(rlimit_gb), **extra}
+def new_report(rlimit_gb: float, **extra: Any) -> dict[str, Any]:
+ """The build.json skeleton; applies the memory cap first (RLIMIT_AS, so a geometry bomb
+ dies in-process)."""
+ _apply_rlimit(rlimit_gb)
+ return {"ok": False, "error_type": "", "error_message": "", "error_file": "",
+ "error_line": None, "error_source": "", "traceback": "", "warnings": [], "exported": {}, **extra}
-def _apply_rlimit(gb: float) -> str:
+def _apply_rlimit(gb: float) -> None:
+ """Best effort: where RLIMIT_AS cannot be set the build runs uncapped."""
if gb <= 0:
- return "rlimit disabled"
+ return
try:
import resource
@@ -49,9 +50,8 @@ def _apply_rlimit(gb: float) -> str:
_soft, hard = resource.getrlimit(resource.RLIMIT_AS)
lim = cap if hard == resource.RLIM_INFINITY else min(cap, hard)
resource.setrlimit(resource.RLIMIT_AS, (lim, hard))
- return f"RLIMIT_AS={lim // 1024**2} MB"
- except (ImportError, ValueError, OSError) as e:
- return f"rlimit not applied: {e}"
+ except (ImportError, ValueError, OSError):
+ pass
def seed_everything(seed: int) -> None:
diff --git a/harness/codeverse3d/languages/wrappers/run_bpy.py b/harness/codeverse3d/languages/wrappers/run_bpy.py
index d957c79a..99e7f8c2 100644
--- a/harness/codeverse3d/languages/wrappers/run_bpy.py
+++ b/harness/codeverse3d/languages/wrappers/run_bpy.py
@@ -167,7 +167,7 @@ def main() -> int:
os.makedirs(out_dir, exist_ok=True)
script = os.path.abspath(args.script)
t0 = time.monotonic()
- report = new_report("blender", args.rlimit_gb, blender_version=bpy.app.version_string)
+ report = new_report(args.rlimit_gb)
if not os.path.isfile(script):
report.update(error_type="FileNotFoundError", error_message=f"script not found: {script}")
write_report(out_dir, report, {}, t0)
diff --git a/harness/codeverse3d/languages/wrappers/run_bpy_links.py b/harness/codeverse3d/languages/wrappers/run_bpy_links.py
index 1d3a2402..28894581 100644
--- a/harness/codeverse3d/languages/wrappers/run_bpy_links.py
+++ b/harness/codeverse3d/languages/wrappers/run_bpy_links.py
@@ -121,7 +121,7 @@ def main() -> int:
t0 = time.monotonic()
script, urdf, out = Path(args.script).resolve(), Path(args.urdf).resolve(), Path(args.out).resolve()
out.mkdir(parents=True, exist_ok=True)
- report = new_report("urdf_blender", args.rlimit_gb, error_file="src/model.py")
+ report = new_report(args.rlimit_gb, error_file="src/model.py")
census: dict = {"objects": [], "links": {}, "unmatched_objects": [], "missing_links": [], "hints": {}}
def fail(error_type: str, message: str, error_file: str = "src/model.py") -> int:
diff --git a/harness/codeverse3d/languages/wrappers/run_cq.py b/harness/codeverse3d/languages/wrappers/run_cq.py
index ab763149..c183643b 100644
--- a/harness/codeverse3d/languages/wrappers/run_cq.py
+++ b/harness/codeverse3d/languages/wrappers/run_cq.py
@@ -198,11 +198,10 @@ def main() -> int:
out_dir = os.path.abspath(args.out)
os.makedirs(out_dir, exist_ok=True)
t0 = time.monotonic()
- report = new_report("cadquery", args.rlimit_gb)
+ report = new_report(args.rlimit_gb)
seed_everything(args.seed)
import cadquery as cq # noqa: PLC0415 — after the rlimit, before the script
- report["cadquery_version"] = getattr(cq, "__version__", "?")
script = os.path.abspath(args.script)
err: dict[str, Any] | None = None
ns: dict[str, Any] | None = {}
diff --git a/harness/codeverse3d/texturing/generate.py b/harness/codeverse3d/texturing/generate.py
index ce3f66e2..7528607d 100644
--- a/harness/codeverse3d/texturing/generate.py
+++ b/harness/codeverse3d/texturing/generate.py
@@ -303,7 +303,7 @@ class GateResult(BaseModel):
duration_s: float = 0.0
-def material_criterion(scores: dict[str, float], rubric_hint: str = "") -> str:
+def material_criterion(scores: dict[str, float]) -> str:
"""The rubric criterion that tracks surface quality (``materials``,
``material_color``, ``materials_shaders_effects``, ``material_truth`` ...)."""
for k in scores:
diff --git a/harness/codeverse3d/texturing/plan.py b/harness/codeverse3d/texturing/plan.py
index ec02b5e4..85adb110 100644
--- a/harness/codeverse3d/texturing/plan.py
+++ b/harness/codeverse3d/texturing/plan.py
@@ -511,13 +511,6 @@ def write_manifest(pack: ScenePack, out_dir: Path) -> Path:
return p
-def load_manifest(path: Path) -> dict[str, dict[str, Any]]:
- p = Path(path)
- if p.is_dir():
- p = p / MANIFEST_NAME
- return json.loads(p.read_text())
-
-
def texture_pack_prompt(manifest: dict[str, dict[str, Any]], *, url_prefix: str = DEFAULT_URL_PREFIX) -> str:
"""Prompt snippet for zone/env generation: what exists and the exact loading idiom.
diff --git a/harness/tests/blender_cadquery/test_blender_lint.py b/harness/tests/blender_cadquery/test_blender_lint.py
index 620fe2e5..0061a6fc 100644
--- a/harness/tests/blender_cadquery/test_blender_lint.py
+++ b/harness/tests/blender_cadquery/test_blender_lint.py
@@ -2,10 +2,8 @@
from __future__ import annotations
-from pathlib import Path
-
from codeverse3d.contracts.artifacts import Severity
-from codeverse3d.languages.blender import lint_blender_file, lint_blender_source
+from codeverse3d.languages.blender import lint_blender_source
GOOD = '''
import bpy
@@ -139,8 +137,3 @@ def test_modifier_apply_with_temp_override_is_fine() -> None:
src = "import bpy\nobj = bpy.context.object\nwith bpy.context.temp_override(object=obj):\n bpy.ops.object.modifier_apply(modifier='Bevel')\nobj.name = 'Body'\n"
r = lint_blender_source(src)
assert not any("modifier_apply" in m for m in _msgs(r, Severity.WARN))
-
-
-def test_missing_file(tmp_path: Path) -> None:
- r = lint_blender_file(tmp_path / "model.py")
- assert not r.passed and "missing" in r.findings[0].message
diff --git a/harness/tests/blender_cadquery/test_blender_runtime.py b/harness/tests/blender_cadquery/test_blender_runtime.py
index 8f04159f..049fc650 100644
--- a/harness/tests/blender_cadquery/test_blender_runtime.py
+++ b/harness/tests/blender_cadquery/test_blender_runtime.py
@@ -17,7 +17,7 @@ from codeverse3d.languages.blender import (
BlenderNotFoundError,
BlenderRuntime,
blender_env,
- lint_blender_file,
+ lint_blender_source,
)
from codeverse3d.prompts.catalog import language_text
@@ -142,7 +142,7 @@ bm.free()
def test_live_error_maps_to_line_and_lint_catches_it(tmp_ws, blender_bin) -> None:
rt = BlenderRuntime(blender=blender_bin)
(tmp_ws.src / "model.py").write_text(BROKEN)
- lint = lint_blender_file(tmp_ws.src / "model.py")
+ lint = lint_blender_source(BROKEN)
assert not lint.passed and any("ensure_lookup_table" in f.message and f.data.get("line") == 10 for f in lint.errors)
r = rt.build(tmp_ws, timeout_s=120)
assert not r.ok and r.error_type == "IndexError" and r.error_file == "src/model.py" and r.error_line == 10
diff --git a/harness/tests/graphics/test_wrap_lint.py b/harness/tests/graphics/test_wrap_lint.py
index 35149e9e..cd4c426b 100644
--- a/harness/tests/graphics/test_wrap_lint.py
+++ b/harness/tests/graphics/test_wrap_lint.py
@@ -5,10 +5,10 @@ from __future__ import annotations
from codeverse3d.contracts.artifacts import Severity
from codeverse3d.languages.glsl_shader import (
HEADER,
+ _check_file,
compose,
detect_convention,
first_error,
- lint_text,
lint_workspace,
parse_glsl_log,
)
@@ -61,17 +61,18 @@ def test_glsl_lint_rules():
"out vec4 fragColor;\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec3 c = texture(iChannel2, vec2(0)).rgb;\n"
" c += texture(u_tex, vec2(0)).rgb;\n float m = 3.0 % 2.0;\n gl_FragColor = vec4(c, 1.0);\n}\n"
)
- kinds = {f.data["kind"] for f in lint_text(bad) if f.severity == Severity.ERROR}
+ kinds = {f.data["kind"] for f in _check_file("src/shader.frag", bad, role="shader") if f.severity == Severity.ERROR}
assert {"version_line", "redeclared_uniform", "custom_uniform", "redeclared_output", "missing_input", "undeclared_sampler",
"float_modulo", "legacy_glsl"} <= kinds
# the comment on line 1 must not trigger anything; the #version is reported on line 2
- ver = next(f for f in lint_text(bad) if f.data["kind"] == "version_line")
+ ver = next(f for f in _check_file("src/shader.frag", bad, role="shader") if f.data["kind"] == "version_line")
assert ver.data["line"] == 2
- assert not [f for f in lint_text(SHADER, COMMON) if f.severity == Severity.ERROR]
+ assert not [f for f in _check_file("src/shader.frag", SHADER, role="shader") + _check_file("src/common.glsl", COMMON, role="common")
+ if f.severity == Severity.ERROR]
# common.glsl must not carry an entry point; no entry at all is an error
- assert any(f.data["kind"] == "entry_in_common" for f in lint_text(SHADER, "void main(){}"))
- assert any(f.data["kind"] == "no_entry" for f in lint_text("vec3 f() { return vec3(0); }"))
- assert any(f.data["kind"] == "buffer_self_ref" for f in lint_text(SHADER, None, SHADER.replace("u_resolution", "u_buffer_a") + "\n"))
+ assert any(f.data["kind"] == "entry_in_common" for f in _check_file("src/common.glsl", "void main(){}", role="common"))
+ assert any(f.data["kind"] == "no_entry" for f in _check_file("src/shader.frag", "vec3 f() { return vec3(0); }", role="shader"))
+ assert any(f.data["kind"] == "buffer_self_ref" for f in _check_file("src/buffer_a.frag", SHADER.replace("u_resolution", "u_buffer_a") + "\n", role="buffer_a"))
def test_glsl_lint_workspace_missing_and_stray(tmp_ws):
diff --git a/harness/tests/orchestrator_tracks/test_graphics_recipes.py b/harness/tests/orchestrator_tracks/test_graphics_recipes.py
index 77f154a8..4db2e69c 100644
--- a/harness/tests/orchestrator_tracks/test_graphics_recipes.py
+++ b/harness/tests/orchestrator_tracks/test_graphics_recipes.py
@@ -15,9 +15,10 @@ from codeverse3d.languages import get_runtime
from codeverse3d.languages.glsl_shader import (
COMMON_GLSL,
GlslShaderRuntime,
+ _check_file,
compose,
+ defined_functions,
first_error,
- lint_text,
lint_workspace,
parse_glsl_log,
write_skeleton,
@@ -309,7 +310,7 @@ def test_recipes_compose_above_common_and_the_seeded_aurora_renders(tmp_path) ->
(ws.src / "shader.frag").write_text(SHADER)
common = (ws.src / "common.glsl").read_text()
recipes = _recipes(ws).read_text()
- assert lint_text(SHADER, common, recipes_src=recipes) == [] and lint_workspace(ws).passed
+ assert lint_workspace(ws).findings == []
comp = compose(SHADER, common, recipes_src=recipes)
assert comp.convention == "mainImage" and not comp.uses_feedback
src = comp.source
@@ -361,12 +362,14 @@ def test_lint_flags_a_redefinition_of_a_seeded_recipe(tmp_path) -> None:
recipes = "float curtain(vec2 p, float t, float seed, out float k) { k = 0.0; return 0.0; }\nvec3 aurora(vec2 p, float t) { return vec3(0.0); }\n"
shader = "// mine\nfloat curtain(vec2 p, float t, float seed, out float k) { k = 1.0; return 1.0; }\n" + SHADER
common = "float hash12(vec2 p) { return 0.0; }\n\nvec3 aurora(vec2 p, float t) { return vec3(1.0); }\n"
- found = [f for f in lint_text(shader, common, recipes_src=recipes) if f.data["kind"] == "redefines_recipe"]
+ names = frozenset(defined_functions(recipes))
+ found = [f for rel, text, role in (("src/shader.frag", shader, "shader"), ("src/common.glsl", common, "common"))
+ for f in _check_file(rel, text, role=role, recipe_names=names) if f.data["kind"] == "redefines_recipe"]
assert [(f.data["file"], f.data["line"]) for f in found] == [("src/shader.frag", 2), ("src/common.glsl", 3)]
assert found[0].message == "src/shader.frag:2: `curtain` is already provided by src/recipes.glsl — call it instead of redefining it"
assert found[1].message.endswith("`aurora` is already provided by src/recipes.glsl — call it instead of redefining it")
assert all(f.severity.value == "error" for f in found) and "harness-owned" in found[0].fix_hint
- assert not [f for f in lint_text(shader, common) if f.data["kind"] == "redefines_recipe"] # no recipes: no rule
+ assert not [f for f in _check_file("src/shader.frag", shader, role="shader") if f.data["kind"] == "redefines_recipe"] # no recipes: no rule
# the workspace lint reads recipes.glsl itself (and does not call it a stray file); buffer_a is checked too
ws = _ws(tmp_path, skeleton=False)
(ws.src / "shader.frag").write_text(SHADER)
diff --git a/harness/tests/scene_runtime/test_assemble.py b/harness/tests/scene_runtime/test_assemble.py
index 1e9abfe3..7471cbd1 100644
--- a/harness/tests/scene_runtime/test_assemble.py
+++ b/harness/tests/scene_runtime/test_assemble.py
@@ -95,12 +95,12 @@ def test_probe_zone_modules_reports_failures_and_bboxes(starter_ws):
(starter_ws.src / "zones" / "broken.js").write_text("export function build(ctx) { throw new Error('kaboom'); }\n")
(starter_ws.src / "zones" / "nobuild.js").write_text("export const x = 1;\n")
report = probe_zone_modules(starter_ws, sun_azimuth_deg=60.0)
- probes, census, other = report # historical 3-tuple unpacking still works
+ probes = report.probes
assert probes["meadow"].ok and probes["meadow"].bbox and probes["meadow"].meshes > 5
assert probes["pondside"].ok
assert not probes["broken"].ok and "kaboom" in probes["broken"].error
assert not probes["nobuild"].ok and "no export build" in probes["nobuild"].error
- assert census.get("ground_y") is not None
+ assert report.census.get("ground_y") is not None
assert not (starter_ws.root / "src" / "_c3v_assemble_probe.js").exists()
# driver-fitted cameras: an overview plus one eye-level spec per measured zone group
specs = report.camera_specs
diff --git a/harness/tests/texturing/test_scene_pack.py b/harness/tests/texturing/test_scene_pack.py
index 52c960cf..34503dd3 100644
--- a/harness/tests/texturing/test_scene_pack.py
+++ b/harness/tests/texturing/test_scene_pack.py
@@ -10,7 +10,6 @@ import pytest
from codeverse3d.contracts.plan import AssetPlan, BBox, CameraPlan, ScenePlan, ZonePlan
from codeverse3d.texturing.plan import (
default_scene_pack_plan,
- load_manifest,
scene_pack_plan,
scene_texture_pack,
texture_pack_prompt,
@@ -59,11 +58,11 @@ def test_scene_texture_pack_writes_manifest_and_prompt(tmp_path: Path, garden_pl
model = FakeImageModel()
out = tmp_path / "public" / "textures"
pack = scene_texture_pack(garden_plan, out, model, "", size=64, cache_dir=tmp_path / "c", n_min=4, n_max=6)
- man = load_manifest(out)
+ man = json.loads(Path(pack.manifest_path).read_text())
assert pack.source == "default" and 4 <= len(man) <= 6 and Path(pack.manifest_path).name == "manifest.json"
for name, e in man.items():
assert (out / e["file"]).is_file() and e["file"] == f"{name}.png" and e["tile_size_m"] > 0 and "family" in e
- assert json.loads(Path(pack.manifest_path).read_text()) == man
+ assert Path(pack.manifest_path).parent == out
snippet = texture_pack_prompt(man)
assert "/public/textures/" in snippet and "RepeatWrapping" in snippet and "SRGBColorSpace" in snippet
assert "loaders.texture.load" in snippet and "tile =" in snippet