Skip to content

Official Codebase of 3DCodeVerse

Python

tests: the prompt-file list is read off the tree, and every prompt file must be reached — the hand-kept list named 12 of 49

gaoypeng93614dec8675
diff --git a/harness/tests/prompts/conftest.py b/harness/tests/prompts/conftest.py
index 7d07cd2e..248cb6e4 100644
--- a/harness/tests/prompts/conftest.py
+++ b/harness/tests/prompts/conftest.py
@@ -23,21 +23,19 @@ STARTER_LIB = Path(__file__).resolve().parents[2] / "codeverse3d" / "languages"
RUNTIME_JS = Path(__file__).resolve().parents[2] / "runtime_js"
HELPERS = Path(__file__).resolve().parent / "helpers"
-#: every file this package owns (relative to codeverse3d/prompts/)
-PROMPT_FILES = [
- "system/harness_contract.md",
- "system/singleshot_format.md",
- "blender/contract.md",
- "blender/cookbook.md",
- "cadquery/contract.md",
- "cadquery/cookbook.md",
- "threejs/contract.md",
- "threejs/cookbook.md",
- "urdf/contract.md",
- "urdf/cookbook.md",
- "scene_threejs/contract.md",
- "scene_threejs/cookbook.md",
-]
+#: every file of the prompt corpus (relative to codeverse3d/prompts/), read off the tree —
+#: test_files.test_every_prompt_file_is_reached says how the package loads each one
+PROMPT_FILES = sorted(p.relative_to(PROMPTS_DIR).as_posix() for p in PROMPTS_DIR.rglob("*")
+ if p.is_file() and p.suffix != ".py" and "__pycache__" not in p.parts)
+#: the documents whose fenced snippets the cookbook header promises RUN: each language's contract + cookbook
+DOC_FILES = [f for f in PROMPT_FILES if f.rsplit("/", 1)[-1] in ("contract.md", "cookbook.md")]
+
+
+def is_template(rel: str) -> bool:
+ """Rendered with a context (jinja): the ``.j2`` files, each language's ``system.md`` and the
+ texturing prompts. Every other file is quoted verbatim and must stay jinja-inert."""
+ return rel.endswith(".j2") or rel.startswith("texturing/") or (rel.endswith("/system.md") and not rel.startswith("system/"))
+
_FENCE = re.compile(r"```(\w[\w-]*)\n(.*?)```", re.DOTALL)
diff --git a/harness/tests/prompts/test_files.py b/harness/tests/prompts/test_files.py
index b983e651..1260ea16 100644
--- a/harness/tests/prompts/test_files.py
+++ b/harness/tests/prompts/test_files.py
@@ -1,41 +1,72 @@
-"""Every prompt file exists, renders through the loader, and keeps its promises."""
+"""Every prompt file exists, renders through the loader, is reached by the package, and keeps its promises."""
from __future__ import annotations
+import ast
+from fnmatch import fnmatch
+
+import jinja2
import pytest
+from codeverse3d.contracts.common import TRACK_LANGUAGES, Language, Track
from codeverse3d.prompts import load_text, prompt_hash, render
-from tests.prompts.conftest import PROMPT_FILES, PROMPTS_DIR, read_prompt
+from codeverse3d.prompts.catalog import language_prompt
+from tests.prompts.conftest import DOC_FILES, PROMPT_FILES, PROMPTS_DIR, is_template, read_prompt
+
+#: files nothing in the package loads, each with the reason it still ships
+UNREACHED = {
+ # the GLSL cookbook tells the agent this example is shipped, but no code copies it into a
+ # workspace (review 2026-09-22, owner question Q9: ship it where the cookbook says, or drop it)
+ "glsl_shader/examples/aurora_ridge.frag",
+}
@pytest.mark.parametrize("rel", PROMPT_FILES)
def test_prompt_file_contract(rel: str) -> None:
- p = PROMPTS_DIR / rel
- assert p.is_file(), f"missing prompt file {rel}"
raw = load_text(rel)
assert prompt_hash(raw)
- # markdown prompts must be jinja-inert: render() with no context must be a no-op
- rendered = render(rel)
- assert rendered == raw, f"{rel} contains live jinja syntax; keep prompt .md files static"
+ if is_template(rel):
+ jinja2.Environment().parse(raw) # a template must at least compile
+ return
+ # quoted verbatim: must be jinja-inert, render() with no context a no-op
+ assert render(rel) == raw, f"{rel} contains live jinja syntax; keep prompt .md files static"
for seq in ("{{", "{%", "{#"):
assert seq not in raw, f"{rel} contains {seq!r} which breaks jinja rendering"
- "rel",
- [f for f in PROMPT_FILES if f.endswith("cookbook.md")],
-)
+def test_every_prompt_file_is_reached_by_the_package() -> None:
+ """A prompt file is loaded by a literal path, an f-string path (``system/role_{role}.j2``) or a
+ per-language name through ``catalog.language_prompt`` / ``language_text`` — or it is dead."""
+ literals: set[str] = set()
+ patterns: list[str] = []
+ names: set[str] = set()
+ for py in (PROMPTS_DIR.parent).rglob("*.py"):
+ for node in ast.walk(ast.parse(py.read_text())):
+ if isinstance(node, ast.Constant) and isinstance(node.value, str):
+ literals.add(node.value)
+ elif isinstance(node, ast.JoinedStr) and isinstance(head := node.values[0], ast.Constant) and "/" in str(head.value):
+ patterns.append("".join(v.value if isinstance(v, ast.Constant) else "*" for v in node.values))
+ elif (isinstance(node, ast.Call) and getattr(node.func, "id", "") in ("language_prompt", "language_text")
+ and len(node.args) == 2 and isinstance(node.args[1], ast.Constant)):
+ names.add(node.args[1].value)
+ per_language = {language_prompt(lang, n) for lang in Language for n in names}
+ reached = {f for f in PROMPT_FILES if f in literals | per_language or any(fnmatch(f, p) for p in patterns)}
+ assert set(PROMPT_FILES) - reached == UNREACHED
+
+
[email protected]("rel", [f for f in DOC_FILES if f.endswith("cookbook.md")])
def test_cookbook_structure(rel: str) -> None:
text = read_prompt(rel)
headings = [line[3:].strip() for line in text.splitlines() if line.startswith("## ")]
assert len(headings) >= 5, f"{rel}: cookbooks are chaptered with '## ' headings"
assert len(headings) == len(set(headings)), f"{rel}: duplicate section headings"
- joined = " | ".join(headings)
- assert "Pitfalls" in joined, f"{rel}: needs a Pitfalls chapter"
+ assert "pitfalls" in " | ".join(headings).lower(), f"{rel}: needs a Pitfalls chapter"
@pytest.mark.parametrize(
- "rel", [f for f in PROMPT_FILES if f.endswith("contract.md") and not f.startswith("system/")]
+ # a shader draws in screen space: it has no metres and no 3D frame to state
+ "rel", sorted(language_prompt(lang, "contract.md") for t, langs in TRACK_LANGUAGES.items() if t is not Track.GRAPHICS
+ for lang in langs)
)
def test_contract_content(rel: str) -> None:
text = read_prompt(rel)
diff --git a/harness/tests/prompts/test_snippets_static.py b/harness/tests/prompts/test_snippets_static.py
index ca117628..9a1268ef 100644
--- a/harness/tests/prompts/test_snippets_static.py
+++ b/harness/tests/prompts/test_snippets_static.py
@@ -11,10 +11,10 @@ import xml.etree.ElementTree as ET
import numpy as np
import pytest
-from tests.prompts.conftest import PROMPT_FILES, blocks, read_prompt
+from tests.prompts.conftest import DOC_FILES, blocks, read_prompt
-PY_FILES = [f for f in PROMPT_FILES if f.split("/")[0] in ("blender", "cadquery", "urdf")]
-JS_FILES = [f for f in PROMPT_FILES if f.split("/")[0] in ("threejs", "scene_threejs")]
+PY_FILES = [f for f in DOC_FILES if f.split("/")[0] in ("blender", "cadquery", "urdf")]
+JS_FILES = [f for f in DOC_FILES if f.split("/")[0] in ("threejs", "scene_threejs")]
JS_FILES.append("system/singleshot_format.md")
XML_FILES = ["urdf/contract.md", "urdf/cookbook.md"]