Skip to content

Official Codebase of 3DCodeVerse

Python

workspace: relocating a run silently broke show/status (absolute paths in record.json)

gaoypeng0744ed4227ba
diff --git a/harness/codeverse/cli/_fmt.py b/harness/codeverse/cli/_fmt.py
index 18ed1557..0be21082 100644
--- a/harness/codeverse/cli/_fmt.py
+++ b/harness/codeverse/cli/_fmt.py
@@ -10,6 +10,7 @@ from rich.panel import Panel
from rich.table import Table
from codeverse.contracts.run import RunRecord
+from codeverse.workspace import Workspace
console = Console(emoji=False)
err_console = Console(stderr=True, style="bold red", emoji=False)
@@ -65,7 +66,10 @@ def print_record_summary(record: RunRecord, ws_root: Path | None = None) -> None
lines.append(f"workspace: {ws_root}")
best = next((r for r in record.rounds if r.index == record.best_round), None)
if best is not None and best.renders is not None and best.renders.contact_sheet:
- lines.append(f"sheet: {best.renders.contact_sheet}")
+ # rebase, never print the stored string: record.json holds the ABSOLUTE path
+ # of the host that produced the run, so a moved/archived run printed a sheet
+ # that does not exist while the real one sat under this root.
+ lines.append(f"sheet: {Workspace(ws_root).rebase(best.renders.contact_sheet)}")
glb = ws_root / "artifacts" / "object.glb"
if glb.is_file():
lines.append(f"glb: {glb}")
diff --git a/harness/codeverse/cli/_judge.py b/harness/codeverse/cli/_judge.py
index 813c39a5..7ef9e92d 100644
--- a/harness/codeverse/cli/_judge.py
+++ b/harness/codeverse/cli/_judge.py
@@ -14,7 +14,6 @@ the spec carries reference images, ``VlmJudge`` otherwise.
from __future__ import annotations
import json
-from pathlib import Path
from typing import Any
from codeverse.cli import _common as C
@@ -95,19 +94,18 @@ def clay_geometry_views(ws: Workspace, index: int) -> RenderSet | None:
def resolve_paths(ws: Workspace, rs: RenderSet | None) -> RenderSet | None:
- """Round records may store workspace-relative render paths; make them absolute."""
+ """Render paths out of a round record, resolved against THIS workspace.
+
+ Delegates to ``Workspace.rebase``: this used to rebase only paths for which
+ ``is_absolute()`` was False, which made it a no-op against every record the harness
+ itself writes (they are all absolute) — so a moved or archived run kept pointing at
+ the host it was produced on.
+ """
if rs is None:
return None
- fixed = []
- for v in rs.views:
- p = Path(v.path)
- fixed.append(v if p.is_absolute() else v.model_copy(update={"path": str(ws.root / p)}))
- sheet = rs.contact_sheet
- if sheet and not Path(sheet).is_absolute():
- sheet = str(ws.root / sheet)
- out_dir = rs.out_dir
- if out_dir and not Path(out_dir).is_absolute():
- out_dir = str(ws.root / out_dir)
+ fixed = [v.model_copy(update={"path": str(ws.rebase(v.path))}) for v in rs.views]
+ sheet = str(ws.rebase(rs.contact_sheet)) if rs.contact_sheet else rs.contact_sheet
+ out_dir = str(ws.rebase(rs.out_dir)) if rs.out_dir else rs.out_dir
return rs.model_copy(update={"views": fixed, "contact_sheet": sheet, "out_dir": out_dir})
diff --git a/harness/codeverse/workspace.py b/harness/codeverse/workspace.py
index 37ea8df8..676e9890 100644
--- a/harness/codeverse/workspace.py
+++ b/harness/codeverse/workspace.py
@@ -61,6 +61,37 @@ class Workspace:
self.root = Path(root).resolve()
# ----------------------------------------------------------------- paths
+ def rebase(self, stored: str | Path) -> Path:
+ """A path out of ``record.json`` / ``run_state.json``, resolved against THIS
+ workspace wherever it was written.
+
+ The records store ABSOLUTE host paths (29 per run: rounds[].renders[].path,
+ contact_sheet, build.glb_path, build.extra_paths, census exports, and
+ run_state.stages[].result_path), so archiving, moving or rsyncing a run silently
+ broke every consumer that trusted them — `3dcv show` printed a contact sheet at
+ the old location that did not exist, while the real one sat under the new root.
+ object.glb kept working because it is recomputed from the workspace, which made
+ the breakage partial and therefore silent.
+
+ Relative paths join the root (what the old ``_judge.resolve_paths`` did, and the
+ only case it handled). An absolute path that still exists is returned as-is. An
+ absolute path that does NOT exist is re-rooted by finding its longest trailing
+ segment that does exist under this root — the run was moved, so the tail is
+ intact even though the prefix is not. Nothing matches: the original is returned
+ so the caller reports a real missing file rather than a silently wrong one.
+ """
+ p = Path(stored)
+ if not p.is_absolute():
+ return self.root / p
+ if p.exists():
+ return p
+ parts = p.parts
+ for i in range(1, len(parts)):
+ candidate = self.root.joinpath(*parts[i:])
+ if candidate.exists():
+ return candidate
+ return p
+
@property
def src(self) -> Path:
return self.root / "src"
diff --git a/harness/tests/core/test_run_layout.py b/harness/tests/core/test_run_layout.py
index 43160c64..644752a1 100644
--- a/harness/tests/core/test_run_layout.py
+++ b/harness/tests/core/test_run_layout.py
@@ -79,3 +79,87 @@ def test_record_blocks_are_additive(tmp_path: Path):
again = RunRecord.model_validate_json(rec.model_dump_json())
assert again.deliverable is not None and again.deliverable.best_round == 1
assert again.telemetry is not None and again.telemetry.schema_version == 1
+
+
+# --------------------------------------------------------------------------- relocation
+def test_a_relocated_run_still_resolves_its_stored_paths(tmp_path):
+ """SMOKE2: record.json stores ABSOLUTE host paths (29 per run — rounds[].renders[]
+ .path, contact_sheet, build.glb_path, build.extra_paths, census exports — plus
+ run_state.stages[].result_path), so archiving, moving or rsyncing a run silently
+ broke every consumer that trusted them. `3dcv show` printed a contact sheet at the
+ OLD location, which did not exist, while the real one sat under the new root;
+ object.glb kept resolving because it is recomputed from the workspace, which made
+ the breakage partial and therefore silent.
+
+ The intended repair, _judge.resolve_paths, only rebased paths for which
+ ``Path(p).is_absolute()`` was False — a no-op against every record the harness itself
+ writes — and _fmt, which is what show/status actually use, never called it at all."""
+ import shutil
+
+ from codeverse.workspace import Workspace
+
+ a = tmp_path / "A" / "run1"
+ (a / "artifacts" / "renders" / "r01").mkdir(parents=True)
+ sheet_a = a / "artifacts" / "renders" / "r01" / "sheet.png"
+ sheet_a.write_bytes(b"PNG")
+ stored = str(sheet_a) # what the writer puts in record.json
+
+ b = tmp_path / "B" / "run1"
+ b.parent.mkdir(parents=True)
+ shutil.move(str(a), str(b))
+
+ ws = Workspace(b)
+ got = ws.rebase(stored)
+ assert got.exists(), f"a moved run must still find its own sheet, got {got}"
+ assert got == b / "artifacts" / "renders" / "r01" / "sheet.png"
+ assert Path(stored) != got
+
+ # an absolute path that IS still valid is left alone
+ assert ws.rebase(str(got)) == got
+ # a relative path joins the root (the only case the old code handled)
+ assert ws.rebase("artifacts/renders/r01/sheet.png") == got
+ # nothing matches -> the original comes back, so the caller reports a real missing
+ # file instead of a silently wrong one
+ missing = tmp_path / "elsewhere" / "nope.png"
+ assert ws.rebase(str(missing)) == missing
+
+
+def test_show_prints_the_sheet_that_exists_after_a_move(tmp_path):
+ """The user-visible half: `3dcv show` must not print a path that is not there."""
+ import shutil
+
+ from codeverse.cli._fmt import console, print_record_summary
+ from codeverse.contracts.artifacts import RenderSet
+ from codeverse.contracts.common import Backends, Language, Track
+ from codeverse.contracts.run import RoundRecord, RunRecord, RunStatus
+ from codeverse.contracts.spec import Spec
+ from codeverse.workspace import Workspace
+
+ a = tmp_path / "A" / "run1"
+ (a / "artifacts" / "renders" / "r01").mkdir(parents=True)
+ sheet_a = a / "artifacts" / "renders" / "r01" / "sheet.png"
+ sheet_a.write_bytes(b"PNG")
+
+ spec = Spec(id="run1", track=Track.STATIC_OBJECT, language=Language.BLENDER,
+ prompt="a wooden chair", backends=Backends(generator="api-agent:gemini:x"))
+ rec = RunRecord(spec=spec, workspace=str(a), status=RunStatus.PASSED, best_round=0,
+ rounds=[RoundRecord(index=0, kind="generate",
+ renders=RenderSet(views=[], contact_sheet=str(sheet_a)))])
+
+ b = tmp_path / "B" / "run1"
+ b.parent.mkdir(parents=True)
+ shutil.move(str(a), str(b))
+
+ # rich's Console holds its own stream, so capsys does not see it; widen it so the
+ # panel does not wrap the path we are asserting on
+ old_width, console.width = console.width, 400
+ try:
+ with console.capture() as cap:
+ print_record_summary(rec, Workspace(b).root)
+ finally:
+ console.width = old_width
+ printed = cap.get()
+ line = next(ln for ln in printed.splitlines() if "sheet:" in ln)
+ shown = line.split("sheet:", 1)[1].strip().rstrip("│ ").strip()
+ assert shown.endswith("sheet.png"), f"the panel wrapped the path: {line!r}"
+ assert Path(shown).exists(), f"show printed a sheet that is not there: {shown!r}"