Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

test(repro): grammar batteries — build/infra + shells/misc

Martin Vogel720ebc5038ee
diff --git a/Makefile.cbm b/Makefile.cbm
index a6308ea4f..a84c4571c 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -436,6 +436,8 @@ TEST_REPRO_SRCS = \
tests/repro/repro_grammar_systems.c \
tests/repro/repro_grammar_web.c \
tests/repro/repro_grammar_config.c \
+ tests/repro/repro_grammar_build.c \
+ tests/repro/repro_grammar_shells.c \
tests/repro/repro_lsp_c_cpp.c \
tests/repro/repro_lsp_go_py.c \
tests/repro/repro_lsp_ts.c \
diff --git a/tests/repro/repro_grammar_build.c b/tests/repro/repro_grammar_build.c
new file mode 100644
index 000000000..a23f5fbe7
--- /dev/null
+++ b/tests/repro/repro_grammar_build.c
@@ -0,0 +1,1063 @@
+/*
+ * repro_grammar_build.c -- Per-grammar INVARIANT battery for the
+ * BUILD / INFRA language family.
+ *
+ * One TEST() per language so per-language RED/GREEN shows on the bug-repro
+ * board. Each test runs a battery adapted to what the language actually models.
+ *
+ * Languages covered (15) and the CBM_LANG_* enum each uses (all verified in
+ * internal/cbm/cbm.h; none missing, none skipped):
+ * Dockerfile -> CBM_LANG_DOCKERFILE
+ * Makefile -> CBM_LANG_MAKEFILE
+ * CMake -> CBM_LANG_CMAKE
+ * Meson -> CBM_LANG_MESON
+ * GN -> CBM_LANG_GN
+ * Just -> CBM_LANG_JUST
+ * K8s -> CBM_LANG_K8S
+ * Kustomize -> CBM_LANG_KUSTOMIZE
+ * GoMod -> CBM_LANG_GOMOD
+ * Requirements -> CBM_LANG_REQUIREMENTS
+ * Gitignore -> CBM_LANG_GITIGNORE
+ * Gitattributes -> CBM_LANG_GITATTRIBUTES
+ * SSHConfig -> CBM_LANG_SSHCONFIG
+ * BitBake -> CBM_LANG_BITBAKE
+ * Puppet -> CBM_LANG_PUPPET
+ *
+ * Langs NOT in CBM_LANG_* (skipped, noted):
+ * none -- all 15 target languages are present in the enum.
+ *
+ * BATTERY DIMENSIONS
+ * ------------------
+ * SINGLE-FILE (cbm_extract_file, via inv_rx + inv_count_* helpers):
+ * 1. extract-clean : inv_extract_clean(src,lang,file) == 1
+ * (parser returned a result and did not set has_error).
+ * 2. labels-valid : inv_count_bad_labels(r) == 0
+ * (every extracted def label is in the known label set).
+ * 3. fqn-wellformed : inv_count_bad_fqns(r) == 0
+ * (no empty / ".." / leading-trailing '.' / whitespace QNs).
+ * 4. ranges-valid : inv_count_bad_ranges(r) == 0
+ * (start_line >= 1 and start_line <= end_line).
+ * 5. defs-present : at least one def with the expected label is extracted.
+ * SKIPPED for languages whose spec has no func_types,
+ * class_types, or reliably-labelled var_types that the
+ * grammar tree walker is known to produce
+ * (REQUIREMENTS, GITIGNORE, GITATTRIBUTES, SSHCONFIG).
+ * 6. calls-extracted : inv_has_call(r, callee) == 1.
+ * Only asserted for languages with non-empty call_types:
+ * MAKEFILE (function_call/call), CMAKE (normal_command),
+ * MESON (function_expression/command), GN (call_expression),
+ * JUST (function_call), BITBAKE (call), PUPPET (function_call).
+ *
+ * FULL-PIPELINE (rh_index_files -> cbm_store_t*, via inv_count_* store helpers):
+ * 7. callable-sourcing : inv_count_calls_by_source(store,project,&mod,&call).
+ * Only asserted for languages with BOTH func_types AND
+ * call_types: JUST, BITBAKE, PUPPET.
+ * 8. no-dangling : inv_count_dangling_edges(store, project, "CALLS") == 0.
+ * Asserted together with dim 7 when the pipeline is run.
+ *
+ * ROBUSTNESS (every language):
+ * R. extract-on-malformed: the extractor must RETURN (not crash/hang) on
+ * deliberately truncated/broken input. inv_extract_clean may return 0
+ * (has_error is fine) but must not return NULL.
+ * Implemented inline at the end of each TEST via cbm_extract_file directly.
+ *
+ * STRUCTURAL BREAKDOWN
+ * --------------------
+ * STRUCTURAL-ONLY (dims 1-4 + R):
+ * REQUIREMENTS -- all empty_types; no defs or calls extracted.
+ * GITIGNORE -- all empty_types; no defs or calls extracted.
+ * GITATTRIBUTES -- all empty_types; no defs or calls extracted.
+ * SSHCONFIG -- all empty_types; no defs or calls extracted.
+ *
+ * STRUCTURAL WITH DEFS (dims 1-5 + R):
+ * DOCKERFILE -- var_types = {env_instruction, arg_instruction} -> "Variable".
+ * GOMOD -- var_types = {require_directive, replace_directive} -> "Variable".
+ * K8S -- semantic extractor (cbm_extract_k8s); extracts kind -> "Class".
+ * KUSTOMIZE -- semantic extractor (cbm_extract_k8s); extracts kind -> "Class".
+ *
+ * CALLABLE (dims 1-6 + R, no pipeline):
+ * GN -- call_types = {call_expression}; no func_types -> no Function def.
+ * Dim 5 SKIPPED (no defs); dim 6 only.
+ * MAKEFILE -- func_types = {rule,recipe} -> "Function";
+ * call_types = {function_call,call}.
+ * Dims 1-6. Pipeline SKIPPED: the recipe body is not a named
+ * scope that enclosing-func can attribute calls inside; calls
+ * would be module-sourced. No pipeline dim.
+ * CMAKE -- func_types = {function_def,macro_def} -> "Function";
+ * call_types = {normal_command}. Dims 1-6. Pipeline SKIPPED:
+ * every statement in CMake is a normal_command; calls inside
+ * function bodies are likely module-sourced (dim 7 RED).
+ * MESON -- func_types = {function_expression} -> "Function";
+ * call_types = {function_expression,command}. Dims 1-6.
+ * Pipeline SKIPPED: function_expression is anonymous (assigned
+ * to a variable); enclosing-func walk may not resolve the name.
+ *
+ * CALLABLE + PIPELINE (dims 1-8):
+ * JUST -- func_types = {recipe} -> "Function";
+ * call_types = {function_call}. Dims 1-8.
+ * Dim 7 expected RED: calls inside a recipe may not be
+ * attributed to the "Function" recipe node because the recipe
+ * body is shell-like, not a structured call graph.
+ * BITBAKE -- func_types = {function_definition, python_function_definition,
+ * recipe} -> "Function"; call_types = {call}. Dims 1-8.
+ * Dim 7 expected RED: BitBake python-embedded blocks and
+ * shell tasks mean the enclosing-func walk has unclear
+ * ancestry paths from call sites to recipe nodes.
+ * PUPPET -- func_types = {function_declaration, lambda} -> "Function";
+ * class_types = {class_definition, node_definition,
+ * resource_declaration, type_declaration} -> "Class";
+ * call_types = {function_call, resource_declaration}.
+ * Dims 1-8. Dim 7 expected GREEN for top-level calls inside
+ * a named function_declaration body; may RED for resource_
+ * declaration call sites (no enclosing function).
+ *
+ * Coding rule: inline comments are line comments only (no /* inside any comment).
+ */
+
+#include "test_framework.h"
+#include "repro_invariant_lib.h"
+#include <store/store.h>
+
+#include <stdio.h>
+#include <string.h>
+
+/* ── Structural-base battery (dims 1-4) ──────────────────────────────────────
+ *
+ * Runs the four core invariants on valid input. No defs-present assertion.
+ * Used for REQUIREMENTS, GITIGNORE, GITATTRIBUTES, SSHCONFIG where the spec
+ * has no func_types, class_types, or labelled var_types that yield defs.
+ * Returns 0 on PASS, 1 on FAIL.
+ */
+static int build_base_battery(const char *lang_tag, const char *src,
+ CBMLanguage lang, const char *file) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ /* 1. extract-clean */
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 2. labels-valid */
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ /* 3. fqn-wellformed */
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ /* 4. ranges-valid */
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Structural battery with defs-present (dims 1-5) ────────────────────────
+ *
+ * Adds the defs-present dimension for languages with class_types, func_types,
+ * or reliably-labelled var_types (DOCKERFILE, GOMOD, K8S, KUSTOMIZE).
+ * Pass NULL for expect_label2 when only one label type is needed.
+ * Returns 0 on PASS, 1 on FAIL.
+ */
+static int build_struct_battery(const char *lang_tag, const char *src,
+ CBMLanguage lang, const char *file,
+ const char *expect_label,
+ const char *expect_label2) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ /* 1. extract-clean */
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 2. labels-valid */
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ /* 3. fqn-wellformed */
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ /* 4. ranges-valid */
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ /* 5. defs-present (primary label) */
+ if (expect_label && inv_count_label(r, expect_label) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label);
+ fails++;
+ }
+
+ /* 5b. defs-present (secondary label, optional) */
+ if (expect_label2 && inv_count_label(r, expect_label2) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label2);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Callable battery (dims 1-6) ─────────────────────────────────────────────
+ *
+ * Adds dims 5 (optional) and 6 (calls-extracted) to the base invariants.
+ * Pass NULL for expect_label when the language has no func/class def to assert
+ * alongside the call (e.g. GN has call_types but no func_types).
+ * Returns 0 on PASS, 1 on FAIL.
+ */
+static int build_callable_battery(const char *lang_tag, const char *src,
+ CBMLanguage lang, const char *file,
+ const char *expect_label,
+ const char *callee) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ /* 1. extract-clean */
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 2. labels-valid */
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ /* 3. fqn-wellformed */
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ /* 4. ranges-valid */
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ /* 5. defs-present (only when a def label is expected) */
+ if (expect_label && inv_count_label(r, expect_label) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label);
+ fails++;
+ }
+
+ /* 6. calls-extracted */
+ if (callee && inv_has_call(r, callee) != 1) {
+ printf(" %sFAIL%s [%s] calls-extracted: no call to \"%s\" found\n",
+ RED, RST, lang_tag, callee);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Full-pipeline battery (dims 7-8) ───────────────────────────────────────
+ *
+ * Indexes the single-file fixture through the production pipeline and asserts
+ * callable-sourcing + no-dangling. Used for JUST, BITBAKE, and PUPPET which
+ * all have both func_types and call_types.
+ *
+ * Dim 7 RED contract notes per language:
+ * JUST -- recipe body is shell-like; the enclosing-func walk for call sites
+ * inside a recipe may not find the recipe node as the Function anchor.
+ * BITBAKE -- python_function_definition and shell recipe bodies have mixed
+ * ancestry paths; enclosing-func may attribute calls at Module level.
+ * PUPPET -- function_declaration bodies should attribute correctly (GREEN);
+ * resource_declaration call sites have no enclosing function_declaration
+ * so those specific calls will be module-sourced (conditional RED).
+ * Returns 0 on PASS, 1 on FAIL.
+ */
+static int build_pipeline_battery(const char *lang_tag, const char *filename,
+ const char *src) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ RFile files[1];
+ files[0].name = filename;
+ files[0].content = src;
+
+ RProj lp;
+ cbm_store_t *store = rh_index_files(&lp, files, 1);
+ if (!store) {
+ printf(" %sFAIL%s [%s] pipeline: rh_index_files returned NULL\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 7. callable-sourcing */
+ int module_sourced = 0;
+ int callable_sourced = 0;
+ inv_count_calls_by_source(store, lp.project, &module_sourced,
+ &callable_sourced);
+ if (module_sourced != 0) {
+ printf(" %sFAIL%s [%s] callable-sourcing: %d in-body CALLS sourced at "
+ "Module (callable=%d) -- known enclosing-func gap\n",
+ RED, RST, lang_tag, module_sourced, callable_sourced);
+ fails++;
+ } else if (callable_sourced < 1) {
+ printf(" %sFAIL%s [%s] callable-sourcing: 0 CALLS edges (fixture "
+ "produced no in-body call edge to attribute)\n",
+ RED, RST, lang_tag);
+ fails++;
+ }
+
+ /* 8. no-dangling */
+ int dangling = inv_count_dangling_edges(store, lp.project, "CALLS");
+ if (dangling != 0) {
+ printf(" %sFAIL%s [%s] no-dangling: %d dangling CALLS endpoint(s)\n",
+ RED, RST, lang_tag, dangling);
+ fails++;
+ }
+
+ rh_cleanup(&lp, store);
+ return fails ? 1 : 0;
+}
+
+/* ── Robustness helper: assert call RETURNS on malformed input ───────────────
+ *
+ * A truncated version of the fixture is passed through cbm_extract_file.
+ * has_error may be set (1) but the call must return non-NULL. If it returns
+ * NULL the extractor crashed or aborted on bad input -- that is a RED
+ * robustness bug. Returns 0 on PASS, 1 on FAIL.
+ */
+static int build_robustness(const char *lang_tag, const char *bad_src,
+ CBMLanguage lang, const char *file) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ CBMFileResult *r = cbm_extract_file(bad_src, (int)strlen(bad_src),
+ lang, "t", file, 0, NULL, NULL);
+ if (!r) {
+ printf(" %sFAIL%s [%s] robustness: extractor returned NULL on malformed input\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+ cbm_free_result(r);
+ return 0;
+}
+
+/* ── Dockerfile ───────────────────────────────────────────────────────────────
+ * Idiomatic two-stage Dockerfile: a builder stage (FROM ... AS ...) followed by
+ * a runtime stage. ENV and ARG instructions are present so the grammar's
+ * dockerfile_var_types = {"env_instruction", "arg_instruction"} -> "Variable"
+ * should produce at least one "Variable" def.
+ *
+ * Dims asserted: 1-5 + R ("Variable").
+ * Dim 5 expected GREEN: ENV instruction should map to "Variable".
+ * RED would indicate env_instruction -> Variable extraction is broken.
+ * Dims 6-8 SKIPPED: no call_types in the spec; no pipeline.
+ * Expected GREEN: dims 1-5. Robustness should pass.
+ */
+TEST(repro_grammar_build_dockerfile) {
+ static const char src[] =
+ "FROM golang:1.22 AS builder\n"
+ "WORKDIR /app\n"
+ "ARG VERSION=0.8.1\n"
+ "COPY . .\n"
+ "RUN go build -o /cbm-server ./cmd/server\n"
+ "\n"
+ "FROM debian:bookworm-slim\n"
+ "ENV PORT=8080\n"
+ "ENV LOG_LEVEL=info\n"
+ "COPY --from=builder /cbm-server /usr/local/bin/cbm-server\n"
+ "EXPOSE 8080\n"
+ "ENTRYPOINT [\"/usr/local/bin/cbm-server\"]\n";
+ static const char bad[] = "FROM golang:1.22 AS\n";
+ if (build_struct_battery("Dockerfile", src, CBM_LANG_DOCKERFILE,
+ "Dockerfile", "Variable", NULL) != 0)
+ return 1;
+ return build_robustness("Dockerfile", bad, CBM_LANG_DOCKERFILE, "Dockerfile");
+}
+
+/* ── Makefile ─────────────────────────────────────────────────────────────────
+ * Idiomatic GNU Makefile with a phony target section, a build rule (rule ->
+ * "Function"), a recipe body using a built-in function call ($(shell ...) which
+ * maps to function_call in tree-sitter-make), and a variable assignment
+ * (variable_assignment -> "Variable"). The rule node is in makefile_func_types
+ * so "build" maps to "Function". The $(shell date) call maps to call_types.
+ *
+ * Dims asserted: 1-6 + R.
+ * Dim 5 expected GREEN: "Function" def for the "build" rule.
+ * RED would indicate rule->Function extraction is broken.
+ * Dim 6 expected GREEN: call to "shell" via $(shell ...) function_call.
+ * RED would indicate makefile function_call extraction is broken.
+ * Dims 7-8 SKIPPED: the recipe body is shell-like; calls inside it are unlikely
+ * to be attributed to the recipe "Function" node by enclosing-func walk.
+ * Running the pipeline would produce module-sourced edges -- the gap is at the
+ * enclosing-func level for Makefile recipes, not a pipeline infrastructure bug.
+ * Expected GREEN: dims 1-6. Robustness should pass.
+ */
+TEST(repro_grammar_build_makefile) {
+ static const char src[] =
+ "VERSION := 0.8.1\n"
+ "BINARY := cbm-server\n"
+ "\n"
+ ".PHONY: all build test clean\n"
+ "\n"
+ "all: build\n"
+ "\n"
+ "build:\n"
+ "\t@echo \"Building $(BINARY) version $(VERSION)\"\n"
+ "\tgo build -ldflags \"-X main.version=$(VERSION)\" -o $(BINARY) ./cmd/server\n"
+ "\n"
+ "test:\n"
+ "\tgo test ./...\n"
+ "\n"
+ "clean:\n"
+ "\trm -f $(BINARY)\n"
+ "\n"
+ "DATE := $(shell date +%Y-%m-%d)\n";
+ static const char bad[] = "build:\n\tgo build -o ";
+ if (build_callable_battery("Makefile", src, CBM_LANG_MAKEFILE, "Makefile",
+ "Function", "shell") != 0)
+ return 1;
+ return build_robustness("Makefile", bad, CBM_LANG_MAKEFILE, "Makefile");
+}
+
+/* ── CMake ────────────────────────────────────────────────────────────────────
+ * Idiomatic CMakeLists.txt: a cmake_minimum_required call (normal_command ->
+ * call extraction), a project() call, add_executable(), target_link_libraries(),
+ * a function definition (cmake_func_types = {"function_def", "macro_def"} ->
+ * "Function"), and a call to that function inside the same file.
+ *
+ * Dims asserted: 1-6 + R.
+ * Dim 5 expected GREEN: "Function" def for the function_def "cbm_setup_target".
+ * RED would indicate function_def->Function extraction is broken.
+ * Dim 6 expected GREEN: call to "add_executable" via normal_command.
+ * RED would indicate CMake normal_command call extraction is broken.
+ * Dims 7-8 SKIPPED: calls inside CMake function_def bodies should in principle
+ * attribute correctly, but the normal_command node covers EVERY CMake statement
+ * (including module-level calls like project() and add_executable()) so many
+ * calls will be module-sourced. A full-pipeline run would produce mixed
+ * module/callable-sourced calls and dim 7 is indeterminate for this fixture.
+ * Expected GREEN: dims 1-6. Robustness should pass.
+ */
+TEST(repro_grammar_build_cmake) {
+ static const char src[] =
+ "cmake_minimum_required(VERSION 3.20)\n"
+ "project(cbm VERSION 0.8.1 LANGUAGES C)\n"
+ "\n"
+ "set(CMAKE_C_STANDARD 11)\n"
+ "\n"
+ "function(cbm_setup_target target)\n"
+ " target_include_directories(${target} PRIVATE include)\n"
+ " target_compile_options(${target} PRIVATE -Wall -Wextra)\n"
+ "endfunction()\n"
+ "\n"
+ "add_executable(cbm-server src/main.c src/server.c)\n"
+ "cbm_setup_target(cbm-server)\n"
+ "target_link_libraries(cbm-server PRIVATE sqlite3)\n";
+ static const char bad[] = "cmake_minimum_required(VERSION 3.20\n";
+ if (build_callable_battery("CMake", src, CBM_LANG_CMAKE, "CMakeLists.txt",
+ "Function", "add_executable") != 0)
+ return 1;
+ return build_robustness("CMake", bad, CBM_LANG_CMAKE, "CMakeLists.txt");
+}
+
+/* ── Meson ────────────────────────────────────────────────────────────────────
+ * Idiomatic meson.build: a project() call (command in meson_call_types), a
+ * function expression (meson_func_types = {"function_expression"} -> "Function")
+ * assigned to a variable, and a call to the built-in executable() function.
+ * Meson functions are anonymous function_expression nodes assigned to bindings;
+ * the function_expression also appears in call_types so the node type is shared
+ * between def extraction and call extraction.
+ *
+ * Dims asserted: 1-6 + R.
+ * Dim 5 expected GREEN: "Function" def for the function_expression assigned to
+ * "cbm_flags". RED would indicate function_expression->Function extraction or
+ * name resolution (from the binding lhs) is broken.
+ * Dim 6 expected GREEN: call to "executable" via function_expression or command.
+ * RED would indicate Meson call extraction is broken.
+ * Dims 7-8 SKIPPED: function_expression nodes are anonymous (the name comes from
+ * the assignment target); the enclosing-func walk may not resolve the binding
+ * name back to the Function node, making calls module-sourced. Pipeline skipped.
+ * Expected GREEN: dims 1-6. Robustness should pass.
+ */
+TEST(repro_grammar_build_meson) {
+ static const char src[] =
+ "project('cbm', 'c',\n"
+ " version: '0.8.1',\n"
+ " default_options: ['c_std=c11'])\n"
+ "\n"
+ "cc = meson.get_compiler('c')\n"
+ "\n"
+ "cbm_flags = func (target)\n"
+ " return ['-DVERSION=\"' + target + '\"']\n"
+ "endfunc\n"
+ "\n"
+ "sqlite = dependency('sqlite3')\n"
+ "executable('cbm-server',\n"
+ " sources: ['src/main.c', 'src/server.c'],\n"
+ " dependencies: [sqlite],\n"
+ " install: true)\n";
+ static const char bad[] = "project('cbm', 'c',\n version: '0.8.1'";
+ if (build_callable_battery("Meson", src, CBM_LANG_MESON, "meson.build",
+ "Function", "executable") != 0)
+ return 1;
+ return build_robustness("Meson", bad, CBM_LANG_MESON, "meson.build");
+}
+
+/* ── GN (Generate Ninja) ──────────────────────────────────────────────────────
+ * Idiomatic BUILD.gn: a config() block and an executable() call
+ * (gn_call_types = {"call_expression"}). GN has no func_types in the spec so
+ * no "Function" def is minted. The call to "executable" should be extracted.
+ *
+ * Dims asserted: 1-4 + 6 + R.
+ * Dim 5 SKIPPED: no func_types or class_types in spec; no defs are extracted.
+ * Dim 6 expected GREEN: call to "executable" via call_expression.
+ * RED would indicate GN call_expression extraction is broken.
+ * Dims 7-8 SKIPPED: no func_types -> no Function anchor for callable-sourcing.
+ * Expected GREEN: dims 1-4 and 6. Robustness should pass.
+ */
+TEST(repro_grammar_build_gn) {
+ static const char src[] =
+ "config(\"cbm_config\") {\n"
+ " include_dirs = [ \"include\" ]\n"
+ " cflags = [ \"-Wall\", \"-Wextra\" ]\n"
+ " defines = [ \"VERSION=\\\"0.8.1\\\"\" ]\n"
+ "}\n"
+ "\n"
+ "executable(\"cbm-server\") {\n"
+ " sources = [\n"
+ " \"src/main.c\",\n"
+ " \"src/server.c\",\n"
+ " ]\n"
+ " configs += [ \":cbm_config\" ]\n"
+ " deps = [ \"//third_party/sqlite3\" ]\n"
+ "}\n";
+ static const char bad[] = "executable(\"cbm-server\") {\n sources = [";
+ if (build_callable_battery("GN", src, CBM_LANG_GN, "BUILD.gn",
+ NULL, "executable") != 0)
+ return 1;
+ return build_robustness("GN", bad, CBM_LANG_GN, "BUILD.gn");
+}
+
+/* ── Just ─────────────────────────────────────────────────────────────────────
+ * Idiomatic justfile with two recipes (just_func_types = {"recipe"} ->
+ * "Function") and a call from one recipe to a built-in (just_call_types =
+ * {"function_call"}). The `build` recipe calls `just_executable` via
+ * a recipe dependency. The `clean` recipe uses the shell idiom.
+ *
+ * Dims asserted: 1-8 (full battery).
+ * Dim 5 expected GREEN: "Function" def for "build" and "test" recipes.
+ * RED would indicate recipe->Function extraction is broken.
+ * Dim 6 expected GREEN: call to "env_var" or the recipe dependency call.
+ * If the just grammar encodes recipe dependencies as function_call nodes this
+ * should be GREEN; RED documents the gap.
+ * Dim 7 expected RED: calls inside a recipe body are shell commands; the
+ * enclosing-func walk looks for a parent node in func_kinds_for_lang, but
+ * recipe body nodes (recipe_body / shell lines) are not typically in that
+ * set. Calls will be module-sourced.
+ * Dim 8 expected GREEN: no dangling CALLS endpoints.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_just) {
+ static const char src[] =
+ "version := \"0.8.1\"\n"
+ "binary := \"cbm-server\"\n"
+ "\n"
+ "build:\n"
+ " go build -ldflags \"-X main.version={{version}}\" -o {{binary}} ./cmd/server\n"
+ "\n"
+ "test: build\n"
+ " go test ./...\n"
+ "\n"
+ "clean:\n"
+ " rm -f {{binary}}\n"
+ "\n"
+ "release version=version:\n"
+ " @echo \"Releasing {{version}}\"\n"
+ " just build\n"
+ " just test\n";
+ static const char bad[] = "build:\n go build -o ";
+ if (build_callable_battery("Just", src, CBM_LANG_JUST, "justfile",
+ "Function", "just") != 0)
+ return 1;
+ if (build_robustness("Just", bad, CBM_LANG_JUST, "justfile") != 0)
+ return 1;
+ return build_pipeline_battery("Just", "justfile", src);
+}
+
+/* ── K8s ──────────────────────────────────────────────────────────────────────
+ * Idiomatic Kubernetes manifest with a Deployment (apiVersion: apps/v1,
+ * kind: Deployment). The K8s/Kustomize semantic extractor cbm_extract_k8s()
+ * is called for CBM_LANG_K8S; it reads the kind field from the YAML tree and
+ * maps it to a def with label "Class" and qualified_name based on the kind.
+ * The grammar itself reuses yaml grammar + yaml_var_types; the semantic layer
+ * adds the kind-based "Class" def.
+ *
+ * Dims asserted: 1-5 + R ("Class" for the Deployment kind).
+ * Dim 5 expected GREEN: "Class" def extracted by cbm_extract_k8s for the kind.
+ * RED documents that the K8s semantic extractor is not minting the kind def.
+ * Dims 6-8 SKIPPED: no call_types in the K8s spec; no pipeline.
+ * Expected GREEN: dims 1-5. Robustness should pass.
+ */
+TEST(repro_grammar_build_k8s) {
+ static const char src[] =
+ "apiVersion: apps/v1\n"
+ "kind: Deployment\n"
+ "metadata:\n"
+ " name: cbm-server\n"
+ " namespace: default\n"
+ " labels:\n"
+ " app: cbm-server\n"
+ "spec:\n"
+ " replicas: 2\n"
+ " selector:\n"
+ " matchLabels:\n"
+ " app: cbm-server\n"
+ " template:\n"
+ " metadata:\n"
+ " labels:\n"
+ " app: cbm-server\n"
+ " spec:\n"
+ " containers:\n"
+ " - name: cbm-server\n"
+ " image: cbm-server:0.8.1\n"
+ " ports:\n"
+ " - containerPort: 8080\n"
+ " env:\n"
+ " - name: LOG_LEVEL\n"
+ " value: info\n";
+ static const char bad[] = "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name:";
+ if (build_struct_battery("K8s", src, CBM_LANG_K8S, "deployment.yaml",
+ "Class", NULL) != 0)
+ return 1;
+ return build_robustness("K8s", bad, CBM_LANG_K8S, "deployment.yaml");
+}
+
+/* ── Kustomize ────────────────────────────────────────────────────────────────
+ * Idiomatic kustomization.yaml: the Kustomize overlay tool's root file
+ * (kind: Kustomization). cbm_extract_k8s() is called for CBM_LANG_KUSTOMIZE
+ * just as for CBM_LANG_K8S; it should mint a "Class" def for the
+ * "Kustomization" kind, which is the canonical Kustomize resource kind.
+ *
+ * Dims asserted: 1-5 + R ("Class" for the Kustomization kind).
+ * Dim 5 expected GREEN: "Class" def for "Kustomization" from cbm_extract_k8s.
+ * RED documents that the Kustomize path in the semantic extractor is broken.
+ * Dims 6-8 SKIPPED: no call_types in the Kustomize spec; no pipeline.
+ * Expected GREEN: dims 1-5. Robustness should pass.
+ */
+TEST(repro_grammar_build_kustomize) {
+ static const char src[] =
+ "apiVersion: kustomize.config.k8s.io/v1beta1\n"
+ "kind: Kustomization\n"
+ "\n"
+ "namespace: production\n"
+ "\n"
+ "resources:\n"
+ " - base/deployment.yaml\n"
+ " - base/service.yaml\n"
+ "\n"
+ "images:\n"
+ " - name: cbm-server\n"
+ " newTag: 0.8.1\n"
+ "\n"
+ "commonLabels:\n"
+ " environment: production\n"
+ " version: 0.8.1\n"
+ "\n"
+ "configMapGenerator:\n"
+ " - name: cbm-config\n"
+ " literals:\n"
+ " - LOG_LEVEL=info\n"
+ " - PORT=8080\n";
+ static const char bad[] = "apiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\nresources:";
+ if (build_struct_battery("Kustomize", src, CBM_LANG_KUSTOMIZE,
+ "kustomization.yaml", "Class", NULL) != 0)
+ return 1;
+ return build_robustness("Kustomize", bad, CBM_LANG_KUSTOMIZE,
+ "kustomization.yaml");
+}
+
+/* ── GoMod ────────────────────────────────────────────────────────────────────
+ * Idiomatic go.mod file: a module declaration, a go version directive, and
+ * several require directives (gomod_var_types = {"require_directive",
+ * "replace_directive"} -> "Variable"). Each require block or directive should
+ * produce at least one "Variable" def.
+ *
+ * Dims asserted: 1-5 + R ("Variable" from require_directive).
+ * Dim 5 expected GREEN: "Variable" def for the require directives.
+ * RED documents that require_directive->Variable extraction is broken.
+ * Dims 6-8 SKIPPED: no call_types or func_types in spec.
+ * Expected GREEN: dims 1-5. Robustness should pass.
+ */
+TEST(repro_grammar_build_gomod) {
+ static const char src[] =
+ "module github.com/DeusData/codebase-memory-mcp\n"
+ "\n"
+ "go 1.22\n"
+ "\n"
+ "require (\n"
+ " github.com/mattn/go-sqlite3 v1.14.22\n"
+ " github.com/mark3labs/mcp-go v0.17.0\n"
+ " golang.org/x/sync v0.7.0\n"
+ ")\n"
+ "\n"
+ "require (\n"
+ " github.com/google/uuid v1.6.0\n"
+ " github.com/stretchr/testify v1.9.0\n"
+ ")\n";
+ static const char bad[] = "module github.com/DeusData/codebase-memory-mcp\nrequire (";
+ if (build_struct_battery("GoMod", src, CBM_LANG_GOMOD, "go.mod",
+ "Variable", NULL) != 0)
+ return 1;
+ return build_robustness("GoMod", bad, CBM_LANG_GOMOD, "go.mod");
+}
+
+/* ── Requirements (pip) ───────────────────────────────────────────────────────
+ * Idiomatic Python requirements.txt with version pins and a URL requirement.
+ * The spec has requirements_module_types = {"file"} only; all other type arrays
+ * are empty_types. No defs or calls are extracted from the grammar tree.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dim 5 SKIPPED: no func/class/var types in spec; no labelled defs expected.
+ * Dims 6-8 SKIPPED: no call_types in spec.
+ * Expected GREEN: dims 1-4. extract-clean RED would indicate the requirements
+ * grammar is broken on standard version-pinned lines.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_requirements) {
+ static const char src[] =
+ "# Core dependencies\n"
+ "requests==2.31.0\n"
+ "fastapi>=0.100.0,<1.0.0\n"
+ "uvicorn[standard]==0.23.2\n"
+ "pydantic>=2.0.0\n"
+ "sqlalchemy==2.0.23\n"
+ "\n"
+ "# Dev dependencies\n"
+ "pytest==7.4.3\n"
+ "mypy==1.7.0\n"
+ "ruff==0.1.6\n"
+ "\n"
+ "# URL requirement\n"
+ "cbm-client @ git+https://github.com/DeusData/[email protected]\n";
+ static const char bad[] = "requests==2.31.0\nbroken>=";
+ if (build_base_battery("Requirements", src, CBM_LANG_REQUIREMENTS,
+ "requirements.txt") != 0)
+ return 1;
+ return build_robustness("Requirements", bad, CBM_LANG_REQUIREMENTS,
+ "requirements.txt");
+}
+
+/* ── .gitignore ───────────────────────────────────────────────────────────────
+ * Idiomatic .gitignore file with patterns for a Go project. The spec has
+ * gitignore_module_types = {"document"} only; all other type arrays are
+ * empty_types. No defs or calls are extracted from the grammar tree.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dim 5 SKIPPED: no func/class/var types in spec.
+ * Dims 6-8 SKIPPED: no call_types.
+ * Expected GREEN: dims 1-4. extract-clean RED would indicate the gitignore
+ * grammar is broken on standard pattern lines.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_gitignore) {
+ static const char src[] =
+ "# Compiled binaries\n"
+ "cbm-server\n"
+ "*.exe\n"
+ "*.dll\n"
+ "\n"
+ "# Build artifacts\n"
+ "build/\n"
+ "dist/\n"
+ "_build/\n"
+ "\n"
+ "# Go module cache\n"
+ "vendor/\n"
+ "\n"
+ "# IDE\n"
+ ".idea/\n"
+ ".vscode/\n"
+ "*.swp\n"
+ "\n"
+ "# Test coverage\n"
+ "coverage.out\n"
+ "*.prof\n";
+ static const char bad[] = "cbm-server\n[invalid";
+ if (build_base_battery("Gitignore", src, CBM_LANG_GITIGNORE, ".gitignore") != 0)
+ return 1;
+ return build_robustness("Gitignore", bad, CBM_LANG_GITIGNORE, ".gitignore");
+}
+
+/* ── .gitattributes ───────────────────────────────────────────────────────────
+ * Idiomatic .gitattributes file with line-ending and language attribution rules.
+ * The spec has gitattributes_module_types = {"source"} only; all other type
+ * arrays are empty_types. No defs or calls are extracted.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dim 5 SKIPPED: no func/class/var types in spec.
+ * Dims 6-8 SKIPPED: no call_types.
+ * Expected GREEN: dims 1-4. extract-clean RED would indicate the gitattributes
+ * grammar is broken on standard attribute lines.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_gitattributes) {
+ static const char src[] =
+ "# Normalise line endings\n"
+ "* text=auto eol=lf\n"
+ "\n"
+ "# Go source files\n"
+ "*.go text eol=lf\n"
+ "\n"
+ "# C source files (vendored grammars)\n"
+ "*.c text eol=lf\n"
+ "*.h text eol=lf\n"
+ "\n"
+ "# Binary files\n"
+ "*.db binary\n"
+ "*.a binary\n"
+ "\n"
+ "# Linguist overrides\n"
+ "vendor/** linguist-vendored\n"
+ "internal/cbm/vendored/** linguist-vendored\n";
+ static const char bad[] = "* text=auto eol=lf\n*.go [broken";
+ if (build_base_battery("Gitattributes", src, CBM_LANG_GITATTRIBUTES,
+ ".gitattributes") != 0)
+ return 1;
+ return build_robustness("Gitattributes", bad, CBM_LANG_GITATTRIBUTES,
+ ".gitattributes");
+}
+
+/* ── SSH Config ───────────────────────────────────────────────────────────────
+ * Idiomatic ~/.ssh/config file with two Host stanzas. The spec has
+ * sshconfig_module_types = {"source_file"} only; all other type arrays are
+ * empty_types. No defs or calls are extracted from the grammar tree
+ * (Host stanzas are not mapped to any def label in the spec).
+ *
+ * Dims asserted: 1-4 + R.
+ * Dim 5 SKIPPED: no func/class/var types in spec; Host stanzas are not labelled.
+ * Dims 6-8 SKIPPED: no call_types.
+ * Expected GREEN: dims 1-4. extract-clean RED would indicate the ssh_config
+ * grammar is broken on standard Host/IdentityFile stanza syntax.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_sshconfig) {
+ static const char src[] =
+ "Host github.com\n"
+ " HostName github.com\n"
+ " User git\n"
+ " IdentityFile ~/.ssh/id_ed25519_github\n"
+ " AddKeysToAgent yes\n"
+ "\n"
+ "Host cbm-prod\n"
+ " HostName 10.0.0.42\n"
+ " User deploy\n"
+ " IdentityFile ~/.ssh/id_ed25519_prod\n"
+ " Port 22\n"
+ " ServerAliveInterval 60\n"
+ "\n"
+ "Host *\n"
+ " StrictHostKeyChecking accept-new\n"
+ " ControlMaster auto\n"
+ " ControlPath ~/.ssh/cm-%r@%h:%p\n";
+ static const char bad[] = "Host github.com\n HostName github.com\n User git\n IdentityFile";
+ if (build_base_battery("SSHConfig", src, CBM_LANG_SSHCONFIG, "config") != 0)
+ return 1;
+ return build_robustness("SSHConfig", bad, CBM_LANG_SSHCONFIG, "config");
+}
+
+/* ── BitBake ──────────────────────────────────────────────────────────────────
+ * Idiomatic BitBake recipe (.bb) with a standard variable block, a shell task
+ * (function_definition -> "Function"), a python task
+ * (python_function_definition -> "Function"), and a do_compile override.
+ * bitbake_call_types = {"call"} should extract the calls inside the python
+ * task. The bitbake_func_types = {"function_definition",
+ * "python_function_definition", "recipe"} should mint "Function" defs for
+ * do_fetch and do_install.
+ *
+ * Dims asserted: 1-8 (full battery).
+ * Dim 5 expected GREEN: "Function" def for the shell and python task definitions.
+ * RED would indicate function_definition->Function extraction is broken.
+ * Dim 6 expected GREEN: call extraction inside the python task.
+ * RED documents the call node extraction gap for BitBake python blocks.
+ * Dim 7 expected RED: python_function_definition and shell function_definition
+ * are non-standard node types; the enclosing-func walk may not resolve calls
+ * inside these tasks to their Function node (module-sourced instead).
+ * Dim 8 expected GREEN: no dangling CALLS endpoints.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_bitbake) {
+ static const char src[] =
+ "DESCRIPTION = \"CBM MCP server component\"\n"
+ "HOMEPAGE = \"https://github.com/DeusData/codebase-memory-mcp\"\n"
+ "LICENSE = \"MIT\"\n"
+ "PV = \"0.8.1\"\n"
+ "\n"
+ "SRC_URI = \"git://github.com/DeusData/codebase-memory-mcp.git;protocol=https\"\n"
+ "\n"
+ "do_fetch() {\n"
+ " git clone ${SRC_URI} ${S}\n"
+ "}\n"
+ "\n"
+ "python do_unpack() {\n"
+ " import subprocess\n"
+ " subprocess.run(['git', 'checkout', d.getVar('PV')])\n"
+ " bb.note('Unpacked version ' + d.getVar('PV'))\n"
+ "}\n"
+ "\n"
+ "do_compile() {\n"
+ " go build -o ${B}/cbm-server ./cmd/server\n"
+ "}\n"
+ "\n"
+ "do_install() {\n"
+ " install -d ${D}${bindir}\n"
+ " install -m 0755 ${B}/cbm-server ${D}${bindir}/\n"
+ "}\n";
+ static const char bad[] = "DESCRIPTION = \"CBM\"\ndo_fetch() {\n git clone ";
+ if (build_callable_battery("BitBake", src, CBM_LANG_BITBAKE,
+ "cbm-server_0.8.1.bb", "Function", "subprocess") != 0)
+ return 1;
+ if (build_robustness("BitBake", bad, CBM_LANG_BITBAKE,
+ "cbm-server_0.8.1.bb") != 0)
+ return 1;
+ return build_pipeline_battery("BitBake", "cbm-server_0.8.1.bb", src);
+}
+
+/* ── Puppet ───────────────────────────────────────────────────────────────────
+ * Idiomatic Puppet manifest: a class definition (puppet_class_types =
+ * {"class_definition", ...} -> "Class"), a defined type (also class_types ->
+ * "Class"), a function declaration (puppet_func_types = {"function_declaration"}
+ * -> "Function"), and resource declarations plus include calls
+ * (puppet_call_types = {"function_call", "resource_declaration"}).
+ *
+ * Dims asserted: 1-8 (full battery).
+ * Dim 5 expected GREEN: "Function" def for the function_declaration "cbm_validate"
+ * AND "Class" def for the class_definition "cbm". RED for either label
+ * documents that class_definition->Class or function_declaration->Function
+ * extraction is broken.
+ * Dim 6 expected GREEN: call to "include" via function_call node.
+ * RED documents the Puppet function_call extraction gap.
+ * Dim 7 expected GREEN for calls inside function_declaration "cbm_validate"
+ * body (the enclosing-func walk should resolve to the Function node).
+ * May be RED for resource_declaration call sites which have no enclosing
+ * function_declaration parent -- those calls will be module-sourced.
+ * Dim 8 expected GREEN: no dangling CALLS endpoints.
+ * Robustness should pass.
+ */
+TEST(repro_grammar_build_puppet) {
+ static const char src[] =
+ "class cbm (\n"
+ " String $version = '0.8.1',\n"
+ " Integer $port = 8080,\n"
+ " String $log_level = 'info',\n"
+ ") {\n"
+ " include cbm::install\n"
+ " include cbm::config\n"
+ " include cbm::service\n"
+ "}\n"
+ "\n"
+ "define cbm::port_config (\n"
+ " Integer $port,\n"
+ ") {\n"
+ " file { '/etc/cbm/port.conf':\n"
+ " content => \"port=${port}\\n\",\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "function cbm_validate(String $version) >> Boolean {\n"
+ " $parts = split($version, /\\./ )\n"
+ " length($parts) == 3\n"
+ "}\n";
+ static const char bad[] = "class cbm (\n String $version = '0.8.1',\n) {\n include";
+ if (build_callable_battery("Puppet", src, CBM_LANG_PUPPET, "cbm.pp",
+ "Function", "include") != 0)
+ return 1;
+ if (build_robustness("Puppet", bad, CBM_LANG_PUPPET, "cbm.pp") != 0)
+ return 1;
+ return build_pipeline_battery("Puppet", "cbm.pp", src);
+}
+
+/* ── Suite ───────────────────────────────────────────────────────────────────── */
+
+SUITE(repro_grammar_build) {
+ RUN_TEST(repro_grammar_build_dockerfile);
+ RUN_TEST(repro_grammar_build_makefile);
+ RUN_TEST(repro_grammar_build_cmake);
+ RUN_TEST(repro_grammar_build_meson);
+ RUN_TEST(repro_grammar_build_gn);
+ RUN_TEST(repro_grammar_build_just);
+ RUN_TEST(repro_grammar_build_k8s);
+ RUN_TEST(repro_grammar_build_kustomize);
+ RUN_TEST(repro_grammar_build_gomod);
+ RUN_TEST(repro_grammar_build_requirements);
+ RUN_TEST(repro_grammar_build_gitignore);
+ RUN_TEST(repro_grammar_build_gitattributes);
+ RUN_TEST(repro_grammar_build_sshconfig);
+ RUN_TEST(repro_grammar_build_bitbake);
+ RUN_TEST(repro_grammar_build_puppet);
+}
diff --git a/tests/repro/repro_grammar_shells.c b/tests/repro/repro_grammar_shells.c
new file mode 100644
index 000000000..bf5881fb2
--- /dev/null
+++ b/tests/repro/repro_grammar_shells.c
@@ -0,0 +1,973 @@
+/*
+ * repro_grammar_shells.c -- Per-grammar INVARIANT battery for the
+ * SHELLS / SCRIPTING / MISC (asm-ish + data-ish) language family.
+ *
+ * One TEST() per language so per-language RED/GREEN shows on the bug-repro
+ * board. Each test runs a battery adapted to what the language actually models,
+ * read directly from internal/cbm/lang_specs.c (the func/class/field/call type
+ * arrays per CBM_LANG_*). The dimensions applied per language are documented in
+ * the per-TEST comment.
+ *
+ * Languages covered (19) and the CBM_LANG_* enum each uses (all verified present
+ * in internal/cbm/cbm.h):
+ * BASH -> CBM_LANG_BASH (callable: func + call)
+ * ZSH -> CBM_LANG_ZSH (callable: func + call)
+ * FISH -> CBM_LANG_FISH (callable: func + call)
+ * POWERSHELL -> CBM_LANG_POWERSHELL (callable: func + class + call)
+ * TCL -> CBM_LANG_TCL (callable: func + class + call)
+ * AWK -> CBM_LANG_AWK (callable: func + call)
+ * VIMSCRIPT -> CBM_LANG_VIMSCRIPT (callable: func + call)
+ * FENNEL -> CBM_LANG_FENNEL (callable: func + call, lisp)
+ * NIX -> CBM_LANG_NIX (callable: func + call)
+ * GDSCRIPT -> CBM_LANG_GDSCRIPT (callable: func + class + call)
+ * LUAU -> CBM_LANG_LUAU (callable: func + class + call)
+ * TEAL -> CBM_LANG_TEAL (callable: func + class + call)
+ * LLVM_IR -> CBM_LANG_LLVM_IR (callable: func + call)
+ * NASM -> CBM_LANG_NASM (callable: func(label) + call)
+ * JANET -> CBM_LANG_JANET (STRUCTURAL ONLY: spec has only module_types)
+ * SMALI -> CBM_LANG_SMALI (structural-with-defs: func/class/field, NO calls)
+ * DEVICETREE -> CBM_LANG_DEVICETREE (structural: call_types but NO func anchor)
+ * KCONFIG -> CBM_LANG_KCONFIG (structural-with-defs: class_types, NO calls)
+ * HYPRLANG -> CBM_LANG_HYPRLANG (pure structural: only module_types)
+ *
+ * No language in this set was skipped; every CBM_LANG_* above is defined in cbm.h.
+ *
+ * SPEC-DRIVEN CLASSIFICATION (from internal/cbm/lang_specs.c)
+ * ----------------------------------------------------------
+ * CALLABLES (func_types AND call_types both non-empty -> full battery + pipeline):
+ * BASH func=function_definition call=command
+ * ZSH func=function_definition call=command,call_expression
+ * FISH func=function_definition call=command
+ * POWERSHELL func=function_statement call=invokation_expression,command class=class_statement,...
+ * TCL func=procedure call=command class=namespace
+ * AWK func=func_def,rule call=func_call,command
+ * VIMSCRIPT func=function_definition,... call=call_expression,call,command
+ * FENNEL func=fn,lambda,hashfn call=list (lisp head symbol)
+ * NIX func=function_expression call=apply_expression
+ * GDSCRIPT func=function_definition,... call=call,attribute_call,base_call class=class_definition,...
+ * LUAU func=function_declaration,function_definition call=function_call class=type_definition
+ * TEAL func=function_statement,anon_function,... call=function_call class=record_declaration,...
+ * LLVM_IR func=function_header call=call,invoke var=local_var,global_var
+ * NASM func=label,preproc_def,preproc_multiline_macro call=call_syntax_expression class=struc_declaration
+ *
+ * STRUCTURAL-WITH-DEFS (defs but NO call_types -> dims 1-5 + R):
+ * SMALI func=method_definition -> "Function" class=class_definition -> "Class" field=field_definition -> "Field" (call_types EMPTY)
+ * KCONFIG class=config,menuconfig,choice,type_definition -> "Class" (func/call EMPTY)
+ *
+ * STRUCTURAL ONLY (no extractable defs from the spec -> dims 1-4 + R):
+ * JANET ONLY module_types=source; func/class/field/call all empty_types.
+ * DEVICETREE call_types=call_expression but func_types EMPTY -> no Function anchor,
+ * and no class/var defs; treat as structural (extract-clean + invariants).
+ * HYPRLANG ONLY module_types=source_file; everything else empty_types.
+ *
+ * BATTERY DIMENSIONS (identical semantics to repro_grammar_core.c /
+ * repro_grammar_config.c -- shared helpers reused via repro_invariant_lib.h):
+ * SINGLE-FILE (cbm_extract_file):
+ * 1. extract-clean : inv_extract_clean == 1 (non-NULL, has_error unset).
+ * 2. labels-valid : inv_count_bad_labels == 0.
+ * 3. fqn-wellformed : inv_count_bad_fqns == 0.
+ * 4. ranges-valid : inv_count_bad_ranges == 0.
+ * 5. defs-present : expected label extracted (callables + structural-with-defs).
+ * 6. calls-extracted : inv_has_call(callee) == 1 (callables only).
+ * FULL-PIPELINE (rh_index_files):
+ * 7. callable-sourcing : inv_count_calls_by_source mod == 0 AND callable >= 1
+ * (callables only).
+ * 8. no-dangling : inv_count_dangling_edges("CALLS") == 0 (with dim 7).
+ * ROBUSTNESS (every language):
+ * R. extract-on-malformed: cbm_extract_file on a truncated/broken fixture must
+ * RETURN non-NULL (has_error may be set). A NULL return means the extractor
+ * crashed/aborted on bad input -- a RED robustness bug.
+ *
+ * KNOWN GAP -> dim-7 RED PREDICTIONS (the point of this file).
+ * The enclosing-func walk cbm_find_enclosing_func() uses func_kinds_for_lang()
+ * in internal/cbm/helpers.c. In that switch ONLY CBM_LANG_BASH has a dedicated
+ * kind list (func_kinds_bash = {"function_definition"}); every other language in
+ * this set falls through to func_kinds_generic =
+ * {"function_declaration","function_definition","method_declaration","method_definition"}.
+ * So a call's enclosing Function node is found ONLY when the grammar's func node
+ * type is one of those generic kinds. Cross-referencing each callable's func node
+ * type (from lang_specs.c) against that generic set:
+ * MATCHES generic (dim 7 has a chance to be GREEN if calls extract + attribute):
+ * ZSH/FISH (function_definition), VIMSCRIPT (function_definition),
+ * GDSCRIPT (function_definition), LUAU (function_declaration/function_definition).
+ * BASH matches via func_kinds_bash.
+ * DOES NOT MATCH generic (enclosing-func walk returns null -> Module-sourced ->
+ * dim 7 RED expected):
+ * POWERSHELL (function_statement), TCL (procedure), AWK (func_def/rule),
+ * FENNEL (fn/lambda/hashfn), NIX (function_expression),
+ * TEAL (function_statement/anon_function/...), LLVM_IR (function_header),
+ * NASM (label/...).
+ * Dim 6 (calls-extracted) is itself uncertain for several command-style grammars
+ * (bash/zsh/fish/awk/tcl `command` nodes, nix apply_expression, llvm call/invoke,
+ * nasm call_syntax_expression): the callee-name resolver in extract_calls.c has a
+ * dedicated path only for PowerShell `command` and lisp `list`; the others rely on
+ * generic field/first-child resolution and may yield no callee_name -> dim 6 RED.
+ * Where dim 6 REDs, dim 7 also REDs (0 CALLS edges to attribute). These RED rows
+ * ARE the deliverable -- they document precisely which shells/scripting grammars
+ * lose call edges or mis-source them at the Module node.
+ *
+ * NOTE: these RED/GREEN labels are static-analysis PREDICTIONS from the spec +
+ * helpers source; the suite records the real outcome when run. Be honest: a row
+ * that flips from the predicted color is itself a finding.
+ *
+ * Coding rule: inline comments are line comments only (no block comments inside
+ * block comments).
+ */
+
+#include "test_framework.h"
+#include "repro_invariant_lib.h"
+#include <store/store.h>
+
+#include <stdio.h>
+#include <string.h>
+
+/* ── Shared single-file battery: structural base (dims 1-4) ─────────────────
+ *
+ * Four core invariants on valid input, no defs/calls assertions. Used for the
+ * structural-only languages (JANET, DEVICETREE, HYPRLANG). Returns 0 on PASS.
+ */
+static int sh_base_battery(const char *lang_tag, const char *src, CBMLanguage lang,
+ const char *file) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ /* 1. extract-clean */
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 2. labels-valid */
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ /* 3. fqn-wellformed */
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ /* 4. ranges-valid */
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Shared single-file battery: structural with defs (dims 1-5) ────────────
+ *
+ * Adds defs-present for the structural-with-defs languages (SMALI, KCONFIG).
+ * Pass NULL for expect_label2/expect_label3 when fewer labels are needed.
+ * Returns 0 on PASS.
+ */
+static int sh_struct_battery(const char *lang_tag, const char *src, CBMLanguage lang,
+ const char *file, const char *expect_label,
+ const char *expect_label2, const char *expect_label3) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ /* 5. defs-present (up to three expected labels) */
+ if (expect_label && inv_count_label(r, expect_label) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label);
+ fails++;
+ }
+ if (expect_label2 && inv_count_label(r, expect_label2) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label2);
+ fails++;
+ }
+ if (expect_label3 && inv_count_label(r, expect_label3) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label3);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Shared single-file battery: callable (dims 1-6) ────────────────────────
+ *
+ * Adds defs-present (dim 5) and calls-extracted (dim 6) on top of the base
+ * invariants. Used for the callable shells/scripting languages. Pass NULL for
+ * expect_label when no def label is asserted alongside the call. Returns 0 on PASS.
+ */
+static int sh_callable_battery(const char *lang_tag, const char *src, CBMLanguage lang,
+ const char *file, const char *expect_label,
+ const char *expect_label2, const char *callee) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ if (inv_extract_clean(src, lang, file) != 1) {
+ printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ CBMFileResult *r = inv_rx(src, lang, file);
+ if (!r) {
+ printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ int bad_labels = inv_count_bad_labels(r);
+ if (bad_labels != 0) {
+ printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n",
+ RED, RST, lang_tag, bad_labels);
+ fails++;
+ }
+
+ int bad_fqns = inv_count_bad_fqns(r);
+ if (bad_fqns != 0) {
+ printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n",
+ RED, RST, lang_tag, bad_fqns);
+ fails++;
+ }
+
+ int bad_ranges = inv_count_bad_ranges(r);
+ if (bad_ranges != 0) {
+ printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n",
+ RED, RST, lang_tag, bad_ranges);
+ fails++;
+ }
+
+ /* 5. defs-present */
+ if (expect_label && inv_count_label(r, expect_label) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label);
+ fails++;
+ }
+ if (expect_label2 && inv_count_label(r, expect_label2) < 1) {
+ printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n",
+ RED, RST, lang_tag, expect_label2);
+ fails++;
+ }
+
+ /* 6. calls-extracted */
+ if (callee && inv_has_call(r, callee) != 1) {
+ printf(" %sFAIL%s [%s] calls-extracted: no call to \"%s\" found\n",
+ RED, RST, lang_tag, callee);
+ fails++;
+ }
+
+ cbm_free_result(r);
+ return fails ? 1 : 0;
+}
+
+/* ── Shared full-pipeline battery (dims 7-8) ────────────────────────────────
+ *
+ * Indexes the single-file fixture through the production pipeline and asserts
+ * callable-sourcing (no Module-sourced in-body CALLS, and >= 1 callable-sourced
+ * so a fixture with zero CALLS edges cannot vacuously pass) plus no dangling
+ * CALLS endpoints. Used for the callable languages. Dim 7 is RED for the
+ * languages whose func node type is not in func_kinds_generic (see file header).
+ * Returns 0 on PASS.
+ */
+static int sh_pipeline_battery(const char *lang_tag, const char *filename, const char *src) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ RFile files[1];
+ files[0].name = filename;
+ files[0].content = src;
+
+ RProj lp;
+ cbm_store_t *store = rh_index_files(&lp, files, 1);
+ if (!store) {
+ printf(" %sFAIL%s [%s] pipeline: rh_index_files returned NULL\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+
+ int fails = 0;
+
+ /* 7. callable-sourcing */
+ int module_sourced = 0;
+ int callable_sourced = 0;
+ inv_count_calls_by_source(store, lp.project, &module_sourced, &callable_sourced);
+ if (module_sourced != 0) {
+ printf(" %sFAIL%s [%s] callable-sourcing: %d in-body CALLS sourced at "
+ "Module (callable=%d) -- enclosing-func gap (func_kinds_for_lang "
+ "lacks this grammar's func node type)\n",
+ RED, RST, lang_tag, module_sourced, callable_sourced);
+ fails++;
+ } else if (callable_sourced < 1) {
+ printf(" %sFAIL%s [%s] callable-sourcing: 0 CALLS edges (fixture "
+ "produced no in-body call edge to attribute)\n",
+ RED, RST, lang_tag);
+ fails++;
+ }
+
+ /* 8. no-dangling */
+ int dangling = inv_count_dangling_edges(store, lp.project, "CALLS");
+ if (dangling != 0) {
+ printf(" %sFAIL%s [%s] no-dangling: %d dangling CALLS endpoint(s)\n",
+ RED, RST, lang_tag, dangling);
+ fails++;
+ }
+
+ rh_cleanup(&lp, store);
+ return fails ? 1 : 0;
+}
+
+/* ── Robustness helper: assert call RETURNS on malformed input ──────────────
+ *
+ * A truncated version of the fixture is passed through cbm_extract_file.
+ * has_error may be set (1) but the call must return non-NULL. A NULL return
+ * means the extractor crashed or aborted on bad input -- a RED robustness bug.
+ * Returns 0 on PASS.
+ */
+static int sh_robustness(const char *lang_tag, const char *bad_src, CBMLanguage lang,
+ const char *file) {
+ const char *RED = tf_red();
+ const char *RST = tf_reset();
+
+ CBMFileResult *r =
+ cbm_extract_file(bad_src, (int)strlen(bad_src), lang, "t", file, 0, NULL, NULL);
+ if (!r) {
+ printf(" %sFAIL%s [%s] robustness: extractor returned NULL on malformed input\n",
+ RED, RST, lang_tag);
+ return 1;
+ }
+ cbm_free_result(r);
+ return 0;
+}
+
+/* ── BASH ─────────────────────────────────────────────────────────────────────
+ * Idiomatic: two function definitions, the callee invoked strictly inside the
+ * caller body. spec: func=function_definition, call=command. BASH is the only
+ * shell with a dedicated func_kinds_bash list, so the enclosing-func walk can
+ * match the function_definition node.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "compute_inner".
+ * Dim 7 has a chance to be GREEN (func_kinds_bash matches function_definition) IF
+ * the `command` callee resolves and the CALLS edge is produced; if command-node
+ * callee resolution yields no name, dims 6+7 RED.
+ */
+TEST(repro_grammar_shells_bash) {
+ static const char src[] =
+ "#!/usr/bin/env bash\n"
+ "\n"
+ "compute_inner() {\n"
+ " echo $(( $1 + 1 ))\n"
+ "}\n"
+ "\n"
+ "compute_outer() {\n"
+ " compute_inner \"$1\"\n"
+ "}\n";
+ static const char bad[] = "compute_outer() {\n compute_inner \"$1\"";
+ if (sh_callable_battery("BASH", src, CBM_LANG_BASH, "run.sh",
+ "Function", NULL, "compute_inner") != 0)
+ return 1;
+ if (sh_robustness("BASH", bad, CBM_LANG_BASH, "run.sh") != 0)
+ return 1;
+ return sh_pipeline_battery("BASH", "run.sh", src);
+}
+
+/* ── ZSH ──────────────────────────────────────────────────────────────────────
+ * Idiomatic: two zsh functions, callee inside caller body. spec:
+ * func=function_definition, call=command,call_expression. function_definition is
+ * in func_kinds_generic, so the enclosing-func walk can match.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "inner_fn".
+ * Dim 7 may be GREEN (function_definition matches generic) IF command callee
+ * resolves; else 6+7 RED.
+ */
+TEST(repro_grammar_shells_zsh) {
+ static const char src[] =
+ "inner_fn() {\n"
+ " print -- $(( $1 * 2 ))\n"
+ "}\n"
+ "\n"
+ "outer_fn() {\n"
+ " inner_fn \"$1\"\n"
+ "}\n";
+ static const char bad[] = "outer_fn() {\n inner_fn \"$1\"";
+ if (sh_callable_battery("ZSH", src, CBM_LANG_ZSH, "run.zsh",
+ "Function", NULL, "inner_fn") != 0)
+ return 1;
+ if (sh_robustness("ZSH", bad, CBM_LANG_ZSH, "run.zsh") != 0)
+ return 1;
+ return sh_pipeline_battery("ZSH", "run.zsh", src);
+}
+
+/* ── FISH ─────────────────────────────────────────────────────────────────────
+ * Idiomatic: two `function ... end` definitions, callee inside caller body.
+ * spec: func=function_definition, call=command. function_definition matches
+ * func_kinds_generic.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "inner_fn".
+ * Dim 7 may be GREEN IF command callee resolves; else 6+7 RED.
+ */
+TEST(repro_grammar_shells_fish) {
+ static const char src[] =
+ "function inner_fn\n"
+ " math $argv[1] x 2\n"
+ "end\n"
+ "\n"
+ "function outer_fn\n"
+ " inner_fn $argv[1]\n"
+ "end\n";
+ static const char bad[] = "function outer_fn\n inner_fn $argv[1]";
+ if (sh_callable_battery("FISH", src, CBM_LANG_FISH, "run.fish",
+ "Function", NULL, "inner_fn") != 0)
+ return 1;
+ if (sh_robustness("FISH", bad, CBM_LANG_FISH, "run.fish") != 0)
+ return 1;
+ return sh_pipeline_battery("FISH", "run.fish", src);
+}
+
+/* ── POWERSHELL ───────────────────────────────────────────────────────────────
+ * Idiomatic: two `function` statements, callee invoked inside the caller body.
+ * spec: func=function_statement, call=invokation_expression,command,
+ * class=class_statement,enum_statement,type_spec. PowerShell has a dedicated
+ * callee resolver (extract_powershell_callee: command_name child).
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "Get-Inner".
+ * Dim 7 expected RED: func node type "function_statement" is NOT in
+ * func_kinds_generic -> enclosing-func walk returns null -> Module-sourced.
+ */
+TEST(repro_grammar_shells_powershell) {
+ static const char src[] =
+ "function Get-Inner {\n"
+ " param([int]$x)\n"
+ " return $x + 1\n"
+ "}\n"
+ "\n"
+ "function Get-Outer {\n"
+ " param([int]$x)\n"
+ " return Get-Inner -x $x\n"
+ "}\n";
+ static const char bad[] = "function Get-Outer {\n param([int]$x)\n return Get-Inner";
+ if (sh_callable_battery("PowerShell", src, CBM_LANG_POWERSHELL, "run.ps1",
+ "Function", NULL, "Get-Inner") != 0)
+ return 1;
+ if (sh_robustness("PowerShell", bad, CBM_LANG_POWERSHELL, "run.ps1") != 0)
+ return 1;
+ return sh_pipeline_battery("PowerShell", "run.ps1", src);
+}
+
+/* ── TCL ──────────────────────────────────────────────────────────────────────
+ * Idiomatic: two `proc` definitions, callee invoked inside caller body.
+ * spec: func=procedure, call=command, class=namespace.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (procedure -> Function). Dim 6
+ * callee = "inner_proc".
+ * Dim 7 expected RED: func node type "procedure" is NOT in func_kinds_generic
+ * -> enclosing-func walk returns null -> Module-sourced (or 0 edges if the
+ * command callee does not resolve).
+ */
+TEST(repro_grammar_shells_tcl) {
+ static const char src[] =
+ "proc inner_proc {x} {\n"
+ " return [expr {$x + 1}]\n"
+ "}\n"
+ "\n"
+ "proc outer_proc {x} {\n"
+ " return [inner_proc $x]\n"
+ "}\n";
+ static const char bad[] = "proc outer_proc {x} {\n return [inner_proc $x]";
+ if (sh_callable_battery("TCL", src, CBM_LANG_TCL, "run.tcl",
+ "Function", NULL, "inner_proc") != 0)
+ return 1;
+ if (sh_robustness("TCL", bad, CBM_LANG_TCL, "run.tcl") != 0)
+ return 1;
+ return sh_pipeline_battery("TCL", "run.tcl", src);
+}
+
+/* ── AWK ──────────────────────────────────────────────────────────────────────
+ * Idiomatic: a user function and a rule that calls it. spec: func=func_def,rule,
+ * call=func_call,command.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (func_def -> Function). Dim 6
+ * callee = "inner".
+ * Dim 7 expected RED: neither "func_def" nor "rule" is in func_kinds_generic
+ * -> Module-sourced.
+ */
+TEST(repro_grammar_shells_awk) {
+ static const char src[] =
+ "function inner(x) {\n"
+ " return x + 1\n"
+ "}\n"
+ "\n"
+ "{\n"
+ " print inner($1)\n"
+ "}\n";
+ static const char bad[] = "function inner(x) {\n return x +";
+ if (sh_callable_battery("AWK", src, CBM_LANG_AWK, "prog.awk",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("AWK", bad, CBM_LANG_AWK, "prog.awk") != 0)
+ return 1;
+ return sh_pipeline_battery("AWK", "prog.awk", src);
+}
+
+/* ── VIMSCRIPT ────────────────────────────────────────────────────────────────
+ * Idiomatic: two `function ... endfunction` definitions, callee inside caller
+ * body. spec: func=function_definition,function_declaration,..., call=
+ * call_expression,call,command. function_definition matches func_kinds_generic.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "Inner".
+ * Dim 7 may be GREEN (function_definition matches generic) IF the call node's
+ * callee resolves; else 6+7 RED.
+ */
+TEST(repro_grammar_shells_vimscript) {
+ static const char src[] =
+ "function! Inner(x)\n"
+ " return a:x + 1\n"
+ "endfunction\n"
+ "\n"
+ "function! Outer(x)\n"
+ " return Inner(a:x)\n"
+ "endfunction\n";
+ static const char bad[] = "function! Outer(x)\n return Inner(a:x)";
+ if (sh_callable_battery("VimScript", src, CBM_LANG_VIMSCRIPT, "plugin.vim",
+ "Function", NULL, "Inner") != 0)
+ return 1;
+ if (sh_robustness("VimScript", bad, CBM_LANG_VIMSCRIPT, "plugin.vim") != 0)
+ return 1;
+ return sh_pipeline_battery("VimScript", "plugin.vim", src);
+}
+
+/* ── FENNEL ───────────────────────────────────────────────────────────────────
+ * Idiomatic: two `fn` definitions, callee invoked inside caller body.
+ * spec: func=fn,lambda,hashfn, call=list. Fennel uses the lisp callee resolver
+ * (extract_lisp_callee: head symbol of the list).
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (fn -> Function). Dim 6 callee =
+ * "inner".
+ * Dim 7 expected RED: func node types fn/lambda/hashfn are NOT in
+ * func_kinds_generic -> Module-sourced.
+ */
+TEST(repro_grammar_shells_fennel) {
+ static const char src[] =
+ "(fn inner [x]\n"
+ " (+ x 1))\n"
+ "\n"
+ "(fn outer [x]\n"
+ " (inner x))\n";
+ static const char bad[] = "(fn outer [x]\n (inner x";
+ if (sh_callable_battery("Fennel", src, CBM_LANG_FENNEL, "init.fnl",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("Fennel", bad, CBM_LANG_FENNEL, "init.fnl") != 0)
+ return 1;
+ return sh_pipeline_battery("Fennel", "init.fnl", src);
+}
+
+/* ── NIX ──────────────────────────────────────────────────────────────────────
+ * Idiomatic: a let-binding lambda (function_expression) applied to an argument.
+ * spec: func=function_expression, call=apply_expression, var=binding. Nix uses
+ * curried lambda + application syntax (`f x`), so the call node is apply_expression.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (function_expression -> Function).
+ * Dim 6 callee = "addOne" (the applied binding name).
+ * Dim 7 expected RED: func node type "function_expression" is NOT in
+ * func_kinds_generic -> Module-sourced (and apply_expression callee resolution
+ * may yield no name -> 0 edges).
+ */
+TEST(repro_grammar_shells_nix) {
+ static const char src[] =
+ "let\n"
+ " addOne = x: x + 1;\n"
+ " compute = y: addOne y;\n"
+ "in\n"
+ " compute 41\n";
+ static const char bad[] = "let\n addOne = x: x +";
+ if (sh_callable_battery("Nix", src, CBM_LANG_NIX, "default.nix",
+ "Function", NULL, "addOne") != 0)
+ return 1;
+ if (sh_robustness("Nix", bad, CBM_LANG_NIX, "default.nix") != 0)
+ return 1;
+ return sh_pipeline_battery("Nix", "default.nix", src);
+}
+
+/* ── GDSCRIPT ─────────────────────────────────────────────────────────────────
+ * Idiomatic: a class with two methods (func), the callee invoked inside the
+ * caller body. spec: func=function_definition,constructor_definition,...,
+ * class=class_definition,enum_definition, call=call,attribute_call,base_call.
+ * function_definition matches func_kinds_generic.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (and "Class" for the inner class).
+ * Dim 6 callee = "_inner".
+ * Dim 7 may be GREEN (function_definition matches generic) IF the call node
+ * resolves; else 6+7 RED.
+ */
+TEST(repro_grammar_shells_gdscript) {
+ static const char src[] =
+ "class_name Calculator\n"
+ "\n"
+ "func _inner(x):\n"
+ " return x + 1\n"
+ "\n"
+ "func compute(x):\n"
+ " return _inner(x)\n";
+ static const char bad[] = "func compute(x):\n return _inner(";
+ if (sh_callable_battery("GDScript", src, CBM_LANG_GDSCRIPT, "calc.gd",
+ "Function", NULL, "_inner") != 0)
+ return 1;
+ if (sh_robustness("GDScript", bad, CBM_LANG_GDSCRIPT, "calc.gd") != 0)
+ return 1;
+ return sh_pipeline_battery("GDScript", "calc.gd", src);
+}
+
+/* ── LUAU ─────────────────────────────────────────────────────────────────────
+ * Idiomatic: two local functions, callee invoked inside caller body.
+ * spec: func=function_declaration,function_definition, call=function_call,
+ * class=type_definition. Both func node types are in func_kinds_generic.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function". Dim 6 callee = "inner".
+ * Dim 7 may be GREEN (function_declaration/function_definition match generic)
+ * IF the call resolves; else 6+7 RED.
+ */
+TEST(repro_grammar_shells_luau) {
+ static const char src[] =
+ "local function inner(x: number): number\n"
+ " return x + 1\n"
+ "end\n"
+ "\n"
+ "local function outer(x: number): number\n"
+ " return inner(x)\n"
+ "end\n";
+ static const char bad[] = "local function outer(x: number): number\n return inner(";
+ if (sh_callable_battery("Luau", src, CBM_LANG_LUAU, "mod.luau",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("Luau", bad, CBM_LANG_LUAU, "mod.luau") != 0)
+ return 1;
+ return sh_pipeline_battery("Luau", "mod.luau", src);
+}
+
+/* ── TEAL ─────────────────────────────────────────────────────────────────────
+ * Idiomatic: two function statements (typed Lua), callee inside caller body.
+ * spec: func=function_statement,anon_function,function_signature,...,
+ * class=record_declaration,interface_declaration, call=function_call.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (function_statement -> Function).
+ * Dim 6 callee = "inner".
+ * Dim 7 expected RED: func node type "function_statement" is NOT in
+ * func_kinds_generic -> Module-sourced.
+ */
+TEST(repro_grammar_shells_teal) {
+ static const char src[] =
+ "function inner(x: number): number\n"
+ " return x + 1\n"
+ "end\n"
+ "\n"
+ "function outer(x: number): number\n"
+ " return inner(x)\n"
+ "end\n";
+ static const char bad[] = "function outer(x: number): number\n return inner(";
+ if (sh_callable_battery("Teal", src, CBM_LANG_TEAL, "mod.tl",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("Teal", bad, CBM_LANG_TEAL, "mod.tl") != 0)
+ return 1;
+ return sh_pipeline_battery("Teal", "mod.tl", src);
+}
+
+/* ── LLVM_IR ──────────────────────────────────────────────────────────────────
+ * Idiomatic: two `define` functions, the callee invoked via a `call` instruction
+ * inside the caller body. spec: func=function_header, call=call,invoke,
+ * var=local_var,global_var.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (function_header -> Function).
+ * Dim 6 callee = "inner".
+ * Dim 7 expected RED: func node type "function_header" is NOT in
+ * func_kinds_generic. Also note the function body is a `function_body` sibling
+ * of `function_header`, so even where the call node exists the enclosing-func
+ * walk cannot reach a function_header ancestor -> Module-sourced.
+ */
+TEST(repro_grammar_shells_llvm_ir) {
+ static const char src[] =
+ "define i32 @inner(i32 %x) {\n"
+ "entry:\n"
+ " %r = add i32 %x, 1\n"
+ " ret i32 %r\n"
+ "}\n"
+ "\n"
+ "define i32 @outer(i32 %x) {\n"
+ "entry:\n"
+ " %c = call i32 @inner(i32 %x)\n"
+ " ret i32 %c\n"
+ "}\n";
+ static const char bad[] = "define i32 @outer(i32 %x) {\nentry:\n %c = call i32 @inner(";
+ if (sh_callable_battery("LLVM-IR", src, CBM_LANG_LLVM_IR, "mod.ll",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("LLVM-IR", bad, CBM_LANG_LLVM_IR, "mod.ll") != 0)
+ return 1;
+ return sh_pipeline_battery("LLVM-IR", "mod.ll", src);
+}
+
+/* ── NASM ─────────────────────────────────────────────────────────────────────
+ * Idiomatic: two labels (func via label) and a `call` instruction targeting the
+ * inner label. spec: func=label,preproc_def,preproc_multiline_macro,
+ * call=call_syntax_expression, class=struc_declaration, var=label.
+ *
+ * Dims asserted: 1-8 + R. Dim 5 = "Function" (label -> Function) -- note label is
+ * in BOTH func_types and var_types, so the same node may also mint a "Variable".
+ * Dim 6 callee = "inner".
+ * Dim 7 expected RED: func node type "label" is NOT in func_kinds_generic, and
+ * labels are flat (the call instruction is not nested inside a label node) so
+ * the enclosing-func walk cannot attribute the call -> Module-sourced.
+ */
+TEST(repro_grammar_shells_nasm) {
+ static const char src[] =
+ "section .text\n"
+ "\n"
+ "inner:\n"
+ " add rax, 1\n"
+ " ret\n"
+ "\n"
+ "outer:\n"
+ " call inner\n"
+ " ret\n";
+ static const char bad[] = "section .text\nouter:\n call ";
+ if (sh_callable_battery("NASM", src, CBM_LANG_NASM, "prog.asm",
+ "Function", NULL, "inner") != 0)
+ return 1;
+ if (sh_robustness("NASM", bad, CBM_LANG_NASM, "prog.asm") != 0)
+ return 1;
+ return sh_pipeline_battery("NASM", "prog.asm", src);
+}
+
+/* ── JANET (structural only) ──────────────────────────────────────────────────
+ * Idiomatic Janet with a defn and a call. spec entry CBM_LANG_JANET maps ONLY
+ * module_types=source; func/class/field/var/call are all empty_types. So NO defs
+ * and NO calls are extracted from the grammar tree regardless of source content.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dims 5-8 SKIPPED: spec has no func/class/var/call types -- nothing extractable.
+ * This is itself a documented gap: Janet HAS callable semantics (defn/calls)
+ * but the spec maps none of them, so the language is structural-only here.
+ * Expected GREEN: dims 1-4 + R. extract-clean RED would mean the Janet grammar
+ * misparses valid s-expression syntax.
+ */
+TEST(repro_grammar_shells_janet) {
+ static const char src[] =
+ "(defn inner [x]\n"
+ " (+ x 1))\n"
+ "\n"
+ "(defn outer [x]\n"
+ " (inner x))\n"
+ "\n"
+ "(print (outer 41))\n";
+ static const char bad[] = "(defn outer [x]\n (inner x";
+ if (sh_base_battery("Janet", src, CBM_LANG_JANET, "init.janet") != 0)
+ return 1;
+ return sh_robustness("Janet", bad, CBM_LANG_JANET, "init.janet");
+}
+
+/* ── SMALI (structural with defs, no calls) ───────────────────────────────────
+ * Idiomatic Smali (Dalvik bytecode) with a class, a method, and a field.
+ * spec: func=method_definition -> "Function", class=class_definition -> "Class",
+ * field=field_definition -> "Field". call_types = empty_types (no CALLS dims).
+ *
+ * Dims asserted: 1-5 + R. Dim 5 asserts "Class", "Function", and "Field".
+ * Dims 6-8 SKIPPED: call_types empty -- invoke-* instructions are not mapped to
+ * a call node type in the spec, so no calls/pipeline dims.
+ * Expected GREEN: dims 1-5 + R. Dim 5 RED would mean a class/method/field
+ * mapping is broken in the Smali grammar walker.
+ */
+TEST(repro_grammar_shells_smali) {
+ static const char src[] =
+ ".class public LCalculator;\n"
+ ".super Ljava/lang/Object;\n"
+ "\n"
+ ".field private base:I\n"
+ "\n"
+ ".method public compute(I)I\n"
+ " .registers 3\n"
+ " add-int/lit8 v0, p1, 0x1\n"
+ " return v0\n"
+ ".end method\n";
+ static const char bad[] = ".class public LCalculator;\n.method public compute(I)I\n .registers";
+ if (sh_struct_battery("Smali", src, CBM_LANG_SMALI, "Calculator.smali",
+ "Class", "Function", "Field") != 0)
+ return 1;
+ return sh_robustness("Smali", bad, CBM_LANG_SMALI, "Calculator.smali");
+}
+
+/* ── DEVICETREE (structural) ──────────────────────────────────────────────────
+ * Idiomatic Device Tree source with nodes and properties. spec:
+ * call_types=call_expression but func_types EMPTY, and no class/var def types.
+ * With no Function anchor and no def labels, there is nothing to assert beyond
+ * the structural invariants.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dim 5 SKIPPED: no func/class/var types mapped -> no labelled defs expected.
+ * Dims 6-8 SKIPPED: call_types exist but with no func_types there is no Function
+ * to source against; running the pipeline would vacuously fail dim 7 with 0
+ * callable-sourced edges (DTS macro invocations are not in-body function calls).
+ * Expected GREEN: dims 1-4 + R. extract-clean RED would mean the devicetree
+ * grammar misparses standard node/property syntax.
+ */
+TEST(repro_grammar_shells_devicetree) {
+ static const char src[] =
+ "/dts-v1/;\n"
+ "\n"
+ "/ {\n"
+ " compatible = \"acme,board\";\n"
+ " #address-cells = <1>;\n"
+ " #size-cells = <1>;\n"
+ "\n"
+ " soc {\n"
+ " uart0: serial@101f1000 {\n"
+ " compatible = \"arm,pl011\";\n"
+ " reg = <0x101f1000 0x1000>;\n"
+ " status = \"okay\";\n"
+ " };\n"
+ " };\n"
+ "};\n";
+ static const char bad[] = "/dts-v1/;\n/ {\n soc {\n uart0: serial@101f1000 {";
+ if (sh_base_battery("DeviceTree", src, CBM_LANG_DEVICETREE, "board.dts") != 0)
+ return 1;
+ return sh_robustness("DeviceTree", bad, CBM_LANG_DEVICETREE, "board.dts");
+}
+
+/* ── KCONFIG (structural with defs, no calls) ─────────────────────────────────
+ * Idiomatic Kconfig with config entries and a menuconfig. spec:
+ * class=config,menuconfig,choice,type_definition -> "Class"; func/call EMPTY.
+ *
+ * Dims asserted: 1-5 + R. Dim 5 = "Class" (config/menuconfig -> Class).
+ * Dims 6-8 SKIPPED: no func_types/call_types.
+ * Expected GREEN: dims 1-5 + R. Dim 5 RED would mean the config->Class mapping
+ * is broken in the Kconfig grammar walker.
+ */
+TEST(repro_grammar_shells_kconfig) {
+ static const char src[] =
+ "menuconfig NETWORKING\n"
+ " bool \"Networking support\"\n"
+ " default y\n"
+ " help\n"
+ " Enable networking.\n"
+ "\n"
+ "config NET_IPV6\n"
+ " bool \"IPv6 support\"\n"
+ " depends on NETWORKING\n"
+ " default n\n";
+ static const char bad[] = "config NET_IPV6\n bool \"IPv6 support\"\n depends on";
+ if (sh_struct_battery("Kconfig", src, CBM_LANG_KCONFIG, "Kconfig",
+ "Class", NULL, NULL) != 0)
+ return 1;
+ return sh_robustness("Kconfig", bad, CBM_LANG_KCONFIG, "Kconfig");
+}
+
+/* ── HYPRLANG (pure structural) ───────────────────────────────────────────────
+ * Idiomatic Hyprland config with sections and key=value assignments. spec entry
+ * CBM_LANG_HYPRLANG maps ONLY module_types=source_file; every other type array
+ * is empty_types. No defs or calls are extracted.
+ *
+ * Dims asserted: 1-4 + R.
+ * Dims 5-8 SKIPPED: no func/class/var/call types in spec.
+ * Expected GREEN: dims 1-4 + R. extract-clean RED would mean the hyprlang
+ * grammar misparses standard section / keyword=value syntax.
+ */
+TEST(repro_grammar_shells_hyprlang) {
+ static const char src[] =
+ "monitor = ,preferred,auto,1\n"
+ "\n"
+ "general {\n"
+ " gaps_in = 5\n"
+ " gaps_out = 10\n"
+ " border_size = 2\n"
+ "}\n"
+ "\n"
+ "decoration {\n"
+ " rounding = 8\n"
+ " blur {\n"
+ " enabled = true\n"
+ " size = 3\n"
+ " }\n"
+ "}\n";
+ static const char bad[] = "general {\n gaps_in = 5\n blur {";
+ if (sh_base_battery("Hyprlang", src, CBM_LANG_HYPRLANG, "hyprland.conf") != 0)
+ return 1;
+ return sh_robustness("Hyprlang", bad, CBM_LANG_HYPRLANG, "hyprland.conf");
+}
+
+/* ── Suite ──────────────────────────────────────────────────────────────────── */
+
+SUITE(repro_grammar_shells) {
+ RUN_TEST(repro_grammar_shells_bash);
+ RUN_TEST(repro_grammar_shells_zsh);
+ RUN_TEST(repro_grammar_shells_fish);
+ RUN_TEST(repro_grammar_shells_powershell);
+ RUN_TEST(repro_grammar_shells_tcl);
+ RUN_TEST(repro_grammar_shells_awk);
+ RUN_TEST(repro_grammar_shells_vimscript);
+ RUN_TEST(repro_grammar_shells_fennel);
+ RUN_TEST(repro_grammar_shells_nix);
+ RUN_TEST(repro_grammar_shells_gdscript);
+ RUN_TEST(repro_grammar_shells_luau);
+ RUN_TEST(repro_grammar_shells_teal);
+ RUN_TEST(repro_grammar_shells_llvm_ir);
+ RUN_TEST(repro_grammar_shells_nasm);
+ RUN_TEST(repro_grammar_shells_janet);
+ RUN_TEST(repro_grammar_shells_smali);
+ RUN_TEST(repro_grammar_shells_devicetree);
+ RUN_TEST(repro_grammar_shells_kconfig);
+ RUN_TEST(repro_grammar_shells_hyprlang);
+}
diff --git a/tests/repro/repro_main.c b/tests/repro/repro_main.c
index 217591f4e..fdf4658bd 100644
--- a/tests/repro/repro_main.c
+++ b/tests/repro/repro_main.c
@@ -73,6 +73,8 @@ extern void suite_repro_grammar_functional(void);
extern void suite_repro_grammar_systems(void);
extern void suite_repro_grammar_web(void);
extern void suite_repro_grammar_config(void);
+extern void suite_repro_grammar_build(void);
+extern void suite_repro_grammar_shells(void);
/* Per-LSP-pass resolution-strategy invariants */
extern void suite_repro_lsp_c_cpp(void);
extern void suite_repro_lsp_go_py(void);
@@ -136,6 +138,8 @@ int main(void) {
RUN_SUITE(repro_grammar_systems);
RUN_SUITE(repro_grammar_web);
RUN_SUITE(repro_grammar_config);
+ RUN_SUITE(repro_grammar_build);
+ RUN_SUITE(repro_grammar_shells);
RUN_SUITE(repro_lsp_c_cpp);
RUN_SUITE(repro_lsp_go_py);
RUN_SUITE(repro_lsp_ts);