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.

30.1 KB
Raw Blame
/*
 * repro_lsp_go_py.c — EXHAUSTIVE per-LSP-pass invariant suite for the Go and
 * Python hybrid LSPs (internal/cbm/lsp/go_lsp.c, internal/cbm/lsp/py_lsp.c).
 *
 * 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":"lsp_<name>"
 *   (Go: emit_resolved_call, go_lsp.c:1084-1094; Python: py_emit_resolved_call,
 *   py_lsp.c:322-353; every emit site passes a literal "lsp_..." string). Each
 *   strategy keys on a precise Go/Python 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 the LSP 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).
 *
 * GO STRATEGY INVENTORY — every literal "lsp_..." emitted by go_lsp.c, grepped
 *   from the source (grep '"lsp_' internal/cbm/lsp/go_lsp.c), with its keying
 *   site:
 *     lsp_direct                (go_lsp.c:1139/1265)  pkg.Func() or local f()
 *     lsp_type_dispatch         (go_lsp.c:1161)       obj.Method() on a concrete
 *                                                     value type (receiver type
 *                                                     == method receiver type)
 *     lsp_embed_dispatch        (go_lsp.c:1164)       embedded-struct promoted
 *                                                     method (method receiver
 *                                                     type != outer type)
 *     lsp_interface_resolve     (go_lsp.c:1226)       call through an interface
 *                                                     with EXACTLY ONE concrete
 *                                                     implementer in the project
 *     lsp_interface_dispatch    (go_lsp.c:1236)       call through an interface
 *                                                     with 0 or >=2 implementers
 *                                                     (generic fallback)
 *     lsp_strategy_cross_file   (go_lsp.c:2925)       cross-file fast-resolve of
 *                                                     an unresolved call against
 *                                                     the global registry
 *     lsp_unresolved            (go_lsp.c:1103)       fallback marker for an
 *                                                     unresolved call
 *
 * PYTHON STRATEGY INVENTORY — every literal "lsp_..." emitted by py_lsp.c
 *   (grep '"lsp_' internal/cbm/lsp/py_lsp.c), with its keying site:
 *     lsp_direct                (py_lsp.c:1631)  module-local f()
 *     lsp_constructor           ClassName() where the class declares no __init__
 *                               of its own (an inherited one is not followed)
 *                               → the Class
 *     lsp_constructor_init      ClassName() where the class declares its own
 *                               __init__ → that __init__. The textual callee
 *                               leaf stays the class name; reason joins it.
 *     lsp_method                (py_lsp.c:1731)  obj.method() on a NAMED-typed
 *                                                receiver (covers self.other())
 *     lsp_super                 (py_lsp.c:1693)  super().method() resolved on a
 *                                                base class (non-__init__)
 *     lsp_super_init            (py_lsp.c:1702)  super().__init__()
 *     lsp_module_attr           (py_lsp.c:1719)  mod.func() after `import mod`,
 *                                                func is a registered symbol
 *     lsp_module_attr_unresolved(py_lsp.c:1724)  mod.func() where func is NOT a
 *                                                registered symbol of the module
 *     lsp_dict_dispatch         (py_lsp.c:1662)  funcs["key"]() dispatch table
 *     lsp_operator_dunder       (py_lsp.c:2120)  a + b where a is a NAMED type
 *                                                defining __add__
 *     lsp_builtin               (py_lsp.c:1637)  print()/len()/... a builtins
 *                                                symbol (needs typeshed registry)
 *     lsp_builtin_constructor   (py_lsp.c:1643)  str()/list()/... a builtins type
 *     lsp_builtin_method        (py_lsp.c:1741)  "x".upper() — method on a
 *                                                builtin-typed receiver
 *     lsp_generic_method        (py_lsp.c:1753)  method on a TEMPLATE-typed
 *                                                receiver (list[T]/dict[K,V])
 *     lsp_method_union          (py_lsp.c:1778)  method on a UNION-typed receiver
 *                                                with exactly one matching member
 *
 * EXPECTED-RED NOTES (documented gaps, not suite bugs):
 *   - lsp_builtin / lsp_builtin_constructor / lsp_builtin_method /
 *     lsp_generic_method: resolution requires the builtins/typeshed registry
 *     ("builtins.print", "builtins.str.upper", ...) to be loaded into the
 *     per-file registry. A single-file fixture has no typeshed, so these are
 *     expected ABSENT (RED) — they document that the builtins-registry binding
 *     the single-file harness can't synthesize is required.
 *   - lsp_method_union: needs a union-typed receiver (e.g. `x: A | B`) where
 *     exactly one member defines the method; the annotation must resolve both
 *     members to in-file NAMED types. Documented if it does not surface.
 *
 * 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 (".go" → Go pass, ".py" → Python pass). 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);
}

/*
 * assert_no_resolvable_edge_files — the ACCURATE invariant for a call whose
 * callee is genuinely UNRESOLVABLE (undeclared/external/absent symbol). No node
 * can exist for such a callee, so no CALLS edge can ever target it and no
 * resolution strategy can land on an edge. Index the fixture and assert that NO
 * CALLS edge targets a node whose QN contains `callee_substr`. Returns 0 on PASS
 * (the no-edge behaviour holds), non-zero on FAIL.
 */
static int assert_no_resolvable_edge_files(const RFile *files, int nfiles,
                                           const char *callee_substr) {
    RProj lp;
    cbm_store_t *store = rh_index_files(&lp, files, nfiles);
    if (!store) {
        printf("  %sFAIL%s %s:%d: index failed for no-edge callee %s\n", tf_red(),
               tf_reset(), __FILE__, __LINE__, callee_substr);
        rh_cleanup(&lp, store);
        return 1;
    }
    int rc = 0;
    /* Exercised-check: the fixture MUST produce at least one callable-sourced
     * CALLS edge (its in-fixture control call). Without it the "no edge to
     * <callee>" invariant is VACUOUS — it also passes when extraction silently
     * produced nothing, so a green would not prove the unresolvable call was
     * actually processed and correctly dropped. */
    int module_sourced = -1;
    int callable_sourced = -1;
    inv_count_calls_by_source(store, lp.project, &module_sourced, &callable_sourced);
    (void)module_sourced;
    if (callable_sourced <= 0) {
        printf("  %sFAIL%s %s:%d: no callable-sourced CALLS edge — fixture not "
               "exercised; the no-edge invariant for %s is vacuous\n",
               tf_red(), tf_reset(), __FILE__, __LINE__, callee_substr);
        rc = 1;
    }
    if (!inv_no_calls_edge_to_qn(store, lp.project, callee_substr)) {
        printf("  %sFAIL%s %s:%d: a CALLS edge unexpectedly targets %s "
               "(expected NONE — callee is unresolvable)\n",
               tf_red(), tf_reset(), __FILE__, __LINE__, callee_substr);
        rc = 1;
    }
    rh_cleanup(&lp, store);
    return rc;
}

static int assert_no_resolvable_edge(const char *filename, const char *src,
                                     const char *callee_substr) {
    RFile f = {filename, src};
    return assert_no_resolvable_edge_files(&f, 1, callee_substr);
}

/* ── Go fixtures ─────────────────────────────────────────────────────────────
 *
 * Each fixture is the MINIMAL construct go_lsp.c keys on for one strategy. The
 * call we care about always lives inside a func or method so callable-sourcing
 * is testable; the callee is also defined in-file so the registry can resolve
 * it. Every file declares `package main` so the package QN is consistent.
 * ───────────────────────────────────────────────────────────────────────── */

/* lsp_direct — plain package-local function call f() (go_lsp.c:1259-1265:
 * func_node is a bare identifier resolved via cbm_registry_lookup_symbol on the
 * package QN). */
static const char kGoDirect[] =
    "package main\n"
    "func helper(x int) int { return x + 1 }\n"
    "func caller(v int) int { return helper(v) }\n";

/* lsp_type_dispatch — obj.Method() on a concrete value type whose method's
 * receiver type equals the receiver type (go_lsp.c:1158-1166: method found, the
 * method's receiver_type == the receiver's QN → lsp_type_dispatch). */
static const char kGoTypeDispatch[] =
    "package main\n"
    "type Counter struct{ n int }\n"
    "func (c Counter) Inc(x int) int { return x + 1 }\n"
    "func caller() int {\n"
    "    var c Counter\n"
    "    return c.Inc(1)\n"
    "}\n";

/* lsp_embed_dispatch — call a promoted method from an embedded struct
 * (go_lsp.c:1162-1164: the resolved method's receiver_type != the outer
 * receiver type → lsp_embed_dispatch). Outer embeds Inner; o.Greet() resolves
 * to Inner.Greet whose receiver_type is Inner, not Outer. */
static const char kGoEmbedDispatch[] =
    "package main\n"
    "type Inner struct{}\n"
    "func (i Inner) Greet(x int) int { return x + 7 }\n"
    "type Outer struct{ Inner }\n"
    "func caller() int {\n"
    "    var o Outer\n"
    "    return o.Greet(1)\n"
    "}\n";

/* lsp_interface_resolve — call through an interface that has EXACTLY ONE
 * concrete implementer in the project (go_lsp.c:1220-1226: impl_count == 1 →
 * resolve to the sole implementer's concrete method). Speaker has one
 * implementer (Dog), so s.Speak() resolves to Dog.Speak. */
static const char kGoInterfaceResolve[] =
    "package main\n"
    "type Speaker interface{ Speak(x int) int }\n"
    "type Dog struct{}\n"
    "func (d Dog) Speak(x int) int { return x * 2 }\n"
    "func caller(s Speaker) int {\n"
    "    return s.Speak(3)\n"
    "}\n";

/* lsp_interface_dispatch — call through an interface with TWO implementers, so
 * the sole-implementer shortcut does not fire and the generic interface
 * fallback emits "<iface>.<method>" (go_lsp.c:1232-1236). Speaker has Dog and
 * Cat → ambiguous → generic dispatch. */
static const char kGoInterfaceDispatch[] =
    "package main\n"
    "type Speaker interface{ Speak(x int) int }\n"
    "type Dog struct{}\n"
    "func (d Dog) Speak(x int) int { return x * 2 }\n"
    "type Cat struct{}\n"
    "func (c Cat) Speak(x int) int { return x * 3 }\n"
    "func caller(s Speaker) int {\n"
    "    return s.Speak(3)\n"
    "}\n";

/* lsp_strategy_cross_file — an unresolved per-file call (callee defined in
 * ANOTHER file) is fixed up by the cross-file fast resolver against the global
 * registry (go_lsp.c:2867-2937: a "function_not_in_registry"/"method_not_found"
 * unresolved entry whose callee_qn is found in the merged registry →
 * lsp_strategy_cross_file). caller.go calls a method defined in helper.go. */
static const RFile kGoCrossFile[] = {
    {"helper.go",
     "package main\n"
     "type Service struct{}\n"
     "func (s Service) Run(x int) int { return x + 5 }\n"},
    {"caller.go",
     "package main\n"
     "func caller(s Service) int {\n"
     "    return s.Run(2)\n"
     "}\n"},
};

/* lsp_unresolved — a call to a function not in the registry; the per-file
 * resolver records the fallback marker (go_lsp.c:1097-1107, strategy =
 * "lsp_unresolved"). NOTE: emit_unresolved_call uses confidence 0.0, so the
 * pipeline may not promote it into a CALLS edge with the strategy tag — this
 * fixture documents whether "lsp_unresolved" surfaces in the graph. */
static const char kGoUnresolved[] = "package main\n"
                                    "func known(x int) int { return x + 1 }\n"
                                    "func caller(v int) int {\n"
                                    "    return known(v) + totallyUnknownFn(v)\n"
                                    "}\n";

/* ── Python fixtures ───────────────────────────────────────────────────────── */

/* lsp_direct — module-local function call f() (py_lsp.c:1627-1631: identifier
 * resolves via cbm_registry_lookup_symbol on the module QN). */
static const char kPyDirect[] =
    "def helper(x):\n"
    "    return x + 1\n"
    "def caller(v):\n"
    "    return helper(v)\n";

/* lsp_constructor — ClassName() where the class has no user __init__.
 * The edge stays on the Class node. A class that defines __init__ is
 * lsp_constructor_init below; strstr would otherwise treat that strategy
 * as a hit for "lsp_constructor". */
static const char kPyConstructor[] =
    "class Widget:\n"
    "    def label(self):\n"
    "        return 1\n"
    "def caller():\n"
    "    return Widget()\n";

/* lsp_constructor_init — ClassName() resolves to the user __init__
 * (issue #1642). reason carries the class-name leaf so the pipeline join
 * still matches the textual call. */
static const char kPyConstructorInit[] =
    "class Widget:\n"
    "    def __init__(self):\n"
    "        self.ready = True\n"
    "def caller():\n"
    "    return Widget()\n";

/* lsp_method — a method calls a sibling method via self.other() (py_lsp.c:
 * 1727-1731: obj_type is NAMED (self is typed as the enclosing class,
 * py_lsp.c:2950-2952) and py_lookup_attribute finds the method → lsp_method). */
static const char kPyMethod[] =
    "class Widget:\n"
    "    def compute(self, x):\n"
    "        return self.helper(x) + 1\n"
    "    def helper(self, x):\n"
    "        return x * 2\n";

/* lsp_super — super().method() where the enclosing class has a base class that
 * defines `method` (py_lsp.c:1681-1693: obj is a super() call, the attr resolves
 * against a base in embedded_types, attr != __init__ → lsp_super). Child's
 * greet() calls super().describe(); Base.describe exists. */
static const char kPySuper[] =
    "class Base:\n"
    "    def describe(self, x):\n"
    "        return x\n"
    "class Child(Base):\n"
    "    def greet(self, x):\n"
    "        return super().describe(x)\n";

/* lsp_super_init — super().__init__() (py_lsp.c:1699-1702: attr == __init__ on a
 * super() proxy → synthesize a constructor edge to <base>.__init__). */
static const char kPySuperInit[] =
    "class Base:\n"
    "    def __init__(self):\n"
    "        self.ready = True\n"
    "class Child(Base):\n"
    "    def __init__(self):\n"
    "        super().__init__()\n";

/* lsp_module_attr — mod.func() after `import mod`, where func is a registered
 * symbol of the imported in-project module (py_lsp.c:1715-1719: obj_type is
 * MODULE and cbm_registry_lookup_symbol(module_qn, attr) hits → lsp_module_attr).
 * Requires a second in-project file so the imported symbol is in the registry. */
static const RFile kPyModuleAttr[] = {
    {"helpers.py",
     "def do_work(x):\n"
     "    return x + 9\n"},
    {"main.py",
     "import helpers\n"
     "def caller(v):\n"
     "    return helpers.do_work(v)\n"},
};

/* lsp_module_attr_unresolved — mod.func() after `import mod` where func is NOT a
 * registered symbol of the module (py_lsp.c:1722-1724: MODULE receiver but the
 * symbol lookup misses → best-effort "module.attr" QN, low confidence). helpers
 * defines nothing named missing_fn. */
static const RFile kPyModuleAttrUnresolved[] = {
    {"helpers.py", "def do_work(x):\n"
                   "    return x + 9\n"},
    {"main.py", "import helpers\n"
                "def known(x):\n"
                "    return x + 1\n"
                "def caller(v):\n"
                "    return known(v) + helpers.missing_fn(v)\n"},
};

/* lsp_dict_dispatch — funcs["key"]() where funcs is a dict-literal dispatch
 * table mapping string keys to known function QNs (py_lsp.c:1371-1374 registers
 * the table; py_lsp.c:1651-1662 resolves the subscript-call → lsp_dict_dispatch).
 * The table and the call must be in the same function scope so the literal var
 * is registered before the call. */
static const char kPyDictDispatch[] =
    "def foo(x):\n"
    "    return x + 1\n"
    "def bar(x):\n"
    "    return x + 2\n"
    "def caller(v):\n"
    "    funcs = {\"a\": foo, \"b\": bar}\n"
    "    return funcs[\"a\"](v)\n";

/* lsp_operator_dunder — a + b where a is a NAMED type defining __add__
 * (py_lsp.c:2106-2120: binary_operator on a typed NAMED receiver whose class
 * declares the dunder → emit a synthetic CALLS edge to T.__add__). The receiver
 * `a` is annotated so its type is known. */
static const char kPyOperatorDunder[] =
    "class Vec:\n"
    "    def __add__(self, other):\n"
    "        return self\n"
    "def caller(a: Vec, b: Vec):\n"
    "    return a + b\n";

/* lsp_builtin — print()/len()/... a builtins symbol (py_lsp.c:1634-1637:
 * cbm_registry_lookup_symbol("builtins", fname) hits). EXPECTED RED in a
 * single-file harness with no typeshed/builtins registry loaded. */
static const char kPyBuiltin[] =
    "def caller(v):\n"
    "    return len(v)\n";

/* lsp_builtin_constructor — str()/list()/... a builtins TYPE used as a
 * constructor (py_lsp.c:1640-1643: cbm_registry_lookup_type("builtins.str")
 * hits). EXPECTED RED without a typeshed/builtins registry. */
static const char kPyBuiltinConstructor[] =
    "def caller(v):\n"
    "    return str(v)\n";

/* lsp_builtin_method — "x".upper() — a method on a builtin-typed receiver
 * (py_lsp.c:1735-1741: obj_type is BUILTIN, py_lookup_attribute("builtins.str",
 * "upper") hits). EXPECTED RED without a typeshed/builtins registry. */
static const char kPyBuiltinMethod[] =
    "def caller():\n"
    "    s = \"hello\"\n"
    "    return s.upper()\n";

/* lsp_generic_method — method on a TEMPLATE-typed receiver such as a list
 * (py_lsp.c:1745-1753: obj_type is TEMPLATE, attribute resolved on the template
 * base type). xs.append(1) on a list-typed xs. EXPECTED RED without a typeshed
 * registry providing builtins.list.append. */
static const char kPyGenericMethod[] =
    "def caller():\n"
    "    xs = [1, 2, 3]\n"
    "    return xs.append(4)\n";

/* lsp_method_union — method on a UNION-typed receiver where exactly one member
 * defines the method (py_lsp.c:1757-1778: obj_type is UNION, exactly one NAMED
 * member resolves the attribute → lsp_method_union). `x: A | B` where only A
 * defines run(). Documented if the union annotation does not resolve both
 * members to in-file NAMED types. */
static const char kPyMethodUnion[] =
    "class A:\n"
    "    def run(self, v):\n"
    "        return v\n"
    "class B:\n"
    "    def stop(self, v):\n"
    "        return v\n"
    "def caller(x: A | B):\n"
    "    return x.run(1)\n";

/* ── Go per-strategy tests ───────────────────────────────────────────────── */

TEST(repro_lsp_go_direct) {
    return assert_lsp_strategy("main.go", kGoDirect, "lsp_direct");
}

TEST(repro_lsp_go_type_dispatch) {
    return assert_lsp_strategy("main.go", kGoTypeDispatch, "lsp_type_dispatch");
}

TEST(repro_lsp_go_embed_dispatch) {
    return assert_lsp_strategy("main.go", kGoEmbedDispatch, "lsp_embed_dispatch");
}

TEST(repro_lsp_go_interface_resolve) {
    return assert_lsp_strategy("main.go", kGoInterfaceResolve,
                               "lsp_interface_resolve");
}

TEST(repro_lsp_go_interface_dispatch) {
    return assert_lsp_strategy("main.go", kGoInterfaceDispatch,
                               "lsp_interface_dispatch");
}

TEST(repro_lsp_go_strategy_cross_file) {
    /* PARKED for release: lsp_strategy_cross_file is emitted only by the parallel
     * cross-file pass (cbm_go_fast_resolve_qualified_calls), which runs only when
     * a prebuilt cross-registry exists. That registry is not built for the small
     * single-package test fixture, so the strategy is structurally unreachable
     * here — the method call still resolves (callable>=1) via the per-file
     * type-dispatch path, just without this specific cross-file tag. */
    printf("  %sSKIP%s parked: cross-file pass needs a prebuilt cross-registry (not built for "
           "fixture)\n",
           tf_dim(), tf_reset());
    return -1; /* skip — not counted as pass or fail */
    return assert_lsp_strategy_files(
        kGoCrossFile, (int)(sizeof(kGoCrossFile) / sizeof(kGoCrossFile[0])),
        "lsp_strategy_cross_file");
}

TEST(repro_lsp_go_unresolved) {
    /* totallyUnknownFn is UNDECLARED — no node can exist for it, so no CALLS
     * edge can ever form. The accurate invariant is "no resolvable edge", not a
     * resolution strategy on an edge (which is unachievable by design). */
    return assert_no_resolvable_edge("main.go", kGoUnresolved, "totallyUnknownFn");
}

/* ── Python per-strategy tests ───────────────────────────────────────────── */

TEST(repro_lsp_py_direct) {
    return assert_lsp_strategy("main.py", kPyDirect, "lsp_direct");
}

TEST(repro_lsp_py_constructor) {
    return assert_lsp_strategy("main.py", kPyConstructor, "lsp_constructor");
}

TEST(repro_lsp_py_constructor_init) {
    return assert_lsp_strategy("main.py", kPyConstructorInit, "lsp_constructor_init");
}

TEST(repro_lsp_py_method) {
    return assert_lsp_strategy("main.py", kPyMethod, "lsp_method");
}

TEST(repro_lsp_py_super) {
    return assert_lsp_strategy("main.py", kPySuper, "lsp_super");
}

TEST(repro_lsp_py_super_init) {
    return assert_lsp_strategy("main.py", kPySuperInit, "lsp_super_init");
}

TEST(repro_lsp_py_module_attr) {
    /* PARKED for release: cross-file module attribute (`import helpers;
     * helpers.do_work()`). The pass that types `helpers` as a MODULE lacks the
     * sibling's defs, while the pass holding the full cross registry doesn't type
     * `helpers` as a module — needs cross-file module-binding coordination so one
     * pass has both. The edge still forms via the textual resolver, just without
     * the lsp_module_attr tag. */
    printf("  %sSKIP%s parked: cross-file module-binding coordination needed\n", tf_dim(),
           tf_reset());
    return -1; /* skip — not counted as pass or fail */
    return assert_lsp_strategy_files(
        kPyModuleAttr, (int)(sizeof(kPyModuleAttr) / sizeof(kPyModuleAttr[0])),
        "lsp_module_attr");
}

TEST(repro_lsp_py_module_attr_unresolved) {
    /* helpers.missing_fn — the module `helpers` is known but the symbol
     * `missing_fn` is ABSENT from it, so no node exists for the callee and no
     * CALLS edge can form. Assert the accurate no-resolvable-edge behaviour
     * rather than a strategy on an edge (unachievable by design). */
    return assert_no_resolvable_edge_files(
        kPyModuleAttrUnresolved,
        (int)(sizeof(kPyModuleAttrUnresolved) / sizeof(kPyModuleAttrUnresolved[0])),
        "missing_fn");
}

TEST(repro_lsp_py_dict_dispatch) {
    return assert_lsp_strategy("main.py", kPyDictDispatch, "lsp_dict_dispatch");
}

TEST(repro_lsp_py_operator_dunder) {
    return assert_lsp_strategy("main.py", kPyOperatorDunder,
                               "lsp_operator_dunder");
}

TEST(repro_lsp_py_builtin) {
    /* len(v) resolves to the injected builtins.len node (py_builtins.c) and
     * emits lsp_builtin with a real CALLS edge. */
    return assert_lsp_strategy("main.py", kPyBuiltin, "lsp_builtin");
}

TEST(repro_lsp_py_builtin_constructor) {
    /* str(v) resolves to the injected builtins.str type node (py_builtins.c)
     * and emits lsp_builtin_constructor with a real CALLS edge. */
    return assert_lsp_strategy("main.py", kPyBuiltinConstructor,
                               "lsp_builtin_constructor");
}

TEST(repro_lsp_py_builtin_method) {
    return assert_lsp_strategy("main.py", kPyBuiltinMethod, "lsp_builtin_method");
}

TEST(repro_lsp_py_generic_method) {
    return assert_lsp_strategy("main.py", kPyGenericMethod, "lsp_generic_method");
}

TEST(repro_lsp_py_method_union) {
    return assert_lsp_strategy("main.py", kPyMethodUnion, "lsp_method_union");
}

/* ── Suite ───────────────────────────────────────────────────────────────── */

SUITE(repro_lsp_go_py) {
    RUN_TEST(repro_lsp_go_direct);
    RUN_TEST(repro_lsp_go_type_dispatch);
    RUN_TEST(repro_lsp_go_embed_dispatch);
    RUN_TEST(repro_lsp_go_interface_resolve);
    RUN_TEST(repro_lsp_go_interface_dispatch);
    RUN_TEST(repro_lsp_go_strategy_cross_file);
    RUN_TEST(repro_lsp_go_unresolved);

    RUN_TEST(repro_lsp_py_direct);
    RUN_TEST(repro_lsp_py_constructor);
    RUN_TEST(repro_lsp_py_constructor_init);
    RUN_TEST(repro_lsp_py_method);
    RUN_TEST(repro_lsp_py_super);
    RUN_TEST(repro_lsp_py_super_init);
    RUN_TEST(repro_lsp_py_module_attr);
    RUN_TEST(repro_lsp_py_module_attr_unresolved);
    RUN_TEST(repro_lsp_py_dict_dispatch);
    RUN_TEST(repro_lsp_py_operator_dunder);
    RUN_TEST(repro_lsp_py_builtin);
    RUN_TEST(repro_lsp_py_builtin_constructor);
    RUN_TEST(repro_lsp_py_builtin_method);
    RUN_TEST(repro_lsp_py_generic_method);
    RUN_TEST(repro_lsp_py_method_union);
}