Official Codebase of 3DCodeVerse
Python
apply_profile: one CV3D_JUDGE__* variable disabled the profile's whole judge block
gaoypeng04881f8576a1
diff --git a/harness/codeverse/config.py b/harness/codeverse/config.pyindex 4f44ac2c..47d89ce5 100644--- a/harness/codeverse/config.py+++ b/harness/codeverse/config.py@@ -235,18 +235,36 @@ class Settings(BaseSettings):if field not in stated and value not in (None, ""):setattr(self, field, value)+ def put_section(section: str, values: dict[str, Any]) -> None:+ """Per-FIELD statedness inside a sub-model.++ ``Settings.model_fields_set`` is SECTION-granular — pydantic marks the whole+ ``judge`` sub-model as set when any ``CV3D_JUDGE__*`` is present — so testing+ it here let one stated field suppress the profile's every other dial:+ ``CV3D_PROFILE=quality CV3D_JUDGE__MAX_PX=800`` judged at n=1 instead of n=3,+ silently, while `3dcv make` printed "judge sigma 0.017 at n=3". The sub-model+ has its own ``model_fields_set``, which is the per-field answer. The values a+ profile writes are DEFAULTS, not statements, so the field-set is restored+ afterwards and re-applying a profile stays idempotent.+ """+ sub = getattr(self, section)+ keep = set() if force else set(sub.model_fields_set)+ update = {k: v for k, v in values.items() if k not in keep}+ if not update:+ return+ new_sub = sub.model_copy(update=update)+ new_sub.__pydantic_fields_set__ = keep+ setattr(self, section, new_sub)+self.profile = p.nameput("default_generator", p.generator)put("default_planner", p.planner)put("default_judge", p.judge)put("default_captioner", p.captioner)put("default_candidates", p.candidates)- if "judge" not in stated:- self.judge = self.judge.model_copy(update={- "max_px": p.judge_max_px, "montages": p.judge_montages,- "detail_crops": p.judge_detail_crops, "samples": p.judge_samples})- if "limits" not in stated:- self.limits = self.limits.model_copy(update={"agent_max_turns": p.max_turns})+ put_section("judge", {"max_px": p.judge_max_px, "montages": p.judge_montages,+ "detail_crops": p.judge_detail_crops, "samples": p.judge_samples})+ put_section("limits", {"agent_max_turns": p.max_turns})return pdef resolve_blender(self) -> str:diff --git a/harness/tests/cost/test_profiles.py b/harness/tests/cost/test_profiles.pyindex 22f0deb7..d9d96d86 100644--- a/harness/tests/cost/test_profiles.py+++ b/harness/tests/cost/test_profiles.py@@ -8,6 +8,7 @@ from pathlib import Pathimport pytestfrom typer.testing import CliRunner+from codeverse.cli._common import resolve_dialfrom codeverse.cli.main import appfrom codeverse.config import Settings, get_settingsfrom codeverse.cost.profiles import PROFILE_NAMES, PROFILES, get_profile, profile_table@@ -81,6 +82,37 @@ def test_a_value_the_user_configured_survives_the_profile_unless_forced():assert s.default_generator == "single-shot:gemini:gemini-3.7-flash"+def test_one_stated_judge_field_does_not_disable_the_whole_judge_block(monkeypatch):+ """SM-03: ``model_fields_set`` on Settings is SECTION-granular — pydantic marks the+ whole ``judge`` sub-model as set when any CV3D_JUDGE__* is present — so stating+ max_px (which no profile even changes) used to suppress judge_samples too:+ ``CV3D_PROFILE=quality CV3D_JUDGE__MAX_PX=800`` judged at n=1 while `3dcv make`+ advertised "judge sigma 0.017 at n=3". Statedness must be per FIELD."""+ monkeypatch.setenv("CV3D_JUDGE__MAX_PX", "800")+ s = Settings()+ s.apply_profile("quality")+ assert s.judge.max_px == 800, "the field the user stated wins"+ assert s.judge.samples == 3, "every field the user did NOT state still follows the profile"+ assert s.judge.montages == 3 and s.judge.detail_crops == 2+ # and the same dial, whichever way the profile was named (cost/profiles.py's invariant)+ monkeypatch.setenv("CV3D_PROFILE", "quality")+ get_settings.cache_clear()+ try:+ settings = get_settings()+ assert resolve_dial(settings, None).judge_samples == resolve_dial(settings, "quality").judge_samples == 3+ finally:+ get_settings.cache_clear()+++def test_applying_a_profile_twice_is_idempotent():+ """A profile writes DEFAULTS, so its own values must not come back as "stated" and+ freeze the next apply_profile (model_copy(update=) marks the copied fields set)."""+ s = Settings()+ s.apply_profile("quality")+ s.apply_profile("economy")+ assert s.judge.samples == 2 and s.judge.max_px == 1024++def test_unknown_profile_is_a_clear_error():with pytest.raises(ValueError, match="unknown profile"):get_profile("cheapest")