Skip to content

Official Codebase of 3DCodeVerse

Python

config: CV3D_RUNTIME_JS override + loud failure when runtime_js is missing

gaoypeng604d51322f0f
diff --git a/harness/codeverse/cli/doctor.py b/harness/codeverse/cli/doctor.py
index 77ecc1d9..c48b8920 100644
--- a/harness/codeverse/cli/doctor.py
+++ b/harness/codeverse/cli/doctor.py
@@ -91,7 +91,11 @@ def check_node() -> list[Row]:
rows.append(("node", "FAIL", f"{v} — too old, need >= {NODE_MIN_STR} (nvm install --lts)"))
else:
rows.append(("node", "OK" if okk else "FAIL", v if okk else f"{v} (need >= {NODE_MIN_STR})"))
- rj = s.runtime_js_dir()
+ try:
+ rj = s.runtime_js_dir()
+ except RuntimeError as e: # non-editable install without CV3D_RUNTIME_JS
+ rows.append(("runtime_js", "FAIL", str(e)))
+ return rows
three = rj / "node_modules" / "three" / "package.json"
pup = rj / "node_modules" / "puppeteer" / "package.json"
if three.is_file():
@@ -120,7 +124,10 @@ def check_gpu_probe(timeout_s: int = 120) -> list[Row]:
from codeverse.proc import run_subprocess
s = get_settings()
- rj = s.runtime_js_dir()
+ try:
+ rj = s.runtime_js_dir()
+ except RuntimeError as e:
+ return [("chrome webgl", "FAIL", str(e))]
launcher = rj / "gpu_launch.cjs"
if not launcher.is_file():
return [("chrome webgl", "SKIP", f"{launcher} missing (spatial render package not installed yet)")]
diff --git a/harness/codeverse/config.py b/harness/codeverse/config.py
index 26bca3d7..65cb333f 100644
--- a/harness/codeverse/config.py
+++ b/harness/codeverse/config.py
@@ -357,7 +357,19 @@ class Settings(BaseSettings):
return ""
def runtime_js_dir(self) -> Path:
- return Path(__file__).resolve().parent.parent / "runtime_js"
+ """The Node runtime (runtime_js/) — repo-relative in an editable install.
+
+ ``CV3D_RUNTIME_JS`` overrides the location (the wheel does not package
+ runtime_js, so a non-editable install MUST point this at a checkout).
+ Missing dir → a loud error at first use instead of a cryptic node crash."""
+ override = os.environ.get("CV3D_RUNTIME_JS", "").strip()
+ d = Path(override).expanduser() if override else Path(__file__).resolve().parent.parent / "runtime_js"
+ if not d.is_dir():
+ raise RuntimeError(
+ f"runtime_js not found at {d} — install the harness editable (pip install -e harness) "
+ "or set CV3D_RUNTIME_JS to a 3dcodeverse/harness/runtime_js checkout (with node_modules installed)"
+ )
+ return d
def _load_yaml(path: Path) -> dict:
diff --git a/harness/tests/core/test_config_env_aliases.py b/harness/tests/core/test_config_env_aliases.py
index 8187a32d..380f0da6 100644
--- a/harness/tests/core/test_config_env_aliases.py
+++ b/harness/tests/core/test_config_env_aliases.py
@@ -132,3 +132,21 @@ def test_deep_merge_overlays_per_key_at_every_depth():
assert base == {"rate": {"tpm": 1, "rpm": 2}, "judge": {"samples": 4}, "scalar": 1}, "no mutation"
# a non-dict overlay replaces a dict outright rather than trying to merge into it
assert _deep_merge({"a": {"b": 1}}, {"a": 5}) == {"a": 5}
+
+
+def test_runtime_js_dir_override_and_loud_failure(tmp_path, monkeypatch):
+ """CV3D_RUNTIME_JS relocates the Node runtime; a missing dir fails loudly at
+ first use (the wheel ships no runtime_js) instead of a cryptic node crash."""
+ import pytest
+
+ from codeverse.config import Settings
+
+ good = tmp_path / "runtime_js"
+ good.mkdir()
+ monkeypatch.setenv("CV3D_RUNTIME_JS", str(good))
+ assert Settings().runtime_js_dir() == good
+ monkeypatch.setenv("CV3D_RUNTIME_JS", str(tmp_path / "nowhere"))
+ with pytest.raises(RuntimeError, match="CV3D_RUNTIME_JS"):
+ Settings().runtime_js_dir()
+ monkeypatch.delenv("CV3D_RUNTIME_JS")
+ assert Settings().runtime_js_dir().name == "runtime_js" # editable checkout resolves