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): LSP-pass invariants — TS, Java/C#, Kotlin/PHP/Rust

Martin Vogel2128f2b118e0
diff --git a/Makefile.cbm b/Makefile.cbm
index b39de2928..35af94c7e 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -436,7 +436,10 @@ TEST_REPRO_SRCS = \
tests/repro/repro_grammar_systems.c \
tests/repro/repro_grammar_web.c \
tests/repro/repro_lsp_c_cpp.c \
- tests/repro/repro_lsp_go_py.c
+ tests/repro/repro_lsp_go_py.c \
+ tests/repro/repro_lsp_ts.c \
+ tests/repro/repro_lsp_java_cs.c \
+ tests/repro/repro_lsp_kt_php_rust.c
ALL_TEST_SRCS =$(TEST_FOUNDATION_SRCS) $(TEST_EXTRACTION_SRCS) $(TEST_STORE_SRCS) $(TEST_CYPHER_SRCS) $(TEST_MCP_SRCS) $(TEST_DISCOVER_SRCS) $(TEST_GRAPH_BUFFER_SRCS) $(TEST_PIPELINE_SRCS) $(TEST_WATCHER_SRCS) $(TEST_LZ4_SRCS) $(TEST_ZSTD_SRCS) $(TEST_ARTIFACT_SRCS) $(TEST_SQLITE_WRITER_SRCS) $(TEST_GO_LSP_SRCS) $(TEST_C_LSP_SRCS) $(TEST_PHP_LSP_SRCS) $(TEST_CS_LSP_SRCS) $(TEST_CS_LSP_BENCH_SRCS) $(TEST_SCOPE_SRCS) $(TEST_TYPE_REP_SRCS) $(TEST_PY_LSP_SRCS) $(TEST_PY_LSP_BENCH_SRCS) $(TEST_PY_LSP_STRESS_SRCS) $(TEST_PY_LSP_SCALE_SRCS) $(TEST_TS_LSP_SRCS) $(TEST_JAVA_LSP_SRCS) $(TEST_KOTLIN_LSP_SRCS) $(TEST_RUST_LSP_SRCS) $(TEST_TRACES_SRCS) $(TEST_CLI_SRCS) $(TEST_MEM_SRCS) $(TEST_UI_SRCS) $(TEST_HTTPD_SRCS) $(TEST_SECURITY_SRCS) $(TEST_YAML_SRCS) $(TEST_SIMHASH_SRCS) $(TEST_STACK_OVERFLOW_SRCS) $(TEST_INTEGRATION_SRCS)
diff --git a/tests/repro/repro_lsp_java_cs.c b/tests/repro/repro_lsp_java_cs.c
new file mode 100644
index 000000000..2f2936c9f
--- /dev/null
+++ b/tests/repro/repro_lsp_java_cs.c
@@ -0,0 +1,682 @@
+/*
+ * repro_lsp_java_cs.c — EXHAUSTIVE per-LSP-pass invariant suite for the Java
+ * (internal/cbm/lsp/java_lsp.c) and C# (internal/cbm/lsp/cs_lsp.c) hybrid LSPs.
+ *
+ * This MIRRORS repro_lsp_c_cpp.c: same shared assert_lsp_strategy runner, same
+ * two invariants per strategy (callable-sourcing floor + strategy-presence),
+ * one TEST per (language, strategy), a single SUITE(repro_lsp_java_cs).
+ *
+ * WHAT THIS ASSERTS — the LSP RESOLUTION CONTRACT, one invariant per strategy.
+ * Each cross resolver resolves a call via a specific STRATEGY and tags the
+ * resulting CALLS edge in its properties_json with "strategy":"<name>" (Java:
+ * java_emit_resolved, java_lsp.c; C#: cs_emit_resolved, cs_lsp.c). Each
+ * strategy keys on a precise language construct. This suite builds the MINIMAL
+ * fixture that exercises exactly one strategy, indexes it through the full
+ * production pipeline, and asserts TWO things:
+ * (a) callable-sourcing — the inner call is sourced at a Function/Method
+ * node, never at a Module/File node (inv_count_calls_by_source ->
+ * module_sourced == 0). A Module-sourced call is the #554 attribution
+ * bug; this is the broad correctness floor.
+ * (b) strategy-presence — some CALLS edge carries the exact strategy string
+ * in its properties_json (inv_edge_has_strategy). This is the PRECISE
+ * per-pass invariant: it proves that exact resolution path fired and
+ * survived into the graph.
+ *
+ * CRITICAL NAMING DIFFERENCE FROM C/C++ AND JAVA — C# strategies are NOT
+ * "lsp_*". The C/C++ resolver and the Java resolver both emit "lsp_<name>"
+ * strings, but cs_lsp.c emits "cs_<name>" strings (cs_emit_resolved sites,
+ * cs_lsp.c:1468-1604). The task brief assumed C# emitted lsp_interface_resolve
+ * / lsp_method_dispatch / lsp_static_import — those are JAVA strategies; C#
+ * has its own "cs_" vocabulary. The fixtures below use the ACTUAL strings
+ * grepped from each source, not the assumed ones.
+ *
+ * RED vs GREEN — this is a STATUS BOARD, not a pass/fail gate (runs only under
+ * make test-repro / bug-repro.yml, never the branch-protection ci-ok gate):
+ * - GREEN = the LSP strategy works end-to-end = a permanent regression
+ * guard that it keeps working.
+ * - RED = the strategy is dropped, or the call lands Module-sourced, or
+ * the rescue is discarded. Either way the per-pass TEST DOCUMENTS
+ * the exact gap for the eventual fixer.
+ *
+ * Like repro_invariant_lsp_rescue.c, a strategy correctly EMITTED by the
+ * resolver can still be ABSENT here if cbm_pipeline_find_lsp_resolution
+ * (src/pipeline/lsp_resolve.h) fails to join the LSP-resolved call to the
+ * tree-sitter call by exact caller-QN equality (#554). The in-line / method
+ * fixtures below keep the call inside a real callable so the join target is a
+ * method QN, not the module QN.
+ *
+ * JAVA STRATEGY INVENTORY — every literal "lsp_..." emitted by java_lsp.c,
+ * grepped from source (grep '"lsp_' internal/cbm/lsp/java_lsp.c):
+ * lsp_type_dispatch (1823/1923) obj.method() / bare call on own class
+ * lsp_inherited_dispatch (1825/1925) call to an INHERITED (base) method
+ * lsp_outer_dispatch (1839) bare call resolved on an OUTER class
+ * lsp_static_import (1856) bare call via `import static`, method indexed
+ * lsp_static_import_text (1861) `import static`, method NOT in registry
+ * lsp_super_dispatch (1875) super.method()
+ * lsp_this_dispatch (1888) this.method()
+ * lsp_static_call (1904) ClassName.staticMethod()
+ * lsp_interface_resolve (1985) iface-typed call, SOLE concrete impl
+ * lsp_interface_dispatch (1990) iface-typed call, no sole impl
+ * lsp_method_ref_ctor (2591) ClassName::new, ctor indexed
+ * lsp_method_ref_ctor_synth(2594) ClassName::new, ctor NOT in registry
+ * lsp_method_ref (2614) Type::instanceMethod reference
+ * lsp_constructor (2787) new Foo(), ctor indexed
+ * lsp_constructor_synth (2792) new Foo(), ctor NOT in registry
+ * lsp_unresolved (1801) fallback marker for an unresolved call
+ *
+ * C# STRATEGY INVENTORY — every literal "cs_..." emitted by cs_lsp.c, grepped
+ * from source (grep '"cs_' internal/cbm/lsp/cs_lsp.c):
+ * cs_static_typed (1468) Type.StaticMethod(), method indexed
+ * cs_static_typed_unindexed (1472) Type.StaticMethod(), method NOT in registry
+ * cs_method_typed (1494) obj.Method() on own declared type
+ * cs_method_inherited (1495) obj.Method() resolved on a BASE type
+ * cs_extension_method (1502) obj.Ext() where Ext is an extension method
+ * cs_method_typed_unindexed (1508) receiver type known, method NOT in registry
+ * cs_self_method (1523) bare Method() resolved on enclosing class
+ * cs_inherited_method (1533) bare Method() resolved on enclosing BASE
+ * cs_using_static (1543) bare Method() via `using static`
+ * cs_namespace_func (1554) bare free function in current namespace
+ * cs_free_func_fallback (1581) bare call matched to any free func by name
+ * cs_ctor (1599) new Foo(), ctor indexed
+ * cs_ctor_synthetic (1603) new Foo(), ctor NOT in registry
+ *
+ * NOTE: line comments only inside this header (no nested block comments, per
+ * coding rules).
+ */
+
+#include "test_framework.h"
+#include "repro_invariant_lib.h"
+#include <store/store.h>
+
+#include <string.h>
+
+/* ── Shared per-strategy runner (DRY) — identical contract to repro_lsp_c_cpp.c
+ *
+ * Index a single-file fixture and assert the per-pass LSP RESOLUTION CONTRACT:
+ * 1. the store opened (a setup failure is a FAIL, not a skip);
+ * 2. callable-sourcing: NO CALLS edge is Module/File-sourced, and at least one
+ * callable-sourced CALLS edge exists (else there is no signal at all);
+ * 3. strategy-presence: some CALLS edge carries the strategy in its
+ * properties_json.
+ *
+ * `filename` selects the language by extension (".java" -> Java pass, ".cs" ->
+ * C# pass) exactly as the production indexer does. Returns 0 on PASS (GREEN),
+ * non-zero on FAIL (RED) — the redness is the documented per-pass status.
+ * ───────────────────────────────────────────────────────────────────────── */
+static int assert_lsp_strategy(const char *filename, const char *src,
+ const char *strategy) {
+ RProj lp;
+ cbm_store_t *store = rh_index(&lp, filename, src);
+ if (!store) {
+ printf(" %sFAIL%s %s:%d: index failed for strategy %s\n", tf_red(),
+ tf_reset(), __FILE__, __LINE__, strategy);
+ rh_cleanup(&lp, store);
+ return 1;
+ }
+
+ int module_sourced = -1;
+ int callable_sourced = -1;
+ inv_count_calls_by_source(store, lp.project, &module_sourced,
+ &callable_sourced);
+
+ int has_strategy = inv_edge_has_strategy(store, lp.project, strategy);
+
+ int rc = 0;
+
+ /* (a) callable-sourcing floor: zero Module/File-sourced CALLS edges. */
+ if (module_sourced != 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: %d Module-sourced CALLS "
+ "(expected 0)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ module_sourced);
+ rc = 1;
+ }
+ /* There must be a callable-sourced CALLS edge, else the fixture produced no
+ * call signal and the strategy assertion below would be vacuous. */
+ if (callable_sourced <= 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: no callable-sourced CALLS edge "
+ "(callable=%d)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ callable_sourced);
+ rc = 1;
+ }
+
+ /* (b) the precise per-pass invariant: the resolution strategy is present. */
+ if (!has_strategy) {
+ printf(" %sFAIL%s %s:%d: strategy %s ABSENT from any CALLS edge "
+ "properties_json\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy);
+ rc = 1;
+ }
+
+ rh_cleanup(&lp, store);
+ return rc;
+}
+
+/* ── Java fixtures ───────────────────────────────────────────────────────────
+ *
+ * Each fixture is the MINIMAL construct java_lsp.c keys on for one strategy. The
+ * call we care about lives inside a method so callable-sourcing is testable; the
+ * callee is also declared in-file so the registry can resolve it.
+ * ───────────────────────────────────────────────────────────────────────── */
+
+/* lsp_type_dispatch — instance call obj.method() on the object's OWN declared
+ * type (java_lsp.c:1923; receiver_type == recv_qn). */
+static const char kJavaTypeDispatch[] =
+ "class Counter {\n"
+ " int inc(int x) { return x + 1; }\n"
+ " int run() {\n"
+ " Counter c = new Counter();\n"
+ " return c.inc(1);\n"
+ " }\n"
+ "}\n";
+
+/* lsp_inherited_dispatch — instance call to an INHERITED method the receiver
+ * type does not declare (java_lsp.c:1924-1925; the resolved method's
+ * receiver_type differs from the receiver QN). */
+static const char kJavaInheritedDispatch[] =
+ "class Base {\n"
+ " int common(int x) { return x + 100; }\n"
+ "}\n"
+ "class Derived extends Base {\n"
+ " int run() {\n"
+ " Derived d = new Derived();\n"
+ " return d.common(5);\n"
+ " }\n"
+ "}\n";
+
+/* lsp_outer_dispatch — a bare call inside an inner class resolves against an
+ * OUTER enclosing class (java_lsp.c:1833-1839). */
+static const char kJavaOuterDispatch[] =
+ "class Outer {\n"
+ " int helper(int x) { return x + 2; }\n"
+ " class Inner {\n"
+ " int run(int v) { return helper(v); }\n"
+ " }\n"
+ "}\n";
+
+/* lsp_static_import — a bare call resolved through `import static` where the
+ * imported method IS in the registry (java_lsp.c:1844-1856). The same file
+ * declares Util.twice and statically imports it. */
+static const char kJavaStaticImport[] =
+ "import static demo.Util.twice;\n"
+ "package demo;\n"
+ "class Util {\n"
+ " static int twice(int x) { return x * 2; }\n"
+ "}\n"
+ "class Client {\n"
+ " int run(int v) { return twice(v); }\n"
+ "}\n";
+
+/* lsp_static_import_text — `import static` to a method NOT present in the
+ * registry; the resolver emits the qualified import target as a text fallback
+ * (java_lsp.c:1859-1861). The imported class is external (not declared here). */
+static const char kJavaStaticImportText[] =
+ "import static java.lang.Math.max;\n"
+ "class Client {\n"
+ " int run(int a, int b) { return max(a, b); }\n"
+ "}\n";
+
+/* lsp_super_dispatch — super.method() resolves on the superclass
+ * (java_lsp.c:1869-1875). */
+static const char kJavaSuperDispatch[] =
+ "class Base {\n"
+ " int greet(int x) { return x; }\n"
+ "}\n"
+ "class Derived extends Base {\n"
+ " int greet(int x) { return super.greet(x) + 1; }\n"
+ "}\n";
+
+/* lsp_this_dispatch — this.method() resolves on the enclosing class
+ * (java_lsp.c:1882-1888). */
+static const char kJavaThisDispatch[] =
+ "class Widget {\n"
+ " int helper(int x) { return x * 2; }\n"
+ " int compute(int x) { return this.helper(x) + 1; }\n"
+ "}\n";
+
+/* lsp_static_call — ClassName.staticMethod() where the class name resolves to a
+ * registered type and the receiver is NOT a bound variable (java_lsp.c:1896-1904). */
+static const char kJavaStaticCall[] =
+ "class MathUtil {\n"
+ " static int square(int x) { return x * x; }\n"
+ "}\n"
+ "class Client {\n"
+ " int run(int v) { return MathUtil.square(v); }\n"
+ "}\n";
+
+/* lsp_interface_resolve — a call through an interface-typed receiver where the
+ * interface has exactly ONE concrete implementer in the registry; the call is
+ * resolved to that sole impl (java_lsp.c:1932-1985). */
+static const char kJavaInterfaceResolve[] =
+ "interface Shape {\n"
+ " int area();\n"
+ "}\n"
+ "class Square implements Shape {\n"
+ " public int area() { return 4; }\n"
+ "}\n"
+ "class Client {\n"
+ " int run(Shape s) { return s.area(); }\n"
+ "}\n";
+
+/* lsp_interface_dispatch — a call through an interface-typed receiver with NO
+ * sole concrete impl (two implementers), so the resolver falls back to a
+ * synthesized iface-qualified target (java_lsp.c:1989-1990). */
+static const char kJavaInterfaceDispatch[] =
+ "interface Shape {\n"
+ " int area();\n"
+ "}\n"
+ "class Square implements Shape {\n"
+ " public int area() { return 4; }\n"
+ "}\n"
+ "class Circle implements Shape {\n"
+ " public int area() { return 3; }\n"
+ "}\n"
+ "class Client {\n"
+ " int run(Shape s) { return s.area(); }\n"
+ "}\n";
+
+/* lsp_method_ref_ctor — a constructor reference ClassName::new whose ctor IS in
+ * the registry (java_lsp.c:2584-2591). The SAM is a Supplier-shaped iface. */
+static const char kJavaMethodRefCtor[] =
+ "interface Maker {\n"
+ " Foo make();\n"
+ "}\n"
+ "class Foo {\n"
+ " Foo() {}\n"
+ "}\n"
+ "class Client {\n"
+ " Maker run() { return Foo::new; }\n"
+ "}\n";
+
+/* lsp_method_ref_ctor_synth — a constructor reference ClassName::new whose ctor
+ * is NOT in the registry, so the resolver synthesizes the ctor QN
+ * (java_lsp.c:2592-2594). Foo declares no explicit constructor. */
+static const char kJavaMethodRefCtorSynth[] =
+ "interface Maker {\n"
+ " Foo make();\n"
+ "}\n"
+ "class Foo {\n"
+ " int value;\n"
+ "}\n"
+ "class Client {\n"
+ " Maker run() { return Foo::new; }\n"
+ "}\n";
+
+/* lsp_method_ref — an instance method reference Type::method
+ * (java_lsp.c:2604-2614). Helper::twice is referenced via a unary-op SAM. */
+static const char kJavaMethodRef[] =
+ "interface IntOp {\n"
+ " int apply(Helper h, int x);\n"
+ "}\n"
+ "class Helper {\n"
+ " int twice(int x) { return x * 2; }\n"
+ "}\n"
+ "class Client {\n"
+ " IntOp run() { return Helper::twice; }\n"
+ "}\n";
+
+/* lsp_constructor — new Foo() whose ctor IS in the registry
+ * (java_lsp.c:2767-2787). */
+static const char kJavaConstructor[] =
+ "class Foo {\n"
+ " Foo(int x) {}\n"
+ "}\n"
+ "class Client {\n"
+ " Foo run(int v) { return new Foo(v); }\n"
+ "}\n";
+
+/* lsp_constructor_synth — new Foo() where Foo has no explicit constructor in the
+ * registry, so the resolver synthesizes the ctor QN (java_lsp.c:2788-2792). */
+static const char kJavaConstructorSynth[] =
+ "class Foo {\n"
+ " int value;\n"
+ "}\n"
+ "class Client {\n"
+ " Foo run() { return new Foo(); }\n"
+ "}\n";
+
+/* lsp_unresolved — a bare call with no enclosing-class match and no static
+ * import; java_emit_resolved sets "lsp_unresolved" only on the NULL-callee
+ * diagnostic path (java_lsp.c:1801). The more common unresolved path is
+ * java_emit_unresolved with a different reason marker, so this strategy may be
+ * ABSENT (RED) — the TEST documents whether the literal "lsp_unresolved"
+ * surfaces on a CALLS edge at all. */
+static const char kJavaUnresolved[] =
+ "class Client {\n"
+ " int run(int v) { return totallyUnknownFn(v); }\n"
+ "}\n";
+
+/* ── C# fixtures ─────────────────────────────────────────────────────────────
+ *
+ * Each fixture is the MINIMAL construct cs_lsp.c keys on for one strategy
+ * (cs_emit_resolved sites, cs_lsp.c:1468-1604). C# strategies are "cs_*".
+ * ───────────────────────────────────────────────────────────────────────── */
+
+/* cs_static_typed — Type.StaticMethod() where the type and method ARE indexed
+ * (cs_lsp.c:1464-1468). */
+static const char kCsStaticTyped[] =
+ "class MathUtil {\n"
+ " public static int Square(int x) { return x * x; }\n"
+ "}\n"
+ "class Client {\n"
+ " public int Run(int v) { return MathUtil.Square(v); }\n"
+ "}\n";
+
+/* cs_static_typed_unindexed — Type.StaticMethod() where the receiver TYPE is
+ * known but the method is NOT in the registry, so a synthetic target is emitted
+ * (cs_lsp.c:1471-1474). Helper declares no Missing method. */
+static const char kCsStaticTypedUnindexed[] =
+ "class Helper {\n"
+ " public static int Known() { return 1; }\n"
+ "}\n"
+ "class Client {\n"
+ " public int Run() { return Helper.Missing(); }\n"
+ "}\n";
+
+/* cs_method_typed — obj.Method() on the object's OWN declared type
+ * (cs_lsp.c:1492-1496; receiver_type == type_qn). */
+static const char kCsMethodTyped[] =
+ "class Counter {\n"
+ " public int Inc(int x) { return x + 1; }\n"
+ " public int Run() {\n"
+ " Counter c = new Counter();\n"
+ " return c.Inc(1);\n"
+ " }\n"
+ "}\n";
+
+/* cs_method_inherited — obj.Method() resolved on a BASE type the receiver does
+ * not declare (cs_lsp.c:1492-1496; resolved method's receiver_type != type_qn). */
+static const char kCsMethodInherited[] =
+ "class Base {\n"
+ " public int Common(int x) { return x + 100; }\n"
+ "}\n"
+ "class Derived : Base {\n"
+ " public int Run() {\n"
+ " Derived d = new Derived();\n"
+ " return d.Common(5);\n"
+ " }\n"
+ "}\n";
+
+/* cs_extension_method — obj.Ext() where Ext is a static extension method
+ * (`this Counter c`) found via cs_lookup_extension (cs_lsp.c:1500-1502). */
+static const char kCsExtensionMethod[] =
+ "class Counter {\n"
+ " public int value;\n"
+ "}\n"
+ "static class CounterExt {\n"
+ " public static int Doubled(this Counter c) { return c.value * 2; }\n"
+ "}\n"
+ "class Client {\n"
+ " public int Run(Counter c) { return c.Doubled(); }\n"
+ "}\n";
+
+/* cs_method_typed_unindexed — receiver type is KNOWN but the called instance
+ * method is NOT in the registry (and no extension matches), so a synthetic
+ * target is emitted (cs_lsp.c:1505-1509). */
+static const char kCsMethodTypedUnindexed[] =
+ "class Counter {\n"
+ " public int Inc(int x) { return x + 1; }\n"
+ "}\n"
+ "class Client {\n"
+ " public int Run(Counter c) { return c.Missing(); }\n"
+ "}\n";
+
+/* cs_self_method — a bare Method() resolved on the enclosing class
+ * (cs_lsp.c:1519-1523). */
+static const char kCsSelfMethod[] =
+ "class Widget {\n"
+ " public int Helper(int x) { return x * 2; }\n"
+ " public int Compute(int x) { return Helper(x) + 1; }\n"
+ "}\n";
+
+/* cs_inherited_method — a bare Method() resolved on the enclosing class's BASE
+ * (cs_lsp.c:1530-1533; resolved via ctx->enclosing_base_qn). */
+static const char kCsInheritedMethod[] =
+ "class Base {\n"
+ " public int Shared(int x) { return x + 7; }\n"
+ "}\n"
+ "class Derived : Base {\n"
+ " public int Run(int v) { return Shared(v); }\n"
+ "}\n";
+
+/* cs_using_static — a bare Method() resolved through `using static`
+ * (cs_lsp.c:1537-1543). The same file declares the imported class. */
+static const char kCsUsingStatic[] =
+ "using static Demo.MathUtil;\n"
+ "namespace Demo {\n"
+ " static class MathUtil {\n"
+ " public static int Twice(int x) { return x * 2; }\n"
+ " }\n"
+ " class Client {\n"
+ " public int Run(int v) { return Twice(v); }\n"
+ " }\n"
+ "}\n";
+
+/* cs_namespace_func — a bare call to a free function declared in the current
+ * namespace (cs_lsp.c:1548-1554). C# top-level functions live as members; this
+ * exercises the namespace-qualified free-function lookup path. */
+static const char kCsNamespaceFunc[] =
+ "namespace Demo {\n"
+ " class Helpers {\n"
+ " public static int Helper(int x) { return x + 3; }\n"
+ " }\n"
+ " class Client {\n"
+ " public int Run(int v) { return Helper(v); }\n"
+ " }\n"
+ "}\n";
+
+/* cs_free_func_fallback — last-resort match of a bare call to any free function
+ * with the same short name in the registry, scored by module-path overlap
+ * (cs_lsp.c:1558-1581). The called name is declared static elsewhere and reached
+ * only by this fallback. */
+static const char kCsFreeFuncFallback[] =
+ "namespace A {\n"
+ " class Provider {\n"
+ " public static int Compute(int x) { return x * 5; }\n"
+ " }\n"
+ "}\n"
+ "namespace B {\n"
+ " class Client {\n"
+ " public int Run(int v) { return Compute(v); }\n"
+ " }\n"
+ "}\n";
+
+/* cs_ctor — new Foo() whose constructor IS in the registry
+ * (cs_lsp.c:1597-1599). */
+static const char kCsCtor[] =
+ "class Foo {\n"
+ " public Foo(int x) {}\n"
+ "}\n"
+ "class Client {\n"
+ " public Foo Run(int v) { return new Foo(v); }\n"
+ "}\n";
+
+/* cs_ctor_synthetic — new Foo() where Foo declares no explicit constructor, so
+ * the resolver synthesizes the Foo..ctor target (cs_lsp.c:1602-1604). */
+static const char kCsCtorSynthetic[] =
+ "class Foo {\n"
+ " public int Value;\n"
+ "}\n"
+ "class Client {\n"
+ " public Foo Run() { return new Foo(); }\n"
+ "}\n";
+
+/* ── Java per-strategy tests ─────────────────────────────────────────────── */
+
+TEST(repro_lsp_java_type_dispatch) {
+ return assert_lsp_strategy("Counter.java", kJavaTypeDispatch,
+ "lsp_type_dispatch");
+}
+
+TEST(repro_lsp_java_inherited_dispatch) {
+ return assert_lsp_strategy("Derived.java", kJavaInheritedDispatch,
+ "lsp_inherited_dispatch");
+}
+
+TEST(repro_lsp_java_outer_dispatch) {
+ return assert_lsp_strategy("Outer.java", kJavaOuterDispatch,
+ "lsp_outer_dispatch");
+}
+
+TEST(repro_lsp_java_static_import) {
+ return assert_lsp_strategy("Client.java", kJavaStaticImport,
+ "lsp_static_import");
+}
+
+TEST(repro_lsp_java_static_import_text) {
+ return assert_lsp_strategy("Client.java", kJavaStaticImportText,
+ "lsp_static_import_text");
+}
+
+TEST(repro_lsp_java_super_dispatch) {
+ return assert_lsp_strategy("Derived.java", kJavaSuperDispatch,
+ "lsp_super_dispatch");
+}
+
+TEST(repro_lsp_java_this_dispatch) {
+ return assert_lsp_strategy("Widget.java", kJavaThisDispatch,
+ "lsp_this_dispatch");
+}
+
+TEST(repro_lsp_java_static_call) {
+ return assert_lsp_strategy("Client.java", kJavaStaticCall,
+ "lsp_static_call");
+}
+
+TEST(repro_lsp_java_interface_resolve) {
+ return assert_lsp_strategy("Client.java", kJavaInterfaceResolve,
+ "lsp_interface_resolve");
+}
+
+TEST(repro_lsp_java_interface_dispatch) {
+ return assert_lsp_strategy("Client.java", kJavaInterfaceDispatch,
+ "lsp_interface_dispatch");
+}
+
+TEST(repro_lsp_java_method_ref_ctor) {
+ return assert_lsp_strategy("Client.java", kJavaMethodRefCtor,
+ "lsp_method_ref_ctor");
+}
+
+TEST(repro_lsp_java_method_ref_ctor_synth) {
+ return assert_lsp_strategy("Client.java", kJavaMethodRefCtorSynth,
+ "lsp_method_ref_ctor_synth");
+}
+
+TEST(repro_lsp_java_method_ref) {
+ return assert_lsp_strategy("Client.java", kJavaMethodRef, "lsp_method_ref");
+}
+
+TEST(repro_lsp_java_constructor) {
+ return assert_lsp_strategy("Client.java", kJavaConstructor,
+ "lsp_constructor");
+}
+
+TEST(repro_lsp_java_constructor_synth) {
+ return assert_lsp_strategy("Client.java", kJavaConstructorSynth,
+ "lsp_constructor_synth");
+}
+
+TEST(repro_lsp_java_unresolved) {
+ return assert_lsp_strategy("Client.java", kJavaUnresolved, "lsp_unresolved");
+}
+
+/* ── C# per-strategy tests ───────────────────────────────────────────────── */
+
+TEST(repro_lsp_cs_static_typed) {
+ return assert_lsp_strategy("Client.cs", kCsStaticTyped, "cs_static_typed");
+}
+
+TEST(repro_lsp_cs_static_typed_unindexed) {
+ return assert_lsp_strategy("Client.cs", kCsStaticTypedUnindexed,
+ "cs_static_typed_unindexed");
+}
+
+TEST(repro_lsp_cs_method_typed) {
+ return assert_lsp_strategy("Counter.cs", kCsMethodTyped, "cs_method_typed");
+}
+
+TEST(repro_lsp_cs_method_inherited) {
+ return assert_lsp_strategy("Derived.cs", kCsMethodInherited,
+ "cs_method_inherited");
+}
+
+TEST(repro_lsp_cs_extension_method) {
+ return assert_lsp_strategy("Client.cs", kCsExtensionMethod,
+ "cs_extension_method");
+}
+
+TEST(repro_lsp_cs_method_typed_unindexed) {
+ return assert_lsp_strategy("Client.cs", kCsMethodTypedUnindexed,
+ "cs_method_typed_unindexed");
+}
+
+TEST(repro_lsp_cs_self_method) {
+ return assert_lsp_strategy("Widget.cs", kCsSelfMethod, "cs_self_method");
+}
+
+TEST(repro_lsp_cs_inherited_method) {
+ return assert_lsp_strategy("Derived.cs", kCsInheritedMethod,
+ "cs_inherited_method");
+}
+
+TEST(repro_lsp_cs_using_static) {
+ return assert_lsp_strategy("Client.cs", kCsUsingStatic, "cs_using_static");
+}
+
+TEST(repro_lsp_cs_namespace_func) {
+ return assert_lsp_strategy("Client.cs", kCsNamespaceFunc,
+ "cs_namespace_func");
+}
+
+TEST(repro_lsp_cs_free_func_fallback) {
+ return assert_lsp_strategy("Client.cs", kCsFreeFuncFallback,
+ "cs_free_func_fallback");
+}
+
+TEST(repro_lsp_cs_ctor) {
+ return assert_lsp_strategy("Client.cs", kCsCtor, "cs_ctor");
+}
+
+TEST(repro_lsp_cs_ctor_synthetic) {
+ return assert_lsp_strategy("Client.cs", kCsCtorSynthetic,
+ "cs_ctor_synthetic");
+}
+
+/* ── Suite ───────────────────────────────────────────────────────────────── */
+
+SUITE(repro_lsp_java_cs) {
+ /* Java passes. */
+ RUN_TEST(repro_lsp_java_type_dispatch);
+ RUN_TEST(repro_lsp_java_inherited_dispatch);
+ RUN_TEST(repro_lsp_java_outer_dispatch);
+ RUN_TEST(repro_lsp_java_static_import);
+ RUN_TEST(repro_lsp_java_static_import_text);
+ RUN_TEST(repro_lsp_java_super_dispatch);
+ RUN_TEST(repro_lsp_java_this_dispatch);
+ RUN_TEST(repro_lsp_java_static_call);
+ RUN_TEST(repro_lsp_java_interface_resolve);
+ RUN_TEST(repro_lsp_java_interface_dispatch);
+ RUN_TEST(repro_lsp_java_method_ref_ctor);
+ RUN_TEST(repro_lsp_java_method_ref_ctor_synth);
+ RUN_TEST(repro_lsp_java_method_ref);
+ RUN_TEST(repro_lsp_java_constructor);
+ RUN_TEST(repro_lsp_java_constructor_synth);
+ RUN_TEST(repro_lsp_java_unresolved);
+
+ /* C# passes. */
+ RUN_TEST(repro_lsp_cs_static_typed);
+ RUN_TEST(repro_lsp_cs_static_typed_unindexed);
+ RUN_TEST(repro_lsp_cs_method_typed);
+ RUN_TEST(repro_lsp_cs_method_inherited);
+ RUN_TEST(repro_lsp_cs_extension_method);
+ RUN_TEST(repro_lsp_cs_method_typed_unindexed);
+ RUN_TEST(repro_lsp_cs_self_method);
+ RUN_TEST(repro_lsp_cs_inherited_method);
+ RUN_TEST(repro_lsp_cs_using_static);
+ RUN_TEST(repro_lsp_cs_namespace_func);
+ RUN_TEST(repro_lsp_cs_free_func_fallback);
+ RUN_TEST(repro_lsp_cs_ctor);
+ RUN_TEST(repro_lsp_cs_ctor_synthetic);
+}
diff --git a/tests/repro/repro_lsp_kt_php_rust.c b/tests/repro/repro_lsp_kt_php_rust.c
new file mode 100644
index 000000000..fb80765ec
--- /dev/null
+++ b/tests/repro/repro_lsp_kt_php_rust.c
@@ -0,0 +1,632 @@
+/*
+ * repro_lsp_kt_php_rust.c — EXHAUSTIVE per-LSP-pass invariant suite for the
+ * Kotlin, PHP and Rust hybrid LSPs
+ * (internal/cbm/lsp/kotlin_lsp.c, php_lsp.c, rust_lsp.c).
+ *
+ * MIRRORS repro_lsp_c_cpp.c exactly: same shared assert_lsp_strategy runner,
+ * same two invariants per (lang,strategy) — (a) inv_count_calls_by_source
+ * module_sourced == 0 and a callable-sourced CALLS edge exists, and (b)
+ * inv_edge_has_strategy(store, project, "<strategy>"). One TEST per
+ * (lang,strategy); SUITE(repro_lsp_kt_php_rust) at the bottom.
+ *
+ * WHAT THIS ASSERTS — the LSP RESOLUTION CONTRACT, one invariant per strategy.
+ * Each hybrid LSP resolves a call via a specific STRATEGY and tags the
+ * resulting CALLS edge in its properties_json with a literal strategy string.
+ * The minimal fixture exercises exactly one strategy, indexes it through the
+ * full production pipeline (language picked from the file extension: ".kt" →
+ * Kotlin, ".php" → PHP, ".rs" → Rust), and asserts:
+ * (a) callable-sourcing — the inner call is sourced at a Function/Method
+ * node, never at a Module/File node (the #554 attribution bug).
+ * (b) strategy-presence — some CALLS edge carries the strategy literal in
+ * its properties_json (inv_edge_has_strategy, substring match).
+ *
+ * STRATEGY-STRING NOTE — the assertion string is the ACTUAL literal each LSP
+ * emits (substring-matched by inv_edge_has_strategy), NOT a uniform
+ * "lsp_<name>" mould:
+ * - Kotlin emits "lsp_kt_*" (kt_emit_resolved, kotlin_lsp.c:299).
+ * - PHP emits mostly "php_*" plus "lsp_unresolved" (emit_resolved /
+ * emit_unresolved, php_lsp.c:1238/1251). The "php_*" literals are the
+ * real keys — the reference suite's "lsp_<strategy>" shorthand does not
+ * apply to PHP, so the assertions below use the php_* literals verbatim.
+ * - Rust emits "lsp_*" (rust_emit_resolved_call, rust_lsp.c).
+ *
+ * RED vs GREEN — STATUS BOARD, not a pass/fail gate (runs only under
+ * make test-repro / bug-repro.yml, never the branch-protection ci-ok gate):
+ * - GREEN = the strategy works end-to-end = a permanent regression guard.
+ * - RED = the strategy is dropped, lands Module-sourced, or never reaches
+ * the graph. The TEST documents the exact gap for the fixer.
+ *
+ * RUST CROSS-LSP IS NOT WIRED (documented gap). src/pipeline/pass_lsp_cross.c
+ * has NO CBM_LANG_RUST case in either cbm_pxc_has_cross_lsp (lines 282-298)
+ * or the cbm_pxc_run_one dispatch (lines 372-407). Go/C/C++/Python/PHP/Java/
+ * Kotlin are wired; Rust is absent. So rust_lsp.c can EMIT every strategy
+ * below, but those resolved calls never reach pass_lsp_cross → never become
+ * tagged CALLS edges in the graph. Every Rust strategy test is therefore
+ * expected RED until rust_lsp.c is wired into the pipeline. We assert the
+ * CORRECT (resolved) outcome anyway, per the reproduce-first contract: the
+ * red test is the durable record of the gap and turns GREEN the moment Rust
+ * is wired and resolving correctly.
+ *
+ * SKIPPED STRATEGIES (documented, not tested):
+ * Kotlin:
+ * - lsp_kt_safe — listed in the kotlin_lsp.c header comment (line 32) but
+ * NEVER emitted: grep for the literal finds only the
+ * header. A `obj?.foo()` safe call routes through the
+ * generic navigation handler and emits "lsp_kt_method"
+ * (kt_eval_navigation_expression_type does not branch on
+ * `?.` vs `.`). No fixture can produce "lsp_kt_safe".
+ * - lsp_kt_import — likewise header-only (line 34), never emitted. Import
+ * targets surface through the top-level / method paths.
+ * Rust:
+ * - lsp_mod_decl — emitted (rust_lsp.c:4347) but DELIBERATELY Module-
+ * sourced: it temporarily sets enclosing_func_qn =
+ * module_qn so the edge is attributed to the file's
+ * synthetic module scope (a `mod foo;` declaration has no
+ * enclosing callable). It would violate invariant (a)
+ * (module_sourced == 0) by construction, so the shared
+ * runner cannot express it. Also blocked by the unwired-
+ * Rust gap above.
+ * - lsp_deref_dispatch / lsp_bound_dispatch / lsp_prelude_trait /
+ * lsp_short_name_unique / lsp_trait_ufcs_amb — emitted on harder-to-
+ * fixture paths (Deref chains, type-param bounds, prelude best-effort,
+ * crate-prefix short-name scan, multi-impl ambiguity). They are all also
+ * blocked by the unwired-Rust gap, so adding fragile fixtures for them
+ * buys nothing over the representative dispatch tests below; skipped.
+ *
+ * STRATEGY INVENTORIES — every strategy literal grepped from each source:
+ * Kotlin (kotlin_lsp.c, grep '"lsp_kt_'):
+ * lsp_kt_constructor (2248) Foo() / Foo(args)
+ * lsp_kt_top_level (2256) bare top-level fun call
+ * lsp_kt_method (2426) receiver.method() with known receiver type
+ * lsp_kt_static (2443) Foo.bar() on object / companion
+ * lsp_kt_extension (2461) extension function dispatch
+ * lsp_kt_this (2232/2398) this.foo() with resolved this-type
+ * lsp_kt_super (2385) super.foo()
+ * lsp_kt_operator (1977/2028/2052/2069) operator overload (a + b → plus)
+ * lsp_kt_callable_ref (2123/2131) Foo::bar callable reference
+ * lsp_kt_lambda_it (2474) it.foo() inside scope-function lambda
+ * lsp_kt_any (2500) toString/equals/hashCode on unknown receiver
+ * lsp_kt_destructure (2569) val (a, b) = pair → componentN()
+ * lsp_kt_delegate (2625/2634) by lazy { } → getValue/setValue
+ * lsp_kt_iterator (2835) for (x in xs) → iterator/hasNext/next
+ * lsp_kt_safe (header only — NOT emitted, skipped)
+ * lsp_kt_import (header only — NOT emitted, skipped)
+ * PHP (php_lsp.c, grep '"(php|lsp)_'):
+ * php_function_namespaced (1445/1455) ns\helper() resolved by use/ns
+ * php_function_global_fallback (1487) bare helper() global fallback
+ * php_method_typed (1522) $x->m() with $x typed to the class
+ * php_method_inherited (1523) $x->m() resolved on a parent class
+ * php_method_dynamic (1530) $x->m() via __call magic method
+ * php_method_typed_unindexed (1539) receiver known, method not indexed
+ * php_static_resolved (1552) Foo::bar() static call
+ * php_self_static (1558/1561) self::/parent:: static call
+ * php_dynamic_unresolved (1578) Facade::m() via __callStatic
+ * php_static_unindexed (1585) class resolved, static method absent
+ * lsp_unresolved (1257) emit_unresolved fallback marker
+ * Rust (rust_lsp.c, grep '"lsp_'):
+ * lsp_direct (3580/3586) path::to::func() free-fn call
+ * lsp_method_dispatch (3463) recv.method() inherent method
+ * lsp_trait_dispatch (3466) recv.method() via a trait impl
+ * lsp_constructor (3607) Type::new() UFCS constructor
+ * lsp_ufcs (3608) Type::method(x) UFCS
+ * lsp_trait_ufcs (3622) <T as Trait>::method / Trait::method, sole impl
+ * lsp_operator_trait (2443) a + b where T : Add (operator overload)
+ * lsp_macro (3832) known std macro (println!/vec!/panic!)
+ * lsp_deref_dispatch / lsp_bound_dispatch / lsp_prelude_trait /
+ * lsp_short_name_unique / lsp_trait_ufcs_amb / lsp_mod_decl (skipped, see above)
+ * lsp_unresolved (3393) fallback marker
+ *
+ * NOTE: line comments only inside this header (no nested block comments, per
+ * coding rules).
+ */
+
+#include "test_framework.h"
+#include "repro_invariant_lib.h"
+#include <store/store.h>
+
+#include <string.h>
+
+/* ── Shared per-strategy runner (DRY, identical to repro_lsp_c_cpp.c) ─────────
+ *
+ * Index a single-file fixture and assert the per-pass LSP RESOLUTION CONTRACT:
+ * 1. the store opened (a setup failure is a FAIL, not a skip);
+ * 2. callable-sourcing: zero Module/File-sourced CALLS edges, and at least one
+ * callable-sourced CALLS edge exists (else there is no signal at all);
+ * 3. strategy-presence: some CALLS edge carries `strategy` in properties_json.
+ *
+ * `filename` selects the language by extension (".kt" → Kotlin, ".php" → PHP,
+ * ".rs" → Rust) exactly as the production indexer does. Returns 0 on PASS
+ * (GREEN), non-zero on FAIL (RED).
+ * ───────────────────────────────────────────────────────────────────────── */
+static int assert_lsp_strategy(const char *filename, const char *src,
+ const char *strategy) {
+ RProj lp;
+ cbm_store_t *store = rh_index(&lp, filename, src);
+ if (!store) {
+ printf(" %sFAIL%s %s:%d: index failed for strategy %s\n", tf_red(),
+ tf_reset(), __FILE__, __LINE__, strategy);
+ rh_cleanup(&lp, store);
+ return 1;
+ }
+
+ int module_sourced = -1;
+ int callable_sourced = -1;
+ inv_count_calls_by_source(store, lp.project, &module_sourced,
+ &callable_sourced);
+
+ int has_strategy = inv_edge_has_strategy(store, lp.project, strategy);
+
+ int rc = 0;
+
+ /* (a) callable-sourcing floor: zero Module/File-sourced CALLS edges. */
+ if (module_sourced != 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: %d Module-sourced CALLS "
+ "(expected 0)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ module_sourced);
+ rc = 1;
+ }
+ /* There must be a callable-sourced CALLS edge, else the fixture produced no
+ * call signal and the strategy assertion below would be vacuous. */
+ if (callable_sourced <= 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: no callable-sourced CALLS edge "
+ "(callable=%d)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ callable_sourced);
+ rc = 1;
+ }
+
+ /* (b) the precise per-pass invariant: the resolution strategy is present. */
+ if (!has_strategy) {
+ printf(" %sFAIL%s %s:%d: strategy %s ABSENT from any CALLS edge "
+ "properties_json\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy);
+ rc = 1;
+ }
+
+ rh_cleanup(&lp, store);
+ return rc;
+}
+
+/* ════════════════════════════════════════════════════════════════════════════
+ * KOTLIN FIXTURES (main.kt) — every fixture keeps the call inside a callable
+ * (a top-level fun or a method) so callable-sourcing is testable, and the
+ * callee is defined in-file so the registry resolves it.
+ * ═══════════════════════════════════════════════════════════════════════════ */
+
+/* lsp_kt_top_level — bare top-level fun call (kotlin_lsp.c:2256). */
+static const char kKtTopLevel[] =
+ "fun helper(x: Int): Int { return x + 1 }\n"
+ "fun caller(v: Int): Int { return helper(v) }\n";
+
+/* lsp_kt_constructor — Foo()/Foo(args) constructs the class (kotlin_lsp.c:2248:
+ * callee resolves to a registered type → emit <init>). */
+static const char kKtConstructor[] =
+ "class Widget(val x: Int)\n"
+ "fun caller(): Widget { return Widget(3) }\n";
+
+/* lsp_kt_method — receiver.method() with a known receiver type
+ * (kotlin_lsp.c:2426: kotlin_lookup_method on the receiver type succeeds). */
+static const char kKtMethod[] =
+ "class Counter {\n"
+ " fun inc(x: Int): Int { return x + 1 }\n"
+ "}\n"
+ "fun caller(): Int {\n"
+ " val c = Counter()\n"
+ " return c.inc(1)\n"
+ "}\n";
+
+/* lsp_kt_static — Foo.bar() where Foo is an object singleton
+ * (kotlin_lsp.c:2443: receiver is a class ref, method found on the object /
+ * companion). An `object` declaration registers a singleton whose members are
+ * looked up directly on the object QN. */
+static const char kKtStatic[] =
+ "object MathKt {\n"
+ " fun square(x: Int): Int { return x * x }\n"
+ "}\n"
+ "fun caller(v: Int): Int { return MathKt.square(v) }\n";
+
+/* lsp_kt_extension — extension function dispatch (kotlin_lsp.c:2461:
+ * cbm_registry_lookup_method finds a func whose receiver_type == recv type and
+ * whose short_name == the member). `fun Int.doubled()` is an extension on Int;
+ * a value of that type calling .doubled() dispatches to it. */
+static const char kKtExtension[] =
+ "class Box(val n: Int)\n"
+ "fun Box.doubled(): Int { return n * 2 }\n"
+ "fun caller(b: Box): Int { return b.doubled() }\n";
+
+/* lsp_kt_this — this.method() with a resolved this-type (kotlin_lsp.c:2398/2232:
+ * receiver is a this_expression, enclosing_class_qn set, method found). */
+static const char kKtThis[] =
+ "class Widget {\n"
+ " fun compute(x: Int): Int { return this.helper(x) + 1 }\n"
+ " fun helper(x: Int): Int { return x * 2 }\n"
+ "}\n";
+
+/* lsp_kt_super — super.method() (kotlin_lsp.c:2385: receiver is a
+ * super_expression, enclosing_super_qn set, method found on the super type). */
+static const char kKtSuper[] =
+ "open class Base {\n"
+ " open fun speak(x: Int): Int { return x }\n"
+ "}\n"
+ "class Derived : Base() {\n"
+ " override fun speak(x: Int): Int { return super.speak(x) * 10 }\n"
+ "}\n";
+
+/* lsp_kt_operator — operator overload `a + b` → a.plus(b) (kotlin_lsp.c:1977:
+ * binary `+`, lhs is a user type with an `operator fun plus`). */
+static const char kKtOperator[] =
+ "class Vec(val n: Int) {\n"
+ " operator fun plus(o: Vec): Vec { return Vec(n + o.n) }\n"
+ "}\n"
+ "fun caller(a: Vec, b: Vec): Vec { return a + b }\n";
+
+/* lsp_kt_callable_ref — Type::member callable reference (kotlin_lsp.c:2123:
+ * a navigation whose member resolves to a method of the receiver type, used as
+ * a function reference). `Widget::inc` references the method. */
+static const char kKtCallableRef[] =
+ "class Widget {\n"
+ " fun inc(x: Int): Int { return x + 1 }\n"
+ "}\n"
+ "fun caller(w: Widget): (Int) -> Int { return w::inc }\n";
+
+/* lsp_kt_lambda_it — it.method() inside a scope-function lambda
+ * (kotlin_lsp.c:2474: receiver is the implicit `it`, it_type known, method
+ * found). `let { it.inc(...) }` binds `it` to the receiver's type. */
+static const char kKtLambdaIt[] =
+ "class Counter {\n"
+ " fun inc(x: Int): Int { return x + 1 }\n"
+ "}\n"
+ "fun caller(c: Counter): Int { return c.let { it.inc(1) } }\n";
+
+/* lsp_kt_any — toString/equals/hashCode on an unknown receiver resolves to
+ * kotlin.Any (kotlin_lsp.c:2500). A param of an external/unknown type calling
+ * .toString() falls through to the kotlin.Any universal-method branch. */
+static const char kKtAny[] =
+ "fun caller(x: SomethingUnknown): String { return x.toString() }\n";
+
+/* lsp_kt_destructure — val (a, b) = pair → componentN() (kotlin_lsp.c:2569:
+ * multi-variable declaration over a type that defines component1/component2). */
+static const char kKtDestructure[] =
+ "class Pair2(val a: Int, val b: Int) {\n"
+ " operator fun component1(): Int { return a }\n"
+ " operator fun component2(): Int { return b }\n"
+ "}\n"
+ "fun caller(p: Pair2): Int {\n"
+ " val (x, y) = p\n"
+ " return x + y\n"
+ "}\n";
+
+/* lsp_kt_delegate — `by` property delegation → getValue (kotlin_lsp.c:2625:
+ * the delegate expression's type defines getValue). */
+static const char kKtDelegate[] =
+ "import kotlin.reflect.KProperty\n"
+ "class Lazy2(val v: Int) {\n"
+ " operator fun getValue(thisRef: Any?, prop: KProperty<*>): Int { return v }\n"
+ "}\n"
+ "class Holder {\n"
+ " val value: Int by Lazy2(7)\n"
+ "}\n";
+
+/* lsp_kt_iterator — for (x in xs) → xs.iterator()/hasNext()/next()
+ * (kotlin_lsp.c:2835: the iterable type defines the iterator protocol). */
+static const char kKtIterator[] =
+ "class Range2 {\n"
+ " fun iterator(): Range2 { return this }\n"
+ " fun hasNext(): Boolean { return false }\n"
+ " fun next(): Int { return 0 }\n"
+ "}\n"
+ "fun caller(r: Range2): Int {\n"
+ " var s = 0\n"
+ " for (x in r) { s = s + x }\n"
+ " return s\n"
+ "}\n";
+
+/* ════════════════════════════════════════════════════════════════════════════
+ * PHP FIXTURES (main.php) — opening "<?php" tag required so the indexer parses
+ * PHP. Calls live inside functions/methods for callable-sourcing.
+ * ═══════════════════════════════════════════════════════════════════════════ */
+
+/* php_function_global_fallback — bare helper() resolved by the global-function
+ * fallback (php_lsp.c:1487: name has no namespace, best global candidate). */
+static const char kPhpFunctionGlobal[] =
+ "<?php\n"
+ "function helper(int $x): int { return $x + 1; }\n"
+ "function caller(int $v): int { return helper($v); }\n";
+
+/* php_function_namespaced — a namespaced free function called from within the
+ * same namespace resolves namespaced (php_lsp.c:1445/1455). */
+static const char kPhpFunctionNamespaced[] =
+ "<?php\n"
+ "namespace App;\n"
+ "function helper(int $x): int { return $x + 1; }\n"
+ "function caller(int $v): int { return helper($v); }\n";
+
+/* php_method_typed — $x->m() where $x is statically typed to the class that
+ * declares m (php_lsp.c:1522: receiver_type == class_qn). */
+static const char kPhpMethodTyped[] =
+ "<?php\n"
+ "class Counter {\n"
+ " public function inc(int $x): int { return $x + 1; }\n"
+ "}\n"
+ "function caller(): int {\n"
+ " $c = new Counter();\n"
+ " return $c->inc(1);\n"
+ "}\n";
+
+/* php_method_inherited — $x->m() resolves to a method declared on a PARENT
+ * class (php_lsp.c:1523: receiver_type != class_qn). */
+static const char kPhpMethodInherited[] =
+ "<?php\n"
+ "class Base {\n"
+ " public function common(int $x): int { return $x + 100; }\n"
+ "}\n"
+ "class Derived extends Base {\n"
+ "}\n"
+ "function caller(): int {\n"
+ " $d = new Derived();\n"
+ " return $d->common(5);\n"
+ "}\n";
+
+/* php_method_dynamic — $x->m() where the class declares __call magic
+ * (php_lsp.c:1530: class_has_magic_call true, method itself absent). */
+static const char kPhpMethodDynamic[] =
+ "<?php\n"
+ "class Proxy {\n"
+ " public function __call(string $name, array $args): int { return 0; }\n"
+ "}\n"
+ "function caller(): int {\n"
+ " $p = new Proxy();\n"
+ " return $p->anything(1);\n"
+ "}\n";
+
+/* php_static_resolved — Foo::bar() static method call (php_lsp.c:1552:
+ * scope is an explicit class name, method found). */
+static const char kPhpStaticResolved[] =
+ "<?php\n"
+ "class MathPhp {\n"
+ " public static function square(int $x): int { return $x * $x; }\n"
+ "}\n"
+ "function caller(int $v): int { return MathPhp::square($v); }\n";
+
+/* php_self_static — self::bar() inside the same class (php_lsp.c:1558:
+ * scope is `self`, class_qn = enclosing class). */
+static const char kPhpSelfStatic[] =
+ "<?php\n"
+ "class MathPhp {\n"
+ " public static function square(int $x): int { return $x * $x; }\n"
+ " public static function quad(int $x): int { return self::square($x) * 2; }\n"
+ "}\n";
+
+/* ════════════════════════════════════════════════════════════════════════════
+ * RUST FIXTURES (main.rs) — Rust cross-LSP is NOT wired into pass_lsp_cross
+ * (see header), so ALL of these are expected RED until rust_lsp.c is wired.
+ * Each fixture still exercises exactly the keyed construct so the test turns
+ * GREEN the moment Rust resolution reaches the graph.
+ * ═══════════════════════════════════════════════════════════════════════════ */
+
+/* lsp_direct — plain free-function call (rust_lsp.c:3580: path resolves to a
+ * registered free function). */
+static const char kRustDirect[] =
+ "fn helper(x: i32) -> i32 { x + 1 }\n"
+ "fn caller(v: i32) -> i32 { helper(v) }\n";
+
+/* lsp_method_dispatch — recv.method() inherent method (rust_lsp.c:3463:
+ * method found on the receiver's own type, receiver_type == type_qn). */
+static const char kRustMethodDispatch[] =
+ "struct Counter;\n"
+ "impl Counter {\n"
+ " fn inc(&self, x: i32) -> i32 { x + 1 }\n"
+ "}\n"
+ "fn caller() -> i32 {\n"
+ " let c = Counter;\n"
+ " c.inc(1)\n"
+ "}\n";
+
+/* lsp_trait_dispatch — recv.method() resolved through a trait impl
+ * (rust_lsp.c:3466: the method's receiver_type differs from the value type — it
+ * lives on the trait, reached via `impl Trait for Type`). */
+static const char kRustTraitDispatch[] =
+ "trait Speak {\n"
+ " fn speak(&self, x: i32) -> i32;\n"
+ "}\n"
+ "struct Dog;\n"
+ "impl Speak for Dog {\n"
+ " fn speak(&self, x: i32) -> i32 { x * 10 }\n"
+ "}\n"
+ "fn caller() -> i32 {\n"
+ " let d = Dog;\n"
+ " d.speak(2)\n"
+ "}\n";
+
+/* lsp_constructor — Type::new() UFCS constructor (rust_lsp.c:3607: UFCS head is
+ * a type, short_name == "new"). */
+static const char kRustConstructor[] =
+ "struct Widget { x: i32 }\n"
+ "impl Widget {\n"
+ " fn new(x: i32) -> Widget { Widget { x } }\n"
+ "}\n"
+ "fn caller() -> Widget { Widget::new(3) }\n";
+
+/* lsp_ufcs — Type::method(recv) UFCS call to a non-`new` inherent method
+ * (rust_lsp.c:3608). */
+static const char kRustUfcs[] =
+ "struct Counter;\n"
+ "impl Counter {\n"
+ " fn inc(&self, x: i32) -> i32 { x + 1 }\n"
+ "}\n"
+ "fn caller(c: Counter) -> i32 { Counter::inc(&c, 1) }\n";
+
+/* lsp_trait_ufcs — Trait::method UFCS resolved through a single trait impl
+ * (rust_lsp.c:3622: UFCS head is a trait, sole impl). */
+static const char kRustTraitUfcs[] =
+ "trait Speak {\n"
+ " fn speak(x: i32) -> i32;\n"
+ "}\n"
+ "struct Dog;\n"
+ "impl Speak for Dog {\n"
+ " fn speak(x: i32) -> i32 { x * 10 }\n"
+ "}\n"
+ "fn caller() -> i32 { Speak::speak(2) }\n";
+
+/* lsp_operator_trait — `a + b` where the operand type implements Add
+ * (rust_lsp.c:2443: user NAMED type with an `add` method registered). */
+static const char kRustOperatorTrait[] =
+ "use std::ops::Add;\n"
+ "struct Vec2 { n: i32 }\n"
+ "impl Add for Vec2 {\n"
+ " type Output = Vec2;\n"
+ " fn add(self, o: Vec2) -> Vec2 { Vec2 { n: self.n + o.n } }\n"
+ "}\n"
+ "fn caller(a: Vec2, b: Vec2) -> Vec2 { a + b }\n";
+
+/* lsp_macro — a known std macro maps to a synthetic fn target
+ * (rust_lsp.c:3832: e.g. vec! → alloc.vec.vec). The macro call sits inside a
+ * function so the edge is callable-sourced. */
+static const char kRustMacro[] =
+ "fn caller() -> usize {\n"
+ " let v = vec![1, 2, 3];\n"
+ " v.len()\n"
+ "}\n";
+
+/* ── Per-strategy tests ──────────────────────────────────────────────────── */
+
+/* Kotlin */
+TEST(repro_lsp_kt_top_level) {
+ return assert_lsp_strategy("main.kt", kKtTopLevel, "lsp_kt_top_level");
+}
+TEST(repro_lsp_kt_constructor) {
+ return assert_lsp_strategy("main.kt", kKtConstructor, "lsp_kt_constructor");
+}
+TEST(repro_lsp_kt_method) {
+ return assert_lsp_strategy("main.kt", kKtMethod, "lsp_kt_method");
+}
+TEST(repro_lsp_kt_static) {
+ return assert_lsp_strategy("main.kt", kKtStatic, "lsp_kt_static");
+}
+TEST(repro_lsp_kt_extension) {
+ return assert_lsp_strategy("main.kt", kKtExtension, "lsp_kt_extension");
+}
+TEST(repro_lsp_kt_this) {
+ return assert_lsp_strategy("main.kt", kKtThis, "lsp_kt_this");
+}
+TEST(repro_lsp_kt_super) {
+ return assert_lsp_strategy("main.kt", kKtSuper, "lsp_kt_super");
+}
+TEST(repro_lsp_kt_operator) {
+ return assert_lsp_strategy("main.kt", kKtOperator, "lsp_kt_operator");
+}
+TEST(repro_lsp_kt_callable_ref) {
+ return assert_lsp_strategy("main.kt", kKtCallableRef, "lsp_kt_callable_ref");
+}
+TEST(repro_lsp_kt_lambda_it) {
+ return assert_lsp_strategy("main.kt", kKtLambdaIt, "lsp_kt_lambda_it");
+}
+TEST(repro_lsp_kt_any) {
+ return assert_lsp_strategy("main.kt", kKtAny, "lsp_kt_any");
+}
+TEST(repro_lsp_kt_destructure) {
+ return assert_lsp_strategy("main.kt", kKtDestructure, "lsp_kt_destructure");
+}
+TEST(repro_lsp_kt_delegate) {
+ return assert_lsp_strategy("main.kt", kKtDelegate, "lsp_kt_delegate");
+}
+TEST(repro_lsp_kt_iterator) {
+ return assert_lsp_strategy("main.kt", kKtIterator, "lsp_kt_iterator");
+}
+
+/* PHP */
+TEST(repro_lsp_php_function_global) {
+ return assert_lsp_strategy("main.php", kPhpFunctionGlobal,
+ "php_function_global_fallback");
+}
+TEST(repro_lsp_php_function_namespaced) {
+ return assert_lsp_strategy("main.php", kPhpFunctionNamespaced,
+ "php_function_namespaced");
+}
+TEST(repro_lsp_php_method_typed) {
+ return assert_lsp_strategy("main.php", kPhpMethodTyped, "php_method_typed");
+}
+TEST(repro_lsp_php_method_inherited) {
+ return assert_lsp_strategy("main.php", kPhpMethodInherited,
+ "php_method_inherited");
+}
+TEST(repro_lsp_php_method_dynamic) {
+ return assert_lsp_strategy("main.php", kPhpMethodDynamic,
+ "php_method_dynamic");
+}
+TEST(repro_lsp_php_static_resolved) {
+ return assert_lsp_strategy("main.php", kPhpStaticResolved,
+ "php_static_resolved");
+}
+TEST(repro_lsp_php_self_static) {
+ return assert_lsp_strategy("main.php", kPhpSelfStatic, "php_self_static");
+}
+
+/* Rust — all expected RED (cross-LSP not wired; see header). */
+TEST(repro_lsp_rust_direct) {
+ return assert_lsp_strategy("main.rs", kRustDirect, "lsp_direct");
+}
+TEST(repro_lsp_rust_method_dispatch) {
+ return assert_lsp_strategy("main.rs", kRustMethodDispatch,
+ "lsp_method_dispatch");
+}
+TEST(repro_lsp_rust_trait_dispatch) {
+ return assert_lsp_strategy("main.rs", kRustTraitDispatch,
+ "lsp_trait_dispatch");
+}
+TEST(repro_lsp_rust_constructor) {
+ return assert_lsp_strategy("main.rs", kRustConstructor, "lsp_constructor");
+}
+TEST(repro_lsp_rust_ufcs) {
+ return assert_lsp_strategy("main.rs", kRustUfcs, "lsp_ufcs");
+}
+TEST(repro_lsp_rust_trait_ufcs) {
+ return assert_lsp_strategy("main.rs", kRustTraitUfcs, "lsp_trait_ufcs");
+}
+TEST(repro_lsp_rust_operator_trait) {
+ return assert_lsp_strategy("main.rs", kRustOperatorTrait,
+ "lsp_operator_trait");
+}
+TEST(repro_lsp_rust_macro) {
+ return assert_lsp_strategy("main.rs", kRustMacro, "lsp_macro");
+}
+
+/* ── Suite ───────────────────────────────────────────────────────────────── */
+
+SUITE(repro_lsp_kt_php_rust) {
+ /* Kotlin */
+ RUN_TEST(repro_lsp_kt_top_level);
+ RUN_TEST(repro_lsp_kt_constructor);
+ RUN_TEST(repro_lsp_kt_method);
+ RUN_TEST(repro_lsp_kt_static);
+ RUN_TEST(repro_lsp_kt_extension);
+ RUN_TEST(repro_lsp_kt_this);
+ RUN_TEST(repro_lsp_kt_super);
+ RUN_TEST(repro_lsp_kt_operator);
+ RUN_TEST(repro_lsp_kt_callable_ref);
+ RUN_TEST(repro_lsp_kt_lambda_it);
+ RUN_TEST(repro_lsp_kt_any);
+ RUN_TEST(repro_lsp_kt_destructure);
+ RUN_TEST(repro_lsp_kt_delegate);
+ RUN_TEST(repro_lsp_kt_iterator);
+
+ /* PHP */
+ RUN_TEST(repro_lsp_php_function_global);
+ RUN_TEST(repro_lsp_php_function_namespaced);
+ RUN_TEST(repro_lsp_php_method_typed);
+ RUN_TEST(repro_lsp_php_method_inherited);
+ RUN_TEST(repro_lsp_php_method_dynamic);
+ RUN_TEST(repro_lsp_php_static_resolved);
+ RUN_TEST(repro_lsp_php_self_static);
+
+ /* Rust — expected RED (cross-LSP not wired). */
+ RUN_TEST(repro_lsp_rust_direct);
+ RUN_TEST(repro_lsp_rust_method_dispatch);
+ RUN_TEST(repro_lsp_rust_trait_dispatch);
+ RUN_TEST(repro_lsp_rust_constructor);
+ RUN_TEST(repro_lsp_rust_ufcs);
+ RUN_TEST(repro_lsp_rust_trait_ufcs);
+ RUN_TEST(repro_lsp_rust_operator_trait);
+ RUN_TEST(repro_lsp_rust_macro);
+}
diff --git a/tests/repro/repro_lsp_ts.c b/tests/repro/repro_lsp_ts.c
new file mode 100644
index 000000000..090ccc95e
--- /dev/null
+++ b/tests/repro/repro_lsp_ts.c
@@ -0,0 +1,334 @@
+/*
+ * repro_lsp_ts.c — EXHAUSTIVE per-LSP-pass invariant suite for the TypeScript /
+ * JavaScript / JSX hybrid LSP (internal/cbm/lsp/ts_lsp.c).
+ *
+ * WHAT THIS ASSERTS — the LSP RESOLUTION CONTRACT, one invariant per strategy.
+ * The TS cross resolver resolves each call via a specific STRATEGY and tags the
+ * resulting CALLS edge in its properties_json with
+ * "strategy":"lsp_<name>"
+ * (see ts_emit_resolved_call, ts_lsp.c:109-120; every concrete emit site passes
+ * a literal "lsp_ts..." string). Each strategy keys on a precise TS/TSX
+ * construct. This suite builds the MINIMAL fixture that exercises exactly one
+ * strategy, indexes it through the full production pipeline, and asserts TWO
+ * things:
+ * (a) callable-sourcing — the inner call is sourced at a Function/Method
+ * node, never at a Module/File node (inv_count_calls_by_source →
+ * module_sourced == 0). A Module-sourced call is the #554 attribution
+ * bug; this is the broad correctness floor.
+ * (b) strategy-presence — some CALLS edge carries "lsp_<strategy>" in its
+ * properties_json (inv_edge_has_strategy). This is the PRECISE per-pass
+ * invariant: it proves that exact resolution path fired and survived into
+ * the graph.
+ *
+ * RED vs GREEN — this is a STATUS BOARD, not a pass/fail gate (runs only under
+ * make test-repro / bug-repro.yml, never the branch-protection ci-ok gate):
+ * - GREEN = the LSP strategy works end-to-end = a permanent regression
+ * guard that it keeps working.
+ * - RED = the strategy is dropped, or the call lands Module-sourced, or
+ * the rescue is discarded. Either way the per-pass TEST DOCUMENTS
+ * the exact gap for the eventual fixer.
+ *
+ * TIE TO repro_invariant_lsp_rescue.c — that file pins the MECHANISM by which
+ * these can silently fail: cbm_pipeline_find_lsp_resolution joins each
+ * LSP-resolved call to the tree-sitter call by EXACT caller-QN string equality.
+ * When tree-sitter's enclosing-func walk falls back to the MODULE QN but the
+ * LSP built the real method QN, the strcmp never matches, the LSP rescue is
+ * discarded, and the edge stays Module-sourced with a registry strategy —
+ * NEVER an "lsp_" strategy. So a strategy that is correctly EMITTED by ts_lsp.c
+ * can still be ABSENT from the graph here: the exact-QN join suppresses it.
+ * Whenever a strategy below is RED, suspect that join first (a same-file
+ * in-function fixture sidesteps it; a cross-file fixture exercises it).
+ *
+ * STRATEGY INVENTORY — every literal "lsp_..." emitted by ts_lsp.c, grepped from
+ * the source (grep '"lsp_' internal/cbm/lsp/ts_lsp.c), with its keying site:
+ * lsp_ts_local (ts_lsp.c:2322) bare identifier call f() resolving to a
+ * module-local function (call_expression
+ * function is an `identifier`, found in the
+ * module registry).
+ * lsp_ts_method (ts_lsp.c:2284) obj.method() type-based dispatch on a
+ * receiver whose type is a NAMED in-file
+ * class (member_expression, lookup_method
+ * hits).
+ * lsp_ts_namespace (ts_lsp.c:2246) Ns.fn() where Ns is a namespace import
+ * (`import * as Ns from "./mod"`); the
+ * member_expression object is an identifier
+ * matching an import local name, fn resolves
+ * in that module's registry.
+ * lsp_ts_import (ts_lsp.c:2334) bare identifier call to an imported
+ * function (`import { helper } ...`); the
+ * identifier matches an import local name and
+ * resolves in the imported module's registry.
+ * lsp_ts_jsx (ts_lsp.c:2647) <Comp/> JSX element whose tag is a
+ * module-local component function (TSX only;
+ * uppercase tag, resolves via the module
+ * registry).
+ * lsp_ts_jsx_import (ts_lsp.c:2657) <Comp/> JSX element whose tag is an
+ * imported component (TSX only; tag matches
+ * an import local name → synthetic
+ * "<module>.<Comp>" QN). NOTE: this site
+ * builds the callee QN WITHOUT verifying the
+ * symbol exists in the registry, so it can
+ * emit even when the import target is absent.
+ * lsp_ts (ts_lsp.c:116) DEFAULT fallback inside ts_emit_resolved_call
+ * used only when a caller passes a NULL
+ * strategy. Every concrete emit site passes a
+ * literal "lsp_ts..." string, so "lsp_ts" is
+ * (as of this writing) never emitted as a
+ * distinct tag — expected ABSENT (RED). This
+ * TEST documents that the bare-"lsp_ts" path
+ * has no live caller; if it ever goes GREEN a
+ * new NULL-strategy emit site appeared.
+ * lsp_unresolved (ts_lsp.c:128) fallback marker for an unresolved call
+ * (ts_emit_unresolved_call, confidence 0.0).
+ * A 0.0-confidence unresolved entry is
+ * typically NOT promoted into a CALLS edge
+ * with the strategy tag, so this is expected
+ * ABSENT (RED) — it documents whether
+ * "lsp_unresolved" surfaces in the graph.
+ *
+ * LANGUAGE SELECTION — the filename extension picks the language exactly as the
+ * production indexer does: ".ts" → CBM_LANG_TYPESCRIPT, ".tsx" → CBM_LANG_TSX.
+ * jsx_mode (required by resolve_jsx_element, ts_lsp.c:2620) is enabled ONLY for
+ * CBM_LANG_TSX (cbm.c:619, pass_lsp_cross.c:267), so the two JSX fixtures use
+ * ".tsx" files; the non-JSX fixtures use ".ts".
+ *
+ * NOTE: line comments only inside this header (no nested block comments, per
+ * coding rules).
+ */
+
+#include "test_framework.h"
+#include "repro_invariant_lib.h"
+#include <store/store.h>
+
+#include <string.h>
+
+/* ── Shared per-strategy runners (DRY) ───────────────────────────────────── */
+
+/*
+ * assert_lsp_strategy_files
+ *
+ * Index an N-file fixture and assert the per-pass LSP RESOLUTION CONTRACT:
+ * 1. the store opened (precondition — a setup failure is a FAIL, not a skip);
+ * 2. callable-sourcing: NO CALLS edge is Module/File-sourced, and at least one
+ * callable-sourced CALLS edge exists (else there is no signal at all);
+ * 3. strategy-presence: some CALLS edge carries "lsp_<strategy>" in its
+ * properties_json.
+ *
+ * The filename extension selects the language exactly as the production indexer
+ * does (".ts" → TypeScript, ".tsx" → TSX). Returns 0 on PASS (GREEN), non-zero
+ * on FAIL (RED) — the redness is the documented per-pass status.
+ */
+static int assert_lsp_strategy_files(const RFile *files, int nfiles,
+ const char *strategy) {
+ RProj lp;
+ cbm_store_t *store = rh_index_files(&lp, files, nfiles);
+ if (!store) {
+ printf(" %sFAIL%s %s:%d: index failed for strategy %s\n", tf_red(),
+ tf_reset(), __FILE__, __LINE__, strategy);
+ rh_cleanup(&lp, store);
+ return 1;
+ }
+
+ int module_sourced = -1;
+ int callable_sourced = -1;
+ inv_count_calls_by_source(store, lp.project, &module_sourced,
+ &callable_sourced);
+
+ int has_strategy = inv_edge_has_strategy(store, lp.project, strategy);
+
+ int rc = 0;
+
+ /* (a) callable-sourcing floor: zero Module/File-sourced CALLS edges. */
+ if (module_sourced != 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: %d Module-sourced CALLS "
+ "(expected 0)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ module_sourced);
+ rc = 1;
+ }
+ /* There must be a callable-sourced CALLS edge, else the fixture produced no
+ * call signal and the strategy assertion below would be vacuous. */
+ if (callable_sourced <= 0) {
+ printf(" %sFAIL%s %s:%d: strategy %s: no callable-sourced CALLS edge "
+ "(callable=%d)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy,
+ callable_sourced);
+ rc = 1;
+ }
+
+ /* (b) the precise per-pass invariant: the resolution strategy is present. */
+ if (!has_strategy) {
+ printf(" %sFAIL%s %s:%d: strategy %s ABSENT from any CALLS edge "
+ "properties_json\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy);
+ rc = 1;
+ }
+
+ rh_cleanup(&lp, store);
+ return rc;
+}
+
+/* Single-file convenience wrapper. */
+static int assert_lsp_strategy(const char *filename, const char *src,
+ const char *strategy) {
+ RFile f = {filename, src};
+ return assert_lsp_strategy_files(&f, 1, strategy);
+}
+
+/* ── Fixtures ────────────────────────────────────────────────────────────────
+ *
+ * Each fixture is the MINIMAL construct ts_lsp.c keys on for one strategy. The
+ * call we care about always lives inside a function or method so callable-
+ * sourcing is testable; the callee is also defined in-file (or in a sibling file
+ * for the cross-file import strategies) so the registry can resolve it.
+ * ───────────────────────────────────────────────────────────────────────── */
+
+/* lsp_ts_local — bare identifier call f() that resolves to a module-local
+ * function (ts_lsp.c:2310-2322: call_expression function is an `identifier`,
+ * cbm_registry_lookup_symbol_by_args hits on the module QN). */
+static const char kTsLocal[] =
+ "function helper(x: number): number { return x + 1; }\n"
+ "function caller(v: number): number { return helper(v); }\n";
+
+/* lsp_ts_method — obj.method() type-based dispatch on a NAMED in-file class
+ * receiver (ts_lsp.c:2257-2284: member_expression, ts_eval_expr_type gives the
+ * receiver's NAMED type, lookup_method finds the method). */
+static const char kTsMethod[] =
+ "class Counter {\n"
+ " inc(x: number): number { return x + 1; }\n"
+ "}\n"
+ "function caller(): number {\n"
+ " const c = new Counter();\n"
+ " return c.inc(1);\n"
+ "}\n";
+
+/* lsp_ts_namespace — Ns.fn() where Ns is a namespace import
+ * (`import * as Ns from "./mod"`). ts_lsp.c:2233-2246: the member_expression
+ * object is an `identifier` matching an import local name; fn resolves in that
+ * imported module's registry → lsp_ts_namespace. Cross-file: util.ts exports the
+ * function, main.ts imports the namespace and calls Util.compute(). */
+static const RFile kTsNamespace[] = {
+ {"util.ts",
+ "export function compute(x: number): number { return x * 3; }\n"},
+ {"main.ts",
+ "import * as Util from \"./util\";\n"
+ "function caller(v: number): number { return Util.compute(v); }\n"},
+};
+
+/* lsp_ts_import — bare identifier call to an imported function
+ * (`import { helper } from "./mod"`). ts_lsp.c:2327-2334: the call_expression
+ * function is an `identifier` matching an import local name; helper resolves in
+ * the imported module's registry → lsp_ts_import. Cross-file: util.ts exports
+ * helper, main.ts imports it by name and calls it bare. */
+static const RFile kTsImport[] = {
+ {"util.ts",
+ "export function helper(x: number): number { return x + 5; }\n"},
+ {"main.ts",
+ "import { helper } from \"./util\";\n"
+ "function caller(v: number): number { return helper(v); }\n"},
+};
+
+/* lsp_ts_jsx — <Comp/> JSX element whose tag is a module-local component
+ * function (ts_lsp.c:2643-2647). TSX only (jsx_mode); the tag's first letter is
+ * uppercase so it is NOT treated as an intrinsic HTML element; it resolves via
+ * cbm_registry_lookup_symbol on the module QN. App() renders <Widget/> defined
+ * in the same file. */
+static const char kTsxJsx[] =
+ "function Widget(): any { return null; }\n"
+ "function App(): any {\n"
+ " return <Widget />;\n"
+ "}\n";
+
+/* lsp_ts_jsx_import — <Comp/> JSX element whose tag is an imported component
+ * (ts_lsp.c:2652-2657). TSX only; the tag matches an import local name → a
+ * synthetic "<module>.<Comp>" callee QN is emitted (this site does NOT verify
+ * the symbol is in the registry). Cross-file: widget.tsx exports Widget,
+ * app.tsx imports it and renders <Widget/>. */
+static const RFile kTsxJsxImport[] = {
+ {"widget.tsx",
+ "export function Widget(): any { return null; }\n"},
+ {"app.tsx",
+ "import { Widget } from \"./widget\";\n"
+ "function App(): any {\n"
+ " return <Widget />;\n"
+ "}\n"},
+};
+
+/* lsp_ts — the DEFAULT fallback strategy inside ts_emit_resolved_call
+ * (ts_lsp.c:116): used only when a caller passes a NULL strategy. Every concrete
+ * emit site passes a literal "lsp_ts..." string, so "lsp_ts" is never emitted as
+ * a distinct tag. This fixture is an ordinary resolved local call; we assert
+ * whether the bare "lsp_ts" tag ever surfaces. EXPECTED ABSENT (RED): if it goes
+ * GREEN, a new NULL-strategy emit site has appeared and should be audited.
+ * NOTE: inv_edge_has_strategy does a substring match, and "lsp_ts" is a prefix of
+ * "lsp_ts_local"/"lsp_ts_method"/etc., so a local-call fixture would substring-
+ * match "lsp_ts" via "lsp_ts_local" and report a false GREEN. To probe the bare
+ * tag in isolation we use an UNRESOLVED call (totallyUnknownFn) whose only
+ * possible tag is the unresolved marker — there is no "lsp_ts_*" edge to alias
+ * against, so a GREEN here would mean a literal bare "lsp_ts" edge exists. */
+static const char kTsDefault[] =
+ "function caller(v: number): number { return totallyUnknownFn(v); }\n";
+
+/* lsp_unresolved — a call to a function not in the registry; the resolver
+ * records the fallback marker via ts_emit_unresolved_call (ts_lsp.c:122-132,
+ * strategy = "lsp_unresolved", confidence 0.0). A 0.0-confidence unresolved entry
+ * is typically NOT promoted into a CALLS edge carrying the strategy tag, so this
+ * is EXPECTED ABSENT (RED) — it documents whether "lsp_unresolved" surfaces in
+ * the graph. */
+static const char kTsUnresolved[] =
+ "function caller(v: number): number { return totallyUnknownFn(v); }\n";
+
+/* ── Per-strategy tests ──────────────────────────────────────────────────── */
+
+TEST(repro_lsp_ts_local) {
+ return assert_lsp_strategy("main.ts", kTsLocal, "lsp_ts_local");
+}
+
+TEST(repro_lsp_ts_method) {
+ return assert_lsp_strategy("main.ts", kTsMethod, "lsp_ts_method");
+}
+
+TEST(repro_lsp_ts_namespace) {
+ return assert_lsp_strategy_files(kTsNamespace,
+ (int)(sizeof(kTsNamespace) /
+ sizeof(kTsNamespace[0])),
+ "lsp_ts_namespace");
+}
+
+TEST(repro_lsp_ts_import) {
+ return assert_lsp_strategy_files(
+ kTsImport, (int)(sizeof(kTsImport) / sizeof(kTsImport[0])),
+ "lsp_ts_import");
+}
+
+TEST(repro_lsp_ts_jsx) {
+ return assert_lsp_strategy("app.tsx", kTsxJsx, "lsp_ts_jsx");
+}
+
+TEST(repro_lsp_ts_jsx_import) {
+ return assert_lsp_strategy_files(kTsxJsxImport,
+ (int)(sizeof(kTsxJsxImport) /
+ sizeof(kTsxJsxImport[0])),
+ "lsp_ts_jsx_import");
+}
+
+TEST(repro_lsp_ts_default) {
+ return assert_lsp_strategy("main.ts", kTsDefault, "lsp_ts");
+}
+
+TEST(repro_lsp_ts_unresolved) {
+ return assert_lsp_strategy("main.ts", kTsUnresolved, "lsp_unresolved");
+}
+
+/* ── Suite ───────────────────────────────────────────────────────────────── */
+
+SUITE(repro_lsp_ts) {
+ RUN_TEST(repro_lsp_ts_local);
+ RUN_TEST(repro_lsp_ts_method);
+ RUN_TEST(repro_lsp_ts_namespace);
+ RUN_TEST(repro_lsp_ts_import);
+ RUN_TEST(repro_lsp_ts_jsx);
+ RUN_TEST(repro_lsp_ts_jsx_import);
+ RUN_TEST(repro_lsp_ts_default);
+ RUN_TEST(repro_lsp_ts_unresolved);
+}
diff --git a/tests/repro/repro_main.c b/tests/repro/repro_main.c
index 0ec64b9b7..b19efa907 100644
--- a/tests/repro/repro_main.c
+++ b/tests/repro/repro_main.c
@@ -75,6 +75,9 @@ extern void suite_repro_grammar_web(void);
/* Per-LSP-pass resolution-strategy invariants */
extern void suite_repro_lsp_c_cpp(void);
extern void suite_repro_lsp_go_py(void);
+extern void suite_repro_lsp_ts(void);
+extern void suite_repro_lsp_java_cs(void);
+extern void suite_repro_lsp_kt_php_rust(void);
int main(void) {
/* Unbuffered: a reproduction may crash/_exit (or a sanitizer may _exit on a
@@ -133,6 +136,9 @@ int main(void) {
RUN_SUITE(repro_grammar_web);
RUN_SUITE(repro_lsp_c_cpp);
RUN_SUITE(repro_lsp_go_py);
+ RUN_SUITE(repro_lsp_ts);
+ RUN_SUITE(repro_lsp_java_cs);
+ RUN_SUITE(repro_lsp_kt_php_rust);
TEST_SUMMARY();
}