Official Codebase of 3DCodeVerse
Python
tests: the offline suite needed Gemini keys, so CI and a fresh clone were red
gaoypeng0cb23a17b842
diff --git a/harness/tests/install/test_hermetic.py b/harness/tests/install/test_hermetic.pynew file mode 100644index 00000000..5766cea1--- /dev/null+++ b/harness/tests/install/test_hermetic.py@@ -0,0 +1,38 @@+"""PORT-2: every non-``live`` test must pass with NO credentials in the environment.++A test that only goes green because this box has 22 Gemini keys is not offline —+it is red on a fresh clone and red on the CI runner, which has none. Guarded by+re-running the two tests that reached for ambient credentials in a subprocess whose+environment has been stripped of every key source (the env vars AND ``$HOME``, since+the key file lives at ``~/.config/astra3d/gemini_keys.env``).+"""++from __future__ import annotations++import os+import subprocess+import sys+from pathlib import Path++import pytest++HARNESS = Path(__file__).resolve().parents[2]+KEY_ENVS = ("GEMINI_API_KEYS", "GEMINI_API_KEY", "GOOGLE_API_KEY", "GOOGLE_GENAI_API_KEY")++#: the two that PORT-2 caught; both are inside the path list .github/workflows/ci.yml runs+CREDENTIAL_FREE = (+ "tests/models/test_health.py::test_probe_model_treats_a_503_as_final",+ "tests/texturing/test_tools_cli.py::test_texture_pass_tool_runs_with_injected_fakes",+)++[email protected]("nodeid", CREDENTIAL_FREE)+def test_passes_with_no_api_keys_in_the_environment(nodeid: str, tmp_path: Path) -> None:+ env = {k: v for k, v in os.environ.items() if k not in KEY_ENVS}+ env["HOME"] = str(tmp_path) # no ~/.config/astra3d/gemini_keys.env either+ env["PYTHONPATH"] = str(HARNESS)++ r = subprocess.run([sys.executable, "-m", "pytest", nodeid, "-q", "-p", "no:cacheprovider"],+ cwd=HARNESS, env=env, capture_output=True, text=True, timeout=300)++ assert r.returncode == 0, f"{nodeid} needs credentials:\n{r.stdout[-3000:]}\n{r.stderr[-2000:]}"diff --git a/harness/tests/models/test_health.py b/harness/tests/models/test_health.pyindex f4d04be7..8759c085 100644--- a/harness/tests/models/test_health.py+++ b/harness/tests/models/test_health.py@@ -109,6 +109,10 @@ def test_probe_model_treats_a_503_as_final(monkeypatch):return "unused"monkeypatch.setattr(gm, "rotate_with_retries", fake_rotate)+ # a non-live test must pass with NO credentials in the environment (a fresh clone,+ # the CI runner): _bare_model builds a real GeminiModel, which refuses to construct+ # without keys, so hand it a fake one instead of borrowing this box's (PORT-2).+ monkeypatch.setattr(gm, "_default_keys", lambda: ["fake-key-for-tests"])m = _bare_model("gemini:gemini-3.7-flash", 30.0)assert m.storm_attempts == 0 and m.max_attempts == 1import contextlibdiff --git a/harness/tests/texturing/conftest.py b/harness/tests/texturing/conftest.pyindex d3d911bb..0a9a2370 100644--- a/harness/tests/texturing/conftest.py+++ b/harness/tests/texturing/conftest.py@@ -3,6 +3,7 @@ its plan + spec, a fake image model, a fake render function and a fake judge."""from __future__ import annotations+import jsonfrom pathlib import Pathfrom typing import Any@@ -12,6 +13,7 @@ import trimeshfrom PIL import Imagefrom codeverse.contracts.artifacts import RenderSet, RenderView+from codeverse.contracts.chat import ChatResponsefrom codeverse.contracts.common import Language, Track, Usagefrom codeverse.contracts.judgment import Judgmentfrom codeverse.contracts.plan import BBox, PartPlan, StaticPlan@@ -112,3 +114,30 @@ class FakeJudge:summary = "judge_error: boom" if self.degraded else "ok"return Judgment(rubric="static_object_v1", scores=scores, overall=overall, passed=overall >= 0.72, summary=summary,usage=Usage(cost_usd=0.01))+++class FakePlanModel:+ """A ChatModel that answers the material-plan call — no credentials, no network.++ ``TextureServices.plan_model`` is one of the five injectable dependencies, and a+ test that leaves it None makes ``material_plan`` build a REAL model from the spec's+ planner id: the test then only passes on a box that happens to have keys (PORT-2).+ """++ id = "fake:plan"++ def __init__(self, payload: dict[str, Any] | None = None):+ self.payload = payload or {"parts": [+ {"part": "Seat", "texture_id": "oak_wood", "material_family": "wood",+ "subject": "light oak", "projection": "planar_y", "tile_size_m": 0.4},+ {"part": "Back", "texture_id": "oak_wood", "material_family": "wood",+ "subject": "light oak", "projection": "box"},+ {"part": "Leg", "texture_id": "steel", "material_family": "metal",+ "subject": "brushed steel", "projection": "cylinder", "metallic": 1, "roughness": 0.3},+ ], "notes": "fake plan"}+ self.calls: list[Any] = []++ def generate(self, req: Any) -> ChatResponse:+ self.calls.append(req)+ return ChatResponse(text=json.dumps(self.payload), parsed=self.payload,+ usage=Usage(cost_usd=0.002, input_tokens=100))diff --git a/harness/tests/texturing/test_tools_cli.py b/harness/tests/texturing/test_tools_cli.pyindex 3c1c74d6..bcc5311a 100644--- a/harness/tests/texturing/test_tools_cli.py+++ b/harness/tests/texturing/test_tools_cli.py@@ -11,7 +11,7 @@ from codeverse.spatial.registry import ToolContext, get_tool, list_toolsfrom codeverse.texturing.generate import FakeImageModelfrom codeverse.texturing.run import TextureServicesfrom codeverse.workspace import Workspace-from tests.texturing.conftest import FakeJudge, fake_render+from tests.texturing.conftest import FakeJudge, FakePlanModel, fake_renderdef _ws(tmp_path: Path, chair_glb, chair_spec, chair_plan, *, texture: bool = True) -> Workspace:@@ -36,8 +36,10 @@ def test_tools_registered_for_object_tracks():def test_texture_pass_tool_runs_with_injected_fakes(tmp_path, chair_glb, chair_spec, chair_plan):ws = _ws(tmp_path, chair_glb, chair_spec, chair_plan)judge = FakeJudge([(0.7, {"materials": 0.5}), (0.72, {"materials": 0.7})])+ # plan_model too: without it material_plan builds a REAL model from the spec's+ # planner id, so this "injected fakes" test only passed on a box that has keys.services = TextureServices(image_model=FakeImageModel(), judge_obj=judge, render=fake_render,- cache_dir=tmp_path / "c")+ plan_model=FakePlanModel(), cache_dir=tmp_path / "c")ctx = ToolContext(workspace=ws, track="static_object", language="blender",extra={"texture_services": services})obs = get_tool("texture_pass").call(ctx, {"model": ""})