Official Codebase of 3DCodeVerse
Python
tests: three helpers pasted 11 times, defined once
gaoypeng0d64a9715521
diff --git a/harness/tests/flywheel_cli/test_flywheel.py b/harness/tests/flywheel_cli/test_flywheel.pyindex bb38b3aa..56083e7f 100644--- a/harness/tests/flywheel_cli/test_flywheel.py+++ b/harness/tests/flywheel_cli/test_flywheel.py@@ -436,8 +436,8 @@ def test_parquet_keeps_the_complexity_columns_the_exporter_writes(tmp_path):write_parquet([{**row, "a_new_metric": 1.0}], tmp_path / "later.parquet")-def test_a_core_only_install_still_gets_a_complete_dataset(runs_dir: Path, tmp_path: Path, monkeypatch):- """Core installs always export JSONL and make parquet optional."""+def _block_pyarrow(monkeypatch) -> None:+ """Make ``import pyarrow`` fail the way a core-only install does."""import builtinsreal_import = builtins.__import__@@ -448,6 +448,11 @@ def test_a_core_only_install_still_gets_a_complete_dataset(runs_dir: Path, tmp_preturn real_import(name, *a, **kw)monkeypatch.setattr(builtins, "__import__", no_pyarrow)+++def test_a_core_only_install_still_gets_a_complete_dataset(runs_dir: Path, tmp_path: Path, monkeypatch):+ """Core installs always export JSONL and make parquet optional."""+ _block_pyarrow(monkeypatch)out = tmp_path / "ds_core"rep = export_samples(runs_dir, out) # must NOT raiseassert rep.n_exported == 3 and rep.n_indexed == 3@@ -461,20 +466,11 @@ def test_a_core_only_install_still_gets_a_complete_dataset(runs_dir: Path, tmp_pdef test_pack_refuses_before_writing_anything_when_pyarrow_is_missing(runs_dir: Path, tmp_path: Path, monkeypatch):"""Packing refuses before writing when its optional dependency is absent."""- import builtins-from typer.testing import CliRunnerfrom codeverse.cli.main import app- real_import = builtins.__import__-- def no_pyarrow(name, *a, **kw):- if name == "pyarrow" or name.startswith("pyarrow."):- raise ModuleNotFoundError("No module named 'pyarrow'")- return real_import(name, *a, **kw)-- monkeypatch.setattr(builtins, "__import__", no_pyarrow)+ _block_pyarrow(monkeypatch)out = tmp_path / "ds_pack"res = CliRunner().invoke(app, ["flywheel", "export", str(runs_dir), str(out), "--pack"])assert res.exit_code == 1diff --git a/harness/tests/orchestrator_tracks/fakes.py b/harness/tests/orchestrator_tracks/fakes.pyindex f1601a3b..0a7e1160 100644--- a/harness/tests/orchestrator_tracks/fakes.py+++ b/harness/tests/orchestrator_tracks/fakes.py@@ -197,6 +197,11 @@ class FakeChatModel:return ChatResponse(text=str(out), usage=usage)+def _planner(payload: Any) -> FakeChatModel:+ """A chat model that answers every planning request with ``payload``."""+ return FakeChatModel(lambda req: payload)++# ----------------------------------------------------------------------------- judgeclass FakeJudge:name = "fake"diff --git a/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py b/harness/tests/orchestrator_tracks/test_candidates_reference_motion.pyindex d8f94e0f..d0427715 100644--- a/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py+++ b/harness/tests/orchestrator_tracks/test_candidates_reference_motion.py@@ -32,13 +32,10 @@ from tests.orchestrator_tracks.fakes import (FakePairwise,FakeRuntime,FakeServices,+ _planner,)-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--# ----------------------------------------------------------------------------- pure logicdef test_round_policy_candidates_and_compaction():pol = RoundPolicy()diff --git a/harness/tests/orchestrator_tracks/test_cost_latency.py b/harness/tests/orchestrator_tracks/test_cost_latency.pyindex 2e341b93..0466bea6 100644--- a/harness/tests/orchestrator_tracks/test_cost_latency.py+++ b/harness/tests/orchestrator_tracks/test_cost_latency.py@@ -34,6 +34,7 @@ from tests.orchestrator_tracks.fakes import (FakeJudge,FakeRuntime,FakeServices,+ _planner,)RUNTIME_JS = get_settings().runtime_js_dir()@@ -264,10 +265,6 @@ def test_single_shot_ctx_is_none_for_cli_backends(tmp_path, settings):# ----------------------------------------------------------------------------- salvage-def _planner(payload):- return FakeChatModel(lambda req: payload)--def _threejs_scene_plan() -> ScenePlan:"""The scene example narrowed to its three.js assets — the only kind these fakes build."""plan = ScenePlan.model_validate(plan_example(Track.SCENE))diff --git a/harness/tests/orchestrator_tracks/test_fix_batch2.py b/harness/tests/orchestrator_tracks/test_fix_batch2.pyindex f458fea4..ea367296 100644--- a/harness/tests/orchestrator_tracks/test_fix_batch2.py+++ b/harness/tests/orchestrator_tracks/test_fix_batch2.py@@ -21,17 +21,13 @@ from codeverse.workspace import Workspacefrom tests.orchestrator_tracks.conftest import fake_clock, make_specfrom tests.orchestrator_tracks.fakes import (FakeAgent,- FakeChatModel,FakeJudge,FakeRuntime,FakeServices,+ _planner,)-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _writer(job, ws):return {"src/object.js": f"// {job.label} r{job.round}\nexport function build(THREE) {{ return new THREE.Group(); }}\n"}diff --git a/harness/tests/orchestrator_tracks/test_integrations2.py b/harness/tests/orchestrator_tracks/test_integrations2.pyindex e63da4a8..805e6455 100644--- a/harness/tests/orchestrator_tracks/test_integrations2.py+++ b/harness/tests/orchestrator_tracks/test_integrations2.py@@ -22,18 +22,14 @@ from codeverse.workspace import Workspacefrom tests.orchestrator_tracks.conftest import make_specfrom tests.orchestrator_tracks.fakes import (FakeAgent,- FakeChatModel,FakeJudge,FakeRuntime,FakeServices,+ _planner,)from tests.orchestrator_tracks.test_tracks import _agent_writer, _scene_writer-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _static_run(tmp_path, chair_plan, settings, **spec_kw):spec = make_spec(max_rounds=0, **spec_kw)ws = Workspace(tmp_path / "runs" / "obj")diff --git a/harness/tests/orchestrator_tracks/test_refactor_batch2.py b/harness/tests/orchestrator_tracks/test_refactor_batch2.pyindex c79b037b..379a2b8b 100644--- a/harness/tests/orchestrator_tracks/test_refactor_batch2.py+++ b/harness/tests/orchestrator_tracks/test_refactor_batch2.py@@ -20,13 +20,10 @@ from tests.orchestrator_tracks.fakes import (FakeJudge,FakeRuntime,FakeServices,+ _planner,)-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _writer(job, ws):return {"src/object.js": f"// {job.label} r{job.round}\nexport function build(THREE) {{ return new THREE.Group(); }}\n"}diff --git a/harness/tests/orchestrator_tracks/test_resume_reconcile.py b/harness/tests/orchestrator_tracks/test_resume_reconcile.pyindex 6bf71633..8a1b2a89 100644--- a/harness/tests/orchestrator_tracks/test_resume_reconcile.py+++ b/harness/tests/orchestrator_tracks/test_resume_reconcile.py@@ -27,13 +27,10 @@ from tests.orchestrator_tracks.fakes import (FakePairwise,FakeRuntime,FakeServices,+ _planner,)-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _writer(job, ws):return {"src/model.py": f"import bpy # {job.label} r{job.round}\n"}diff --git a/harness/tests/orchestrator_tracks/test_round_economics.py b/harness/tests/orchestrator_tracks/test_round_economics.pyindex ab18f391..606b4776 100644--- a/harness/tests/orchestrator_tracks/test_round_economics.py+++ b/harness/tests/orchestrator_tracks/test_round_economics.py@@ -32,10 +32,10 @@ from codeverse.workspace import Workspacefrom tests.orchestrator_tracks.conftest import fake_clock, make_specfrom tests.orchestrator_tracks.fakes import (FakeAgent,- FakeChatModel,FakeJudge,FakeRuntime,FakeServices,+ _planner,)@@ -380,10 +380,6 @@ def _ctx(tmp_path, spec, settings, *, policy: RoundPolicy | None = None, agent=N# ----------------------------------------------------------------------------- end to end-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _writer(job, ws):return {"src/object.js": f"// {job.label} r{job.round}\nexport function build(THREE) {{}}\n"}diff --git a/harness/tests/orchestrator_tracks/test_tracks.py b/harness/tests/orchestrator_tracks/test_tracks.pyindex cac740de..b2776335 100644--- a/harness/tests/orchestrator_tracks/test_tracks.py+++ b/harness/tests/orchestrator_tracks/test_tracks.py@@ -25,13 +25,10 @@ from tests.orchestrator_tracks.fakes import (FakeJudge,FakeRuntime,FakeServices,+ _planner,)-def _planner(plan_dict):- return FakeChatModel(lambda req: plan_dict)--def _agent_writer(job, ws):"""Writes every file named in files_hint-ish prompt: we just write object.js + parts from the prompt table."""files = {}diff --git a/harness/tests/orchestrator_tracks/test_transport_retry.py b/harness/tests/orchestrator_tracks/test_transport_retry.pyindex 4100fa8b..67b636be 100644--- a/harness/tests/orchestrator_tracks/test_transport_retry.py+++ b/harness/tests/orchestrator_tracks/test_transport_retry.py@@ -11,7 +11,6 @@ import pytestfrom codeverse.contracts.agent import AgentJob, AgentResultfrom codeverse.contracts.common import Language, Usagefrom codeverse.contracts.run import RunStatus-from codeverse.conventions import to_snakefrom codeverse.proc import EventLogfrom codeverse.tracks.static_object import StaticObjectTrackfrom codeverse.tracks.steps import RoundFailed, looks_transport@@ -24,6 +23,7 @@ from tests.orchestrator_tracks.fakes import (FakeRuntime,FakeServices,)+from tests.orchestrator_tracks.test_tracks import _agent_writer as _writer# --------------------------------------------------------------- signature unit@@ -58,19 +58,6 @@ def test_agent_verdicts_do_not_match(msg):CRASH = ["rc=247; response=<empty>; stderr tail: Error: 503 UNAVAILABLE (crash-test)"]-def _writer(job: AgentJob, ws: Workspace) -> dict[str, str]:- """Template writer (test_tracks.py): parts from the prompt table + a per-round object.js."""- files: dict[str, str] = {}- for line in job.prompt.splitlines():- if "| " in line and line.startswith("| ") and not line.startswith("| part") and not line.startswith("|---"):- name = line.split("|")[1].strip()- if name:- files[f"src/parts/{to_snake(name)}.js"] = (- f"export function build{name}(THREE) {{ /* {job.label} r{job.round} */ return new THREE.Group(); }}\n")- files["src/object.js"] = f"// {job.label} r{job.round}\nexport function build(THREE) {{ return new THREE.Group(); }}\n"- return files--class CrashingAgent(FakeAgent):"""The first ``crashes`` sessions at ``crash_round`` die like a crashed CLI(-1 = every session there dies, forever)."""