Official Codebase of 3DCodeVerse
Python
gl_frames: the tool renders the judged times by default, not its own list
gaoypeng73d6be6ec437
diff --git a/harness/codeverse3d/spatial/gl_render.py b/harness/codeverse3d/spatial/gl_render.pyindex 62e5e53a..e3050f2c 100644--- a/harness/codeverse3d/spatial/gl_render.py+++ b/harness/codeverse3d/spatial/gl_render.py@@ -42,7 +42,6 @@ GPU_ENV: dict[str, str] = {CPU_ENV: dict[str, str] = {"LIBGL_ALWAYS_SOFTWARE": "1", "GALLIUM_DRIVER": "llvmpipe"}_ENV_PASS = ("PATH", "HOME", "LANG", "LC_ALL", "PYTHONHASHSEED", "LD_LIBRARY_PATH", "XDG_RUNTIME_DIR", "TMPDIR")-DEFAULT_TIMES: tuple[float, ...] = (0.0, 1.0, 2.5, 4.0, 6.0)EXIT_CONTEXT = 3RESULT_NAME = "gl_result.json"JOB_NAME = "gl_job.json"@@ -116,7 +115,7 @@ class GlHost:# ------------------------------------------------------------------ publicdef render_fragment_shader(self, frag_src: str, out_dir: Path, *, width: int = 1280, height: int = 720,- times: Sequence[float] = DEFAULT_TIMES, buffer_a_src: str | None = None,+ times: Sequence[float], buffer_a_src: str | None = None,feedback: bool = False, extra_times: Sequence[float] = ()) -> GlResult:job = {"mode": "shader", "frag_src": frag_src, "buffer_a_src": buffer_a_src, "feedback": bool(feedback),"width": int(width), "height": int(height), "times": [float(t) for t in times],@@ -124,7 +123,7 @@ class GlHost:return self._run(job, out_dir)def run_program(self, program_path: Path, out_dir: Path, *, width: int = 1280, height: int = 720,- times: Sequence[float] = DEFAULT_TIMES, extra_times: Sequence[float] = (),+ times: Sequence[float], extra_times: Sequence[float] = (),cwd: Path | None = None) -> GlResult:program_path = Path(program_path).resolve()job = {"mode": "program", "program_path": str(program_path), "program_cwd": str(cwd or program_path.parent),diff --git a/harness/codeverse3d/spatial/tools.py b/harness/codeverse3d/spatial/tools.pyindex 706fe01d..2b23f965 100644--- a/harness/codeverse3d/spatial/tools.py+++ b/harness/codeverse3d/spatial/tools.py@@ -519,7 +519,7 @@ class GlProbeArgs(BaseModel):class GlFramesArgs(BaseModel):- times: list[float] = Field(default=[0.0, 1.0, 2.5, 4.0, 6.0], description="times (s) to render, 1..8 values")+ times: list[float] | None = Field(default=None, description="times (s) to render, 1..8 values; default: the times the judge sees")width: int = Field(default=0, ge=0, le=1920, description="override width (0 = plan resolution)")height: int = Field(default=0, ge=0, le=1080, description="override height (0 = plan resolution)")@@ -533,7 +533,7 @@ def _runtime(ctx: ToolContext):return get_runtime(lang)-def _run_build(ctx: ToolContext, *, times: list[float], width: int = 0, height: int = 0) -> tuple[Observation | None, BuildResult | None, list[str]]:+def _run_build(ctx: ToolContext, *, times: list[float] | None, width: int = 0, height: int = 0) -> tuple[Observation | None, BuildResult | None, list[str]]:"""Lint → build; returns (error observation | None, build, lint warnings)."""ws = ctx.workspacert = _runtime(ctx)@@ -567,12 +567,14 @@ def gl_probe(ctx: ToolContext, args: GlProbeArgs) -> Observation:images=[str(p) for p in frames[:1]], limit=3000)-@tool("gl_frames", GlFramesArgs, "Render frames at the judged times (0,1,2.5,4,6 s by default) → labelled contact sheet + per-frame metrics (luminance, colour, detail, motion, NaN) + the gl_frames gate. LOOK at the sheet.",+@tool("gl_frames", GlFramesArgs, "Render frames (by default at the times the judge sees) → labelled contact sheet + per-frame metrics (luminance, colour, detail, motion, NaN) + the gl_frames gate. LOOK at the sheet.",languages=GRAPHICS_LANGS, cost_hint="slow")def gl_frames(ctx: ToolContext, args: GlFramesArgs) -> Observation:- if not args.times or len(args.times) > MAX_FRAMES:- raise ToolUsageError(f"times must hold 1..{MAX_FRAMES} values", "gl_frames(times=[0, 1, 2.5, 4, 6])")- err, br, warns = _run_build(ctx, times=sorted(set(float(t) for t in args.times)), width=args.width, height=args.height)+ if args.times is not None and not 1 <= len(args.times) <= MAX_FRAMES:+ raise ToolUsageError(f"times must hold 1..{MAX_FRAMES} values", "gl_frames() renders the judged times")+ # None → the build's own default, `judge_times(plan duration)`: the frames the judge will see+ times = sorted(set(float(t) for t in args.times)) if args.times else None+ err, br, warns = _run_build(ctx, times=times, width=args.width, height=args.height)if err is not None:return errassert br is not Nonediff --git a/harness/tests/spatial_tools/test_tools.py b/harness/tests/spatial_tools/test_tools.pyindex bbc72def..f5ba354d 100644--- a/harness/tests/spatial_tools/test_tools.py+++ b/harness/tests/spatial_tools/test_tools.py@@ -338,6 +338,29 @@ def test_gl_tools_lead_with_the_frame_gate_verdict(tmp_ws: Workspace, monkeypatcassert obs.numbers["gate_errors"] == 1, name+def test_gl_frames_renders_the_judged_times_by_default(tmp_ws: Workspace, monkeypatch: pytest.MonkeyPatch) -> None:+ """Regression (audit 2026-09-24 N17): the tool rendered its own (0, 1, 2.5, 4, 6) whatever the+ loop; on a 2 s loop the judge sees (0, .5, 1, 1.5, 2) — the build's `judge_times(duration)`."""+ from codeverse3d.contracts.plan import GraphicsPlan, PassPlan+ from codeverse3d.languages.glsl_shader import GlslShaderRuntime+ from codeverse3d.spatial.gl_render import GlResult++ seen: list[list[float]] = []++ class _Host:+ def render_fragment_shader(self, frag_src, out_dir, *, times, **kw):+ seen.append([float(t) for t in times])+ return GlResult(ok=False, mode="shader", stage="compile", error_type="Error", error_message="stop here")++ tmp_ws.write_json(tmp_ws.plan_path, GraphicsPlan(+ title="T", summary="s", style="st", passes=[PassPlan(name="Sky", description="d")], motion="m",+ key_visuals=["k"], duration_s=2.0))+ (tmp_ws.src / "shader.frag").write_text("void mainImage(out vec4 fragColor, in vec2 fragCoord) { fragColor = vec4(1.0); }\n")+ _patch_runtime(monkeypatch, GlslShaderRuntime(host=_Host()))+ obs = get_tool("gl_frames").call(ToolContext(workspace=tmp_ws, language="glsl_shader", track="graphics"), {})+ assert seen == [[0.0, 0.5, 1.0, 1.5, 2.0]], obs.text++# --------------------------------------------------------------------------- the gate tools on a stooldef _stool_plan_with_missing_backrest() -> StaticPlan:return StaticPlan(object_name="Stool", summary="s", overall_bbox=BBox(center=(0, 0, 0.225), extents=(0.4, 0.4, 0.45)),