Official Codebase of 3DCodeVerse
Python
packaging: a wheel shipped no scene starter tree, and write_example() wrote nothing without saying so
gaoypeng9103555d7f8d
diff --git a/harness/codeverse/languages/scene_threejs/skeleton.py b/harness/codeverse/languages/scene_threejs/skeleton.pyindex 84c87c91..5b770637 100644--- a/harness/codeverse/languages/scene_threejs/skeleton.py+++ b/harness/codeverse/languages/scene_threejs/skeleton.py@@ -32,11 +32,23 @@ def _write(path: Path, text: str, written: list[Path]) -> None:def write_example(ws: Workspace) -> list[Path]:- """Copy the full example scene into ws.src (overwrites)."""+ """Copy the full example scene into ws.src (overwrites).++ Raises when the starter tree is not there: rglob over a missing directory yields+ nothing, so this used to write ZERO files and report success — which is exactly what+ a non-editable (wheel) install produced before the starter tree was added to+ package-data, and it surfaced much later as an empty scene rather than a bad install.+ """+ if not STARTER_DIR.is_dir():+ raise FileNotFoundError(+ f"scene_threejs starter tree missing: {STARTER_DIR} — this install has no package data "+ f"(a non-editable install needs [tool.setuptools.package-data] to ship languages/**/starter/**/*)")written: list[Path] = []for src in sorted(STARTER_DIR.rglob("*.js")):rel = src.relative_to(STARTER_DIR)_write(ws.src / rel, src.read_text(), written)+ if not written:+ raise FileNotFoundError(f"scene_threejs starter tree at {STARTER_DIR} contains no .js files")return writtendiff --git a/harness/pyproject.toml b/harness/pyproject.tomlindex 5041746a..7ac8923d 100644--- a/harness/pyproject.toml+++ b/harness/pyproject.toml@@ -60,7 +60,15 @@ dev = ["pytest>=8", "pytest-timeout>=2.3", "ruff>=0.5", "pyarrow>=15"]include = ["codeverse*"][tool.setuptools.package-data]-codeverse = ["prompts/**/*", "judges/rubrics/*.yaml", "languages/**/wrappers/*", "spatial/js/*"]+# Every non-python file a runtime reads at call time. `languages/**/*.md` + the+# scene starter tree were missing and `spatial/js/*` matched nothing at all (no such+# directory), so a wheel install shipped no starter files: skeleton.write_example()+# rglob'd an absent directory and wrote ZERO files while reporting success.+codeverse = ["prompts/**/*", "judges/rubrics/*.yaml", "languages/**/wrappers/*",+ "languages/**/*.md", "languages/**/starter/**/*"]++[tool.setuptools.exclude-package-data]+codeverse = ["**/__pycache__/*"] # a wheel must not carry the build host's bytecode[tool.ruff]line-length = 100diff --git a/harness/tests/core/test_portability.py b/harness/tests/core/test_portability.pyindex 510a432b..63bb2ec9 100644--- a/harness/tests/core/test_portability.py+++ b/harness/tests/core/test_portability.py@@ -32,6 +32,7 @@ from codeverse.spatial.node import (parse_node_version,require_node_version,)+from codeverse.workspace import WorkspaceHARNESS = Path(__file__).resolve().parents[2]PY_FLOOR = (3, 10)@@ -84,6 +85,38 @@ def test_runtime_js_engines_matches_node_min() -> None:assert pkg["engines"]["node"] == f">={NODE_MIN_STR}"+def test_package_data_ships_every_file_a_runtime_reads() -> None:+ """PORT-4: a wheel built from this tree shipped no scene_threejs starter tree and no+ CONTRACT.md, and the declared glob ``spatial/js/*`` matched nothing at all (there is no+ such directory). skeleton.write_example() then rglob'd an absent directory and wrote+ ZERO files while reporting success. Every non-python file under codeverse/ must be+ covered by a package-data glob, and no glob may be dead."""+ cfg = tomllib.loads((HARNESS / "pyproject.toml").read_text())+ globs = cfg["tool"]["setuptools"]["package-data"]["codeverse"]+ pkg = HARNESS / "codeverse"+ shipped: set[Path] = set()+ for g in globs:+ hits = {p for p in pkg.glob(g) if p.is_file()}+ assert hits, f"dead package-data glob (matches nothing): {g!r}"+ shipped |= hits+ data = {p for p in pkg.rglob("*")+ if p.is_file() and p.suffix not in (".py", ".pyc") and "__pycache__" not in p.parts}+ missing = sorted(str(p.relative_to(pkg)) for p in data - shipped)+ assert not missing, f"data files no wheel would ship: {missing}"+ excluded = cfg["tool"]["setuptools"]["exclude-package-data"]["codeverse"]+ assert any("__pycache__" in g for g in excluded), "a wheel must not carry the build host's bytecode"+++def test_write_example_refuses_to_write_nothing(tmp_path, monkeypatch) -> None:+ """The other half of PORT-4: an install without the starter tree must fail loudly at+ the moment it is needed, not hand back an empty scene."""+ from codeverse.languages.scene_threejs import skeleton++ monkeypatch.setattr(skeleton, "STARTER_DIR", tmp_path / "gone" / "src")+ with pytest.raises(FileNotFoundError, match="starter tree missing"):+ skeleton.write_example(Workspace(tmp_path / "ws").create())++# ------------------------------------------------------------------- nothing exceeds it@pytest.mark.parametrize("path", _py_files(), ids=lambda p: str(p.relative_to(HARNESS)))def test_module_parses_and_stays_on_the_floor(path: Path) -> None: