Skip to content

Official Codebase of 3DCodeVerse

Python

cleanup: C1 — Spatial tool report formatting

gaoypenge97916ff7b3f
diff --git a/harness/codeverse/spatial/mcp_server.py b/harness/codeverse/spatial/mcp_server.py
index 3b7f942e..e94339ec 100644
--- a/harness/codeverse/spatial/mcp_server.py
+++ b/harness/codeverse/spatial/mcp_server.py
@@ -24,6 +24,7 @@ from PIL import Image
from codeverse.spatial.observe import fmt_numbers
from codeverse.spatial.registry import Observation, ToolContext, ToolDef, list_tools
+from codeverse.spatial.tool_common import spec_dict
from codeverse.workspace import Workspace
MAX_IMAGES = 4
@@ -34,15 +35,12 @@ SERVER_NAME = "3dcv"
def build_context(workspace: Path, *, track: str = "", language: str = "", round_index: int = 0) -> ToolContext:
"""ToolContext for ``workspace``; track/language fall back to spec.json."""
- ws = Workspace(workspace)
- if (not track or not language) and ws.spec_path.is_file():
- try:
- spec = json.loads(ws.spec_path.read_text())
- except json.JSONDecodeError:
- spec = {}
- track = track or str(spec.get("track", ""))
- language = language or str(spec.get("language", ""))
- return ToolContext(workspace=ws, round_index=round_index, language=language, track=track)
+ ctx = ToolContext(workspace=Workspace(workspace), round_index=round_index, language=language, track=track)
+ if not track or not language:
+ spec = spec_dict(ctx)
+ ctx.track = track or str(spec.get("track", ""))
+ ctx.language = language or str(spec.get("language", ""))
+ return ctx
def encode_image(path: str, max_side: int = MAX_IMAGE_SIDE) -> str | None:
diff --git a/harness/codeverse/spatial/observe.py b/harness/codeverse/spatial/observe.py
index 88680106..2fce8da7 100644
--- a/harness/codeverse/spatial/observe.py
+++ b/harness/codeverse/spatial/observe.py
@@ -5,6 +5,8 @@
* ``tail_lines`` – last ``n`` lines of a log.
* ``image_budget`` – cap image lists (contact sheet kept first).
* ``rel_path`` – workspace-relative display path (never leak host paths in text).
+* ``lint_lines`` / ``build_failure_lines`` – the one lint / BUILD FAILED report
+ format shared by the ``build`` and ``gl_probe`` / ``gl_frames`` tools.
* ``text_observation`` / ``gate_observation`` / ``render_observation`` – the
standard Observation builders (truncation + image budget applied once).
"""
@@ -15,7 +17,7 @@ from collections.abc import Iterable, Sequence
from pathlib import Path
from typing import Any
-from codeverse.contracts.artifacts import GateReport, RenderSet, Severity
+from codeverse.contracts.artifacts import BuildResult, GateReport, RenderSet, Severity
from codeverse.spatial.registry import Observation
MAX_IMAGES = 6
@@ -124,6 +126,47 @@ _SEV_ORDER = {Severity.ERROR: 0, Severity.WARN: 1, Severity.INFO: 2}
_SEV_TAG = {Severity.ERROR: "ERROR", Severity.WARN: "WARN", Severity.INFO: "info"}
+# --------------------------------------------------------------------------- build reports
+def lint_lines(report: GateReport, root: Path, *, errors_only: bool) -> list[str]:
+ """``- ERROR (src/x.py): msg`` (+ `` fix: …``) for the errors or the warnings
+ of a lint report — INFO findings are never shown to the agent."""
+ want = Severity.ERROR if errors_only else Severity.WARN
+ out = []
+ for f in report.findings:
+ if f.severity != want:
+ continue
+ loc = f" ({rel_path(f.target, root)})" if f.target else ""
+ out.append(f"- {_SEV_TAG[f.severity]}{loc}: {sanitize_text(f.message, root)}")
+ if f.fix_hint:
+ out.append(f" fix: {sanitize_text(f.fix_hint, root)}")
+ return out
+
+
+def error_file_display(error_file: str, root: Path) -> str:
+ """``BuildResult.error_file`` for the agent: runtimes report either an absolute
+ path (→ workspace-relative) or an already-relative one (kept — ``rel_path``
+ would resolve it against the cwd and fall back to the bare file name)."""
+ if not error_file or not Path(error_file).is_absolute():
+ return error_file
+ return rel_path(error_file, root)
+
+
+def build_failure_lines(br: BuildResult, root: Path, lint_warns: Sequence[str], *, tail_n: int) -> list[str]:
+ """``BUILD FAILED: <type>: <message> at <file>:<line>`` + stderr tail (when it
+ adds to the message) + up to 10 lint hints — the failure report of every
+ build-running tool."""
+ where = f" at {error_file_display(br.error_file, root)}:{br.error_line}" if br.error_file else ""
+ # the location stays on the headline even when the message is multi-line (GLSL)
+ head, _, rest = sanitize_text(br.error_message, root).partition("\n")
+ lines = [f"BUILD FAILED: {br.error_type or 'Error'}: {head}{where}"] + ([rest] if rest else [])
+ tail = tail_lines(sanitize_text(br.stderr_tail, root), tail_n)
+ if tail and tail not in br.error_message:
+ lines.append("stderr (tail):\n" + tail)
+ if lint_warns:
+ lines.append("lint hints:\n" + "\n".join(lint_warns[:10]))
+ return lines
+
+
def gate_observation(report: GateReport, *, title: str = "", max_findings: int = 20, images: Iterable[str] = ()) -> Observation:
"""Errors first, each with its fix hint; counts in ``numbers``."""
findings = sorted(report.findings, key=lambda f: _SEV_ORDER.get(f.severity, 3))
diff --git a/harness/codeverse/spatial/registry.py b/harness/codeverse/spatial/registry.py
index d0d7d338..be084d53 100644
--- a/harness/codeverse/spatial/registry.py
+++ b/harness/codeverse/spatial/registry.py
@@ -29,6 +29,10 @@ from pydantic import BaseModel, Field
from codeverse.workspace import Workspace
+class NoArgs(BaseModel):
+ """This tool takes no arguments."""
+
+
class Observation(BaseModel):
ok: bool = True
text: str = Field(description="human/LLM-readable summary (≤ ~2k chars)")
diff --git a/harness/codeverse/spatial/tool_common.py b/harness/codeverse/spatial/tool_common.py
index 08dc983d..14e78d75 100644
--- a/harness/codeverse/spatial/tool_common.py
+++ b/harness/codeverse/spatial/tool_common.py
@@ -24,7 +24,7 @@ from codeverse.workspace import Workspace
__all__ = [
"ToolUnavailable", "lazy", "spec_dict", "language_of", "track_of",
- "glb_path", "load_plan", "resolve_views", "check_mode", "tool_out_dir", "render_cache_dir",
+ "glb_path", "reference_path", "load_plan", "resolve_views", "check_mode", "tool_out_dir", "render_cache_dir",
"cached_render_glb", "gl_metrics_summary", "VIEW_BY_NAME", "RENDER_MODES",
]
@@ -73,6 +73,26 @@ def track_of(ctx: ToolContext) -> str:
return ctx.track or str(spec_dict(ctx).get("track", ""))
+def reference_path(ctx: ToolContext, index: int, *, tool: str) -> tuple[Path, dict]:
+ """``spec.references[index]`` as ``(absolute path, reference dict)``.
+
+ Usage errors name ``tool`` in their example call (``compare_silhouette`` /
+ ``compare_reference`` share this lookup).
+ """
+ refs = spec_dict(ctx).get("references") or []
+ if not refs:
+ raise ToolUsageError("the spec has no reference images — nothing to compare against")
+ if index >= len(refs):
+ raise ToolUsageError(f"reference_index {index} out of range (have {len(refs)})",
+ f"{tool}(reference_index=0)")
+ ref = refs[index]
+ ref = ref if isinstance(ref, dict) else {"path": ref.path, "role": ref.role, "note": ref.note}
+ p = Path(ref["path"])
+ if not p.is_absolute():
+ p = ctx.workspace.root / p
+ return p, ref
+
+
def glb_path(ctx: ToolContext) -> Path:
p = ctx.workspace.artifacts / "object.glb"
if not p.is_file():
diff --git a/harness/codeverse/spatial/tools.py b/harness/codeverse/spatial/tools.py
index 327be5e6..a34cc329 100644
--- a/harness/codeverse/spatial/tools.py
+++ b/harness/codeverse/spatial/tools.py
@@ -16,18 +16,20 @@ from typing import Any
from pydantic import BaseModel, Field
from codeverse.config import get_settings
-from codeverse.contracts.artifacts import BuildResult, GateReport, Measurement, Severity
+from codeverse.contracts.artifacts import BuildResult, GateReport, Measurement
from codeverse.spatial.connectivity import check_connectivity as _check_connectivity
from codeverse.spatial.contract import check_contract as _check_contract
from codeverse.spatial.measure import GlbLoadError, measure_glb, measure_summary_table
from codeverse.spatial.observe import (
+ build_failure_lines,
+ error_file_display,
gate_observation,
+ lint_lines,
rel_path,
sanitize_text,
- tail_lines,
text_observation,
)
-from codeverse.spatial.registry import Observation, ToolContext, ToolUsageError, tool
+from codeverse.spatial.registry import NoArgs, Observation, ToolContext, ToolUsageError, tool
from codeverse.spatial.sections import cross_section as _cross_section
from codeverse.spatial.tool_common import (
gl_metrics_summary,
@@ -41,27 +43,7 @@ from codeverse.spatial.tool_common import (
_STDERR_TAIL_LINES = 30
-class NoArgs(BaseModel):
- """This tool takes no arguments."""
-
-
# --------------------------------------------------------------------------- build
-def _lint_lines(report: GateReport, root, *, errors_only: bool) -> list[str]:
- out = []
- for f in report.findings:
- if errors_only and f.severity != Severity.ERROR:
- continue
- if not errors_only and f.severity == Severity.ERROR:
- continue
- if f.severity == Severity.INFO:
- continue
- loc = f" ({rel_path(f.target, root)})" if f.target else ""
- out.append(f"- {f.severity.value.upper()}{loc}: {sanitize_text(f.message, root)}")
- if f.fix_hint:
- out.append(f" fix: {sanitize_text(f.fix_hint, root)}")
- return out
-
-
def _measure_after_build(ctx: ToolContext, br: BuildResult) -> tuple[Measurement | None, str]:
if not br.glb_path:
return None, "build reported success but no GLB path"
@@ -108,8 +90,8 @@ def build(ctx: ToolContext, args: NoArgs) -> Observation:
language = language_of(ctx)
rt = lazy("codeverse.languages", "get_runtime")(language)
lint: GateReport = rt.lint(ws)
- lint_errors = _lint_lines(lint, ws.root, errors_only=True)
- lint_warns = _lint_lines(lint, ws.root, errors_only=False)
+ lint_errors = lint_lines(lint, ws.root, errors_only=True)
+ lint_warns = lint_lines(lint, ws.root, errors_only=False)
if lint_errors:
text = "LINT FAILED — fix these before building:\n" + "\n".join(lint_errors)
if lint_warns:
@@ -119,14 +101,8 @@ def build(ctx: ToolContext, args: NoArgs) -> Observation:
ws.write_json(ws.artifacts / "build_last.json", br)
numbers: dict[str, Any] = {"stage": "build", "ok": br.ok, "duration_ms": br.duration_ms}
if not br.ok:
- where = f" at {rel_path(br.error_file, ws.root)}:{br.error_line}" if br.error_file else ""
- lines = [f"BUILD FAILED: {br.error_type or 'Error'}: {sanitize_text(br.error_message, ws.root)}{where}"]
- tail = tail_lines(sanitize_text(br.stderr_tail, ws.root), _STDERR_TAIL_LINES)
- if tail:
- lines.append("stderr (tail):\n" + tail)
- if lint_warns:
- lines.append("lint hints:\n" + "\n".join(lint_warns[:10]))
- numbers.update({"error_type": br.error_type, "error_file": rel_path(br.error_file, ws.root), "error_line": br.error_line})
+ lines = build_failure_lines(br, ws.root, lint_warns, tail_n=_STDERR_TAIL_LINES)
+ numbers.update({"error_type": br.error_type, "error_file": error_file_display(br.error_file, ws.root), "error_line": br.error_line})
return text_observation(lines, ok=False, numbers=numbers, limit=3000)
if not br.glb_path and language in _SCENE_LANGS + _GL_LANGS:
# languages without a GLB deliverable: report the language's own artifacts
diff --git a/harness/codeverse/spatial/tools_graphics.py b/harness/codeverse/spatial/tools_graphics.py
index cfed515e..db7e61f0 100644
--- a/harness/codeverse/spatial/tools_graphics.py
+++ b/harness/codeverse/spatial/tools_graphics.py
@@ -11,14 +11,9 @@ from pathlib import Path
from pydantic import BaseModel, Field
-from codeverse.contracts.artifacts import BuildResult, GateReport, Severity
+from codeverse.contracts.artifacts import BuildResult, GateReport
from codeverse.contracts.common import Language
-from codeverse.spatial.observe import (
- rel_path,
- sanitize_text,
- tail_lines,
- text_observation,
-)
+from codeverse.spatial.observe import build_failure_lines, lint_lines, rel_path, text_observation
from codeverse.spatial.registry import Observation, ToolContext, ToolUsageError, tool
from codeverse.spatial.tool_common import gl_metrics_summary, language_of, lazy, tool_out_dir
@@ -46,26 +41,7 @@ def _runtime(ctx: ToolContext):
return get_runtime(lang)
-def _lint_block(report: GateReport, root: Path) -> tuple[list[str], list[str]]:
- errs, warns = [], []
- for f in report.findings:
- if f.severity == Severity.INFO:
- continue
- line = f"- {sanitize_text(f.message, root)}" + (f"\n fix: {sanitize_text(f.fix_hint, root)}" if f.fix_hint else "")
- (errs if f.severity == Severity.ERROR else warns).append(line)
- return errs, warns
-
-
-def _failure_text(br: BuildResult, root: Path, lint_warns: list[str]) -> str:
- shown = br.error_file if not Path(br.error_file).is_absolute() else rel_path(br.error_file, root)
- where = f" at {shown}:{br.error_line}" if br.error_file else ""
- lines = [f"BUILD FAILED: {br.error_type or 'Error'}{where}", sanitize_text(br.error_message, root)]
- tail = tail_lines(sanitize_text(br.stderr_tail, root), 25)
- if tail and tail not in br.error_message:
- lines.append("log tail:\n" + tail)
- if lint_warns:
- lines.append("lint hints:\n" + "\n".join(lint_warns[:8]))
- return "\n".join(lines)
+_STDERR_TAIL_LINES = 25
def _run_build(ctx: ToolContext, *, times: list[float], preview: bool, width: int = 0, height: int = 0) -> tuple[Observation | None, BuildResult | None, list[str]]:
@@ -76,7 +52,8 @@ def _run_build(ctx: ToolContext, *, times: list[float], preview: bool, width: in
ws = ctx.workspace
rt = _runtime(ctx)
lint: GateReport = rt.lint(ws)
- errs, warns = _lint_block(lint, ws.root)
+ errs = lint_lines(lint, ws.root, errors_only=True)
+ warns = lint_lines(lint, ws.root, errors_only=False)
if errs:
text = "LINT FAILED — fix these before rendering:\n" + "\n".join(errs)
if warns:
@@ -88,7 +65,7 @@ def _run_build(ctx: ToolContext, *, times: list[float], preview: bool, width: in
br: BuildResult = rt.build(ws, **kw)
ws.write_json(ws.artifacts / "build_last.json", br)
if not br.ok:
- return text_observation(_failure_text(br, ws.root, warns), ok=False, limit=3000,
+ return text_observation(build_failure_lines(br, ws.root, warns, tail_n=_STDERR_TAIL_LINES), ok=False, limit=3000,
numbers={"stage": "build", "error_type": br.error_type, "error_file": br.error_file,
"error_line": br.error_line}), br, warns
return None, br, warns
diff --git a/harness/codeverse/spatial/tools_reference.py b/harness/codeverse/spatial/tools_reference.py
index 09b2d4a1..c9bb9f47 100644
--- a/harness/codeverse/spatial/tools_reference.py
+++ b/harness/codeverse/spatial/tools_reference.py
@@ -13,8 +13,6 @@ Registered from ``spatial/tools.py`` (one appended import) so
from __future__ import annotations
-from pathlib import Path
-
from pydantic import BaseModel, Field
from codeverse.spatial.observe import fmt_numbers, image_budget
@@ -25,8 +23,8 @@ from codeverse.spatial.tool_common import (
VIEW_BY_NAME,
cached_render_glb,
glb_path,
+ reference_path,
render_cache_dir,
- spec_dict,
)
#: what the agent should compare, in the order that decides whether the object
@@ -50,27 +48,12 @@ class CompareReferenceArgs(BaseModel):
size: int = Field(default=512, ge=256, le=1024, description="render size in px (square)")
-def _reference_path(ctx: ToolContext, index: int) -> tuple[Path, dict]:
- refs = spec_dict(ctx).get("references") or []
- if not refs:
- raise ToolUsageError("the spec has no reference images — nothing to compare against")
- if index >= len(refs):
- raise ToolUsageError(f"reference_index {index} out of range (have {len(refs)})",
- "compare_reference(reference_index=0)")
- ref = refs[index]
- ref = ref if isinstance(ref, dict) else {"path": ref.path, "role": ref.role, "note": ref.note}
- p = Path(ref["path"])
- if not p.is_absolute():
- p = ctx.workspace.root / p
- return p, ref
-
-
@tool("compare_reference", CompareReferenceArgs,
"Put the REFERENCE image and a render of your object side by side (+ outline diff and IoU). Use it to check "
"you built the right thing: part inventory, counts, proportions, profiles.", cost_hint="slow")
def compare_reference(ctx: ToolContext, args: CompareReferenceArgs) -> Observation:
glb = glb_path(ctx)
- ref_path, ref = _reference_path(ctx, args.reference_index)
+ ref_path, ref = reference_path(ctx, args.reference_index, tool="compare_reference")
if not ref_path.is_file():
return Observation.error(f"reference image {ref_path.name} not found")
if args.view not in VIEW_BY_NAME:
diff --git a/harness/codeverse/spatial/tools_render.py b/harness/codeverse/spatial/tools_render.py
index 032f6921..6dd64671 100644
--- a/harness/codeverse/spatial/tools_render.py
+++ b/harness/codeverse/spatial/tools_render.py
@@ -8,8 +8,6 @@ paths.
from __future__ import annotations
-from pathlib import Path
-
from pydantic import BaseModel, Field
from codeverse.conventions import OBJECT_VIEWS, OBJECT_VIEWS_QUICK
@@ -22,9 +20,9 @@ from codeverse.spatial.tool_common import (
cached_render_glb,
check_mode,
glb_path,
+ reference_path,
render_cache_dir,
resolve_views,
- spec_dict,
)
_DEFAULT_VIEWS = [v.name for v in OBJECT_VIEWS_QUICK]
@@ -104,15 +102,7 @@ class CompareSilhouetteArgs(BaseModel):
@tool("compare_silhouette", CompareSilhouetteArgs, "Silhouette IoU / aspect-ratio error between a rendered view and a reference image (+ diff image).", cost_hint="slow")
def compare_silhouette(ctx: ToolContext, args: CompareSilhouetteArgs) -> Observation:
glb = glb_path(ctx)
- refs = spec_dict(ctx).get("references") or []
- if not refs:
- raise ToolUsageError("the spec has no reference images — nothing to compare against")
- if args.reference_index >= len(refs):
- raise ToolUsageError(f"reference_index {args.reference_index} out of range (have {len(refs)})", "compare_silhouette(reference_index=0)")
- ref = refs[args.reference_index]
- ref_path = Path(ref["path"] if isinstance(ref, dict) else ref.path)
- if not ref_path.is_absolute():
- ref_path = ctx.workspace.root / ref_path
+ ref_path, _ref = reference_path(ctx, args.reference_index, tool="compare_silhouette")
if not ref_path.is_file():
return Observation.error(f"reference image {ref_path.name} not found")
if args.view not in VIEW_BY_NAME:
diff --git a/harness/codeverse/spatial/tools_scene.py b/harness/codeverse/spatial/tools_scene.py
index cce8e97c..144e7e07 100644
--- a/harness/codeverse/spatial/tools_scene.py
+++ b/harness/codeverse/spatial/tools_scene.py
@@ -14,7 +14,7 @@ from pydantic import BaseModel, Field
from codeverse.contracts.artifacts import GateReport, RenderSet
from codeverse.contracts.common import Language, Track
from codeverse.spatial.observe import fmt_numbers, gate_observation, render_observation, truncate
-from codeverse.spatial.registry import Observation, ToolContext, ToolUsageError, tool
+from codeverse.spatial.registry import NoArgs, Observation, ToolContext, ToolUsageError, tool
from codeverse.spatial.tool_common import lazy, load_plan, tool_out_dir
@@ -57,10 +57,6 @@ def joint_sweep(ctx: ToolContext, args: JointSweepArgs) -> Observation:
# --------------------------------------------------------------------------- scenes
-class NoArgs(BaseModel):
- """This tool takes no arguments."""
-
-
@tool("shader_probe", NoArgs, "Compile every GLSL/ShaderMaterial in the scene headlessly and report shader errors with line numbers.",
languages=(Language.SCENE_THREEJS.value,), cost_hint="slow")
def shader_probe(ctx: ToolContext, args: NoArgs) -> Observation:
diff --git a/harness/tests/graphics/test_gl_runtime.py b/harness/tests/graphics/test_gl_runtime.py
index 414b2664..66c4e9e8 100644
--- a/harness/tests/graphics/test_gl_runtime.py
+++ b/harness/tests/graphics/test_gl_runtime.py
@@ -112,3 +112,22 @@ def test_gl_tools_probe_and_frames(tmp_ws, host, monkeypatch):
(ws.src / "shader.frag").write_text("#version 330 core\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) { fragColor = vec4(1.0); }\n")
obs = get_tool("gl_probe").call(ctx, {})
assert not obs.ok and "LINT FAILED" in obs.text and "#version" in obs.text
+
+
+def test_gl_probe_compile_error_report(tmp_ws, host, monkeypatch):
+ """Pin: the gl_probe failure report names the error type and the agent's
+ (workspace-relative) file:line, from any cwd, without host paths."""
+ ws = _ws_with_plan(tmp_ws)
+ GlslShaderRuntime(host=host).skeleton(ws, PLAN)
+ (ws.src / "shader.frag").write_text(
+ "// line 1\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec2 uv = fragCoord / u_resolution.xy;\n"
+ " float v = twice(nope);\n fragColor = vec4(uv, v, 1.0);\n}\n")
+ monkeypatch.setattr("codeverse.languages.glsl_shader.runtime.GlslShaderRuntime.host", lambda self, timeout_s=None: host)
+ ctx = ToolContext(workspace=ws, language="glsl_shader", track="graphics")
+ obs = get_tool("gl_probe").call(ctx, {})
+ assert not obs.ok and obs.numbers["stage"] == "build"
+ first = obs.text.splitlines()[0]
+ assert first.startswith("BUILD FAILED: GlslCompileError") and "at src/shader.frag:4" in first
+ assert "nope" in obs.text and str(ws.root) not in obs.text
+ assert obs.text.count("nope") == 1 # the compile log is the message — the stderr tail is not repeated
+ assert obs.numbers["error_type"] == "GlslCompileError" and obs.numbers["error_line"] == 4
diff --git a/harness/tests/spatial_tools/test_observe.py b/harness/tests/spatial_tools/test_observe.py
index d589113e..7792da0e 100644
--- a/harness/tests/spatial_tools/test_observe.py
+++ b/harness/tests/spatial_tools/test_observe.py
@@ -2,11 +2,20 @@ from __future__ import annotations
from pathlib import Path
-from codeverse.contracts.artifacts import GateFinding, GateReport, RenderSet, RenderView, Severity
+from codeverse.contracts.artifacts import (
+ BuildResult,
+ GateFinding,
+ GateReport,
+ RenderSet,
+ RenderView,
+ Severity,
+)
from codeverse.spatial.observe import (
+ build_failure_lines,
fmt_numbers,
gate_observation,
image_budget,
+ lint_lines,
rel_path,
render_observation,
sanitize_text,
@@ -62,3 +71,26 @@ def test_render_observation(tmp_path: Path) -> None:
assert obs.ok and obs.images[0].endswith("sheet.png") and len(obs.images) == 2
assert "a/view_front.png" in obs.text and str(tmp_path) not in obs.text
assert "cam=(0, 1, 2)" in obs.text
+
+
+def test_lint_lines_split_by_severity(tmp_path: Path) -> None:
+ rep = GateReport(gate="lint:x", passed=False, findings=[
+ GateFinding(gate="lint:x", severity=Severity.ERROR, target=str(tmp_path / "src" / "a.py"), message="bad", fix_hint="fix it"),
+ GateFinding(gate="lint:x", severity=Severity.WARN, message="meh"),
+ GateFinding(gate="lint:x", severity=Severity.INFO, message="fyi"),
+ ])
+ assert lint_lines(rep, tmp_path, errors_only=True) == ["- ERROR (src/a.py): bad", " fix: fix it"]
+ assert lint_lines(rep, tmp_path, errors_only=False) == ["- WARN: meh"]
+
+
+def test_build_failure_lines_relative_file_and_tail_dedupe(tmp_path: Path) -> None:
+ # (ii) an already-relative error_file is shown as-is from any cwd (rel_path would give the bare name)
+ # (iii) a stderr tail that is already part of the message is not repeated
+ log = "0:4: 'nope' undeclared"
+ br = BuildResult(ok=False, language="glsl_shader", error_type="GlslCompileError", error_file="src/shader.frag",
+ error_line=4, error_message="GLSL compile error:\n" + log, stderr_tail=log)
+ lines = build_failure_lines(br, tmp_path, ["- WARN: w"], tail_n=25)
+ assert lines == ["BUILD FAILED: GlslCompileError: GLSL compile error: at src/shader.frag:4", log, "lint hints:\n- WARN: w"]
+ br2 = br.model_copy(update={"error_file": str(tmp_path / "src" / "a.py"), "error_message": "boom", "stderr_tail": "l1\nl2"})
+ lines = build_failure_lines(br2, tmp_path, [], tail_n=1)
+ assert lines == ["BUILD FAILED: GlslCompileError: boom at src/a.py:4", "stderr (tail):\nl2"]