Official Codebase of 3DCodeVerse
Python
glsl_shader: keep lint_text — the c3d-glsl-craft skill cites it by name, and the skills freshness gate requires every cited name to exist
gaoypeng60bcced536ba
diff --git a/harness/codeverse3d/languages/glsl_shader/__init__.py b/harness/codeverse3d/languages/glsl_shader/__init__.pyindex c8bf8889..eb23f4a6 100644--- a/harness/codeverse3d/languages/glsl_shader/__init__.py+++ b/harness/codeverse3d/languages/glsl_shader/__init__.py@@ -263,6 +263,19 @@ def lint_workspace(ws: Workspace) -> GateReport:return GateReport.of(GATE, findings)+def lint_text(shader_src: str, common_src: str | None = None, buffer_a_src: str | None = None, *,+ recipes_src: str | None = None) -> list[GateFinding]:+ """Lint in-memory sources (tests; the c3d-glsl-craft skill cites it); ``recipes_src`` is the harness-owned recipe file whose+ names the agent files may not redefine (it is not linted itself)."""+ reserved = frozenset(defined_functions(recipes_src)) if recipes_src else frozenset()+ out = _check_file(SHADER, shader_src, role="shader", recipe_names=reserved)+ if common_src is not None:+ out += _check_file(COMMON, common_src, role="common", recipe_names=reserved)+ if buffer_a_src is not None:+ out += _check_file(BUFFER_A, buffer_a_src, role="buffer_a", recipe_names=reserved)+ return out++# ===================================================================== skeletonCOMMON_GLSL = """// src/common.glsl — helpers pasted above shader.frag by the harness (no #include needed).// Keep ONLY functions / constants here; no main(), no uniforms, no #version.diff --git a/harness/tests/graphics/test_wrap_lint.py b/harness/tests/graphics/test_wrap_lint.pyindex a33b90d9..ec529090 100644--- a/harness/tests/graphics/test_wrap_lint.py+++ b/harness/tests/graphics/test_wrap_lint.py@@ -5,11 +5,11 @@ from __future__ import annotationsfrom codeverse3d.contracts.artifacts import Severityfrom codeverse3d.languages.glsl_shader import (HEADER,- _check_file,compose,defined_functions,detect_convention,first_error,+ lint_text,lint_workspace,parse_glsl_log,strip_comments,@@ -63,18 +63,17 @@ def test_glsl_lint_rules():"out vec4 fragColor;\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n vec3 c = texture(iChannel2, vec2(0)).rgb;\n"" c += texture(u_tex, vec2(0)).rgb;\n float m = 3.0 % 2.0;\n gl_FragColor = vec4(c, 1.0);\n}\n")- kinds = {f.data["kind"] for f in _check_file("src/shader.frag", bad, role="shader") if f.severity == Severity.ERROR}+ kinds = {f.data["kind"] for f in lint_text(bad) if f.severity == Severity.ERROR}assert {"version_line", "redeclared_uniform", "custom_uniform", "redeclared_output", "missing_input", "undeclared_sampler","float_modulo", "legacy_glsl"} <= kinds# the comment on line 1 must not trigger anything; the #version is reported on line 2- ver = next(f for f in _check_file("src/shader.frag", bad, role="shader") if f.data["kind"] == "version_line")+ ver = next(f for f in lint_text(bad) if f.data["kind"] == "version_line")assert ver.data["line"] == 2- assert not [f for f in _check_file("src/shader.frag", SHADER, role="shader") + _check_file("src/common.glsl", COMMON, role="common")- if f.severity == Severity.ERROR]+ assert not [f for f in lint_text(SHADER, COMMON) if f.severity == Severity.ERROR]# common.glsl must not carry an entry point; no entry at all is an error- assert any(f.data["kind"] == "entry_in_common" for f in _check_file("src/common.glsl", "void main(){}", role="common"))- assert any(f.data["kind"] == "no_entry" for f in _check_file("src/shader.frag", "vec3 f() { return vec3(0); }", role="shader"))- assert any(f.data["kind"] == "buffer_self_ref" for f in _check_file("src/buffer_a.frag", SHADER.replace("u_resolution", "u_buffer_a") + "\n", role="buffer_a"))+ assert any(f.data["kind"] == "entry_in_common" for f in lint_text(SHADER, "void main(){}"))+ assert any(f.data["kind"] == "no_entry" for f in lint_text("vec3 f() { return vec3(0); }"))+ assert any(f.data["kind"] == "buffer_self_ref" for f in lint_text(SHADER, None, SHADER.replace("u_resolution", "u_buffer_a") + "\n"))def test_mixed_comments_blank_only_the_comments():@@ -87,7 +86,7 @@ def test_mixed_comments_blank_only_the_comments():assert "tweak" not in stripped and "inside" not in strippedassert defined_functions(src) == {"fogAmt": 2, "x": 5}shader = src + SHADER- assert any(f.data["kind"] == "custom_uniform" for f in _check_file("src/shader.frag", shader, role="shader"))+ assert any(f.data["kind"] == "custom_uniform" for f in lint_text(shader))def test_glsl_lint_workspace_missing_and_stray(tmp_ws):diff --git a/harness/tests/orchestrator_tracks/test_graphics_recipes.py b/harness/tests/orchestrator_tracks/test_graphics_recipes.pyindex 4db2e69c..77f154a8 100644--- a/harness/tests/orchestrator_tracks/test_graphics_recipes.py+++ b/harness/tests/orchestrator_tracks/test_graphics_recipes.py@@ -15,10 +15,9 @@ from codeverse3d.languages import get_runtimefrom codeverse3d.languages.glsl_shader import (COMMON_GLSL,GlslShaderRuntime,- _check_file,compose,- defined_functions,first_error,+ lint_text,lint_workspace,parse_glsl_log,write_skeleton,@@ -310,7 +309,7 @@ def test_recipes_compose_above_common_and_the_seeded_aurora_renders(tmp_path) ->(ws.src / "shader.frag").write_text(SHADER)common = (ws.src / "common.glsl").read_text()recipes = _recipes(ws).read_text()- assert lint_workspace(ws).findings == []+ assert lint_text(SHADER, common, recipes_src=recipes) == [] and lint_workspace(ws).passedcomp = compose(SHADER, common, recipes_src=recipes)assert comp.convention == "mainImage" and not comp.uses_feedbacksrc = comp.source@@ -362,14 +361,12 @@ def test_lint_flags_a_redefinition_of_a_seeded_recipe(tmp_path) -> None:recipes = "float curtain(vec2 p, float t, float seed, out float k) { k = 0.0; return 0.0; }\nvec3 aurora(vec2 p, float t) { return vec3(0.0); }\n"shader = "// mine\nfloat curtain(vec2 p, float t, float seed, out float k) { k = 1.0; return 1.0; }\n" + SHADERcommon = "float hash12(vec2 p) { return 0.0; }\n\nvec3 aurora(vec2 p, float t) { return vec3(1.0); }\n"- names = frozenset(defined_functions(recipes))- found = [f for rel, text, role in (("src/shader.frag", shader, "shader"), ("src/common.glsl", common, "common"))- for f in _check_file(rel, text, role=role, recipe_names=names) if f.data["kind"] == "redefines_recipe"]+ found = [f for f in lint_text(shader, common, recipes_src=recipes) if f.data["kind"] == "redefines_recipe"]assert [(f.data["file"], f.data["line"]) for f in found] == [("src/shader.frag", 2), ("src/common.glsl", 3)]assert found[0].message == "src/shader.frag:2: `curtain` is already provided by src/recipes.glsl — call it instead of redefining it"assert found[1].message.endswith("`aurora` is already provided by src/recipes.glsl — call it instead of redefining it")assert all(f.severity.value == "error" for f in found) and "harness-owned" in found[0].fix_hint- assert not [f for f in _check_file("src/shader.frag", shader, role="shader") if f.data["kind"] == "redefines_recipe"] # no recipes: no rule+ assert not [f for f in lint_text(shader, common) if f.data["kind"] == "redefines_recipe"] # no recipes: no rule# the workspace lint reads recipes.glsl itself (and does not call it a stray file); buffer_a is checked toows = _ws(tmp_path, skeleton=False)(ws.src / "shader.frag").write_text(SHADER)