Official Codebase of 3DCodeVerse
Python
tests: threejs_render, urdf_joints, blender_cadquery, second pass — nine exceptions did not hold (−125 lines)
gaoypengadb0e24aa577
diff --git a/harness/tests/blender_cadquery/test_artifact_stage.py b/harness/tests/blender_cadquery/test_artifact_stage.pyindex 03776966..adb70f83 100644--- a/harness/tests/blender_cadquery/test_artifact_stage.py+++ b/harness/tests/blender_cadquery/test_artifact_stage.py@@ -2,8 +2,6 @@from __future__ import annotations-import pytest-from codeverse3d.workspace import Workspace@@ -48,20 +46,3 @@ def test_promote_replaces_an_existing_dir(tmp_ws: Workspace) -> None:stage.promote()stage.discard()assert [p.name for p in meshes.iterdir()] == ["new.glb"] # old members do not survive---def test_invalidate_standalone_and_name_validation(tmp_ws: Workspace) -> None:- _seed(tmp_ws)- tmp_ws.stage_artifacts("build.json", "object.glb", "meshes").invalidate()- for name in ("build.json", "object.glb", "meshes"):- assert not (tmp_ws.artifacts / name).exists(), name- stage = tmp_ws.stage_artifacts("build.json")- with pytest.raises(ValueError):- stage.path("other.json")- with pytest.raises(ValueError):- stage.invalidate("other.json")- with pytest.raises(FileNotFoundError):- stage.promote("build.json") # a named promote of something never staged is a bug- stage.discard()- with pytest.raises(ValueError):- tmp_ws.stage_artifacts()diff --git a/harness/tests/threejs_render/test_build.py b/harness/tests/threejs_render/test_build.pyindex 9e509b2c..20992042 100644--- a/harness/tests/threejs_render/test_build.py+++ b/harness/tests/threejs_render/test_build.py@@ -141,14 +141,3 @@ def test_build_runs_exported_selfcheck(stool_ws: Workspace):p.write_text(src + "export function selfcheck(THREE_, root) { return true; }\n")res = ThreeJsRuntime().build(stool_ws)assert res.ok and res.census["selfcheck_ran"] is True---def test_build_async_build_and_texture_strip(stool_ws: Workspace):- (stool_ws.src / "object.js").write_text(- "import * as THREE from 'three';\nexport async function build(T) { const g = new THREE.Group(); g.name='Async';\n"- " const m = new THREE.Mesh(new THREE.BoxGeometry(0.2,0.2,0.2), new THREE.MeshStandardMaterial({map: new THREE.Texture()}));\n"- " m.name='Box'; m.position.y = 0.1; g.add(m); return g; }\n")- res = ThreeJsRuntime().build(stool_ws)- assert res.ok, res.error_message- assert any("texture" in w for w in res.census["warnings"])- assert "Async" in trimesh.load(res.glb_path, force="scene").graph.nodes # the awaited group was exporteddiff --git a/harness/tests/threejs_render/test_lint.py b/harness/tests/threejs_render/test_lint.pyindex 68f94fec..52bfb081 100644--- a/harness/tests/threejs_render/test_lint.py+++ b/harness/tests/threejs_render/test_lint.py@@ -23,13 +23,6 @@ def _msgs(rep, sev=None):return [f.message for f in rep.findings if sev is None or f.severity == sev]-def test_clean_workspace_passes(stool_ws: Workspace, no_node_syntax):- rep = lint_workspace(stool_ws)- assert rep.gate == "lint:threejs"- assert rep.passed, rep.findings- assert rep.findings == []--def test_missing_object_js(tmp_path: Path, no_node_syntax):ws = Workspace(tmp_path)(ws.src / "parts").mkdir(parents=True)diff --git a/harness/tests/threejs_render/test_node.py b/harness/tests/threejs_render/test_node.pyindex b6570838..ad99f701 100644--- a/harness/tests/threejs_render/test_node.py+++ b/harness/tests/threejs_render/test_node.py@@ -1,4 +1,4 @@-"""run_node: last-JSON parsing, timeouts, error propagation."""+"""run_node: last-JSON parsing, error propagation, the scrubbed env."""from __future__ import annotations@@ -21,15 +21,6 @@ def test_missing_script_raises(tmp_path: Path):run_node(tmp_path / "nope.mjs", [], timeout_s=5)-def test_run_node_timeout_kills(tmp_path: Path):- script = tmp_path / "hang.mjs"- script.write_text("setInterval(() => {}, 1000); console.log('started');")- with pytest.raises(NodeError) as ei:- run_node(script, [], timeout_s=1.5)- assert ei.value.result is not None and ei.value.result.timed_out--@pytest.mark.nodedef test_run_node_env_is_scrubbed_of_secrets(tmp_path: Path, monkeypatch):"""Generated js (scene.js, agent modules) runs under run_node: no credentials."""diff --git a/harness/tests/threejs_render/test_runtime_js.py b/harness/tests/threejs_render/test_runtime_js.pyindex d5cf0930..39871c3e 100644--- a/harness/tests/threejs_render/test_runtime_js.py+++ b/harness/tests/threejs_render/test_runtime_js.py@@ -31,20 +31,6 @@ def test_export_cli_writes_census_and_error_json(stool_ws: Workspace, tmp_path:assert (stool_ws.artifacts / "export_error.json").is_file()-def test_render_glb_driver_reports_invalid_requests_as_last_json(tmp_path: Path):- rt = runtime_js_dir()- with pytest.raises(NodeError) as ei:- run_node(rt / "render_glb.mjs",- ["--glb", str(tmp_path / "missing.glb"), "--out", str(tmp_path / "out"),- "--views", json.dumps([{"name": "front", "azimuth": 0.0, "elevation": 8.0}])],- timeout_s=60)- rec = ei.value.result.last_json- assert ei.value.result.rc == 1 and rec["ok"] is False and "GLB not found" in rec["error"]- with pytest.raises(NodeError) as ei:- run_node(rt / "render_glb.mjs", ["--glb", "x.glb", "--out", "o", "--views", "[]"], timeout_s=60)- assert "non-empty JSON list" in ei.value.result.last_json["error"]--def test_serve_and_importmap(tmp_path: Path):script = tmp_path / "s.cjs"root = tmp_path / "root"diff --git a/harness/tests/urdf_joints/test_live_blender.py b/harness/tests/urdf_joints/test_live_blender.pyindex dfb97ff9..dc69e8db 100644--- a/harness/tests/urdf_joints/test_live_blender.py+++ b/harness/tests/urdf_joints/test_live_blender.py@@ -1,4 +1,4 @@-"""Real Blender builds (marked ``blender``): cabinet+door with yourdfpy FK, a rest-shifted drawer, wrapper failures."""+"""Real Blender builds (marked ``blender``): cabinet+door with yourdfpy FK, a rest-shifted drawer, typed wrapper failures, sys.exit(0)."""from __future__ import annotations@@ -74,30 +74,6 @@ def test_script_error_and_missing_object(tmp_path, cabinet_plan):assert not res.ok and res.error_type == "MissingLinkObjects" and "Handle" in res.error_message-@needs_blender-def test_wrapper_unsafe_link_name_is_a_build_error(tmp_path):- """End-to-end: a traversal-shaped URDF link name fails the build before the agent- script runs; meshes/ is never created, nothing lands outside it."""- import json as _json- import subprocess-- from codeverse3d.languages.urdf import WRAPPER-- (tmp_path / "robot.urdf").write_text('<robot name="r"><link name="../evil"/></robot>')- (tmp_path / "model.py").write_text("import bpy\n")- out = tmp_path / "art"- blender = get_settings().resolve_blender()- subprocess.run(- [blender, "-b", "--factory-startup", "--python", str(WRAPPER), "--",- "--script", str(tmp_path / "model.py"), "--urdf", str(tmp_path / "robot.urdf"),- "--out", str(out)],- capture_output=True, text=True, timeout=180, check=False)- build = _json.loads((out / "build.json").read_text())- assert not build["ok"] and build["error_type"] == "UnsafeLinkName"- assert "../evil" in build["error_message"]- assert not (out / "meshes").exists() and not (tmp_path / "evil.glb").exists()--@needs_blenderdef test_links_script_that_calls_sys_exit_0_still_builds(tmp_path):"""``sys.exit(0)`` ends the script, not the build: the objects it made are the linksdiff --git a/harness/tests/urdf_joints/test_mimic.py b/harness/tests/urdf_joints/test_mimic.pyindex cfec15bf..7b233914 100644--- a/harness/tests/urdf_joints/test_mimic.py+++ b/harness/tests/urdf_joints/test_mimic.py@@ -65,19 +65,6 @@ def test_a_driven_joint_follows_its_driver_through_the_chain(tmp_path):assert fk(r, {"runner_slide": 0.1})["runner"][2, 3] == pytest.approx(fk(r, {})["runner"][2, 3] + 0.1)-def test_the_contact_sheet_and_joint_narrowing_show_only_input_joints(tmp_path):- from codeverse3d.spatial.joints_model import fk- from codeverse3d.spatial.joints_poses import limit_poses-- r = _robot(tmp_path)- labels = [lab for lab, _ in limit_poses(r)]- assert labels == ["rest", "runner_slide@upper"], labels- assert not any("rib_" in lab for lab in labels)- # and the one non-rest pose really moves the ribs, through the driver- _, q = limit_poses(r)[1]- assert fk(r, q)["rib_a"][:3, :3].tolist() != fk(r, {})["rib_a"][:3, :3].tolist()--def test_the_sweep_poses_the_mechanism_the_way_it_moves(tmp_path):r = _robot(tmp_path)rep = sweep_collisions(r, pose_samples(r))diff --git a/harness/tests/urdf_joints/test_sweep.py b/harness/tests/urdf_joints/test_sweep.pyindex 517036ad..4d7b3e5a 100644--- a/harness/tests/urdf_joints/test_sweep.py+++ b/harness/tests/urdf_joints/test_sweep.py@@ -1,40 +1,24 @@-"""Collision sweep: good design clean, bad pivot penetrates, floating detection, motion direction."""+"""Collision sweep: rest penetration, floating detection, weld policy, finding aggregation."""from __future__ import annotationsimport pytestfrom codeverse3d.contracts.artifacts import GateFinding, Severity-from codeverse3d.spatial.joints_model import UrdfError, load_urdf+from codeverse3d.spatial.joints_model import load_urdffrom codeverse3d.spatial.joints_poses import pose_samplesfrom codeverse3d.spatial.joints_sweep import (MAX_PAIR_FINDINGS,aggregate_findings,- motion_direction_check,sweep_collisions,sweep_findings,)from tests.urdf_joints.conftest import (write_carcass_drawer_robot,write_mesh_robot,- write_prims_robot,)-def test_bad_axis_swings_door_into_body(tmp_path):- r = load_urdf(write_prims_robot(tmp_path / "cab.urdf", axis_z=+1))- rep = sweep_collisions(r, pose_samples(r))- assert rep.summary.rest_max_penetration_m == 0.0- assert rep.summary.max_penetration_m > 0.1- assert set(rep.summary.overlapping_poses) == {"hinge@mid", "hinge@upper"}- assert rep.summary.worst_pair == ("body", "door")- f = sweep_findings(rep)- assert all(x.severity == Severity.ERROR for x in f) and len(f) == 2- assert "pivot" in f[0].fix_hint- ov = rep.per_pose[-1].overlaps[0]- assert ov.volume_m3 is not None and ov.volume_m3 > 1e-4 and not ov.approx--def test_rest_penetration_and_floating(tmp_path):# door 30 mm inside the body at rest (fully swallowed: FCL surface collide misses it);# handle (fixed child of the door) pushed 20 mm off the door face → not attached@@ -70,18 +54,6 @@ def test_hinged_child_near_parent_is_only_a_warning(tmp_path):assert rep_ok.summary.floating_at_rest == []-def test_motion_direction(tmp_path):- r = load_urdf(write_prims_robot(tmp_path / "cab.urdf", axis_z=-1))- ok = motion_direction_check(r, "hinge", "front")- assert ok.ok and ok.observed_dir[1] < -0.9- bad = motion_direction_check(r, "hinge", "back")- assert not bad.ok and "WRONG" in bad.message- with pytest.raises(UrdfError):- motion_direction_check(r, "hinge", "sideways")- with pytest.raises(UrdfError):- motion_direction_check(r, "nope", "front")--@pytest.mark.parametrize("fcl", [True, False], ids=["fcl", "trimesh-fallback"])def test_agent_style_meshes_penetration_is_real_and_deterministic(tmp_path, monkeypatch, fcl):"""Non-watertight, inverted-winding links (the wrapper's usual output), both backends, deterministic."""