Skip to content

Official Codebase of 3DCodeVerse

Python

reference: PlausibilityVerdict extends GateAnswer and reference_set.json is written once — the restated fields and _publish's write go

gaoypeng211cdc756ed6
diff --git a/harness/codeverse3d/reference.py b/harness/codeverse3d/reference.py
index 6c243fb1..1b5c43c1 100644
--- a/harness/codeverse3d/reference.py
+++ b/harness/codeverse3d/reference.py
@@ -66,23 +66,29 @@ MismatchKind = Literal[
]
-class PlausibilityVerdict(BaseModel):
- """One vision call's answer about ONE candidate reference image.
-
- ``ok`` is computed in code from the booleans + ``contradictions`` (see
- :func:`decide`), never taken from the model.
- """
+class GateAnswer(BaseModel):
+ """What the vision model reports (observations only — no verdict)."""
- ok: bool = False
+ depicted_object: str = ""
shows_requested_object: bool = False
single_object: bool = False
plain_background: bool = False
no_text_or_watermark: bool = False
is_photo_collage: bool = False
- depicted_object: str = Field(default="", description="what the vision model says the image shows")
- contradictions: list[str] = Field(default_factory=list,
- description="explicit spec constraints the image contradicts")
+ contradictions: list[str] = Field(default_factory=list)
reason: str = ""
+
+
+class PlausibilityVerdict(GateAnswer):
+ """One vision call's answer about ONE candidate reference image: the model's
+ observations (``depicted_object`` — what it says the image shows; ``contradictions`` —
+ the explicit spec constraints the image contradicts) plus the verdict.
+
+ ``ok`` is computed in code from the booleans + ``contradictions`` (see
+ :func:`decide`), never taken from the model.
+ """
+
+ ok: bool = False
model_id: str = ""
def failure(self) -> str:
@@ -518,19 +524,6 @@ def conflict_note(info: dict[str, Any]) -> str:
# ===================================================================== gate
-class GateAnswer(BaseModel):
- """What the vision model reports (observations only — no verdict)."""
-
- depicted_object: str = ""
- shows_requested_object: bool = False
- single_object: bool = False
- plain_background: bool = False
- no_text_or_watermark: bool = False
- is_photo_collage: bool = False
- contradictions: list[str] = Field(default_factory=list)
- reason: str = ""
-
-
def decide(ans: GateAnswer, *, model_id: str = "") -> PlausibilityVerdict:
"""Observations → verdict, in code. ALL of the checks must hold."""
ok = (
@@ -541,18 +534,12 @@ def decide(ans: GateAnswer, *, model_id: str = "") -> PlausibilityVerdict:
and not ans.is_photo_collage
and not ans.contradictions
)
- return PlausibilityVerdict(
- ok=ok,
- shows_requested_object=ans.shows_requested_object,
- single_object=ans.single_object,
- plain_background=ans.plain_background,
- no_text_or_watermark=ans.no_text_or_watermark,
- is_photo_collage=ans.is_photo_collage,
- depicted_object=ans.depicted_object.strip()[:80],
- contradictions=[c.strip()[:200] for c in ans.contradictions if c.strip()][:6],
- reason=ans.reason.strip()[:300],
- model_id=model_id,
- )
+ return PlausibilityVerdict(**{
+ **ans.model_dump(),
+ "depicted_object": ans.depicted_object.strip()[:80],
+ "contradictions": [c.strip()[:200] for c in ans.contradictions if c.strip()][:6],
+ "reason": ans.reason.strip()[:300],
+ }, ok=ok, model_id=model_id)
def check_plausible(
@@ -759,7 +746,8 @@ def _refresh_conflicts(spec: Spec, rs: ReferenceSet) -> None:
def _publish(rs: ReferenceSet, out_dir: Path | None) -> ReferenceSet:
- """Copy accepted images into the run and repoint their paths (idempotent)."""
+ """Copy accepted images into the run and repoint their paths (idempotent). The set
+ itself is written by ``ground_spec``, which records the all-rejected case too."""
if out_dir is None or not rs.accepted:
return rs
out_dir = Path(out_dir)
@@ -777,7 +765,6 @@ def _publish(rs: ReferenceSet, out_dir: Path | None) -> ReferenceSet:
log.warning("could not copy reference into the run (%s); using the cache path", e)
continue
v.path = str(dst)
- (out_dir / "reference_set.json").write_text(rs.model_dump_json(indent=2))
return rs
diff --git a/harness/tests/reference/test_synth.py b/harness/tests/reference/test_synth.py
index cf14302c..6ca605f3 100644
--- a/harness/tests/reference/test_synth.py
+++ b/harness/tests/reference/test_synth.py
@@ -2,7 +2,6 @@
from __future__ import annotations
-import json
from pathlib import Path
from codeverse3d.models.base import ModelError
@@ -95,10 +94,11 @@ def test_prompt_writer_failure_falls_back_to_the_brief(cache_dir: Path):
assert rs.ok and "coffee grinder" in rs.subject
-def test_out_dir_copies_accepted_images_and_writes_the_set(cache_dir: Path, tmp_path: Path):
+def test_out_dir_copies_accepted_images(cache_dir: Path, tmp_path: Path):
+ """The copies only: ``ground_spec`` writes reference_set.json (test_run_and_cli), once,
+ including the all-rejected set ``_publish`` never saw."""
out = tmp_path / "run" / "artifacts" / "reference"
rs = synth_reference(make_spec(), model=_chat(), image_model=FakeImageModel(), n_views=2,
cache_dir=cache_dir, out_dir=out)
- assert all(Path(v.path).parent == out for v in rs.accepted)
- saved = json.loads((out / "reference_set.json").read_text())
- assert saved["synthesized"] is True and len(saved["views"]) == 2
+ assert len(rs.accepted) == 2 and all(Path(v.path).parent == out for v in rs.accepted)
+ assert rs.synthesized and not (out / "reference_set.json").exists()