Skip to content

Official Codebase of 3DCodeVerse

Python

contracts: GateReport.of — one constructor where 19 sites computed passed from their own errors

gaoypeng232ba0ec2313
diff --git a/harness/codeverse3d/contracts/artifacts.py b/harness/codeverse3d/contracts/artifacts.py
index dc97825f..206dea6d 100644
--- a/harness/codeverse3d/contracts/artifacts.py
+++ b/harness/codeverse3d/contracts/artifacts.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+from collections.abc import Sequence
from enum import StrEnum
from typing import Any, Literal
@@ -56,6 +57,12 @@ class GateReport(BaseModel):
findings: list[GateFinding] = Field(default_factory=list)
duration_ms: int = 0
+ @classmethod
+ def of(cls, gate: str, findings: Sequence[GateFinding] = (), *, duration_ms: int = 0) -> GateReport:
+ """The report whose verdict is its findings: ``passed`` iff none is an ERROR."""
+ return cls(gate=gate, passed=not any(f.severity == Severity.ERROR for f in findings),
+ findings=list(findings), duration_ms=duration_ms)
+
@property
def errors(self) -> list[GateFinding]:
return [f for f in self.findings if f.severity == Severity.ERROR]
diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.py
index 8e5f964b..e808c163 100644
--- a/harness/codeverse3d/languages/blender/__init__.py
+++ b/harness/codeverse3d/languages/blender/__init__.py
@@ -289,8 +289,7 @@ def lint_blender_source(
findings = _rules(c, source, target=target, expect_names=expect_names, expect_bpy=expect_bpy)
for f in findings:
f.target = target
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.monotonic() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.monotonic() - t0) * 1000))
def lint_blender_file(path: Path, *, target: str = "src/model.py") -> GateReport:
@@ -415,8 +414,7 @@ def lint_workspace(ws: Workspace) -> GateReport:
findings.extend(rep.findings)
entry_tree, _ = safe_parse(entry.read_text(), ENTRY_REL)
findings.extend(_layout_rules(ws, parts, entry_tree))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.monotonic() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.monotonic() - t0) * 1000))
# ===================================================================== skeleton
diff --git a/harness/codeverse3d/languages/cadquery/__init__.py b/harness/codeverse3d/languages/cadquery/__init__.py
index c07e4268..e38ff5e3 100644
--- a/harness/codeverse3d/languages/cadquery/__init__.py
+++ b/harness/codeverse3d/languages/cadquery/__init__.py
@@ -209,8 +209,7 @@ def lint_cadquery_source(source: str, *, target: str = "src/model.py") -> GateRe
findings = _rules(c, tree, source)
for f in findings:
f.target = target
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.monotonic() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.monotonic() - t0) * 1000))
def lint_cadquery_file(path: Path, *, target: str = "src/model.py") -> GateReport:
diff --git a/harness/codeverse3d/languages/glsl_shader/__init__.py b/harness/codeverse3d/languages/glsl_shader/__init__.py
index 5b1c04f9..7b9638c7 100644
--- a/harness/codeverse3d/languages/glsl_shader/__init__.py
+++ b/harness/codeverse3d/languages/glsl_shader/__init__.py
@@ -263,8 +263,7 @@ def lint_workspace(ws: Workspace) -> GateReport:
for rel in stray:
findings.append(GateFinding(gate=GATE, severity=Severity.WARN, target=rel, message=f"{rel} is not part of the shader contract and is ignored",
fix_hint="keep code in src/shader.frag (+ src/common.glsl, src/buffer_a.frag)", data={"kind": "stray_file", "file": rel}))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings)
+ return GateReport.of(GATE, findings)
def lint_text(shader_src: str, common_src: str | None = None, buffer_a_src: str | None = None, *,
diff --git a/harness/codeverse3d/languages/opengl_python/__init__.py b/harness/codeverse3d/languages/opengl_python/__init__.py
index a8c860cb..af0c907c 100644
--- a/harness/codeverse3d/languages/opengl_python/__init__.py
+++ b/harness/codeverse3d/languages/opengl_python/__init__.py
@@ -176,8 +176,7 @@ def lint_workspace(ws: Workspace) -> GateReport:
if rel != PROGRAM:
findings.append(GateFinding(gate=GATE, severity=Severity.WARN, target=rel, message=f"{rel}: extra python module is ignored by the harness",
fix_hint="keep all code in src/program.py (GLSL may live in src/*.glsl)", data={"kind": "stray_file", "file": rel}))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings)
+ return GateReport.of(GATE, findings)
# ===================================================================== skeleton
diff --git a/harness/codeverse3d/languages/scene_threejs/__init__.py b/harness/codeverse3d/languages/scene_threejs/__init__.py
index 42b6728e..f0d13eea 100644
--- a/harness/codeverse3d/languages/scene_threejs/__init__.py
+++ b/harness/codeverse3d/languages/scene_threejs/__init__.py
@@ -161,8 +161,7 @@ def lint(ws: Workspace) -> GateReport:
for b in big:
findings.append(_f(Severity.WARN, f"large file {b} > {MAX_LINES} lines", target=b.split(" ")[0],
hint="split into zones/assets/shaders modules"))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.time() - t0) * 1000))
# ===================================================================== skeleton
diff --git a/harness/codeverse3d/languages/threejs/__init__.py b/harness/codeverse3d/languages/threejs/__init__.py
index 0c6192e7..5f59ca1e 100644
--- a/harness/codeverse3d/languages/threejs/__init__.py
+++ b/harness/codeverse3d/languages/threejs/__init__.py
@@ -263,8 +263,7 @@ def lint_workspace(ws: Workspace) -> GateReport:
message=f"planned part {part.name} is not assembled by src/object.js",
fix_hint=f"import {{ build{to_pascal(part.name)} }} from './parts/{to_snake(part.name)}.js' and root.add(...)"))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.time() - t0) * 1000))
# ===================================================================== skeleton
diff --git a/harness/codeverse3d/languages/urdf/__init__.py b/harness/codeverse3d/languages/urdf/__init__.py
index 3891497a..09346e36 100644
--- a/harness/codeverse3d/languages/urdf/__init__.py
+++ b/harness/codeverse3d/languages/urdf/__init__.py
@@ -508,8 +508,7 @@ def lint_workspace(ws: Workspace) -> GateReport:
findings.append(_f(Severity.ERROR, f"missing {MODEL_REL}", target=MODEL_REL, fix="Write src/model.py (pure bpy, one object per link)."))
else:
findings.extend(lint_model_text(model_p.read_text(), link_names))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.time() - t0) * 1000))
# ===================================================================== skeleton
diff --git a/harness/codeverse3d/spatial/connectivity.py b/harness/codeverse3d/spatial/connectivity.py
index c8922425..83733092 100644
--- a/harness/codeverse3d/spatial/connectivity.py
+++ b/harness/codeverse3d/spatial/connectivity.py
@@ -622,12 +622,11 @@ def check_connectivity(
# reducing per CHILD instead hid a second, genuinely open join.
contacts = [r for r in rows if r[3] == "contact"]
planned.extend(contacts if contacts else rows[:1] if len(rows) <= 1 else [min(rows, key=lambda r: r[2])])
- passed = not any(f.severity == Severity.ERROR for f in findings)
- if passed and len(big) > 1:
+ if len(big) > 1 and not any(f.severity == Severity.ERROR for f in findings):
findings.append(GateFinding(gate=GATE, severity=Severity.INFO,
message=f"all {len(big)} parts are connected ({len(edges)} contacts, gap ≤ {gap_m * 1000:.0f} mm)"))
findings.append(_ledger(names, parts, edges, exact, overlaps, planned, unresolved, gap_m))
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.time() - t0) * 1000))
def _nearest_supported(
diff --git a/harness/codeverse3d/spatial/contract.py b/harness/codeverse3d/spatial/contract.py
index 41590838..f34e0a45 100644
--- a/harness/codeverse3d/spatial/contract.py
+++ b/harness/codeverse3d/spatial/contract.py
@@ -400,7 +400,6 @@ def check_contract(measurement: Measurement, plan: Plan, *, language: str, tol_m
findings = _check_scene_plan(measurement, plan, language, tol_m)
else:
findings = _check_object_plan(measurement, plan, language, tol_m)
- passed = not any(f.severity == Severity.ERROR for f in findings)
- if passed and not findings:
+ if not findings:
findings.append(GateFinding(gate=GATE, severity=Severity.INFO, message="all plan parts present and within tolerance"))
- return GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(GATE, findings, duration_ms=int((time.time() - t0) * 1000))
diff --git a/harness/codeverse3d/spatial/frame_metrics.py b/harness/codeverse3d/spatial/frame_metrics.py
index a9a224d6..a1f67a9e 100644
--- a/harness/codeverse3d/spatial/frame_metrics.py
+++ b/harness/codeverse3d/spatial/frame_metrics.py
@@ -423,8 +423,7 @@ def frame_findings(metrics: dict[str, Any]) -> GateReport:
n = len(checks)
findings.append(_f(Severity.INFO, "overall", f"{n} camera frame(s) checked: exposure, geometry and coverage within limits", "",
kind="frames_ok", n_views=n))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=FRAME_GATE, passed=passed, findings=findings)
+ return GateReport.of(FRAME_GATE, findings)
def frame_gate_from_renders(source: RenderSet | Path | str) -> GateReport:
diff --git a/harness/codeverse3d/spatial/frame_stats.py b/harness/codeverse3d/spatial/frame_stats.py
index 1ad9f9e0..fb518d23 100644
--- a/harness/codeverse3d/spatial/frame_stats.py
+++ b/harness/codeverse3d/spatial/frame_stats.py
@@ -178,5 +178,4 @@ def frame_gate(seq: SequenceStats, *, motion_expected: bool = True, gate: str =
if seq.mean_edge_density < LOW_DETAIL_EDGE and not seq.all_black and not seq.all_blown:
add(Severity.WARN, "low_detail", f"very low visual detail (edge density {seq.mean_edge_density:.4f}); the image is a near-flat gradient",
"add structure: fbm layers, shapes (sdf), stars/particles, lines — the rubric rewards visual richness")
- passed = not any(x.severity == Severity.ERROR for x in f)
- return GateReport(gate=gate, passed=passed, findings=f)
+ return GateReport.of(gate, f)
diff --git a/harness/codeverse3d/spatial/probes.py b/harness/codeverse3d/spatial/probes.py
index 8ad7b84b..e7ff1292 100644
--- a/harness/codeverse3d/spatial/probes.py
+++ b/harness/codeverse3d/spatial/probes.py
@@ -158,8 +158,7 @@ def probe_report(summary: dict[str, Any], *, duration_ms: int = 0) -> tuple[Gate
if cam0 and cam0.get("dark_frac", 0) > 0.85:
findings.append(_f(gate, Severity.WARN, f"camera '{cam0.get('name')}' frame is {cam0['dark_frac']:.0%} black — no lights or nothing in view?",
target=str(cam0.get("name")), hint="add a DirectionalLight + HemisphereLight in env, aim the camera at the content"))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=gate, passed=passed, findings=findings, duration_ms=duration_ms), census
+ return GateReport.of(gate, findings, duration_ms=duration_ms), census
def _census_findings(c: dict[str, Any]) -> list[GateFinding]:
diff --git a/harness/codeverse3d/spatial/scene_placement.py b/harness/codeverse3d/spatial/scene_placement.py
index 6d64a576..d754a526 100644
--- a/harness/codeverse3d/spatial/scene_placement.py
+++ b/harness/codeverse3d/spatial/scene_placement.py
@@ -276,8 +276,7 @@ def placement_findings(table: dict[str, Any] | PlacementTable, *, indoor: bool =
+ ("; table truncated (first 400 assets / time budget)" if t.truncated else ""))
findings.insert(0, _f(Severity.INFO, summary, target="scene", kind="summary", counts=counts, checked=t.checked, total=t.total,
exempt=t.exempt, truncated=t.truncated))
- passed = not any(f.severity == Severity.ERROR for f in findings)
- return GateReport(gate=GATE, passed=passed, findings=findings)
+ return GateReport.of(GATE, findings)
# --------------------------------------------------------------------------- plan-aware checks
@@ -604,9 +603,7 @@ def placement_gate_safe(census: dict[str, Any] | None, *, plan: Any = None,
report = placement_findings(table, indoor=is_interior(plan))
extra = _cap_per_kind(contract_findings(census, plan, layouts=layouts, unavailable=unavailable))
if extra:
- findings = report.findings + extra
- passed = not any(f.severity == Severity.ERROR for f in findings)
- report = GateReport(gate=GATE, passed=passed, findings=findings, duration_ms=report.duration_ms)
+ report = GateReport.of(GATE, report.findings + extra, duration_ms=report.duration_ms)
return report
except Exception as e: # noqa: BLE001 — advisory instrumentation must not fail the round
log.warning("scene placement gate failed: %s", e)
diff --git a/harness/codeverse3d/tracks/articulated_object.py b/harness/codeverse3d/tracks/articulated_object.py
index 56c9fc19..c4d7d798 100644
--- a/harness/codeverse3d/tracks/articulated_object.py
+++ b/harness/codeverse3d/tracks/articulated_object.py
@@ -145,8 +145,7 @@ def default_joint_sweep(ws: Workspace, plan: Plan | None, out_dir: Path) -> tupl
findings += [f.model_copy(update={"gate": SWEEP_GATE}) for f in joints.buried_links(robot)]
except Exception as e: # noqa: BLE001 — an extra check never fails the gate
log.warning("buried-link check failed: %s", e)
- gate = GateReport(gate=SWEEP_GATE, passed=not any(f.severity == Severity.ERROR for f in findings), findings=findings,
- duration_ms=int((time.time() - t0) * 1000))
+ gate = GateReport.of(SWEEP_GATE, findings, duration_ms=int((time.time() - t0) * 1000))
views: list[RenderView] = []
out_dir.mkdir(parents=True, exist_ok=True)
try:
@@ -411,5 +410,4 @@ def default_motion_checks(ws: Workspace, plan: Plan | None) -> GateReport | None
gate=MOTION_GATE, severity=Severity.ERROR, target=j.name,
message=f"{chk.message}. Plan says: \"{j.motion}\"",
fix_hint=hint, data=data))
- return GateReport(gate=MOTION_GATE, passed=not any(f.severity == Severity.ERROR for f in findings),
- findings=findings, duration_ms=int((time.time() - t0) * 1000))
+ return GateReport.of(MOTION_GATE, findings, duration_ms=int((time.time() - t0) * 1000))
diff --git a/harness/codeverse3d/tracks/depth.py b/harness/codeverse3d/tracks/depth.py
index f4a58530..5908f338 100644
--- a/harness/codeverse3d/tracks/depth.py
+++ b/harness/codeverse3d/tracks/depth.py
@@ -346,5 +346,4 @@ def budget_gate(measurement: Any, build: Any, budget: DepthBudget) -> Any:
message=f"{tris:,} triangles ({per_unit:.0f} per built object) inside the "
f"{budget.min_tris:,}–{budget.max_tris:,} budget",
data={"kind": "tri_budget_ok", "tris": tris, "target": budget.target_tris}))
- return GateReport(gate=BUDGET_GATE, findings=findings,
- passed=not any(f.severity is Severity.ERROR for f in findings))
+ return GateReport.of(BUDGET_GATE, findings)
diff --git a/harness/codeverse3d/tracks/scene.py b/harness/codeverse3d/tracks/scene.py
index e595d844..367bf2af 100644
--- a/harness/codeverse3d/tracks/scene.py
+++ b/harness/codeverse3d/tracks/scene.py
@@ -142,7 +142,7 @@ class ScenePipeline:
fix_hint="the budget is <= 200 draw calls and <= 2 M triangles: merge static geometry "
"(BufferGeometryUtils.mergeGeometries) and put anything repeated > 5x in ONE "
"InstancedMesh per material — a per-object mesh loop is what costs the frame rate"))
- out = [GateReport(gate="render_console", passed=not errs, findings=findings)]
+ out = [GateReport.of("render_console", findings)]
try:
# scene_frames: exposure / camera-in-geometry / coverage checks from metrics.json
# (missing metrics → a passing empty report); its ERROR findings carry fix hints
diff --git a/harness/tests/core/test_contract_additions.py b/harness/tests/core/test_contract_additions.py
index 205e073b..903eded4 100644
--- a/harness/tests/core/test_contract_additions.py
+++ b/harness/tests/core/test_contract_additions.py
@@ -5,7 +5,7 @@ from __future__ import annotations
import pytest
from pydantic import ValidationError
-from codeverse3d.contracts.artifacts import GateFinding, RenderSet, RenderView, Severity
+from codeverse3d.contracts.artifacts import GateFinding, GateReport, RenderSet, RenderView, Severity
from codeverse3d.contracts.common import (
ENTRY_FILE,
LANGUAGE_LABEL,
@@ -61,6 +61,13 @@ def test_as_line_formats_defaults_flags_and_empty_fields():
assert _finding(target=None).as_line(with_target=True, with_hint=False) == "leg floats"
+def test_a_gate_report_of_its_findings_passes_iff_none_is_an_error():
+ warn, err = _finding(severity=Severity.WARN), _finding()
+ assert GateReport.of("contract").passed and GateReport.of("contract", [warn]).passed
+ rep = GateReport.of("contract", (warn, err), duration_ms=7)
+ assert not rep.passed and rep.findings == [warn, err] and rep.errors == [err] and rep.duration_ms == 7
+
+
# ------------------------------------------------------------------ render flags
def test_render_view_judge_flag_defaults_none():
v = RenderView(name="front", path="front.png")