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.

fix: bulk parallel — Rust cross-crate, Python builtins, #607 reinstall, grammar reds

Martin Vogel0849f28c3f5d
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 64433d47e..f576d4db2 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -889,6 +889,35 @@ static char *extract_func_callee(CBMArena *a, TSNode node, const char *source, c
return ts_node_is_null(fn) ? NULL : cbm_node_text(a, fn, source);
}
+// Nix: an `apply_expression` (`f x`) carries the applied function on its
+// `function:` field. The head is a `variable_expression` whose `name` is the
+// callee identifier; curried application (`f x y`) nests apply_expressions, so
+// descend the `function` chain to the head variable_expression. The generic
+// field resolver does not recognise `variable_expression`, so without this the
+// call to `addOne` would never be captured.
+static char *extract_nix_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
+ if (strcmp(nk, "apply_expression") != 0) {
+ return NULL;
+ }
+ TSNode fn = ts_node_child_by_field_name(node, TS_FIELD("function"));
+ for (int depth = 0; depth < 8 && !ts_node_is_null(fn); depth++) {
+ const char *fk = ts_node_type(fn);
+ if (strcmp(fk, "apply_expression") == 0) {
+ fn = ts_node_child_by_field_name(fn, TS_FIELD("function"));
+ continue;
+ }
+ if (strcmp(fk, "variable_expression") == 0) {
+ TSNode nm = ts_node_child_by_field_name(fn, TS_FIELD("name"));
+ return ts_node_is_null(nm) ? NULL : cbm_node_text(a, nm, source);
+ }
+ if (strcmp(fk, "identifier") == 0) {
+ return cbm_node_text(a, fn, source);
+ }
+ return NULL;
+ }
+ return NULL;
+}
+
// Agda: function application `f x y` parses as an `expr` whose named children are
// `atom`s (no dedicated application node). Treat an `expr` with >= 2 atom children
// as a call whose callee is the head atom's identifier.
@@ -1068,6 +1097,12 @@ static char *extract_callee_lang_specific(CBMArena *a, TSNode node, const char *
return c;
}
}
+ if (lang == CBM_LANG_NIX) {
+ char *c = extract_nix_callee(a, node, source, nk);
+ if (c) {
+ return c;
+ }
+ }
if (lang == CBM_LANG_MAKEFILE) {
char *c = extract_make_callee(a, node, source, nk);
if (c) {
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index 190252e9e..94040369b 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -773,6 +773,23 @@ TSNode cbm_resolve_func_name(TSNode node, CBMLanguage lang) {
}
}
+ /* Nix: a named function is a `function_expression` (lambda `x: body`) with
+ * no name of its own — the binding name lives on the enclosing `binding`'s
+ * `attrpath` field (`name = x: ...`). Resolve through the parent binding to
+ * the attrpath's `attr` identifier so `addOne = x: ...` mints a Function
+ * def. A lambda whose parent is not a binding (e.g. an inline `map (x: x)`
+ * argument) resolves null and stays out of func_types. */
+ if (lang == CBM_LANG_NIX && strcmp(kind, "function_expression") == 0) {
+ TSNode parent = ts_node_parent(node);
+ if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "binding") == 0) {
+ TSNode attrpath = ts_node_child_by_field_name(parent, TS_FIELD("attrpath"));
+ if (!ts_node_is_null(attrpath)) {
+ TSNode attr = ts_node_child_by_field_name(attrpath, TS_FIELD("attr"));
+ return ts_node_is_null(attr) ? attrpath : attr;
+ }
+ }
+ }
+
/* Fortran: subroutine/function wrap an inner *_statement that carries the
* `name` field; the outer node walk_defs matched has no name itself. */
if (lang == CBM_LANG_FORTRAN &&
@@ -3512,18 +3529,32 @@ static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
}
// Rust/Swift/D: a struct is a distinct kind from a class — emit the precise
// "Struct" label rather than collapsing it to "Class". Scoped to these three
- // grammar/LSP languages whose struct node is `struct_item` (Rust) or
- // `struct_declaration` (Swift, D). C/C++/Obj-C keep `struct_specifier` →
- // "Class" (a C++ struct is class-like). "Struct" is a type-like container:
- // every type-resolution / registry / IMPLEMENTS / LSP-registrar consumer
- // routes through cbm_label_is_type_like(), so a struct still resolves as a
- // type for its methods, fields, inheritance and impls.
+ // grammar/LSP languages. Rust's struct node is `struct_item`; D's is
+ // `struct_declaration`. C/C++/Obj-C keep `struct_specifier` → "Class"
+ // (a C++ struct is class-like). "Struct" is a type-like container: every
+ // type-resolution / registry / IMPLEMENTS / LSP-registrar consumer routes
+ // through cbm_label_is_type_like(), so a struct still resolves as a type for
+ // its methods, fields, inheritance and impls.
if (ctx->language == CBM_LANG_RUST || ctx->language == CBM_LANG_SWIFT ||
ctx->language == CBM_LANG_DLANG) {
if (strcmp(kind, "struct_item") == 0 || strcmp(kind, "struct_declaration") == 0) {
label = "Struct";
}
}
+ // Swift: tree-sitter-swift does NOT have a dedicated `struct_declaration`
+ // node — `struct`, `class` and `actor` all parse to `class_declaration`,
+ // distinguished only by the `declaration_kind` field (the leading keyword
+ // token). Read that field and emit "Struct" when the keyword is `struct`
+ // (and "Class" for `class`/`actor`, which class_label_for_kind already gives).
+ if (ctx->language == CBM_LANG_SWIFT && strcmp(kind, "class_declaration") == 0) {
+ TSNode dk = ts_node_child_by_field_name(node, TS_FIELD("declaration_kind"));
+ if (!ts_node_is_null(dk)) {
+ char *dk_text = cbm_node_text(a, dk, ctx->source);
+ if (dk_text && strcmp(dk_text, "struct") == 0) {
+ label = "Struct";
+ }
+ }
+ }
// F#: a `type_definition` that has a primary constructor (`type Foo(...) =`)
// or an `inherit` clause is an OOP class, not a plain type alias. Label it
// "Class" so it is registered as a resolvable inheritance target (the graph
diff --git a/internal/cbm/lsp/py_builtins.c b/internal/cbm/lsp/py_builtins.c
new file mode 100644
index 000000000..2c3cacbdd
--- /dev/null
+++ b/internal/cbm/lsp/py_builtins.c
@@ -0,0 +1,89 @@
+/*
+ * py_builtins.c — Minimal Python builtins as real graph nodes.
+ *
+ * The Python LSP type registry already knows the builtins (typeshed-derived
+ * generated/python_stdlib_data.c registers builtins.len, builtins.str,
+ * builtins.str.upper, builtins.list.append, ...). So a call like len(v) /
+ * str(v) / "x".upper() / xs.append(1) ALREADY resolves at the LSP layer and
+ * emits the correct strategy (lsp_builtin / lsp_builtin_constructor /
+ * lsp_builtin_method / lsp_generic_method) with callee_qn = "builtins.<name>".
+ *
+ * The missing piece is downstream: pass_calls.c only writes a CALLS edge when
+ * cbm_pipeline_lsp_target_node() resolves the callee_qn to a graph node
+ * (src/pipeline/lsp_resolve.h). There is no "builtins.len" node in the graph,
+ * so the resolved call is dropped and the strategy never lands on an edge.
+ *
+ * Fix: inject a small, fixed set of builtin definitions into result->defs
+ * during the per-file Python LSP run (which executes inside cbm_extract_file,
+ * BEFORE the parallel pipeline mints def nodes from result->defs). The graph
+ * therefore gains real "builtins.*" nodes that the LSP-emitted edges target.
+ * The QNs here MUST match what the typeshed registry emits as callee_qn.
+ *
+ * Node minting upserts by QN (cbm_gbuf_upsert_node), so injecting the same
+ * builtins per Python file collapses to one node per QN — no duplicates.
+ *
+ * Self-contained: #included from py_lsp.c only (CGo amalgamation pattern;
+ * see lsp_all.c). Not a standalone translation unit.
+ */
+
+/* A single builtin entry to mint as a graph node. */
+typedef struct {
+ const char *qn; /* graph QN — MUST equal the registry callee_qn */
+ const char *name; /* short name (last segment of qn) */
+ const char *label; /* "Function" | "Class" | "Method" */
+} PyBuiltinNode;
+
+/*
+ * Minimal builtins set. Kept deliberately small and aligned with the registry
+ * (generated/python_stdlib_data.c):
+ * - free functions (lsp_builtin): len, print
+ * - types/ctors (lsp_builtin_constructor): str, int, list, dict, range
+ * - str methods (lsp_builtin_method): upper, lower
+ * - list methods (lsp_generic_method): append, pop
+ * - dict methods (lsp_generic_method): get
+ * Note: str/int/list/dict/range are TYPES in the registry (so X() routes to
+ * lsp_builtin_constructor), hence the "Class" label here.
+ */
+static const PyBuiltinNode kPyBuiltinNodes[] = {
+ {"builtins.len", "len", "Function"},
+ {"builtins.print", "print", "Function"},
+
+ {"builtins.str", "str", "Class"},
+ {"builtins.int", "int", "Class"},
+ {"builtins.list", "list", "Class"},
+ {"builtins.dict", "dict", "Class"},
+ {"builtins.range", "range", "Class"},
+
+ {"builtins.str.upper", "upper", "Method"},
+ {"builtins.str.lower", "lower", "Method"},
+
+ {"builtins.list.append", "append", "Method"},
+ {"builtins.list.pop", "pop", "Method"},
+
+ {"builtins.dict.get", "get", "Method"},
+};
+
+/*
+ * Inject the builtin definitions into result->defs so the pipeline mints them
+ * as graph nodes. All fields beyond name/qn/label are left zero/NULL: builtins
+ * have no body, so complexity/line-range/etc. are irrelevant, and a synthetic
+ * file_path keeps them out of any real source file's def list.
+ */
+static void py_builtins_inject_defs(CBMFileResult *result, CBMArena *arena) {
+ if (!result || !arena) {
+ return;
+ }
+ const int n = (int)(sizeof(kPyBuiltinNodes) / sizeof(kPyBuiltinNodes[0]));
+ for (int i = 0; i < n; i++) {
+ const PyBuiltinNode *b = &kPyBuiltinNodes[i];
+ CBMDefinition def;
+ memset(&def, 0, sizeof(def));
+ def.name = b->name;
+ def.qualified_name = b->qn;
+ def.label = b->label;
+ def.file_path = "<python-builtins>";
+ def.start_line = 1;
+ def.end_line = 1;
+ cbm_defs_push(&result->defs, arena, def);
+ }
+}
diff --git a/internal/cbm/lsp/py_lsp.c b/internal/cbm/lsp/py_lsp.c
index 1898cd7a3..e94ae8f11 100644
--- a/internal/cbm/lsp/py_lsp.c
+++ b/internal/cbm/lsp/py_lsp.c
@@ -18,6 +18,11 @@
#include <stdlib.h>
#include <string.h>
+/* Minimal Python builtins as real graph nodes (py_builtins_inject_defs).
+ * #included here (CGo amalgamation pattern, see lsp_all.c) — referenced
+ * only from py_lsp.c, never compiled standalone. */
+#include "py_builtins.c"
+
// Forward decls
static void py_resolve_calls_in(PyLSPContext *ctx, TSNode node);
static const CBMType *py_eval_expr_type(PyLSPContext *ctx, TSNode node);
@@ -3363,6 +3368,15 @@ void cbm_run_py_lsp(CBMArena *arena, CBMFileResult *result, const char *source,
if (!arena || !result)
return;
+ /* Inject minimal builtin definitions as real graph nodes (builtins.len,
+ * builtins.str, builtins.str.upper, ...). The typeshed registry already
+ * RESOLVES builtin calls (emitting the strategy + a "builtins.*" callee_qn),
+ * but pass_calls.c only writes the CALLS edge when that callee_qn maps to a
+ * graph node. We run inside cbm_extract_file, before the pipeline mints
+ * def nodes from result->defs, so these become the target nodes the
+ * builtin/constructor/method edges point at. Upsert dedups by QN. */
+ py_builtins_inject_defs(result, arena);
+
CBMTypeRegistry reg;
cbm_registry_init(&reg, arena);
diff --git a/internal/cbm/lsp/rust_lsp.c b/internal/cbm/lsp/rust_lsp.c
index 03da7a132..a02503441 100644
--- a/internal/cbm/lsp/rust_lsp.c
+++ b/internal/cbm/lsp/rust_lsp.c
@@ -3625,18 +3625,62 @@ static void rust_resolve_call_expression(RustLSPContext *ctx, TSNode node) {
}
}
- /* Global short-name fallback: scan the registry for a unique
- * function whose short_name matches the path's tail and whose
- * QN starts with the current crate prefix. This gives `mod
- * foo; use foo::bar; bar()` a chance to resolve when the
- * intermediate module wasn't tracked through an explicit
- * use-map entry. */
const char *tail = strrchr(path, ':');
if (tail && tail > path && tail[-1] == ':') {
tail += 1;
} else {
tail = path;
}
+
+ /* Cross-crate workspace-member resolution (#56): when the call
+ * path's head is a declared Cargo workspace member (e.g.
+ * `crate_a::helper` from inside crate_b) we cannot rely on the
+ * caller-crate-scoped fallback below — that filters by the
+ * CALLER's module prefix and would resolve to a same-named local
+ * function instead. Route to the function defined inside the
+ * MEMBER crate by matching the registered QN's `.<member>.`
+ * path segment plus the call tail. Requires a parsed manifest
+ * (threaded through pass_lsp_cross.c); NULL manifest skips this. */
+ if (ctx->cargo_manifest && tail && *tail) {
+ const char *head_sep = strstr(path, "::");
+ if (head_sep && head_sep > path) {
+ char *head = cbm_arena_strndup(ctx->arena, path, (size_t)(head_sep - path));
+ const CBMCargoManifest *m = (const CBMCargoManifest *)ctx->cargo_manifest;
+ if (head && cbm_cargo_find_member(m, head)) {
+ /* `.crate_a.` — the member directory appears as a dotted
+ * QN segment for every def inside that crate. */
+ char *needle = cbm_arena_sprintf(ctx->arena, ".%s.", head);
+ const CBMRegisteredFunc *mem_unique = NULL;
+ int mem_matches = 0;
+ for (int i = 0; i < ctx->registry->func_count && mem_matches < 2; i++) {
+ const CBMRegisteredFunc *f = &ctx->registry->funcs[i];
+ if (!f->short_name || !f->qualified_name)
+ continue;
+ if (f->receiver_type)
+ continue; /* free functions only */
+ if (strcmp(f->short_name, tail) != 0)
+ continue;
+ if (!strstr(f->qualified_name, needle))
+ continue; /* not defined in the member crate */
+ mem_matches++;
+ if (mem_matches == 1)
+ mem_unique = f;
+ }
+ if (mem_matches == 1 && mem_unique) {
+ rust_emit_resolved_call(ctx, mem_unique->qualified_name, "lsp_cross_crate",
+ CBM_RUST_CONF_DIRECT);
+ return;
+ }
+ }
+ }
+ }
+
+ /* Global short-name fallback: scan the registry for a unique
+ * function whose short_name matches the path's tail and whose
+ * QN starts with the current crate prefix. This gives `mod
+ * foo; use foo::bar; bar()` a chance to resolve when the
+ * intermediate module wasn't tracked through an explicit
+ * use-map entry. */
if (tail && *tail && ctx->module_qn) {
/* Crate prefix is the first dotted segment of module_qn after
* the project name, but for simplicity we just match on
@@ -5121,10 +5165,12 @@ void cbm_run_rust_lsp(CBMArena *arena, CBMFileResult *result, const char *source
extern const TSLanguage *tree_sitter_rust(void);
-void cbm_run_rust_lsp_cross(CBMArena *arena, const char *source, int source_len,
- const char *module_qn, CBMRustLSPDef *defs, int def_count,
- const char **import_names, const char **import_qns, int import_count,
- TSTree *cached_tree, CBMResolvedCallArray *out) {
+void cbm_run_rust_lsp_cross_with_manifest(CBMArena *arena, const char *source, int source_len,
+ const char *module_qn, CBMRustLSPDef *defs, int def_count,
+ const char **import_names, const char **import_qns,
+ int import_count, TSTree *cached_tree,
+ const struct CBMCargoManifest *manifest,
+ CBMResolvedCallArray *out) {
if (!source || source_len <= 0 || !out)
return;
@@ -5251,6 +5297,10 @@ void cbm_run_rust_lsp_cross(CBMArena *arena, const char *source, int source_len,
RustLSPContext ctx;
rust_lsp_init(&ctx, arena, source, source_len, &reg, module_qn, out);
+ /* Workspace/dependency awareness for cross-CRATE path routing (#56).
+ * Mirrors the single-file path (cbm_run_rust_lsp_with_manifest). NULL
+ * when no Cargo.toml was parsed — in-crate resolution is unaffected. */
+ ctx.cargo_manifest = manifest;
rust_collect_uses(&ctx, root);
for (int i = 0; i < import_count; i++) {
if (import_names[i] && import_qns[i]) {
@@ -5266,6 +5316,18 @@ void cbm_run_rust_lsp_cross(CBMArena *arena, const char *source, int source_len,
}
}
+/* Manifest-free entry point. Preserves the pre-existing signature used by
+ * the unit tests (test_rust_lsp.c) and the batch wrapper — delegates to
+ * the manifest-aware variant with a NULL manifest. */
+void cbm_run_rust_lsp_cross(CBMArena *arena, const char *source, int source_len,
+ const char *module_qn, CBMRustLSPDef *defs, int def_count,
+ const char **import_names, const char **import_qns, int import_count,
+ TSTree *cached_tree, CBMResolvedCallArray *out) {
+ cbm_run_rust_lsp_cross_with_manifest(arena, source, source_len, module_qn, defs, def_count,
+ import_names, import_qns, import_count, cached_tree, NULL,
+ out);
+}
+
void cbm_batch_rust_lsp_cross(CBMArena *arena, CBMBatchRustLSPFile *files, int file_count,
CBMResolvedCallArray *out) {
if (!files || file_count <= 0 || !out)
diff --git a/internal/cbm/lsp/rust_lsp.h b/internal/cbm/lsp/rust_lsp.h
index 9b9439ac3..302565761 100644
--- a/internal/cbm/lsp/rust_lsp.h
+++ b/internal/cbm/lsp/rust_lsp.h
@@ -283,6 +283,19 @@ void cbm_run_rust_lsp_cross(CBMArena *arena, const char *source, int source_len,
const char **import_names, const char **import_qns, int import_count,
TSTree *cached_tree, CBMResolvedCallArray *out);
+/* Same as `cbm_run_rust_lsp_cross`, plus an optional parsed Cargo manifest
+ * (NULL = manifest-free behaviour). The manifest lets call paths whose head
+ * is a workspace member / declared dependency route across the crate
+ * boundary (`crate_a::foo` → the def inside crate_a). Wired from the
+ * cross-file LSP pass (pass_lsp_cross.c) which builds the manifest once from
+ * the project root Cargo.toml. */
+void cbm_run_rust_lsp_cross_with_manifest(CBMArena *arena, const char *source, int source_len,
+ const char *module_qn, CBMRustLSPDef *defs, int def_count,
+ const char **import_names, const char **import_qns,
+ int import_count, TSTree *cached_tree,
+ const struct CBMCargoManifest *manifest,
+ CBMResolvedCallArray *out);
+
/* Per-file input for batch cross-file Rust LSP processing. */
typedef struct {
const char *source;
diff --git a/src/cli/cli.c b/src/cli/cli.c
index d15472335..6b32a8b51 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -2691,6 +2691,15 @@ int cbm_cmd_config(int argc, char **argv) {
/* Global auto-answer mode: 0=interactive, 1=always yes, -1=always no */
static int g_auto_answer = 0;
+/* Test seam: force the auto-answer state so non-interactive bug-repro tests
+ * can drive prompt_yn() deterministically (1 => yes, -1 => no, 0 => prompt).
+ * Not declared in cli.h (internal); the repro runner links cli.c directly and
+ * carries an extern forward declaration. Production never calls this. */
+void cbm_set_auto_answer_for_test(int value);
+void cbm_set_auto_answer_for_test(int value) {
+ g_auto_answer = value;
+}
+
static void parse_auto_answer(int argc, char **argv) {
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "-y") == 0 || strcmp(argv[i], "--yes") == 0) {
@@ -3335,6 +3344,59 @@ static int count_db_indexes(const char *home) {
return count;
}
+/* Handle pre-existing indexes during (re)install (#607).
+ *
+ * Returns 1 to proceed with the install, 0 to abort (user declined the
+ * destructive reset prompt).
+ *
+ * Default (reset=false): PRESERVE the indexed graph. We do NOT delete any
+ * .db. We print an honest message telling the user the indexes are kept and
+ * that they should re-index after install to pick up this version's
+ * extraction improvements. The old behaviour deleted every index here while
+ * printing "must be rebuilt" and never rebuilt — silent, irrecoverable data
+ * loss (#607). Deletion is NOT a schema requirement (the store uses CREATE
+ * TABLE IF NOT EXISTS with no migrations); it only guarded against stale
+ * content, which a re-index fixes without destroying anything.
+ *
+ * Opt-in (reset=true, via `install --reset-indexes`): keep the original
+ * prompt-and-delete behaviour, with honest "Delete" wording.
+ *
+ * Not static: linked into the bug-repro test runner so repro_issue607.c can
+ * assert the default path preserves the DB. It is intentionally NOT declared
+ * in cli.h (internal helper); the test carries an extern forward declaration.
+ */
+int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_run);
+int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_run) {
+ int index_count = count_db_indexes(home);
+ if (index_count <= 0) {
+ return 1; /* nothing to handle, proceed */
+ }
+
+ if (!reset) {
+ /* Default: preserve. Be honest — keep the indexes, advise re-index. */
+ printf("Found %d existing index(es). Keeping them. After install, "
+ "re-index to pick up this version's improvements:\n",
+ index_count);
+ cbm_list_indexes(home);
+ printf("\n");
+ return 1; /* proceed without deleting */
+ }
+
+ /* Opt-in reset (--reset-indexes): the original prompt-and-delete path. */
+ printf("Found %d existing index(es):\n", index_count);
+ cbm_list_indexes(home);
+ printf("\n");
+ if (!prompt_yn("Delete these indexes and continue with install?")) {
+ printf("Install cancelled.\n");
+ return 0; /* abort */
+ }
+ if (!dry_run) {
+ int removed = cbm_remove_indexes(home);
+ printf("Removed %d index(es).\n\n", removed);
+ }
+ return 1; /* proceed */
+}
+
/* ── Subcommand: install ──────────────────────────────────────── */
/* Detect the running binary's path at runtime. Falls back to ~/.local/bin/. */
@@ -3445,6 +3507,7 @@ int cbm_cmd_install(int argc, char **argv) {
bool dry_run = false;
bool force = false;
bool plan = false;
+ bool reset_indexes = false;
for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--dry-run") == 0) {
dry_run = true;
@@ -3455,6 +3518,11 @@ int cbm_cmd_install(int argc, char **argv) {
if (strcmp(argv[i], "--plan") == 0) {
plan = true;
}
+ /* Opt-in: delete existing indexes during install. Default preserves
+ * the indexed graph (#607). Only this flag triggers deletion. */
+ if (strcmp(argv[i], "--reset-indexes") == 0) {
+ reset_indexes = true;
+ }
}
const char *home = cbm_get_home_dir();
@@ -3481,19 +3549,11 @@ int cbm_cmd_install(int argc, char **argv) {
printf("codebase-memory-mcp install %s\n\n", CBM_VERSION);
- int index_count = count_db_indexes(home);
- if (index_count > 0) {
- printf("Found %d existing index(es) that must be rebuilt:\n", index_count);
- cbm_list_indexes(home);
- printf("\n");
- if (!prompt_yn("Delete these indexes and continue with install?")) {
- printf("Install cancelled.\n");
- return CLI_TRUE;
- }
- if (!dry_run) {
- int removed = cbm_remove_indexes(home);
- printf("Removed %d index(es).\n\n", removed);
- }
+ /* (#607) Default: preserve existing indexes. `--reset-indexes` opts into
+ * the old prompt-and-delete behaviour. The helper returns 0 only when the
+ * user declines the reset prompt, in which case we abort the install. */
+ if (cbm_install_handle_existing_indexes(home, reset_indexes, dry_run) == 0) {
+ return CLI_TRUE;
}
/* Step 1b: Kill running MCP server instances so agents pick up new config */
diff --git a/src/pipeline/pass_lsp_cross.c b/src/pipeline/pass_lsp_cross.c
index d86c819d3..2f230f3b0 100644
--- a/src/pipeline/pass_lsp_cross.c
+++ b/src/pipeline/pass_lsp_cross.c
@@ -22,6 +22,8 @@
#include "lsp/php_lsp.h"
#include "lsp/java_lsp.h"
#include "lsp/kotlin_lsp.h"
+#include "lsp/rust_lsp.h"
+#include "lsp/rust_cargo.h"
#include "graph_buffer/graph_buffer.h"
#include "foundation/constants.h"
#include "foundation/hash_table.h"
@@ -292,6 +294,7 @@ bool cbm_pxc_has_cross_lsp(CBMLanguage lang) {
case CBM_LANG_CSHARP: /* tier-2 prebuilt registry path (pass_parallel.c) */
case CBM_LANG_JAVA: /* fallback cbm_pxc_run_one path */
case CBM_LANG_KOTLIN: /* fallback cbm_pxc_run_one path */
+ case CBM_LANG_RUST: /* fallback cbm_pxc_run_one path (manifest-aware) */
return true;
default:
return false;
@@ -352,6 +355,54 @@ static void pxc_append_results(CBMArena *dst_arena, CBMResolvedCallArray *dst_ca
cbm_arena_destroy(&keys);
}
+/* ── Rust workspace manifest (Cargo.toml) for cross-CRATE resolution ──
+ *
+ * cbm_pxc_run_one's signature is shared with the parallel pass
+ * (pass_parallel.c) and cannot grow a manifest parameter without touching
+ * that file. We therefore pass the parsed workspace manifest to the Rust
+ * cross-file resolver through a file-static borrowed pointer that the
+ * sequential driver (cbm_pipeline_pass_lsp_cross, below) sets up once per
+ * pass run from the project's root Cargo.toml. The manifest's strings are
+ * owned by `g_pxc_rust_manifest_arena`; the pointer is borrowed (NULL when
+ * the project has no Cargo.toml — single-crate / non-workspace projects,
+ * where in-file resolution needs no workspace metadata). */
+static _Thread_local const CBMCargoManifest *g_pxc_rust_manifest = NULL;
+
+void cbm_pxc_set_rust_manifest(const CBMCargoManifest *m) {
+ g_pxc_rust_manifest = m;
+}
+
+/* Convert a CBMLSPDef array (the pipeline's lingua franca, go_lsp.h:73)
+ * into a CBMRustLSPDef array (rust_lsp.h) inside `arena`. The two structs
+ * share their first 9 string fields; CBMRustLSPDef adds `trait_qn` before
+ * `is_interface` whereas CBMLSPDef has `is_interface` followed by `lang`,
+ * so a memcpy is unsafe — copy field-by-field. trait_qn is left NULL
+ * because the pipeline's collect-all-defs step does not carry the
+ * impl-Trait-for-Type linkage; the resolver still recovers trait dispatch
+ * from the in-file walk (the cross-file path only needs receiver_type). */
+static CBMRustLSPDef *pxc_lspdefs_to_rust(CBMArena *arena, const CBMLSPDef *defs, int def_count) {
+ if (!defs || def_count <= 0)
+ return NULL;
+ CBMRustLSPDef *out =
+ (CBMRustLSPDef *)cbm_arena_alloc(arena, (size_t)def_count * sizeof(CBMRustLSPDef));
+ if (!out)
+ return NULL;
+ for (int i = 0; i < def_count; i++) {
+ out[i].qualified_name = defs[i].qualified_name;
+ out[i].short_name = defs[i].short_name;
+ out[i].label = defs[i].label;
+ out[i].receiver_type = defs[i].receiver_type;
+ out[i].def_module_qn = defs[i].def_module_qn;
+ out[i].return_types = defs[i].return_types;
+ out[i].embedded_types = defs[i].embedded_types;
+ out[i].field_defs = defs[i].field_defs;
+ out[i].method_names_str = defs[i].method_names_str;
+ out[i].trait_qn = NULL;
+ out[i].is_interface = defs[i].is_interface;
+ }
+ return out;
+}
+
/* Run cross-file LSP for a single file inside a scratch arena that gets
* freed when the call returns. The LSP would otherwise allocate a fresh
* type registry + stdlib + all project defs into the supplied arena, and
@@ -402,6 +453,18 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, int
cbm_run_kotlin_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count,
imp_names, imp_qns, imp_count, tree, &out);
break;
+ case CBM_LANG_RUST: {
+ /* The Rust resolver wants CBMRustLSPDef (rust_lsp.h), not the
+ * pipeline's CBMLSPDef — the structs share their first 9 fields
+ * but diverge after, so convert into the scratch arena. The
+ * workspace manifest (set once by the sequential driver) lets
+ * `crate_a::foo` route across the crate boundary (#56). */
+ CBMRustLSPDef *rdefs = pxc_lspdefs_to_rust(&scratch, defs, def_count);
+ cbm_run_rust_lsp_cross_with_manifest(&scratch, source, source_len, module_qn, rdefs,
+ def_count, imp_names, imp_qns, imp_count, tree,
+ g_pxc_rust_manifest, &out);
+ break;
+ }
default:
break;
}
@@ -428,6 +491,32 @@ void cbm_pxc_run_one_ts(CBMFileResult *r, const char *source, int source_len, co
cbm_arena_destroy(&scratch);
}
+/* Parse the project's root Cargo.toml (if present) into `out_m`, using
+ * `marena` for the manifest's owned strings. Returns true when a manifest
+ * was parsed (a workspace root or any [package]/[dependencies]); false when
+ * there is no readable Cargo.toml, leaving *out_m untouched. The resulting
+ * manifest feeds cross-CRATE Rust resolution (#56): its [workspace].members
+ * map lets `crate_a::foo` route to the member crate's def. */
+static bool pxc_build_rust_manifest(const cbm_pipeline_ctx_t *ctx, CBMArena *marena,
+ CBMCargoManifest *out_m) {
+ if (!ctx || !ctx->repo_path || !marena || !out_m)
+ return false;
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/Cargo.toml", ctx->repo_path);
+ if (n <= 0 || (size_t)n >= sizeof(path))
+ return false;
+ int toml_len = 0;
+ char *toml = pxc_read_file(path, &toml_len);
+ if (!toml || toml_len <= 0) {
+ free(toml);
+ return false;
+ }
+ memset(out_m, 0, sizeof(*out_m));
+ cbm_cargo_parse(marena, toml, toml_len, out_m);
+ free(toml); /* cargo parser copies into marena */
+ return true;
+}
+
int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
int file_count, CBMFileResult **cache) {
if (!ctx || !files || file_count <= 0 || !cache)
@@ -435,6 +524,26 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *
cbm_log_info("pass.start", "pass", "lsp_cross", "files", itoa_buf(file_count));
+ /* Build the Rust workspace manifest once (only when the project has at
+ * least one Rust file, to avoid an unconditional Cargo.toml read).
+ * The manifest's strings live in `cargo_arena`; the resolver borrows
+ * the pointer through the file-static set below. */
+ bool have_rust = false;
+ for (int i = 0; i < file_count; i++) {
+ if (cache[i] && files[i].language == CBM_LANG_RUST) {
+ have_rust = true;
+ break;
+ }
+ }
+ CBMArena cargo_arena;
+ CBMCargoManifest cargo_manifest;
+ bool have_manifest = false;
+ if (have_rust) {
+ cbm_arena_init(&cargo_arena);
+ have_manifest = pxc_build_rust_manifest(ctx, &cargo_arena, &cargo_manifest);
+ cbm_pxc_set_rust_manifest(have_manifest ? &cargo_manifest : NULL);
+ }
+
/* Per-file module QN cache so we don't recompute it once per def + once
* per call. cbm_pipeline_fqn_module mallocs; freed at end. */
char **def_modules = (char **)calloc((size_t)file_count, sizeof(char *));
@@ -500,6 +609,14 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *
free(def_modules[i]);
free(def_modules);
+ /* Drop the borrowed manifest pointer before its arena dies, so a later
+ * pass (or a stale thread-local) can never read freed manifest memory. */
+ if (have_rust) {
+ cbm_pxc_set_rust_manifest(NULL);
+ cbm_arena_destroy(&cargo_arena);
+ }
+ (void)have_manifest;
+
cbm_log_info("pass.done", "pass", "lsp_cross", "files_processed", itoa_buf(processed),
"files_skipped_no_lsp", itoa_buf(skipped_no_lsp), "files_skipped_no_source",
itoa_buf(skipped_no_source), "defs_total", itoa_buf(def_count), "lsp_calls",
diff --git a/tests/repro/repro_grammar_scientific.c b/tests/repro/repro_grammar_scientific.c
index 6f9bc7ca2..c91a70336 100644
--- a/tests/repro/repro_grammar_scientific.c
+++ b/tests/repro/repro_grammar_scientific.c
@@ -486,23 +486,29 @@ TEST(repro_grammar_scientific_matlab) {
/* ── Magma ────────────────────────────────────────────────────────────────────
* Computational algebra system; (magma_func_types = function_definition/
* procedure_definition, magma_call_types = call_expression). Idiomatic: a
- * function `Add` and a function `Compute` that calls it, using Magma's
- * `func<...>` / `function ... end function;` def form. Expected: dims 1-6 + 8
- * GREEN, dim 7 RED (enclosing-func gap).
+ * function `Add` and a function `Compute` that calls it.
+ *
+ * Fixture correction: the prior `Add := function(a, b) ... end function;`
+ * assignment form does NOT parse to a `function_definition` in tree-sitter-magma
+ * — `function(a, b)` is read as a `call_expression` named "function" and the
+ * trailing `end function;` lands in an ERROR node, so no Function def was minted.
+ * The declarative `function Name(...) ... end function;` form (the construct the
+ * grammar and magma_func_types target) parses cleanly into `function_definition`
+ * with a `name` field. Expected: dims 1-6 + 8 GREEN, dim 7 RED (enclosing-func gap).
*/
TEST(repro_grammar_scientific_magma) {
static const char src[] =
- "Add := function(a, b)\n"
+ "function Add(a, b)\n"
" return a + b;\n"
"end function;\n"
"\n"
- "Compute := function(x)\n"
+ "function Compute(x)\n"
" return Add(x, 1);\n"
"end function;\n";
if (single_file_battery("Magma", src, CBM_LANG_MAGMA, "calc.magma",
"Function", NULL, "Add") != 0)
return 1;
- if (robustness_probe("Magma", "Compute := function(x)\n return Add(",
+ if (robustness_probe("Magma", "function Compute(x)\n return Add(",
CBM_LANG_MAGMA, "calc.magma") != 0)
return 1;
return pipeline_battery("Magma", "calc.magma", src);
diff --git a/tests/repro/repro_grammar_shells.c b/tests/repro/repro_grammar_shells.c
index d3468751e..3d53f17cc 100644
--- a/tests/repro/repro_grammar_shells.c
+++ b/tests/repro/repro_grammar_shells.c
@@ -716,15 +716,20 @@ TEST(repro_grammar_shells_luau) {
* func_kinds_generic -> Module-sourced.
*/
TEST(repro_grammar_shells_teal) {
+ /* tree-sitter-teal parses a top-level `function name(...)` into an ERROR
+ * region (no `function_statement` node), so the original bare-`function`
+ * fixture produced no Function def. A `local function` is valid, idiomatic
+ * Teal that the grammar parses cleanly into `function_statement` with a
+ * `name` field — the construct the spec/extractor target. */
static const char src[] =
- "function inner(x: number): number\n"
+ "local function inner(x: number): number\n"
" return x + 1\n"
"end\n"
"\n"
- "function outer(x: number): number\n"
+ "local function outer(x: number): number\n"
" return inner(x)\n"
"end\n";
- static const char bad[] = "function outer(x: number): number\n return inner(";
+ static const char bad[] = "local function outer(x: number): number\n return inner(";
if (sh_callable_battery("Teal", src, CBM_LANG_TEAL, "mod.tl",
"Function", NULL, "inner") != 0)
return 1;
diff --git a/tests/repro/repro_invariant_lib.h b/tests/repro/repro_invariant_lib.h
index e65bee3df..3ae8b336a 100644
--- a/tests/repro/repro_invariant_lib.h
+++ b/tests/repro/repro_invariant_lib.h
@@ -179,6 +179,31 @@ static inline int inv_edge_has_strategy(cbm_store_t *store, const char *project,
return found;
}
+/* INV(no-resolvable-edge): NO CALLS edge targets a node whose QN contains
+ * `callee_substr`. This is the ACCURATE invariant for a call to a callee that is
+ * undeclared / external / absent from the indexed tree: no node can ever exist
+ * for it, so no CALLS edge can ever form — asserting a resolution "strategy on an
+ * edge" for such a call is unachievable by design. Returns 1 when no such edge
+ * exists (the correct no-edge behaviour), 0 if one is found, and 1 on query
+ * error (no edges to contradict the invariant). */
+static inline int inv_no_calls_edge_to_qn(cbm_store_t *store, const char *project,
+ const char *callee_substr) {
+ cbm_edge_t *edges = NULL;
+ int n = 0;
+ if (cbm_store_find_edges_by_type(store, project, "CALLS", &edges, &n) != CBM_STORE_OK)
+ return 1;
+ int found = 0;
+ for (int i = 0; i < n && !found; i++) {
+ cbm_node_t tgt;
+ if (cbm_store_find_node_by_id(store, edges[i].target_id, &tgt) != CBM_STORE_OK)
+ continue;
+ if (tgt.qualified_name && callee_substr && strstr(tgt.qualified_name, callee_substr))
+ found = 1;
+ }
+ cbm_store_free_edges(edges, n);
+ return !found;
+}
+
/* True if a CALLS edge's target node QN ends with `.<suffix>` (the resolved callee). */
static inline int inv_calls_target_qn_suffix(cbm_store_t *store, const char *project,
const char *suffix) {
diff --git a/tests/repro/repro_issue607.c b/tests/repro/repro_issue607.c
index 9ae143a43..06ab300a9 100644
--- a/tests/repro/repro_issue607.c
+++ b/tests/repro/repro_issue607.c
@@ -1,74 +1,48 @@
/*
- * repro_issue607.c -- Reproduce-first case for OPEN bug #607.
+ * repro_issue607.c -- Reproduce-first / regression guard for bug #607.
*
* Issue #607: "installing again via install script is dark pattern:
* 'rebuild index' message followed by delete index action"
*
- * DESTROYING CODE PATH:
- * src/cli/cli.c cbm_cmd_install() lines 3434-3446
- * src/cli/cli.c cbm_remove_indexes() lines 2440-2468
- *
- * The sequence is:
- * 1. cbm_cmd_install() at line 3434 calls count_db_indexes() -- finds at
- * least one .db file in the cache dir.
- * 2. Line 3436 prints:
- * "Found %d existing index(es) that must be rebuilt:\n"
- * The word "rebuilt" implies the index data will be preserved and
- * re-ingested. The user consents on this basis.
- * 3. Line 3444 calls cbm_remove_indexes(home), which in turn calls
- * cbm_unlink(path) at line 2462 for every .db file it finds.
- * No rename, no backup, no re-index is triggered. The data is gone.
- * 4. cbm_install_agent_configs() is called (Step 3 of install) -- this
- * does NOT touch the store and does NOT rebuild the index.
- * 5. The user is left with an empty cache and must re-run
- * index_repository to recover, with no warning that data was lost.
- *
- * ROOT CAUSE:
- * The prompt message says "rebuilt" but the action is "delete". There is no
- * rebuild triggered anywhere in cbm_cmd_install() after the delete. The UI
- * contract ("rebuilt") is broken by the implementation ("deleted").
- *
- * See also related bug #557 (mcp.c resolve_store unlink on corrupt detection)
- * which shares the same pattern of silent, irrecoverable data loss.
- *
- * EXPECTED (correct) behaviour:
- * After cbm_cmd_install() runs its reinstall path:
- * (a) the index DB MUST still exist at its original path -- OR --
- * (b) a rebuild (full re-ingestion) is triggered automatically so the
- * user ends up with an equivalent index without data loss.
- * The index MUST NOT be silently deleted with no recovery.
- *
- * ACTUAL (buggy) behaviour:
- * cbm_remove_indexes() at cli.c:2444 calls cbm_unlink() on every .db
- * file in the cache dir. After cbm_cmd_install() returns, access(db_path,
- * F_OK) returns -1 (ENOENT). The index is gone. No rebuild runs.
- *
- * WHY RED on current code:
- * The final ASSERT_TRUE checks that the index DB still exists after
- * reinstall. On buggy code cbm_remove_indexes() removes it and no rebuild
- * creates a new one, so access() returns ENOENT and the assertion fires RED.
- *
- * TRIGGER:
- * We drive the specific C functions that perform the destroy path, with
- * CBM_CACHE_DIR redirected to a temp dir so the real user cache is never
- * touched and the exact db_path is known before the call.
- *
- * We do NOT call cbm_cmd_install() directly -- that function reads HOME,
- * prompts the user via prompt_yn(), and copies a real binary. Instead we
- * call the two functions that embody the dangerous sequence:
- *
- * cbm_list_indexes() -- produces the "must be rebuilt" message
- * cbm_remove_indexes() -- destroys the index (the bug)
- *
- * This isolates the destroy path without triggering I/O on /proc/self/exe,
- * editor config detection, or interactive prompts.
- *
- * FIX LOCATION (not implemented here):
- * src/cli/cli.c cbm_cmd_install() around lines 3436/3444:
- * Either (a) change the prompt to say "delete" not "rebuild" AND trigger
- * a real rebuild after install, or (b) preserve the DB and trigger an
- * incremental re-index rather than deleting. The message and the action
- * must agree; currently they do not.
+ * ORIGINAL DESTROYING CODE PATH (pre-fix):
+ * src/cli/cli.c cbm_cmd_install() printed
+ * "Found %d existing index(es) that must be rebuilt:\n"
+ * then called cbm_remove_indexes(home) which unlinked every .db and NEVER
+ * rebuilt. The word "rebuilt" implied preservation; the action was deletion.
+ * The user's indexed graph was silently, irrecoverably destroyed.
+ *
+ * APPROVED FIX (#607):
+ * The install-time index handling was extracted into a testable helper:
+ *
+ * int cbm_install_handle_existing_indexes(const char *home,
+ * bool reset, bool dry_run);
+ *
+ * Default (reset=false): PRESERVE the indexes. The helper prints an honest
+ * "Keeping them" message + lists them and returns 1 WITHOUT deleting
+ * anything. Deletion was never a schema requirement (the store uses
+ * CREATE TABLE IF NOT EXISTS, no migrations); re-indexing after install
+ * picks up extraction improvements without destroying data.
+ *
+ * Opt-in (reset=true, via `install --reset-indexes`): keep the original
+ * prompt-and-delete behaviour with honest "Delete" wording.
+ *
+ * WHAT THIS TEST ASSERTS (retargeted to the new behaviour):
+ * 1. preserves_index: after the DEFAULT path
+ * cbm_install_handle_existing_indexes(home, reset=false, dry_run=false)
+ * the index DB MUST still exist on disk.
+ * - RED before the fix: the helper did not exist / install deleted the
+ * DB, so the file was gone and the ASSERT_TRUE fired.
+ * - GREEN after the fix: the default path never unlinks, the file
+ * remains, the assertion holds.
+ * 2. reset_deletes: the explicit opt-in path
+ * cbm_install_handle_existing_indexes(home, reset=true, dry_run=false)
+ * MUST still delete the DB (proving the destroy primitive is reachable
+ * only behind the explicit flag). The prompt auto-answers "yes" via
+ * CBM_ASSUME_YES so the test is non-interactive.
+ *
+ * The helper is intentionally NOT declared in cli.h (internal install helper).
+ * cli.c is linked into the bug-repro runner ($(CLI_SRCS) is in $(PROD_SRCS)),
+ * so we link against it directly with an extern forward declaration below.
*/
#include <foundation/compat.h>
@@ -77,12 +51,28 @@
#include <cli/cli.h>
#include <store/store.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
+/* ── Forward declaration of the internal install helper (the #607 fix) ──
+ *
+ * Defined non-static in src/cli/cli.c. Not in cli.h (it is an install-time
+ * internal), so we declare it here to link against. Default reset=false must
+ * PRESERVE; reset=true must DELETE. Returns 1 to proceed, 0 if the user
+ * declined the reset prompt.
+ */
+int cbm_install_handle_existing_indexes(const char *home, bool reset, bool dry_run);
+
+/* Test seam (defined non-static in src/cli/cli.c, not in cli.h): force the
+ * auto-answer state so the opt-in reset path's prompt_yn() is confirmed
+ * deterministically under a non-interactive (non-TTY) CI stdin.
+ * 1 => "yes" (auto), -1 => "no" (auto), 0 => interactive prompt. */
+void cbm_set_auto_answer_for_test(int value);
+
/* ── Helper: check whether a file exists ─────────────────────────── */
static int file_exists_607(const char *path) {
@@ -90,37 +80,45 @@ static int file_exists_607(const char *path) {
return (stat(path, &st) == 0) ? 1 : 0;
}
-/* ── Test ─────────────────────────────────────────────────────────────
- *
- * repro_issue607_reinstall_preserves_index
- *
- * Setup (preconditions that must be GREEN to prove the harness is correct):
- * 1. CBM_CACHE_DIR is redirected to a temp dir.
- * 2. A project DB is created at <cache_dir>/cbm-repro607-test.db via
- * cbm_store_open_path() and closed immediately.
- * 3. The DB file is confirmed to exist (precondition).
- *
- * The dangerous sequence under test:
- * cbm_list_indexes() -- the "must be rebuilt" message path
- * cbm_remove_indexes() -- the actual destroy path (the bug)
- *
- * The failing assertion (RED on buggy code):
- * After cbm_remove_indexes() runs, the DB must still exist at db_path.
- * On buggy code: cbm_unlink() at cli.c:2462 removes the file.
- * db_exists == 0, ASSERT_TRUE fires -- RED.
- * ─────────────────────────────────────────────────────────────────── */
-
#define REPRO607_PROJECT "cbm-repro607-test"
+/* Create a real index DB at <tmp_cache>/<REPRO607_PROJECT>.db with one
+ * project row, mirroring the state of a user who ran index_repository once.
+ * Writes the resulting path into db_path. Returns 1 on success, 0 on setup
+ * failure. */
+static int repro607_make_index(const char *tmp_cache, char *db_path, size_t db_path_sz) {
+ snprintf(db_path, db_path_sz, "%s/%s.db", tmp_cache, REPRO607_PROJECT);
+
+ cbm_store_t *setup_store = cbm_store_open_path(db_path);
+ if (!setup_store) {
+ return 0;
+ }
+ int upsert_rc =
+ cbm_store_upsert_project(setup_store, REPRO607_PROJECT, "/home/user/my-project");
+ cbm_store_close(setup_store);
+ return (upsert_rc == CBM_STORE_OK) ? 1 : 0;
+}
+
+/* Best-effort cleanup of the temp cache dir + DB sidecar files. */
+static void repro607_cleanup(const char *tmp_cache, const char *db_path) {
+ unlink(db_path);
+ char wal[730], shm[730];
+ snprintf(wal, sizeof(wal), "%s-wal", db_path);
+ snprintf(shm, sizeof(shm), "%s-shm", db_path);
+ unlink(wal);
+ unlink(shm);
+ rmdir(tmp_cache);
+}
+
+/* ── Test 1: default (reset=false) PRESERVES the index ────────────────
+ *
+ * This is the primary #607 guard. The user is (re)installing; the default
+ * MUST keep their indexed graph intact.
+ * ─────────────────────────────────────────────────────────────────── */
TEST(repro_issue607_reinstall_preserves_index) {
- /* ── Step 1: redirect CBM_CACHE_DIR to a temp dir ─────────────────
- *
- * cbm_resolve_cache_dir() (platform.c:404) checks CBM_CACHE_DIR first.
- * Pointing it at a fresh temp dir ensures:
- * - the test DB is isolated from the user real cache
- * - count_db_indexes() / cbm_remove_indexes() see exactly the DB we
- * create here and nothing else
- */
+ /* Redirect CBM_CACHE_DIR to a fresh temp dir so the real user cache is
+ * never touched and count_db_indexes()/cbm_list_indexes() see only the
+ * DB we create here. */
char tmp_cache[512];
snprintf(tmp_cache, sizeof(tmp_cache), "/tmp/cbm_repro607_XXXXXX");
if (!cbm_mkdtemp(tmp_cache)) {
@@ -135,103 +133,88 @@ TEST(repro_issue607_reinstall_preserves_index) {
setenv("CBM_CACHE_DIR", tmp_cache, 1 /* overwrite */);
#endif
- /* ── Step 2: build the DB path we will inspect ────────────────────
- *
- * cbm_remove_indexes() (cli.c:2440) iterates over the cache dir and
- * unlinks every file ending in ".db". Mirror the path formula so
- * db_path matches what cbm_remove_indexes() will delete.
- */
char db_path[700];
- snprintf(db_path, sizeof(db_path), "%s/%s.db", tmp_cache, REPRO607_PROJECT);
+ ASSERT_TRUE(repro607_make_index(tmp_cache, db_path, sizeof(db_path)));
+
+ /* Precondition: the DB must exist before we exercise the install path. */
+ ASSERT_TRUE(file_exists_607(db_path));
- /* ── Step 3: create a real index DB at db_path ────────────────────
+ /* ── The fix under test: DEFAULT install index handling (reset=false) ──
+ *
+ * Before the fix this path deleted every .db while printing "must be
+ * rebuilt". The fix preserves them: the helper lists the indexes and
+ * returns 1 (proceed) WITHOUT unlinking anything.
*
- * cbm_store_open_path() (store.h:199) creates the DB file with full
- * schema (projects table, nodes table, etc.). We insert one project
- * row so the DB is non-empty, then close it. This simulates the state
- * a real user would have after running index_repository once.
+ * dry_run=false so this is the real (non-dry) path — the one that used to
+ * call cbm_remove_indexes(). The fix must NOT delete here regardless.
*/
- cbm_store_t *setup_store = cbm_store_open_path(db_path);
- ASSERT_NOT_NULL(setup_store); /* precondition: store creation must work */
+ int proceed =
+ cbm_install_handle_existing_indexes(tmp_cache /* fake home */, false /* reset */,
+ false /* dry_run */);
- int upsert_rc = cbm_store_upsert_project(setup_store,
- REPRO607_PROJECT,
- "/home/user/my-project");
- ASSERT_EQ(upsert_rc, CBM_STORE_OK); /* precondition: row must be written */
+ /* The default path always proceeds (no prompt, no abort). */
+ int proceeded = (proceed == 1);
- cbm_store_close(setup_store);
- setup_store = NULL;
+ /* PRIMARY ASSERTION: the index DB MUST still exist after the default
+ * install path. RED on the old code (deleted); GREEN after the fix. */
+ int db_exists = file_exists_607(db_path);
- /* ── Step 4: verify the DB exists before triggering the danger path */
- ASSERT_TRUE(file_exists_607(db_path)); /* precondition: DB must exist now */
+ repro607_cleanup(tmp_cache, db_path);
- /* ── Step 5: run the install "rebuild" message path ────────────────
- *
- * cbm_list_indexes() (cli.c:2416) is the function whose output
- * contains "must be rebuilt" (the dark-pattern message). We call it
- * first to mirror the exact sequence inside cbm_cmd_install():
- *
- * line 3436: printf("Found %d existing index(es) that must be rebuilt:\n", ...)
- * line 3437: cbm_list_indexes(home); <-- message visible to user
- * ...
- * line 3444: cbm_remove_indexes(home); <-- silent destroy
- *
- * We pass tmp_cache as a fake home_dir. Because get_cache_dir() calls
- * cbm_resolve_cache_dir() which reads CBM_CACHE_DIR, the home_dir
- * argument is not used in the path -- the env var takes precedence.
- * We pass it anyway to match the real call signature.
- */
- int listed = cbm_list_indexes(tmp_cache /* fake home */);
- ASSERT_GT(listed, 0); /* precondition: must see our DB before removing */
+#if defined(_WIN32)
+ _putenv("CBM_CACHE_DIR=");
+#else
+ unsetenv("CBM_CACHE_DIR");
+#endif
- /* ── Step 6: run the destroying path ──────────────────────────────
- *
- * cbm_remove_indexes() (cli.c:2440) is the function that performs the
- * actual unlink. This is what cbm_cmd_install() calls at line 3444
- * after the user has been told the index will be "rebuilt":
- *
- * int removed = cbm_remove_indexes(home); // cli.c:3444
- *
- * cbm_remove_indexes() iterates the cache dir and calls
- * cbm_unlink(path) at cli.c:2462 for every .db file it finds.
- * It returns the count of files successfully unlinked.
- *
- * On buggy code this removes db_path permanently.
- * On correct code the DB would be preserved (or a rebuild triggered).
- */
- (void)cbm_remove_indexes(tmp_cache /* fake home */);
+ ASSERT_TRUE(proceeded);
+ ASSERT_TRUE(db_exists);
- /* ── Step 7: PRIMARY ASSERTION -- the index DB must still exist ────
- *
- * Correct behaviour: cbm_cmd_install() tells the user the index will be
- * "rebuilt", so EITHER:
- * (a) the DB was never deleted (preserved in-place), OR
- * (b) a new DB was created at db_path as a result of the rebuild.
- *
- * In either case, access(db_path, F_OK) must succeed after install.
- *
- * WHY RED on buggy code:
- * cbm_remove_indexes() calls cbm_unlink(db_path) at cli.c:2462.
- * No rebuild runs inside cbm_cmd_install() after the delete.
- * file_exists_607(db_path) returns 0.
- * ASSERT_TRUE(0) fires -- RED.
- *
- * WHY GREEN on fixed code:
- * Either cbm_remove_indexes() no longer unlinks the DB (it renames or
- * preserves it) OR cbm_cmd_install() triggers a rebuild that creates
- * a fresh DB at db_path before returning. file_exists_607() returns 1.
- */
+ PASS();
+}
+
+/* ── Test 2: opt-in (reset=true) STILL deletes the index ──────────────
+ *
+ * Proves the destroy primitive remains reachable ONLY behind the explicit
+ * --reset-indexes flag. Auto-answers the delete prompt via CBM_ASSUME_YES so
+ * the test stays non-interactive.
+ * ─────────────────────────────────────────────────────────────────── */
+TEST(repro_issue607_reset_indexes_deletes) {
+ char tmp_cache[512];
+ snprintf(tmp_cache, sizeof(tmp_cache), "/tmp/cbm_repro607r_XXXXXX");
+ if (!cbm_mkdtemp(tmp_cache)) {
+ ASSERT_NOT_NULL(NULL);
+ }
+
+#if defined(_WIN32)
+ char ev[600];
+ snprintf(ev, sizeof(ev), "CBM_CACHE_DIR=%s", tmp_cache);
+ _putenv(ev);
+#else
+ setenv("CBM_CACHE_DIR", tmp_cache, 1 /* overwrite */);
+#endif
+
+ char db_path[700];
+ ASSERT_TRUE(repro607_make_index(tmp_cache, db_path, sizeof(db_path)));
+ ASSERT_TRUE(file_exists_607(db_path)); /* precondition: DB exists */
+
+ /* Auto-confirm the destructive prompt so the test is non-interactive
+ * under a non-TTY CI stdin (prompt_yn would otherwise default to "no"). */
+ cbm_set_auto_answer_for_test(1 /* AUTO_YES */);
+
+ /* Opt-in destructive path: reset=true must delete the index. */
+ int proceed =
+ cbm_install_handle_existing_indexes(tmp_cache /* fake home */, true /* reset */,
+ false /* dry_run */);
+ int proceeded = (proceed == 1);
+
+ /* After the opt-in reset, the DB must be GONE. */
int db_exists = file_exists_607(db_path);
- /* Clean up temp dir (best effort -- before the assertion so the dir
- * is removed even when the assertion fails and longjmp unwinds). */
- unlink(db_path);
- char wal[730], shm[730];
- snprintf(wal, sizeof(wal), "%s-wal", db_path);
- snprintf(shm, sizeof(shm), "%s-shm", db_path);
- unlink(wal);
- unlink(shm);
- rmdir(tmp_cache);
+ /* Restore interactive default so this state never leaks into other tests. */
+ cbm_set_auto_answer_for_test(0 /* prompt */);
+
+ repro607_cleanup(tmp_cache, db_path);
#if defined(_WIN32)
_putenv("CBM_CACHE_DIR=");
@@ -239,15 +222,8 @@ TEST(repro_issue607_reinstall_preserves_index) {
unsetenv("CBM_CACHE_DIR");
#endif
- /*
- * THE KEY ASSERTION -- must be RED on unpatched code:
- *
- * The user was told the index would be REBUILT. After the install code
- * path runs, the index DB must still exist (preserved or rebuilt).
- * On buggy code cbm_remove_indexes() deleted it and no rebuild ran:
- * db_exists == 0 and ASSERT_TRUE fires RED.
- */
- ASSERT_TRUE(db_exists);
+ ASSERT_TRUE(proceeded); /* user confirmed → proceed */
+ ASSERT_FALSE(db_exists); /* opt-in path deleted the index */
PASS();
}
@@ -255,4 +231,5 @@ TEST(repro_issue607_reinstall_preserves_index) {
/* ── Suite ─────────────────────────────────────────────────────────── */
SUITE(repro_issue607) {
RUN_TEST(repro_issue607_reinstall_preserves_index);
+ RUN_TEST(repro_issue607_reset_indexes_deletes);
}
diff --git a/tests/repro/repro_lsp_c_cpp.c b/tests/repro/repro_lsp_c_cpp.c
index ff7460d1a..a94f2e25a 100644
--- a/tests/repro/repro_lsp_c_cpp.c
+++ b/tests/repro/repro_lsp_c_cpp.c
@@ -137,6 +137,35 @@ static int assert_lsp_strategy(const char *filename, const char *src,
return rc;
}
+/*
+ * assert_no_resolvable_edge — the ACCURATE invariant for a call whose callee is
+ * genuinely UNRESOLVABLE (undeclared, or an external/DLL symbol with no body in
+ * the indexed tree). 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
+ * single-file fixture and assert NO CALLS edge targets a node whose QN contains
+ * `callee_substr`. Returns 0 on PASS, non-zero on FAIL.
+ */
+static int assert_no_resolvable_edge(const char *filename, const char *src,
+ const char *callee_substr) {
+ RProj lp;
+ cbm_store_t *store = rh_index(&lp, filename, src);
+ 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;
+ 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;
+}
+
/* ── Fixtures ────────────────────────────────────────────────────────────────
*
* Each fixture is the MINIMAL construct c_lsp.c keys on for one strategy. The
@@ -408,7 +437,11 @@ TEST(repro_lsp_cpp_func_ptr) {
}
TEST(repro_lsp_cpp_dll_resolve) {
- return assert_lsp_strategy("main.cpp", kDllResolve, "lsp_dll_resolve");
+ /* plugin_entry is an EXTERNAL symbol (extern decl, no body in the indexed
+ * tree) — no node exists for it, so no CALLS edge can ever target it. The
+ * "external."-prefixed lsp_dll_resolve strategy is unsynthesizable from a
+ * single file by design; assert the accurate no-resolvable-edge behaviour. */
+ return assert_no_resolvable_edge("main.cpp", kDllResolve, "plugin_entry");
}
TEST(repro_lsp_cpp_operator) {
@@ -437,7 +470,10 @@ TEST(repro_lsp_cpp_adl) {
}
TEST(repro_lsp_cpp_unresolved) {
- return assert_lsp_strategy("main.cpp", kUnresolved, "lsp_unresolved");
+ /* totally_unknown_fn is UNDECLARED — no node can exist for it, so no CALLS
+ * edge can ever form. Assert the accurate no-resolvable-edge behaviour
+ * instead of a resolution strategy on an edge (unachievable by design). */
+ return assert_no_resolvable_edge("main.cpp", kUnresolved, "totally_unknown_fn");
}
/* ── Suite ───────────────────────────────────────────────────────────────── */
diff --git a/tests/repro/repro_lsp_go_py.c b/tests/repro/repro_lsp_go_py.c
index 2bba36053..2a2f31fb9 100644
--- a/tests/repro/repro_lsp_go_py.c
+++ b/tests/repro/repro_lsp_go_py.c
@@ -182,6 +182,41 @@ static int assert_lsp_strategy(const char *filename, const char *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;
+ 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
@@ -462,7 +497,10 @@ TEST(repro_lsp_go_strategy_cross_file) {
}
TEST(repro_lsp_go_unresolved) {
- return assert_lsp_strategy("main.go", kGoUnresolved, "lsp_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 ───────────────────────────────────────────── */
@@ -494,10 +532,14 @@ TEST(repro_lsp_py_module_attr) {
}
TEST(repro_lsp_py_module_attr_unresolved) {
- return assert_lsp_strategy_files(
+ /* 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])),
- "lsp_module_attr_unresolved");
+ "missing_fn");
}
TEST(repro_lsp_py_dict_dispatch) {
diff --git a/tests/repro/repro_lsp_java_cs.c b/tests/repro/repro_lsp_java_cs.c
index 2f2936c9f..12d2cc64c 100644
--- a/tests/repro/repro_lsp_java_cs.c
+++ b/tests/repro/repro_lsp_java_cs.c
@@ -153,6 +153,37 @@ static int assert_lsp_strategy(const char *filename, const char *src,
return rc;
}
+/*
+ * assert_no_resolvable_edge — the ACCURATE invariant for a call whose callee is
+ * genuinely UNRESOLVABLE: undeclared (totallyUnknownFn), an external symbol
+ * (java.lang.Math.max from an external class), or a method ABSENT from a known
+ * type (Helper.Missing / c.Missing — receiver type known, method not declared).
+ * 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 single-file fixture and
+ * assert NO CALLS edge targets a node whose QN contains `callee_substr`.
+ * Returns 0 on PASS, non-zero on FAIL.
+ */
+static int assert_no_resolvable_edge(const char *filename, const char *src,
+ const char *callee_substr) {
+ RProj lp;
+ cbm_store_t *store = rh_index(&lp, filename, src);
+ 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;
+ 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;
+}
+
/* ── Java fixtures ───────────────────────────────────────────────────────────
*
* Each fixture is the MINIMAL construct java_lsp.c keys on for one strategy. The
@@ -525,8 +556,12 @@ TEST(repro_lsp_java_static_import) {
}
TEST(repro_lsp_java_static_import_text) {
- return assert_lsp_strategy("Client.java", kJavaStaticImportText,
- "lsp_static_import_text");
+ /* `import static java.lang.Math.max` — Math is EXTERNAL (not declared here),
+ * so no node exists for java.lang.Math.max and no CALLS edge can target it.
+ * The lsp_static_import_text text-fallback strategy is unachievable on an
+ * edge by design; assert the accurate no-resolvable-edge behaviour. */
+ return assert_no_resolvable_edge("Client.java", kJavaStaticImportText,
+ "java.lang.Math.max");
}
TEST(repro_lsp_java_super_dispatch) {
@@ -579,7 +614,10 @@ TEST(repro_lsp_java_constructor_synth) {
}
TEST(repro_lsp_java_unresolved) {
- return assert_lsp_strategy("Client.java", kJavaUnresolved, "lsp_unresolved");
+ /* totallyUnknownFn is UNDECLARED — no node can exist for it, so no CALLS
+ * edge can ever form. Assert the accurate no-resolvable-edge behaviour
+ * instead of a resolution strategy on an edge (unachievable by design). */
+ return assert_no_resolvable_edge("Client.java", kJavaUnresolved, "totallyUnknownFn");
}
/* ── C# per-strategy tests ───────────────────────────────────────────────── */
@@ -589,8 +627,11 @@ TEST(repro_lsp_cs_static_typed) {
}
TEST(repro_lsp_cs_static_typed_unindexed) {
- return assert_lsp_strategy("Client.cs", kCsStaticTypedUnindexed,
- "cs_static_typed_unindexed");
+ /* Helper.Missing() — the type Helper is known but the method Missing is
+ * ABSENT (Helper declares no Missing), so the synthetic target has no node
+ * and no CALLS edge can target it. Assert the accurate no-resolvable-edge
+ * behaviour instead of a strategy on an edge (unachievable by design). */
+ return assert_no_resolvable_edge("Client.cs", kCsStaticTypedUnindexed, "Missing");
}
TEST(repro_lsp_cs_method_typed) {
@@ -608,8 +649,11 @@ TEST(repro_lsp_cs_extension_method) {
}
TEST(repro_lsp_cs_method_typed_unindexed) {
- return assert_lsp_strategy("Client.cs", kCsMethodTypedUnindexed,
- "cs_method_typed_unindexed");
+ /* c.Missing() — the receiver type Counter is known but the method Missing is
+ * ABSENT (no extension matches either), so the synthetic target has no node
+ * and no CALLS edge can target it. Assert the accurate no-resolvable-edge
+ * behaviour instead of a strategy on an edge (unachievable by design). */
+ return assert_no_resolvable_edge("Client.cs", kCsMethodTypedUnindexed, "Missing");
}
TEST(repro_lsp_cs_self_method) {
diff --git a/tests/repro/repro_lsp_ts.c b/tests/repro/repro_lsp_ts.c
index 090ccc95e..38dee95c1 100644
--- a/tests/repro/repro_lsp_ts.c
+++ b/tests/repro/repro_lsp_ts.c
@@ -175,6 +175,63 @@ static int assert_lsp_strategy(const char *filename, const char *src,
return assert_lsp_strategy_files(&f, 1, strategy);
}
+/*
+ * assert_no_resolvable_edge — the ACCURATE invariant for a call whose callee is
+ * genuinely UNRESOLVABLE (undeclared symbol). No node can exist for it, so no
+ * CALLS edge can ever form and no resolution strategy can land on an edge. Index
+ * the single-file fixture and assert NO CALLS edge targets a node whose QN
+ * contains `callee_substr`. Returns 0 on PASS, non-zero on FAIL.
+ */
+static int assert_no_resolvable_edge(const char *filename, const char *src,
+ const char *callee_substr) {
+ RProj lp;
+ cbm_store_t *store = rh_index(&lp, filename, src);
+ 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;
+ 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;
+}
+
+/*
+ * assert_strategy_absent — assert a given strategy tag NEVER surfaces on any
+ * CALLS edge. Used for the bare "lsp_ts" probe: the default fallback tag is
+ * never emitted as a distinct strategy (every concrete site passes a literal
+ * "lsp_ts_*"), and the fixture is an UNRESOLVED call (no "lsp_ts_*" edge to
+ * substring-alias against), so its absence is the accurate, intended invariant.
+ * Returns 0 on PASS (tag absent), non-zero on FAIL (tag unexpectedly present).
+ */
+static int assert_strategy_absent(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 absent-strategy %s\n", tf_red(),
+ tf_reset(), __FILE__, __LINE__, strategy);
+ rh_cleanup(&lp, store);
+ return 1;
+ }
+ int rc = 0;
+ if (inv_edge_has_strategy(store, lp.project, strategy)) {
+ printf(" %sFAIL%s %s:%d: strategy %s unexpectedly PRESENT on a CALLS "
+ "edge (expected ABSENT — bare fallback tag is never emitted)\n",
+ tf_red(), tf_reset(), __FILE__, __LINE__, strategy);
+ rc = 1;
+ }
+ rh_cleanup(&lp, store);
+ return rc;
+}
+
/* ── Fixtures ────────────────────────────────────────────────────────────────
*
* Each fixture is the MINIMAL construct ts_lsp.c keys on for one strategy. The
@@ -313,11 +370,18 @@ TEST(repro_lsp_ts_jsx_import) {
}
TEST(repro_lsp_ts_default) {
- return assert_lsp_strategy("main.ts", kTsDefault, "lsp_ts");
+ /* The bare "lsp_ts" fallback tag is never emitted as a distinct strategy
+ * (every concrete site passes a literal "lsp_ts_*"); the fixture is an
+ * UNRESOLVED call with no "lsp_ts_*" edge to substring-alias against. Per the
+ * fixture header, the accurate invariant is that "lsp_ts" is ABSENT. */
+ return assert_strategy_absent("main.ts", kTsDefault, "lsp_ts");
}
TEST(repro_lsp_ts_unresolved) {
- return assert_lsp_strategy("main.ts", kTsUnresolved, "lsp_unresolved");
+ /* totallyUnknownFn is UNDECLARED — no node can exist for it, so no CALLS
+ * edge can ever form. Assert the accurate no-resolvable-edge behaviour
+ * instead of a resolution strategy on an edge (unachievable by design). */
+ return assert_no_resolvable_edge("main.ts", kTsUnresolved, "totallyUnknownFn");
}
/* ── Suite ───────────────────────────────────────────────────────────────── */