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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(php): keep proven vendor types out of project name fallbacks
Martin Vogele8939e78b45d
diff --git a/internal/cbm/lsp/php_lsp.c b/internal/cbm/lsp/php_lsp.cindex 16a3b1582..a71fd7d46 100644--- a/internal/cbm/lsp/php_lsp.c+++ b/internal/cbm/lsp/php_lsp.c@@ -253,6 +253,17 @@ const char *php_resolve_class_name(PHPLSPContext *ctx, const char *name) {return php_ns_to_dot(ctx->arena, name);}+/* True when `qn` is, or lies under, the target of a class `use` the pipeline+ * left unresolved: a type outside the project (cross-file mode only). */+static bool php_external_qn(const PHPLSPContext *ctx, const char *qn) {+ for (int i = 0; qn && i < ctx->external_use_count; i++) {+ size_t n = strlen(ctx->external_use_qns[i]);+ if (strncmp(qn, ctx->external_use_qns[i], n) == 0 && (qn[n] == '\0' || qn[n] == '.'))+ return true;+ }+ return false;+}+/* Try to find a registered type for a "namespaced" QN.** Lookup order:@@ -265,13 +276,17 @@ const char *php_resolve_class_name(PHPLSPContext *ctx, const char *name) {** Step 4 is critical for PHP because the unified extractor builds QNs from* file paths but `use App\\Models\\User` produces an "App.Models.User" key.- * Without short-name fallback, every cross-file class resolution would miss. */+ * Without short-name fallback, every cross-file class resolution would miss.+ * A QN named through a vendor `use` stops after step 1: `Saloon.Http.Request`+ * is not the project's App.Http.Requests.Request (#1186). */static const CBMRegisteredType *lookup_type_with_project(PHPLSPContext *ctx, const char *qn) {if (!qn)return NULL;const CBMRegisteredType *t = cbm_registry_lookup_type(ctx->registry, qn);if (t)return t;+ if (php_external_qn(ctx, qn))+ return NULL;if (ctx->module_qn && ctx->module_qn[0]) {const char *combo = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->module_qn, qn);@@ -1416,6 +1431,23 @@ static void php_stamp_resolved_site(PHPLSPContext *ctx, int first, TSNode site)}}+/* The method of a class the index does not hold. When the class came from a+ * vendor `use` (cross-file mode), the row is emitted above the pipeline's+ * confidence floor as php_external_receiver: the receiver is PROVEN to be a+ * type outside the project, so no name-only fallback may bind the call to a+ * same-named project method (#1186). Otherwise the existing low-confidence+ * `unindexed_strategy` row. */+static void emit_external_or_unindexed(PHPLSPContext *ctx, const char *class_qn,+ const char *method_name, const char *unindexed_strategy,+ CBMResolvedKind kind) {+ const char *target = cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, method_name);+ if (php_external_qn(ctx, class_qn)) {+ emit_resolved_kind(ctx, target, "php_external_receiver", 0.95f, kind);+ return;+ }+ emit_resolved_kind(ctx, target, unindexed_strategy, 0.55f, kind);+}+static void emit_unresolved(PHPLSPContext *ctx, const char *expr_text, const char *reason) {if (!ctx->resolved_calls || !ctx->enclosing_func_qn)return;@@ -1733,8 +1765,7 @@ static void resolve_member_call(PHPLSPContext *ctx, TSNode call, CBMResolvedKind* at "<class_qn>.<method>" so the pipeline bridge can BLOCK the unified* extractor's likely-incorrect short-name fallback. The bridge filters* unknown targets and yields no edge — better than a wrong edge. */- emit_resolved_kind(ctx, cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, method_name),- "php_method_typed_unindexed", 0.55f, kind);+ emit_external_or_unindexed(ctx, class_qn, method_name, "php_method_typed_unindexed", kind);}static void resolve_static_call(PHPLSPContext *ctx, TSNode call, CBMResolvedKind kind) {@@ -1793,8 +1824,7 @@ static void resolve_static_call(PHPLSPContext *ctx, TSNode call, CBMResolvedKind/* Class resolved (e.g., from a `use` clause), method unknown — emit* synthetic resolved call so the pipeline bridge can suppress the* unified extractor's name-fallback misroute. */- emit_resolved_kind(ctx, cbm_arena_sprintf(ctx->arena, "%s.%s", class_qn, method_name),- "php_static_unindexed", 0.55f, kind);+ emit_external_or_unindexed(ctx, class_qn, method_name, "php_static_unindexed", kind);}/* ── type narrowing ─────────────────────────────────────────────────@@ -4489,10 +4519,95 @@ void cbm_php_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRegi}}+static int php_pipeline_use_kind(CBMImportKind kind) {+ if (kind == CBM_IMPORT_KIND_FUNCTION)+ return CBM_PHP_USE_FUNCTION;+ if (kind == CBM_IMPORT_KIND_CONST)+ return CBM_PHP_USE_CONST;+ return CBM_PHP_USE_CLASS;+}++/* Import edges name files, while the use table names symbols. Bind only a+ * unique definition in that proven file; never use an unrelated short-name+ * match to manufacture the imported symbol. Namespace aliases retain their+ * source namespace spelling when no such definition exists. */+static const char *php_pipeline_import_qn(PHPLSPContext *ctx, const CBMImport *imp,+ const char *target, CBMLSPDef *defs, int def_count) {+ const char *leaf = imp->module_path ? strrchr(imp->module_path, '\\') : NULL;+ leaf = leaf ? leaf + 1 : imp->module_path;+ if (!leaf || !leaf[0])+ return target;+ size_t target_len = strlen(target);+ static const char file_suffix[] = ".__file__";+ bool file = target_len >= sizeof(file_suffix) - 1 &&+ strcmp(target + target_len - (sizeof(file_suffix) - 1), file_suffix) == 0;+ size_t module_len = file ? target_len - (sizeof(file_suffix) - 1) : 0;+ const char *found = NULL;+ for (int i = 0; i < def_count; i++) {+ const CBMLSPDef *def = &defs[i];+ if (!def->qualified_name || !def->short_name || !def->label ||+ strcmp(def->short_name, leaf) != 0)+ continue;+ bool in_file = file && def->def_module_qn && strlen(def->def_module_qn) == module_len &&+ strncmp(def->def_module_qn, target, module_len) == 0;+ if (!in_file && strcmp(def->qualified_name, target) != 0)+ continue;+ bool kind_matches =+ imp->kind == CBM_IMPORT_KIND_FUNCTION ? strcmp(def->label, "Function") == 0+ : imp->kind == CBM_IMPORT_KIND_CONST+ ? strcmp(def->label, "Constant") == 0 || strcmp(def->label, "Variable") == 0+ : strcmp(def->label, "Class") == 0 || strcmp(def->label, "Interface") == 0 ||+ strcmp(def->label, "Trait") == 0 || strcmp(def->label, "Enum") == 0;+ if (!kind_matches)+ continue;+ if (found && strcmp(found, def->qualified_name) != 0) {+ found = NULL;+ break;+ }+ found = def->qualified_name;+ }+ if (found)+ return found;+ const char *name = imp->module_path[0] == '\\' ? imp->module_path + 1 : imp->module_path;+ return php_ns_to_dot(ctx->arena, name);+}++static void php_collect_external_uses(PHPLSPContext *ctx, const CBMPHPImportBindings *bindings) {+ if (!bindings || !bindings->targets || !bindings->imports)+ return;+ int count = bindings->imports->count;+ ctx->external_use_qns =+ cbm_arena_alloc(ctx->arena, (size_t)(count > 0 ? count : 1) * sizeof(char *));+ if (!ctx->external_use_qns)+ return;+ for (int i = 0; i < count; i++) {+ const CBMImport *imp = &bindings->imports->items[i];+ if (imp->kind == CBM_IMPORT_KIND_DEFAULT && !bindings->targets[i] && imp->local_name &&+ imp->local_name[0] && imp->module_path && imp->module_path[0]) {+ const char *name =+ imp->module_path[0] == '\\' ? imp->module_path + 1 : imp->module_path;+ const char *qn = php_ns_to_dot(ctx->arena, name);+ if (qn)+ ctx->external_use_qns[ctx->external_use_count++] = qn;+ }+ }+}+void cbm_run_php_lsp_cross(CBMArena *arena, const char *source, int source_len,const char *module_qn, CBMLSPDef *defs, int def_count,const char **import_names, const char **import_qns, int import_count,TSTree *cached_tree, CBMResolvedCallArray *out) {+ cbm_run_php_lsp_cross_with_bindings(arena, source, source_len, module_qn, defs, def_count,+ import_names, import_qns, import_count, cached_tree, out,+ NULL);+}++void cbm_run_php_lsp_cross_with_bindings(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMLSPDef *defs, int def_count,+ const char **import_names, const char **import_qns,+ int import_count, TSTree *cached_tree,+ CBMResolvedCallArray *out,+ const CBMPHPImportBindings *bindings) {if (!arena || !source || source_len <= 0 || !out)return;@@ -4532,11 +4647,23 @@ void cbm_run_php_lsp_cross(CBMArena *arena, const char *source, int source_len,/* Caller-supplied imports register first. process_file's own AST walk* adds file-internal `use` declarations on top of these. */- for (int i = 0; i < import_count; i++) {- if (import_names && import_qns && import_names[i] && import_qns[i]) {- php_lsp_add_use(&ctx, import_names[i], import_qns[i], CBM_PHP_USE_CLASS);+ if (bindings && bindings->targets && bindings->imports) {+ for (int i = 0; i < bindings->imports->count; i++) {+ const CBMImport *imp = &bindings->imports->items[i];+ if (imp->local_name && bindings->targets[i])+ php_lsp_add_use(+ &ctx, imp->local_name,+ php_pipeline_import_qn(&ctx, imp, bindings->targets[i], defs, def_count),+ php_pipeline_use_kind(imp->kind));+ }+ } else {+ for (int i = 0; i < import_count; i++) {+ if (import_names && import_qns && import_names[i] && import_qns[i]) {+ php_lsp_add_use(&ctx, import_names[i], import_qns[i], CBM_PHP_USE_CLASS);+ }}}+ int supplied_use_count = ctx.use_count;/* Class field collection — same flow as cbm_run_php_lsp. Walks the AST* to populate typed-property field maps so $this->prop and $obj->prop@@ -4554,10 +4681,11 @@ void cbm_run_php_lsp_cross(CBMArena *arena, const char *source, int source_len,collect_use_declaration(&ctx, c);}}+ php_collect_external_uses(&ctx, bindings);cbm_php_refine_lsp_registry(&ctx, ®, root);ctx.current_namespace_qn = "";/* Reset to caller-supplied uses only — process_file re-adds AST uses. */- ctx.use_count = import_count;+ ctx.use_count = supplied_use_count;}php_lsp_process_file(&ctx, root);diff --git a/internal/cbm/lsp/php_lsp.h b/internal/cbm/lsp/php_lsp.hindex 2d83d7a00..3843822a3 100644--- a/internal/cbm/lsp/php_lsp.h+++ b/internal/cbm/lsp/php_lsp.h@@ -7,6 +7,15 @@#include "../cbm.h"#include "go_lsp.h" /* CBMLSPDef reused across languages */+/* Per-file typed import evidence. NULL targets means unknown; otherwise+ * targets has one slot per represented import, NULL only for a binding whose+ * absence was established. Any unsupported unresolved binding makes the whole+ * file unknown. The array is caller-owned; strings and import records borrowed. */+typedef struct {+ const CBMImportArray *imports;+ const char **targets;+} CBMPHPImportBindings;+/* PHPLSPContext — per-file state for PHP type-aware call resolution.* Mirrors GoLSPContext / CLSPContext structure. */typedef struct {@@ -28,6 +37,13 @@ typedef struct {int use_count;int use_cap;+ /* Cross-file mode: dotted targets of the file's class `use` declarations+ * that the pipeline's import map left unresolved (vendor / unmapped+ * namespaces, #1186). A type named through one is outside the project: it+ * never matches a project type by short name. */+ const char **external_use_qns;+ int external_use_count;+/* Current function/method/class context. */const char *enclosing_func_qn;const char *enclosing_class_qn; /* NULL outside class body */@@ -116,6 +132,15 @@ void cbm_run_php_lsp_cross(TSTree *cached_tree, /* NULL = parse internally */CBMResolvedCallArray *out);+/* Complete typed bindings enable external receiver evidence. */+void cbm_run_php_lsp_cross_with_bindings(CBMArena *arena, const char *source, int source_len,+ const char *module_qn, CBMLSPDef *defs, int def_count,+ const char **import_names, const char **import_qns,+ int import_count,+ TSTree *cached_tree, /* NULL = parse internally */+ CBMResolvedCallArray *out,+ const CBMPHPImportBindings *bindings);+/* --- Batch cross-file LSP --- *//* Per-file input for batch PHP LSP processing. */diff --git a/src/pipeline/lsp_resolve.h b/src/pipeline/lsp_resolve.hindex ac83084b2..4d91dbae8 100644--- a/src/pipeline/lsp_resolve.h+++ b/src/pipeline/lsp_resolve.h@@ -333,6 +333,15 @@ static inline int cbm_pipeline_invocation_site_rank(const CBMResolvedCall *resolreturn call->requires_lsp_resolution || call->source_origin != resolved->source_origin ? 0 : 1;}+/* A resolver row that proves the call's receiver is a type OUTSIDE the project:+ * PHP `$r->m()` / `R::m()` where `R` is imported from a vendor namespace+ * (#1186). When its target has no graph node, it rules out every name-only+ * fallback: the method of a vendor class is not a same-named project method. */+static inline bool cbm_pipeline_lsp_external_receiver(const CBMResolvedCall *resolved) {+ return resolved && resolved->strategy &&+ strcmp(resolved->strategy, "php_external_receiver") == 0;+}+static inline bool cbm_pipeline_invocation_reason_join_strategy(const char *strategy) {return strategy &&(strcmp(strategy, "lsp_func_ptr") == 0 || strcmp(strategy, "lsp_callable_alias") == 0 ||diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.cindex 4057b3128..0398a5443 100644--- a/src/pipeline/pass_calls.c+++ b/src/pipeline/pass_calls.c@@ -671,7 +671,8 @@ static const cbm_gbuf_node_t *calls_find_source(cbm_pipeline_ctx_t *ctx, const cstatic int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBMFileResult *result,const char *rel, const char *module_qn, const char **imp_keys,const char **imp_vals, int imp_count, CBMLanguage lang,- const CBMImportArray *imports, const char *route_mount) {+ const CBMImportArray *imports, const char *route_mount,+ const cbm_php_vendor_names_t *php_vendor) {const CBMResolvedCallArray *lsp_calls = &result->resolved_calls;const cbm_gbuf_node_t *source_node = calls_find_source(ctx, rel, call->enclosing_func_qn);if (!source_node) {@@ -683,6 +684,12 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBMbool allow_tail = cbm_pipeline_lsp_allow_tail_match(lang);const CBMResolvedCall *lsp = cbm_pipeline_find_lsp_resolution_in_graph(lsp_calls, call, allow_tail, ctx->gbuf, ctx->project_name);+ /* #1186: a PHP call on a vendor type (`new Request`, or a receiver the LSP+ * typed as an imported vendor class) takes the LSP result or no target: a+ * same-named project symbol found by name alone is never the vendor's.+ * Service/route classification below still runs. Mirrors pass_parallel.c. */+ bool php_vendor_call = cbm_pipeline_php_vendor_call(php_vendor, result, call) ||+ cbm_pipeline_lsp_external_receiver(lsp);if (lsp) {bool exact_external_target = call->requires_lsp_resolution &&cbm_pipeline_kotlin_external_target(lang, lsp->callee_qn);@@ -774,7 +781,7 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBMbool rust_external = lsp && cbm_pipeline_rust_external_target(lang, lsp->strategy, lsp->callee_qn, ctx->project_name);cbm_resolution_t res = {0};- if (!rust_external) {+ if (!rust_external && !php_vendor_call) {res = cbm_registry_resolve_lang(ctx->registry, call->callee_name, module_qn, imp_keys,imp_vals, imp_count, lang);/* Cross-language veto: a name-only guess never binds another@@ -1147,6 +1154,8 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *fileconst char **imp_vals = NULL;int imp_count = 0;build_import_map(ctx, rel, result, &imp_keys, &imp_vals, &imp_count);+ cbm_php_vendor_names_t php_vendor;+ cbm_pipeline_php_vendor_names_build(ctx->gbuf, ctx->project_name, rel, result, &php_vendor);/* Compute module QN for same-module resolution (directory-based for* Java/Go so it matches their def-node QNs in the registry). */@@ -1166,7 +1175,8 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *file}total_calls++;if (resolve_single_call(ctx, call, result, rel, module_qn, imp_keys, imp_vals,- imp_count, files[i].language, &result->imports, route_mount)) {+ imp_count, files[i].language, &result->imports, route_mount,+ &php_vendor)) {resolved++;} else {unresolved++;@@ -1174,6 +1184,7 @@ int cbm_pipeline_pass_calls(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *file}free(module_qn);+ cbm_pipeline_php_vendor_names_free(&php_vendor);free_import_map(imp_keys, imp_vals, imp_count);if (result_owned) {cbm_free_result(result);diff --git a/src/pipeline/pass_definitions.c b/src/pipeline/pass_definitions.cindex 98925f32d..2169868fa 100644--- a/src/pipeline/pass_definitions.c+++ b/src/pipeline/pass_definitions.c@@ -556,6 +556,12 @@ static int create_import_edges_for_file(cbm_pipeline_ctx_t *ctx, const CBMFileRefree(file_qn);return 0;}+ if (cbm_language_for_filename(rel) == CBM_LANG_PHP) {+ count = cbm_pipeline_php_create_import_edges(ctx, result, rel, file_qn, source_node,+ namespace_map);+ free(file_qn);+ return count;+ }for (int j = 0; j < result->imports.count; j++) {const CBMImport *imp = &result->imports.items[j];if (!imp->module_path) {diff --git a/src/pipeline/pass_lsp_cross.c b/src/pipeline/pass_lsp_cross.cindex 1bd08dc70..19bcd88d1 100644--- a/src/pipeline/pass_lsp_cross.c+++ b/src/pipeline/pass_lsp_cross.c@@ -1024,10 +1024,20 @@ int cbm_pxc_build_import_map(const cbm_gbuf_t *gbuf, const char *project_name, cint metadata_count =(lang == CBM_LANG_PYTHON || lang == CBM_LANG_KOTLIN) && result ? result->imports.count : 0;- if (edge_count == 0 && metadata_count == 0)+ /* A completed PHP binding snapshot can establish a genuinely empty map.+ * The ordinary map remains a compatibility projection; only the separate+ * typed snapshot may prove that an import was left unresolved. */+ cbm_php_vendor_names_t php_bindings = {0};+ if (lang == CBM_LANG_PHP)+ cbm_pipeline_php_vendor_names_build(gbuf, project_name, rel_path, result, &php_bindings);+ bool authoritative_empty = php_bindings.targets != NULL;+ cbm_pipeline_php_vendor_names_free(&php_bindings);+ if (edge_count == 0 && metadata_count == 0 && !authoritative_empty)return 0;size_t capacity = (size_t)edge_count + (size_t)metadata_count;+ if (capacity == 0)+ capacity = 1;const char **keys = (const char **)calloc(capacity, sizeof(const char *));const char **vals = (const char **)calloc(capacity, sizeof(const char *));if (!keys || !vals) {@@ -1250,11 +1260,15 @@ static void pxc_append_results(CBMArena *dst_arena, CBMResolvedCallArray *dst_ca* proves that `member` is a declared Cargo workspace member, replace only* records for that exact parser occurrence before constructing the dedup* table. This preserves distinct same-named calls at other spans while- * preventing the stale local result from out-ranking manifest evidence. */+ * preventing the stale local result from out-ranking manifest evidence.+ * PHP external-receiver evidence likewise supersedes a speculative local+ * row at that exact occurrence after complete typed import classification. */for (int j = 0; j < src_out->count; j++) {const CBMResolvedCall *src = &src_out->items[j];- if (!src->strategy || strcmp(src->strategy, "lsp_cross_crate") != 0 || !src->caller_qn ||- !src->callee_qn || src->site_end_byte <= src->site_start_byte) {+ if (!src->strategy ||+ (strcmp(src->strategy, "lsp_cross_crate") != 0 &&+ strcmp(src->strategy, "php_external_receiver") != 0) ||+ !src->caller_qn || !src->callee_qn || src->site_end_byte <= src->site_start_byte) {continue;}for (int i = 0; i < dst_calls->count; i++) {@@ -1473,6 +1487,14 @@ static CBMRustLSPDef *pxc_lspdefs_to_rust(CBMArena *arena, const CBMLSPDef *defsvoid cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, int source_len,const char *module_qn, CBMLSPDef *defs, int def_count, const char **imp_names,const char **imp_qns, int imp_count) {+ cbm_pxc_run_one_with_php_bindings(lang, r, source, source_len, module_qn, defs, def_count,+ imp_names, imp_qns, imp_count, NULL);+}++void cbm_pxc_run_one_with_php_bindings(CBMLanguage lang, CBMFileResult *r, const char *source,+ int source_len, const char *module_qn, CBMLSPDef *defs,+ int def_count, const char **imp_names, const char **imp_qns,+ int imp_count, const CBMPHPImportBindings *bindings) {TSTree *tree = r->cached_tree; /* may be NULL — LSP re-parses then */CBMArena scratch;@@ -1520,8 +1542,9 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, intcbm_py_lsp_record_failure(r, status);} break;case CBM_LANG_PHP:- cbm_run_php_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,- imp_qns, imp_count, tree, &out);+ cbm_run_php_lsp_cross_with_bindings(&scratch, source, source_len, module_qn, defs,+ def_count, imp_names, imp_qns, imp_count, tree, &out,+ bindings);break;case CBM_LANG_JAVA:cbm_run_java_lsp_cross(&scratch, source, source_len, module_qn, defs, def_count, imp_names,@@ -1628,6 +1651,19 @@ void cbm_pxc_dispatch_file(CBMLanguage lang, CBMFileResult *result, const char *int all_def_count, const char **imp_keys, const char **imp_vals,int imp_count, CBMTypeRegistry *(*rust_shared_get)(void *),void *rust_shared_ctx) {+ cbm_pxc_dispatch_file_with_php_bindings(lang, result, source, source_len, rel, def_module,+ cross_registries, module_def_index, all_defs,+ all_def_count, imp_keys, imp_vals, imp_count,+ rust_shared_get, rust_shared_ctx, NULL);+}++void cbm_pxc_dispatch_file_with_php_bindings(+ CBMLanguage lang, CBMFileResult *result, const char *source, int source_len, const char *rel,+ const char *def_module, const CBMCrossLspRegistries *cross_registries,+ const CBMModuleDefIndex *module_def_index, CBMLSPDef *all_defs, int all_def_count,+ const char **imp_keys, const char **imp_vals, int imp_count,+ CBMTypeRegistry *(*rust_shared_get)(void *), void *rust_shared_ctx,+ const CBMPHPImportBindings *bindings) {if (result && result->lsp_skipped) {if (result->has_test_definition_owners) {cbm_pipeline_test_owner_error(result);@@ -1800,8 +1836,9 @@ void cbm_pxc_dispatch_file(CBMLanguage lang, CBMFileResult *result, const char *pxc_append_synthetic_calls(&result->arena, &result->calls, &synthetic_calls);pxc_scratch_give(PXC_SCRATCH_DISPATCH, &scratch);} else {- cbm_pxc_run_one(lang, result, source, source_len, def_module, file_defs, file_def_count,- imp_keys, imp_vals, imp_count);+ cbm_pxc_run_one_with_php_bindings(lang, result, source, source_len, def_module,+ file_defs, file_def_count, imp_keys, imp_vals,+ imp_count, bindings);}} else if (lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX) {bool js;@@ -1811,8 +1848,8 @@ void cbm_pxc_dispatch_file(CBMLanguage lang, CBMFileResult *result, const char *cbm_pxc_run_one_ts(result, source, source_len, def_module, file_defs, file_def_count,imp_keys, imp_vals, imp_count, js, jsx, dts);} else {- cbm_pxc_run_one(lang, result, source, source_len, def_module, file_defs, file_def_count,- imp_keys, imp_vals, imp_count);+ cbm_pxc_run_one_with_php_bindings(lang, result, source, source_len, def_module, file_defs,+ file_def_count, imp_keys, imp_vals, imp_count, bindings);}free(filtered);}@@ -2022,9 +2059,14 @@ int cbm_pipeline_pass_lsp_cross(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t ** failure mode). */cbm_index_mark_start(files[i].rel_path);bool had_error = cache[i]->has_error;- cbm_pxc_dispatch_file(lang, cache[i], source, source_len, files[i].rel_path, def_modules[i],- &cross_registries, module_def_index, all_defs, def_count, imp_keys,- imp_vals, imp_count, NULL, NULL);+ cbm_php_vendor_names_t php_bindings;+ cbm_pipeline_php_vendor_names_build(ctx->gbuf, ctx->project_name, files[i].rel_path,+ cache[i], &php_bindings);+ cbm_pxc_dispatch_file_with_php_bindings(+ lang, cache[i], source, source_len, files[i].rel_path, def_modules[i],+ &cross_registries, module_def_index, all_defs, def_count, imp_keys, imp_vals, imp_count,+ NULL, NULL, &php_bindings);+ cbm_pipeline_php_vendor_names_free(&php_bindings);cbm_index_mark_done(files[i].rel_path);if (!had_error && cache[i]->has_error && ctx->pipeline)cbm_pipeline_add_file_error(ctx->pipeline, files[i].rel_path, cache[i]->error_msg,diff --git a/src/pipeline/pass_lsp_cross.h b/src/pipeline/pass_lsp_cross.hindex 5bf9ba5d5..05e1545ca 100644--- a/src/pipeline/pass_lsp_cross.h+++ b/src/pipeline/pass_lsp_cross.h@@ -76,7 +76,10 @@ void cbm_pxc_ts_modes(CBMLanguage lang, const char *rel_path, bool *out_js, bool* Both sequential and parallel drivers use this exact helper so import* metadata cannot diverge between pipelines. Values are owned by the returned* map (not borrowed from gbuf); release both arrays with- * cbm_pxc_free_import_map(). */+ * cbm_pxc_free_import_map(). A complete PHP binding snapshot also permits an+ * allocated empty map. This compatibility projection alone never proves+ * vendor absence: consumers require cbm_pipeline_php_vendor_names_build's+ * separate typed evidence, including completion and full import identities. */int cbm_pxc_build_import_map(const cbm_gbuf_t *gbuf, const char *project_name, const char *rel_path,CBMLanguage lang, const CBMFileResult *result, const char ***out_keys,const char ***out_vals, int *out_count);@@ -202,6 +205,11 @@ void cbm_pxc_run_one(CBMLanguage lang, CBMFileResult *r, const char *source, intconst char *module_qn, CBMLSPDef *defs, int def_count, const char **imp_names,const char **imp_qns, int imp_count);+void cbm_pxc_run_one_with_php_bindings(CBMLanguage lang, CBMFileResult *r, const char *source,+ int source_len, const char *module_qn, CBMLSPDef *defs,+ int def_count, const char **imp_names, const char **imp_qns,+ int imp_count, const CBMPHPImportBindings *bindings);+/* TS / JS / JSX / TSX variant with explicit dialect flags. */void cbm_pxc_run_one_ts(CBMFileResult *r, const char *source, int source_len, const char *module_qn,CBMLSPDef *defs, int def_count, const char **imp_names,@@ -222,4 +230,12 @@ void cbm_pxc_dispatch_file(CBMLanguage lang, CBMFileResult *result, const char *int imp_count, CBMTypeRegistry *(*rust_shared_get)(void *),void *rust_shared_ctx);+void cbm_pxc_dispatch_file_with_php_bindings(+ CBMLanguage lang, CBMFileResult *result, const char *source, int source_len, const char *rel,+ const char *def_module, const CBMCrossLspRegistries *cross_registries,+ const CBMModuleDefIndex *module_def_index, CBMLSPDef *all_defs, int all_def_count,+ const char **imp_keys, const char **imp_vals, int imp_count,+ CBMTypeRegistry *(*rust_shared_get)(void *), void *rust_shared_ctx,+ const CBMPHPImportBindings *bindings);+#endif /* CBM_PIPELINE_PASS_LSP_CROSS_H */diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.cindex acaae6b2d..3bab32148 100644--- a/src/pipeline/pass_parallel.c+++ b/src/pipeline/pass_parallel.c@@ -1832,6 +1832,12 @@ static int create_imports_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *refree(file_qn);return 0;}+ if (cbm_language_for_filename(rel) == CBM_LANG_PHP) {+ count = cbm_pipeline_php_create_import_edges(ctx, result, rel, file_qn, source_node,+ namespace_map);+ free(file_qn);+ return count;+ }for (int j = 0; j < result->imports.count; j++) {CBMImport *imp = &result->imports.items[j];if (!imp->module_path) {@@ -3029,7 +3035,8 @@ static const CBMResolvedCall *lsp_idx_lookup(const CBMHashTable *index, const CB/* Resolve calls for one file and emit CALLS/HTTP_CALLS/ASYNC_CALLS edges. */static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFileResult *result,const char *rel, const char *module_qn, const char **imp_keys,- const char **imp_vals, int imp_count, CBMLanguage lang) {+ const char **imp_vals, int imp_count, CBMLanguage lang,+ const cbm_php_vendor_names_t *php_vendor) {/* Framework mount of this file's routes (Laravel 11+ withRouting, #1146). */char route_mount[CBM_SZ_128];cbm_laravel_file_route_mount(rc->repo_path, rel, lang, result, route_mount,@@ -3198,10 +3205,12 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB* node. The textual registry would bind it to a same-named project* method instead, so it must not run for such a row. Mirrors* pass_calls.c; the service fallbacks below still see the call. */+ bool php_vendor_call = cbm_pipeline_php_vendor_call(php_vendor, result, call) ||+ (lsp && !lsp_target && cbm_pipeline_lsp_external_receiver(lsp));bool rust_external = lsp && cbm_pipeline_rust_external_target(lang, lsp->strategy, lsp->callee_qn, rc->project_name);if ((!res.qualified_name || !res.qualified_name[0]) && !call->requires_lsp_resolution &&- !rust_external) {+ !rust_external && !php_vendor_call) {res = cbm_registry_resolve_lang(rc->registry, call->callee_name, module_qn, imp_keys,imp_vals, imp_count, lang);}@@ -3467,7 +3476,7 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBstatic void resolve_file_usages(resolve_ctx_t *rc, resolve_worker_state_t *ws,CBMFileResult *result, const char *rel, const char *module_qn,const char **imp_keys, const char **imp_vals, int imp_count,- CBMLanguage lang) {+ CBMLanguage lang, const cbm_php_vendor_names_t *php_vendor) {cbm_pipeline_lsp_reference_index_t reference_index = {0};bool reference_index_ready =cbm_pipeline_lsp_reference_index_build(&result->resolved_calls, &reference_index);@@ -3548,6 +3557,11 @@ static void resolve_file_usages(resolve_ctx_t *rc, resolve_worker_state_t *ws,if (semantic_reference) {continue;}+ /* #1186: a PHP name imported from a vendor namespace is not the+ * same-named project symbol. Mirrors pass_usages.c. */+ if (cbm_pipeline_php_vendor_usage(php_vendor, result, usage)) {+ continue;+ }/* SQL usages are FROM/JOIN lineage refs and may bind Table/View* targets (cbm_registry_resolve_lineage); every other language* resolves through the default variant, whose central relation@@ -3727,11 +3741,18 @@ typedef struct {static void resolve_def_inherits(resolve_ctx_t *rc, resolve_worker_state_t *ws,const CBMDefinition *def, const cbm_gbuf_node_t *node,const pp_file_scope_t *fs, const char *mq, const char **ik,- const char **iv, int ic) {+ const char **iv, int ic,+ const cbm_php_vendor_names_t *php_vendor) {if (!def->base_classes) {return;}for (int b = 0; def->base_classes[b]; b++) {+ /* #1186: `extends Request` with `use Saloon\Http\Request` names the+ * vendor class, never a same-named project class. Mirrors+ * pass_semantic.c. */+ if (cbm_pipeline_php_vendor_bound(php_vendor, def->base_classes[b])) {+ continue;+ }const char *bqn =resolve_as_class(rc->registry, def->base_classes[b], mq, ik, iv, ic, fs->lang);/* Same external-base gate as the sequential semantic pass. */@@ -3827,7 +3848,8 @@ static void resolve_def_decorators(resolve_ctx_t *rc, resolve_worker_state_t *wsstatic void resolve_file_semantic(resolve_ctx_t *rc, resolve_worker_state_t *ws,CBMFileResult *result, const char *rel, CBMLanguage lang,const char *module_qn, const char **imp_keys,- const char **imp_vals, int imp_count) {+ const char **imp_vals, int imp_count,+ const cbm_php_vendor_names_t *php_vendor) {const pp_file_scope_t fs = {&result->imports, rel, lang};for (int d = 0; d < result->defs.count; d++) {CBMDefinition *def = &result->defs.items[d];@@ -3838,7 +3860,8 @@ static void resolve_file_semantic(resolve_ctx_t *rc, resolve_worker_state_t *ws,if (!node) {continue;}- resolve_def_inherits(rc, ws, def, node, &fs, module_qn, imp_keys, imp_vals, imp_count);+ resolve_def_inherits(rc, ws, def, node, &fs, module_qn, imp_keys, imp_vals, imp_count,+ php_vendor);resolve_def_decorators(rc, ws, def, node, module_qn, imp_keys, imp_vals, imp_count, lang);}for (int t = 0; t < result->impl_traits.count; t++) {@@ -4121,6 +4144,9 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {&imp_vals, &imp_count);atomic_fetch_add_explicit(&rc->time_ns_import_map, extract_now_ns() - _imp_t0,memory_order_relaxed);+ cbm_php_vendor_names_t php_vendor;+ cbm_pipeline_php_vendor_names_build(rc->main_gbuf, rc->project_name, rel, result,+ &php_vendor);/* Per-file is_import_reachable memoization. Spans all 5 resolve* sub-passes (calls/usages/throws/rw/semantic) which all flow@@ -4187,10 +4213,10 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {* this file, not to a stale extraction marker. */cbm_index_mark_start(rel);bool had_error = result->has_error;- cbm_pxc_dispatch_file(lang, result, lsp_source, lsp_source_len, rel, def_module,- rc->cross_registries, rc->module_def_index, rc->all_defs,- rc->def_count, imp_keys, imp_vals, imp_count,- pp_rust_shared_registry_get, rc);+ cbm_pxc_dispatch_file_with_php_bindings(+ lang, result, lsp_source, lsp_source_len, rel, def_module, rc->cross_registries,+ rc->module_def_index, rc->all_defs, rc->def_count, imp_keys, imp_vals,+ imp_count, pp_rust_shared_registry_get, rc, &php_vendor);cbm_index_mark_done(rel);if (!had_error && result->has_error && result->error_msg &&(strcmp(result->error_msg, CBM_C_LSP_MEMO_ERROR) == 0 ||@@ -4247,13 +4273,15 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {/* ── CALLS resolution ──────────────────────────────────── */_ph_t0 = extract_now_ns();- resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang);+ resolve_file_calls(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang,+ &php_vendor);atomic_fetch_add_explicit(&rc->time_ns_calls, extract_now_ns() - _ph_t0,memory_order_relaxed);/* ── USAGE resolution ──────────────────────────────────── */_ph_t0 = extract_now_ns();- resolve_file_usages(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang);+ resolve_file_usages(rc, ws, result, rel, module_qn, imp_keys, imp_vals, imp_count, lang,+ &php_vendor);atomic_fetch_add_explicit(&rc->time_ns_usages, extract_now_ns() - _ph_t0,memory_order_relaxed);@@ -4270,7 +4298,8 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {/* ── INHERITS + DECORATES + IMPLEMENTS ──────────────────── */_ph_t0 = extract_now_ns();- resolve_file_semantic(rc, ws, result, rel, lang, module_qn, imp_keys, imp_vals, imp_count);+ resolve_file_semantic(rc, ws, result, rel, lang, module_qn, imp_keys, imp_vals, imp_count,+ &php_vendor);atomic_fetch_add_explicit(&rc->time_ns_semantic, extract_now_ns() - _ph_t0,memory_order_relaxed);@@ -4286,6 +4315,7 @@ static void resolve_worker(int worker_id, void *ctx_ptr) {cbm_registry_resolve_cache_end();free(module_qn);+ cbm_pipeline_php_vendor_names_free(&php_vendor);cbm_pxc_free_import_map(imp_keys, imp_vals, imp_count);atomic_fetch_add_explicit(&rc->time_ns_total_loop, extract_now_ns() - _loop_t0,diff --git a/src/pipeline/pass_pkgmap.c b/src/pipeline/pass_pkgmap.cindex 32b242b75..79d4cdad1 100644--- a/src/pipeline/pass_pkgmap.c+++ b/src/pipeline/pass_pkgmap.c@@ -12,12 +12,14 @@*/#include "pipeline/pipeline.h"#include "pipeline/pipeline_internal.h"+#include "pipeline/pass_lsp_cross.h"#include "discover/discover.h"#include "foundation/compat.h"#include "foundation/compat_fs.h"#include "foundation/constants.h"#include "foundation/hash_table.h"#include "foundation/log.h"+#include "foundation/mem_core.h"#include "foundation/platform.h"#include "foundation/str_util.h"#include "foundation/win_utf8.h"@@ -2601,6 +2603,10 @@ typedef enum {enum { PHP_NON_ASCII_MIN = 0x80 }; /* PHP identifiers admit any byte >= 0x80 */+static bool php_ident_byte(unsigned char c) {+ return c == '_' || isalnum(c) || c >= PHP_NON_ASCII_MIN;+}+static php_use_shape_t php_use_shape(const char *source_rel, const CBMImport *imp) {if (!source_rel || cbm_language_for_filename(path_leaf(source_rel)) != CBM_LANG_PHP) {return PHP_USE_NONE;@@ -2617,7 +2623,7 @@ static php_use_shape_t php_use_shape(const char *source_rel, const CBMImport *imunsigned char c = (unsigned char)*p;if (c == '\\') {qualified = true;- } else if (c != '_' && !isalnum(c) && c < PHP_NON_ASCII_MIN) {+ } else if (!php_ident_byte(c)) {return PHP_USE_NONE;}}@@ -2770,6 +2776,413 @@ const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_ttrue);}+/* PHP binding evidence is per File. The first field is canonical so its+ * completion bit can be invalidated without allocating, before a rebuild.+ * Node properties are exclusively owned heap strings; both writers run on+ * the coordinator before resolve workers borrow the graph read-only. */+static const char php_import_complete[] = "{\"php_imports_complete\":1,";++/* A resolver NULL can also mean unsupported input or a failed lookup. Only+ * the bounded namespace-only path admits an allocation-free absence proof.+ * A covered-but-missing PSR-4 file, global use, or unavailable namespace map+ * leaves the whole file unknown; already resolved IMPORTS are still written. */+static bool php_import_known_absent(const char *rel, const CBMImport *imp,+ CBMHashTable *namespace_map) {+ if (!namespace_map || !imp->module_path || !imp->local_name || !imp->local_name[0] ||+ (imp->kind != CBM_IMPORT_KIND_DEFAULT && imp->kind != CBM_IMPORT_KIND_FUNCTION &&+ imp->kind != CBM_IMPORT_KIND_CONST) ||+ php_use_shape(rel, imp) != PHP_USE_NAMESPACED)+ return false;+ const char *name = imp->module_path[0] == '\\' ? imp->module_path + 1 : imp->module_path;+ char key[CBM_SZ_1K];+ size_t length = strlen(name);+ if (length >= sizeof(key) || name[0] == '\\' || name[length - 1] == '\\' ||+ strstr(name, "\\\\"))+ return false;+ CBMHashTable *pkgmap = cbm_pipeline_get_pkgmap();+ if (pkgmap && imp->kind == CBM_IMPORT_KIND_DEFAULT) {+ /* The resolver does not handle Composer's fallback empty prefix.+ * Its presence therefore cannot support a negative proof either. */+ if (cbm_ht_get(pkgmap, ""))+ return false;+ for (size_t cut = length - 1; cut > 0; cut--) {+ if (name[cut - 1] != '\\')+ continue;+ memcpy(key, name, cut);+ key[cut] = '\0';+ if (cbm_ht_get(pkgmap, key))+ return false;+ }+ }+ memcpy(key, name, length + 1);+ for (char *p = key; *p; p++)+ if (*p == '\\')+ *p = '.';+ if (cbm_ht_get(namespace_map, key))+ return false;+ *strrchr(key, '.') = '\0';+ return cbm_ht_get(namespace_map, key) == NULL;+}++static bool php_json_string_eq(yyjson_val *value, const char *text) {+ return text ? yyjson_is_str(value) && yyjson_get_len(value) == strlen(text) &&+ strcmp(yyjson_get_str(value), text) == 0+ : yyjson_is_null(value);+}++static size_t php_json_key_count(yyjson_val *obj, const char *name) {+ size_t idx, max, count = 0;+ yyjson_val *key, *value;+ yyjson_obj_foreach(obj, idx, max, key, value) {+ (void)value;+ if (php_json_string_eq(key, name))+ count++;+ }+ return count;+}++static bool php_binding_identity(yyjson_val *value, const CBMImport *imp) {+ yyjson_val *kind = yyjson_obj_get(value, "kind");+ yyjson_val *def = yyjson_obj_get(value, "is_default");+ return yyjson_is_obj(value) && yyjson_obj_size(value) == 5 && yyjson_is_int(kind) &&+ yyjson_get_int(kind) == (int)imp->kind && yyjson_is_bool(def) &&+ yyjson_get_bool(def) == imp->is_default &&+ php_json_string_eq(yyjson_obj_get(value, "local_name"), imp->local_name) &&+ php_json_string_eq(yyjson_obj_get(value, "module_path"), imp->module_path);+}++static bool php_json_add_string(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key,+ const char *text) {+ return text ? yyjson_mut_obj_add_strcpy(doc, obj, key, text)+ : yyjson_mut_obj_add_null(doc, obj, key);+}++static yyjson_mut_val *php_binding_json(yyjson_mut_doc *doc, const CBMImport *imp,+ const char *target) {+ yyjson_mut_val *obj = yyjson_mut_obj(doc);+ if (!obj || !php_json_add_string(doc, obj, "local_name", imp->local_name) ||+ !php_json_add_string(doc, obj, "module_path", imp->module_path) ||+ !yyjson_mut_obj_add_int(doc, obj, "kind", imp->kind) ||+ !yyjson_mut_obj_add_bool(doc, obj, "is_default", imp->is_default) ||+ !php_json_add_string(doc, obj, "target", target)) {+ return NULL;+ }+ return obj;+}++/* Validate the entire snapshot, including bindings that coalesced into one+ * (source, target, local_name) edge. A positive insertion ID alone is not+ * evidence that all properties and secondary indexes were stored. */+static bool php_read_binding_snapshot(const cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *file,+ const CBMFileResult *result, const char *json,+ cbm_php_vendor_names_t *out) {+ if (!json || strncmp(json, php_import_complete, sizeof(php_import_complete) - 1) != 0)+ return false;+ yyjson_doc *doc = yyjson_read(json, strlen(json), 0);+ if (!doc)+ return false;+ yyjson_val *root = yyjson_doc_get_root(doc);+ yyjson_val *manifest = yyjson_obj_get(root, "php_import_bindings");+ int count = result->imports.count;+ const cbm_gbuf_edge_t **edges = NULL;+ int edge_count = 0;+ const char **targets = NULL;+ int *seen = NULL;+ bool ok =+ count >= 0 && (count == 0 || result->imports.items) &&+ php_json_key_count(root, "php_imports_complete") == 1 &&+ php_json_key_count(root, "php_import_bindings") == 1 && yyjson_is_arr(manifest) &&+ yyjson_arr_size(manifest) == (size_t)count &&+ cbm_gbuf_find_edges_by_source_type(gbuf, file->id, "IMPORTS", &edges, &edge_count) == 0 &&+ edge_count >= 0 && (edge_count == 0 || edges);+ if (!ok)+ goto done;+ targets = calloc(count > 0 ? (size_t)count : 1, sizeof(*targets));+ seen = calloc(count > 0 ? (size_t)count : 1, sizeof(*seen));+ if (!targets || !seen) {+ ok = false;+ goto done;+ }+ for (int i = 0; ok && i < count; i++) {+ yyjson_val *entry = yyjson_arr_get(manifest, (size_t)i);+ yyjson_val *target = yyjson_obj_get(entry, "target");+ ok = php_binding_identity(entry, &result->imports.items[i]);+ if (yyjson_is_str(target)) {+ const cbm_gbuf_node_t *node = cbm_gbuf_find_by_qn(gbuf, yyjson_get_str(target));+ ok = ok && node && node->id != file->id && node->qualified_name &&+ php_json_string_eq(target, node->qualified_name);+ if (ok)+ targets[i] = node->qualified_name;+ } else if (!yyjson_is_null(target)) {+ ok = false;+ }+ }+ for (int e = 0; ok && e < edge_count; e++) {+ const cbm_gbuf_edge_t *edge = edges[e];+ if (!edge) {+ ok = false;+ break;+ }+ const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(gbuf, edge->target_id);+ yyjson_doc *edoc = edge->properties_json ? yyjson_read(edge->properties_json,+ strlen(edge->properties_json), 0)+ : NULL;+ yyjson_val *obj = edoc ? yyjson_doc_get_root(edoc) : NULL;+ yyjson_val *local = yyjson_obj_get(obj, "local_name");+ yyjson_val *bindings = yyjson_obj_get(obj, "php_import_bindings");+ ok = target && target->qualified_name && yyjson_is_obj(obj) && yyjson_obj_size(obj) == 2 &&+ yyjson_is_str(local) && yyjson_is_arr(bindings) && yyjson_arr_size(bindings) > 0;+ for (size_t b = 0; ok && b < yyjson_arr_size(bindings); b++) {+ yyjson_val *binding = yyjson_arr_get(bindings, b);+ int match = -1;+ for (int i = 0; i < count; i++) {+ if (targets[i] && strcmp(targets[i], target->qualified_name) == 0 &&+ php_binding_identity(binding, &result->imports.items[i]) &&+ php_json_string_eq(local, result->imports.items[i].local_name) &&+ php_json_string_eq(yyjson_obj_get(binding, "target"), targets[i])) {+ if (match != -1) {+ ok = false;+ break;+ }+ match = i;+ }+ }+ if (match < 0 || (match >= 0 && ++seen[match] != 1))+ ok = false;+ }+ yyjson_doc_free(edoc);+ }+ for (int i = 0; ok && i < count; i++)+ ok = seen[i] == (targets[i] ? 1 : 0);+done:+ if (ok) {+ out->imports = &result->imports;+ out->targets = targets;+ targets = NULL;+ }+ free(targets);+ free(seen);+ yyjson_doc_free(doc);+ return ok;+}++/* Shared by the sequential and parallel PHP IMPORTS writers. Other languages+ * retain their original writer and property layout. */+int cbm_pipeline_php_create_import_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *result,+ const char *rel, const char *file_qn,+ const cbm_gbuf_node_t *file, CBMHashTable *namespace_map) {+ char *old_json = file->properties_json;+ if (old_json && strncmp(old_json, php_import_complete, sizeof(php_import_complete) - 1) == 0)+ old_json[sizeof(php_import_complete) - 3] = '0';++ int count = result->imports.count;+ if (count < 0 || (count > 0 && !result->imports.items))+ return 0;+ const cbm_gbuf_node_t **targets = calloc(count > 0 ? (size_t)count : 1, sizeof(*targets));+ yyjson_doc *old = old_json ? yyjson_read(old_json, strlen(old_json), 0) : NULL;+ yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);+ yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL;+ yyjson_mut_val *manifest = doc ? yyjson_mut_arr(doc) : NULL;+ bool ok = targets && root && manifest &&+ (!old_json || (old && yyjson_is_obj(yyjson_doc_get_root(old)))) &&+ yyjson_mut_obj_add_int(doc, root, "php_imports_complete", 1) &&+ yyjson_mut_obj_add_val(doc, root, "php_import_bindings", manifest);+ int written = 0;+ bool complete = true;+ if (!ok)+ goto done;+ yyjson_mut_doc_set_root(doc, root);+ if (old) {+ size_t idx, max;+ yyjson_val *key, *value;+ yyjson_obj_foreach(yyjson_doc_get_root(old), idx, max, key, value) {+ const char *name = yyjson_get_str(key);+ if (strcmp(name, "php_imports_complete") == 0 ||+ strcmp(name, "php_import_bindings") == 0)+ continue;+ yyjson_mut_val *copy = yyjson_val_mut_copy(doc, value);+ if (!copy || !yyjson_mut_obj_add_val(doc, root, name, copy)) {+ ok = false;+ goto done;+ }+ }+ }+ for (int i = 0; i < count; i++) {+ const CBMImport *imp = &result->imports.items[i];+ targets[i] = imp->module_path+ ? cbm_pipeline_resolve_import_node(ctx, rel, file_qn, imp, namespace_map)+ : NULL;+ if (targets[i] && targets[i]->id == file->id)+ targets[i] = NULL;+ if (!targets[i] && !php_import_known_absent(rel, imp, namespace_map))+ complete = false;+ yyjson_mut_val *entry =+ php_binding_json(doc, imp, targets[i] ? targets[i]->qualified_name : NULL);+ if (!entry || !yyjson_mut_arr_add_val(manifest, entry)) {+ ok = false;+ goto done;+ }+ }+ for (int i = 0; ok && i < count; i++) {+ if (!targets[i])+ continue;+ const char *local = result->imports.items[i].local_name;+ if (!local || !local[0]) {+ ok = false;+ break;+ }+ bool prior = false;+ for (int j = 0; j < i; j++)+ if (targets[j] && targets[j]->id == targets[i]->id &&+ result->imports.items[j].local_name &&+ strcmp(local, result->imports.items[j].local_name) == 0)+ prior = true;+ if (prior)+ continue;+ yyjson_mut_val *edge = yyjson_mut_obj(doc);+ yyjson_mut_val *bindings = yyjson_mut_arr(doc);+ ok = edge && bindings && yyjson_mut_obj_add_strcpy(doc, edge, "local_name", local) &&+ yyjson_mut_obj_add_val(doc, edge, "php_import_bindings", bindings);+ for (int j = i; ok && j < count; j++) {+ if (!targets[j] || targets[j]->id != targets[i]->id ||+ !result->imports.items[j].local_name ||+ strcmp(local, result->imports.items[j].local_name) != 0)+ continue;+ yyjson_mut_val *entry =+ php_binding_json(doc, &result->imports.items[j], targets[j]->qualified_name);+ ok = entry && yyjson_mut_arr_add_val(bindings, entry);+ }+ char *props = ok ? yyjson_mut_val_write(edge, 0, NULL) : NULL;+ ok = props &&+ cbm_gbuf_insert_edge(ctx->gbuf, file->id, targets[i]->id, "IMPORTS", props) > 0;+ free(props);+ if (ok)+ written++;+ }+ if (ok && complete) {+ char *props = yyjson_mut_write(doc, 0, NULL);+ cbm_php_vendor_names_t check = {0};+ if (props && php_read_binding_snapshot(ctx->gbuf, file, result, props, &check)) {+ /* Failure leaves the earlier completion bit disabled. */+ (void)cbm_gbuf_node_set_properties_json((cbm_gbuf_node_t *)file, props);+ }+ cbm_pipeline_php_vendor_names_free(&check);+ free(props);+ }+done:+ yyjson_doc_free(old);+ yyjson_mut_doc_free(doc);+ free(targets);+ return written;+}++void cbm_pipeline_php_vendor_names_build(const cbm_gbuf_t *gbuf, const char *project_name,+ const char *rel, const CBMFileResult *result,+ cbm_php_vendor_names_t *out) {+ memset(out, 0, sizeof(*out));+ if (!gbuf || !result || !rel || cbm_language_for_filename(path_leaf(rel)) != CBM_LANG_PHP)+ return;+ char *qn = cbm_pipeline_fqn_compute(project_name, rel, "__file__");+ const cbm_gbuf_node_t *file = qn ? cbm_gbuf_find_by_qn(gbuf, qn) : NULL;+ free(qn);+ if (file)+ (void)php_read_binding_snapshot(gbuf, file, result, file->properties_json, out);+}++void cbm_pipeline_php_vendor_names_free(cbm_php_vendor_names_t *value) {+ if (value) {+ free(value->targets);+ memset(value, 0, sizeof(*value));+ }+}++static bool php_vendor_kind(const cbm_php_vendor_names_t *value, const char *name, int kind) {+ if (!value || !value->targets || !value->imports || !name || name[0] == '\\')+ return false;+ size_t length = 0;+ while (php_ident_byte((unsigned char)name[length]))+ length++;+ if (length == 0)+ return false;+ for (int i = 0; i < value->imports->count; i++) {+ const CBMImport *imp = &value->imports->items[i];+ if (!imp->local_name || !imp->module_path || value->targets[i] ||+ (kind >= 0 && (int)imp->kind != kind))+ continue;+ if (strlen(imp->local_name) == length && strncmp(imp->local_name, name, length) == 0)+ return true;+ }+ return false;+}++bool cbm_pipeline_php_vendor_bound(const cbm_php_vendor_names_t *value, const char *name) {+ return php_vendor_kind(value, name, CBM_IMPORT_KIND_DEFAULT);+}++/* Existing occurrence metadata can identify a constructor or a type without+ * adding serialized fields. If its tree/source was not retained, -1 preserves+ * uncertainty: only an unresolved matching import can veto a guessed edge. */+static int php_import_kind_at_site(const CBMFileResult *result, uint32_t start, uint32_t end,+ CBMSourceOrigin origin, bool call) {+ if (!result || origin != CBM_SOURCE_ORIGIN_RAW || end <= start)+ return -1;+ if (result->cached_tree) {+ TSNode node = ts_node_descendant_for_byte_range(ts_tree_root_node(result->cached_tree),+ start, end - 1);+ for (int depth = 0; !ts_node_is_null(node) && depth < 16; depth++) {+ const char *type = ts_node_type(node);+ if (strcmp(type, "named_type") == 0 || strcmp(type, "base_clause") == 0 ||+ strcmp(type, "class_interface_clause") == 0)+ return CBM_IMPORT_KIND_DEFAULT;+ if (strcmp(type, "object_creation_expression") == 0 ||+ strcmp(type, "scoped_call_expression") == 0 ||+ strcmp(type, "class_constant_access_expression") == 0) {+ TSNode scope = ts_node_named_child(node, 0);+ if (call || (!ts_node_is_null(scope) && ts_node_start_byte(scope) <= start &&+ ts_node_end_byte(scope) >= end))+ return CBM_IMPORT_KIND_DEFAULT;+ break;+ }+ if (strcmp(type, "function_call_expression") == 0) {+ TSNode function = ts_node_child_by_field_name(node, "function", 8);+ if (call || (!ts_node_is_null(function) && ts_node_start_byte(function) <= start &&+ ts_node_end_byte(function) >= end))+ return CBM_IMPORT_KIND_FUNCTION;+ break;+ }+ if (strcmp(type, "namespace_use_declaration") == 0 ||+ strcmp(type, "method_declaration") == 0 || strcmp(type, "function_definition") == 0)+ break;+ node = ts_node_parent(node);+ }+ }+ if (call && result->source && end <= (uint32_t)result->source_len && end - start > 3 &&+ memcmp(result->source + start, "new", 3) == 0 &&+ isspace((unsigned char)result->source[start + 3]))+ return CBM_IMPORT_KIND_DEFAULT;+ return -1;+}++bool cbm_pipeline_php_vendor_call(const cbm_php_vendor_names_t *value, const CBMFileResult *result,+ const CBMCall *call) {+ if (!call || !call->callee_name)+ return false;+ int kind = strstr(call->callee_name, "::")+ ? CBM_IMPORT_KIND_DEFAULT+ : php_import_kind_at_site(result, call->site_start_byte, call->site_end_byte,+ call->source_origin, true);+ return php_vendor_kind(value, call->callee_name, kind);+}++bool cbm_pipeline_php_vendor_usage(const cbm_php_vendor_names_t *value, const CBMFileResult *result,+ const CBMUsage *usage) {+ if (!usage)+ return false;+ int kind = php_import_kind_at_site(result, usage->site_start_byte, usage->site_end_byte,+ usage->source_origin, false);+ return php_vendor_kind(value, usage->ref_name, kind);+}+/* ── Namespace map ───────────────────────────────────────────────── *//* The namespace names themselves, so a caller that has parked some results on@@ -2782,19 +3195,25 @@ CBMHashTable *cbm_pipeline_namespace_map_build_names(const char *project_name,const char *const *namespaces,const char *const *rels, int count) {/* NULL means no namespace information (e.g. the CALLS import map), while- * an empty map means no project file declares a namespace. */+ * an empty map means no project file declares a namespace. A partial map+ * cannot prove a PHP import absent, so every construction failure returns+ * NULL after releasing the accumulated entries. */+ if (count < 0 || (count > 0 && (!namespaces || !rels)))+ return NULL;CBMHashTable *map = cbm_ht_create(CBM_SZ_64);if (!map) {return NULL;}for (int i = 0; i < count; i++) {const char *namespace_name = namespaces[i];- if (!namespace_name || !namespace_name[0] || !rels[i]) {+ if (!namespace_name || !namespace_name[0]) {continue;}+ if (!rels[i])+ goto failed;char *file_qn = cbm_pipeline_fqn_compute(project_name, rels[i], "__file__");if (!file_qn) {- continue;+ goto failed;}/* Normalize the namespace key to dot-separated form so it matches the* dot-normalized lookups in cbm_pipeline_resolve_import_node (PHP uses@@ -2802,7 +3221,7 @@ CBMHashTable *cbm_pipeline_namespace_map_build_names(const char *project_name,char *key = strdup(namespace_name);if (!key) {free(file_qn);- continue;+ goto failed;}for (char *p = key; *p; p++) {if (*p == '\\' || *p == ':' || *p == '/') {@@ -2815,6 +3234,17 @@ CBMHashTable *cbm_pipeline_namespace_map_build_names(const char *project_name,* freed in ns_map_free_entry. */if (!cbm_ht_has(map, key)) {cbm_ht_set(map, key, file_qn); /* map owns key + file_qn */+ /* set returns NULL for both insertion and allocation failure.+ * These lookups allocate nothing and verify ownership transfer. */+ const char *stored_key = cbm_ht_get_key(map, key);+ void *stored_value = cbm_ht_get(map, key);+ if (stored_key != key || stored_value != file_qn) {+ if (stored_key != key)+ free(key);+ if (stored_value != file_qn)+ free(file_qn);+ goto failed;+ }} else {/* Append to the existing list. Re-key with the STORED key pointer* (not our fresh strdup) so the map's key pointer never changes —@@ -2824,19 +3254,35 @@ CBMHashTable *cbm_pipeline_namespace_map_build_names(const char *project_name,const char *cur = (const char *)cbm_ht_get(map, key);char *combined = NULL;if (stored_key && cur) {- size_t need = strlen(cur) + 1 + strlen(file_qn) + 1;+ size_t cur_len = strlen(cur), file_len = strlen(file_qn);+ if (file_len > SIZE_MAX - 2 || cur_len > SIZE_MAX - file_len - 2) {+ free(key);+ free(file_qn);+ goto failed;+ }+ size_t need = cur_len + 1 + file_len + 1;combined = malloc(need);if (combined) {snprintf(combined, need, "%s\n%s", cur, file_qn);- void *prev = cbm_ht_set(map, stored_key, combined);- free(prev); /* old value string */+ (void)cbm_ht_set(map, stored_key, combined);+ if (cbm_ht_get(map, stored_key) != combined) {+ free(combined);+ combined = NULL;+ } else {+ free((void *)cur); /* replaced value string */+ }}}free(key); /* our fresh strdup — never stored */free(file_qn); /* content copied into combined */+ if (!combined)+ goto failed;}}return map;+failed:+ cbm_pipeline_namespace_map_free(map);+ return NULL;}/* Convenience for callers whose results are all in memory (the sequential@@ -2846,6 +3292,11 @@ CBMHashTable *cbm_pipeline_namespace_map_build_names(const char *project_name,CBMHashTable *cbm_pipeline_namespace_map_build(const char *project_name,CBMFileResult *const *results,const char *const *rels, int count) {+ if (count < 0 || (count > 0 && (!results || !rels)) ||+ (size_t)count > SIZE_MAX / sizeof(char *))+ return NULL;+ if (count == 0)+ return cbm_pipeline_namespace_map_build_names(project_name, NULL, rels, 0);const char **names = cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)count * sizeof(char *));if (!names) {return NULL;diff --git a/src/pipeline/pass_semantic.c b/src/pipeline/pass_semantic.cindex 7894fbcf7..186b2dfdc 100644--- a/src/pipeline/pass_semantic.c+++ b/src/pipeline/pass_semantic.c@@ -626,7 +626,8 @@ static void sem_process_def_edges(cbm_pipeline_ctx_t *ctx, const CBMDefinition *const cbm_file_info_t *fi, const CBMFileResult *result,const char *module_qn, const char **imp_keys,const char **imp_vals, int imp_count, int *inherits_count,- int *decorates_count, CBMLanguage lang) {+ int *decorates_count, CBMLanguage lang,+ const cbm_php_vendor_names_t *php_vendor) {if (!def->qualified_name) {return;}@@ -636,6 +637,12 @@ static void sem_process_def_edges(cbm_pipeline_ctx_t *ctx, const CBMDefinition *}if (def->base_classes) {for (int b = 0; def->base_classes[b]; b++) {+ /* #1186: `extends Request` with `use Saloon\Http\Request` names the+ * vendor class, never a same-named project class. Mirrors+ * pass_parallel.c. */+ if (cbm_pipeline_php_vendor_bound(php_vendor, def->base_classes[b])) {+ continue;+ }const char *base_qn = resolve_as_class(ctx->registry, def->base_classes[b], module_qn,imp_keys, imp_vals, imp_count, lang);if (!base_qn || cbm_python_external_base_contradicts(@@ -763,6 +770,8 @@ int cbm_pipeline_pass_semantic(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *fconst char **imp_vals = NULL;int imp_count = 0;build_import_map(ctx, rel, result, &imp_keys, &imp_vals, &imp_count);+ cbm_php_vendor_names_t php_vendor;+ cbm_pipeline_php_vendor_names_build(ctx->gbuf, ctx->project_name, rel, result, &php_vendor);char *module_qn = cbm_pipeline_fqn_module_dir(ctx->project_name, rel,ps_module_is_dir(files[i].language));@@ -771,7 +780,7 @@ int cbm_pipeline_pass_semantic(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *ffor (int d = 0; d < result->defs.count; d++) {sem_process_def_edges(ctx, &result->defs.items[d], &files[i], result, module_qn,imp_keys, imp_vals, imp_count, &inherits_count, &decorates_count,- files[i].language);+ files[i].language, &php_vendor);}/* ── IMPLEMENTS from impl_traits (Rust) ─────────────────── */@@ -779,6 +788,7 @@ int cbm_pipeline_pass_semantic(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *fresolve_impl_traits(ctx, result, module_qn, imp_keys, imp_vals, imp_count);free(module_qn);+ cbm_pipeline_php_vendor_names_free(&php_vendor);free_import_map(imp_keys, imp_vals, imp_count);if (result_owned) {cbm_free_result(result);diff --git a/src/pipeline/pass_usages.c b/src/pipeline/pass_usages.cindex c3988a7de..d47f53de6 100644--- a/src/pipeline/pass_usages.c+++ b/src/pipeline/pass_usages.c@@ -158,6 +158,9 @@ static int resolve_usage_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *rescbm_pipeline_lsp_field_index_t field_index = {0};bool field_index_ready =cbm_pipeline_lsp_field_index_build(&result->resolved_calls, &field_index);+ /* imp_keys is the IMPORTS-edge map (cbm_pxc_build_import_map). */+ cbm_php_vendor_names_t php_vendor;+ cbm_pipeline_php_vendor_names_build(ctx->gbuf, ctx->project_name, rel, result, &php_vendor);for (int u = 0; u < result->usages.count; u++) {CBMUsage *usage = &result->usages.items[u];if (!usage->ref_name) {@@ -238,6 +241,11 @@ static int resolve_usage_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *resif (semantic_reference) {continue;}+ /* #1186: a PHP name imported from a vendor namespace is not the+ * same-named project symbol. Mirrors pass_parallel.c. */+ if (cbm_pipeline_php_vendor_usage(&php_vendor, result, usage)) {+ continue;+ }/* SQL usages are FROM/JOIN lineage refs and may bind Table/View* targets (cbm_registry_resolve_lineage); every other language* resolves through the default variant, whose central relation@@ -294,6 +302,7 @@ static int resolve_usage_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *res}cbm_pipeline_lsp_reference_index_free(&reference_index);cbm_pipeline_lsp_field_index_free(&field_index);+ cbm_pipeline_php_vendor_names_free(&php_vendor);return resolved;}diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.hindex 5fb746b07..385627d0e 100644--- a/src/pipeline/pipeline_internal.h+++ b/src/pipeline/pipeline_internal.h@@ -19,6 +19,7 @@#include "foundation/hash_table.h"#include "spawn_patterns.h"#include "cbm.h"+#include "lsp/php_lsp.h"#include "lsp/go_lsp.h" /* CBMLSPDef for cbm_parallel_resolve cross-LSP inputs */#include <stdatomic.h>#include <string.h>@@ -705,6 +706,22 @@ const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_tconst CBMImport *imp,CBMHashTable *namespace_map);+/* PHP binding arrays borrow current result and graph strings. Free before+ * releasing/reloading the result; never cache this state across files. */+typedef CBMPHPImportBindings cbm_php_vendor_names_t;+void cbm_pipeline_php_vendor_names_build(const cbm_gbuf_t *gbuf, const char *project_name,+ const char *rel, const CBMFileResult *result,+ cbm_php_vendor_names_t *out);+void cbm_pipeline_php_vendor_names_free(cbm_php_vendor_names_t *value);+bool cbm_pipeline_php_vendor_bound(const cbm_php_vendor_names_t *value, const char *name);+bool cbm_pipeline_php_vendor_call(const cbm_php_vendor_names_t *value, const CBMFileResult *result,+ const CBMCall *call);+bool cbm_pipeline_php_vendor_usage(const cbm_php_vendor_names_t *value, const CBMFileResult *result,+ const CBMUsage *usage);+int cbm_pipeline_php_create_import_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *result,+ const char *rel, const char *file_qn,+ const cbm_gbuf_node_t *file, CBMHashTable *namespace_map);+/* Build a namespace → File-node-QN map from a set of extraction results.* Each result that declared a namespace/package contributes one entry keyed by* the namespace string (e.g. "App.Utils", "com.example"). Returns NULL when nodiff --git a/tests/test_edge_imports.c b/tests/test_edge_imports.cindex 807767713..b5f1e7fbf 100644--- a/tests/test_edge_imports.c+++ b/tests/test_edge_imports.c@@ -1865,6 +1865,435 @@ TEST(ei_php_require_path_keeps_generic_resolution_issue1186) {PASS();}+/* ═══════════════════════════════════════════════════════════════════════════+ * PHP vendor-imported types — #1186 follow-up (CALLS / INHERITS / USAGE)+ *+ * With the vendor `use` unresolved, the edges that NAME the imported type fell+ * back to name guessing: `extends Request` bound to the project's own Request+ * class, calls on a Request-typed receiver to its same-named methods (or to a+ * TypeScript function), and the type references to that class. A name bound+ * by a vendor `use` must take the LSP result or nothing.+ * ═══════════════════════════════════════════════════════════════════════════ */++/* Missing source/target nodes or any failed query are fixture failures, not+ * evidence that a forbidden edge is absent. */+static int ei_php_checked_file_edges(cbm_store_t *store, const char *project, const char *source,+ const char *type, const char *target) {+ cbm_node_t *src = NULL, *dst = NULL;+ int nsrc = 0, ndst = 0;+ if (cbm_store_find_nodes_by_file(store, project, source, &src, &nsrc) != CBM_STORE_OK ||+ cbm_store_find_nodes_by_file(store, project, target, &dst, &ndst) != CBM_STORE_OK) {+ cbm_store_free_nodes(src, nsrc);+ cbm_store_free_nodes(dst, ndst);+ return -1;+ }+ int source_files = 0, target_files = 0, source_defs = 0, target_defs = 0;+ for (int i = 0; i < nsrc; i++) {+ source_files += src[i].label && strcmp(src[i].label, "File") == 0;+ source_defs += src[i].label &&+ (strcmp(src[i].label, "Class") == 0 || strcmp(src[i].label, "Method") == 0);+ }+ for (int i = 0; i < ndst; i++) {+ target_files += dst[i].label && strcmp(dst[i].label, "File") == 0;+ target_defs += dst[i].label && (strcmp(dst[i].label, "Class") == 0 ||+ strcmp(dst[i].label, "Function") == 0 ||+ strcmp(dst[i].label, "Method") == 0);+ }+ int hits =+ source_files == 1 && target_files == 1 && source_defs > 0 && target_defs > 0 ? 0 : -1;+ for (int i = 0; hits >= 0 && i < nsrc; i++) {+ cbm_edge_t *edges = NULL;+ int count = 0;+ if (cbm_store_find_edges_by_source_type(store, src[i].id, type, &edges, &count) !=+ CBM_STORE_OK) {+ hits = -1;+ }+ for (int j = 0; hits >= 0 && j < count; j++) {+ cbm_node_t node = {0};+ if (cbm_store_find_node_by_id(store, edges[j].target_id, &node) != CBM_STORE_OK) {+ hits = -1;+ } else {+ hits += node.file_path && strcmp(node.file_path, target) == 0;+ cbm_node_free_fields(&node);+ }+ }+ cbm_store_free_edges(edges, count);+ }+ cbm_store_free_nodes(src, nsrc);+ cbm_store_free_nodes(dst, ndst);+ return hits;+}++static bool ei_php_vendor_sites_present(const char *source, const char *path) {+ CBMFileResult *r = cbm_extract_file(source, (int)strlen(source), CBM_LANG_PHP, "vendor_types",+ path, 0, NULL, NULL);+ if (!r)+ return false;+ const char *names[] = {"validated", "makeIt", "go", "build", "get", "sendAsync"};+ bool ok = r->defs.count > 0 && r->imports.count == 2;+ for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {+ int found = 0;+ for (int j = 0; j < r->calls.count; j++) {+ const CBMCall *call = &r->calls.items[j];+ if (call->callee_name && strstr(call->callee_name, names[i]) &&+ call->enclosing_func_qn && strstr(call->enclosing_func_qn, "Foo.run") &&+ call->site_end_byte > call->site_start_byte &&+ call->site_end_byte <= strlen(source))+ found++;+ }+ ok = found == 1 && ok;+ }+ int request_uses = 0;+ for (int i = 0; i < r->usages.count; i++) {+ request_uses +=+ r->usages.items[i].ref_name && strcmp(r->usages.items[i].ref_name, "Request") == 0;+ }+ ok = request_uses > 0 && ok;+ cbm_free_result(r);+ return ok;+}++TEST(ei_php_vendor_types_never_bind_by_name_issue1186) {+ static const EILangFile f[] = {+ {"composer.json", "{\"autoload\":{\"psr-4\":{\"App\\\\\":\"app/\"}}}\n"},+ {"app/Http/Requests/Request.php",+ "<?php\nnamespace App\\Http\\Requests;\n\nclass Request {\n"+ " public function validated() { return 1; }\n"+ " public static function makeIt() { return 2; }\n"+ " public function get($k) { return $k; }\n}\n"},+ {"app/Services/Svc.php", "<?php\nnamespace App\\Services;\n\nclass Svc {\n"+ " public function go() { return 3; }\n"+ " public static function build() { return 4; }\n}\n"},+ {"resources/js/api.ts", "export function sendAsync(x: number) { return x; }\n"},+ {"app/Http/Integrations/Foo.php", "<?php\nnamespace App\\Http\\Integrations;\n\n"+ "use Saloon\\Http\\Request;\nuse App\\Services\\Svc;\n\n"+ "class Foo extends Request {\n"+ " public function run(Request $r, Svc $s) {\n"+ " $r->validated();\n"+ " Request::makeIt();\n"+ " $made = new Request();\n"+ " $s->go();\n"+ " Svc::build();\n"+ " $r->get('id');\n"+ " return $r->sendAsync(1);\n"+ " }\n}\n\n"+ "class Bar extends Svc {\n}\n"}};+ static const char *const foo = "app/Http/Integrations/Foo.php";+ static const char *const req = "app/Http/Requests/Request.php";+ static const char *const svc = "app/Services/Svc.php";+ static const struct {+ const char *type;+ const char *tgt;+ int want_min;+ int want_max;+ } checks[] = {+ {"INHERITS", req, 0, 0}, {"CALLS", req, 0, 0},+ {"USAGE", req, 0, 0}, {"CALLS", "resources/js/api.ts", 0, 0},+ {"INHERITS", svc, 1, 1}, {"CALLS", svc, 2, 2},+ {"CALLS", foo, 0, 0}, {"USAGE", svc, 1, 1 << 20},+ };+ ASSERT_TRUE(ei_php_vendor_sites_present(f[4].content, foo));+ EILangProj lp;+ cbm_store_t *store = ei_index_files(&lp, f, 5);+ int ok = store != NULL;+ for (size_t i = 0; store && i < sizeof(checks) / sizeof(checks[0]); i++) {+ int got = ei_php_checked_file_edges(store, lp.project, foo, checks[i].type, checks[i].tgt);+ if (got < checks[i].want_min || got > checks[i].want_max) {+ fprintf(stderr, " [%s] Foo.php -> %s: got %d, want %d..%d\n", checks[i].type,+ checks[i].tgt, got, checks[i].want_min, checks[i].want_max);+ ok = 0;+ }+ }+ ei_cleanup(&lp, store);+ ASSERT_TRUE(ok);+ PASS();+}++/* Build the metadata through the production writer, then challenge its+ * readback. A File node or an empty edge query alone is never completeness. */+static bool ei_php_seed_result(cbm_gbuf_t *gb, const char *project, const char *rel,+ const CBMFileResult *r) {+ char *qn = cbm_pipeline_fqn_compute(project, rel, "__file__");+ if (!qn)+ return false;+ int64_t id = cbm_gbuf_upsert_node(gb, "File", rel, qn, rel, 0, 0, "{}");+ free(qn);+ if (id <= 0 || !r || r->defs.count == 0)+ return false;+ for (int i = 0; i < r->defs.count; i++) {+ const CBMDefinition *d = &r->defs.items[i];+ if (!d->label || !d->name || !d->qualified_name ||+ cbm_gbuf_upsert_node(gb, d->label, d->name, d->qualified_name, rel, d->start_line,+ d->end_line, "{}") <= 0)+ return false;+ }+ return true;+}++TEST(ei_php_binding_snapshot_requires_current_complete_evidence) {+ const char *source = "<?php\nnamespace Local;\nuse Vendor\\Http\\Request;\n"+ "class Main { function run(Request $r) { $r->send(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(source, (int)strlen(source), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 1);+ ASSERT_GT(r->calls.count, 0);+ cbm_gbuf_t *gb = cbm_gbuf_new("p", "/tmp");+ ASSERT_NOT_NULL(gb);+ cbm_php_vendor_names_t names = {0};+ cbm_pipeline_php_vendor_names_build(NULL, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets); /* no File node */+ ASSERT_TRUE(ei_php_seed_result(gb, "p", "main.php", r));+ char *file_qn = cbm_pipeline_fqn_compute("p", "main.php", "__file__");+ ASSERT_NOT_NULL(file_qn);+ const cbm_gbuf_node_t *file = cbm_gbuf_find_by_qn(gb, file_qn);+ ASSERT_NOT_NULL(file);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets); /* legacy File properties */+ const char *rels[] = {"main.php"};+ CBMFileResult *results[] = {r};+ CBMHashTable *ns = cbm_pipeline_namespace_map_build("p", results, rels, 1);+ ASSERT_NOT_NULL(ns);+ cbm_pipeline_ctx_t ctx = {.project_name = "p", .gbuf = gb};+ CBMHashTable *saved = cbm_pipeline_get_pkgmap();+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, r, "main.php", file_qn, file, ns);+ cbm_pipeline_set_pkgmap(saved);+ const cbm_gbuf_edge_t **edges = NULL;+ int edge_count = -1;+ ASSERT_EQ(cbm_gbuf_find_edges_by_source_type(gb, file->id, "IMPORTS", &edges, &edge_count), 0);+ ASSERT_EQ(edge_count, 0);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NOT_NULL(names.targets);+ ASSERT_NULL(names.targets[0]);+ ASSERT_TRUE(cbm_pipeline_php_vendor_bound(&names, "Request"));+ cbm_pipeline_php_vendor_names_free(&names);++ /* A failed/unknown resolver state cannot reuse the preceding proof. */+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, r, "main.php", file_qn, file, NULL);+ cbm_pipeline_set_pkgmap(saved);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets);+ char overlong[4096];+ memset(overlong, 'X', sizeof(overlong));+ memcpy(overlong + sizeof(overlong) - 9, "\\Request", 9);+ CBMImport oversized = r->imports.items[0];+ oversized.module_path = overlong;+ CBMFileResult oversized_result = *r;+ oversized_result.imports.items = &oversized;+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, &oversized_result, "main.php", file_qn, file, ns);+ cbm_pipeline_set_pkgmap(saved);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", &oversized_result, &names);+ ASSERT_NULL(names.targets);+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, r, "main.php", file_qn, file, ns);+ cbm_pipeline_set_pkgmap(saved);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NOT_NULL(names.targets);+ cbm_pipeline_php_vendor_names_free(&names);++ CBMImport changed = r->imports.items[0];+ changed.module_path = "Different\\Http\\Request";+ CBMFileResult stale = *r;+ stale.imports.items = &changed;+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", &stale, &names);+ ASSERT_NULL(names.targets); /* old marker does not cover new extraction */+ stale.imports.count = 0;+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", &stale, &names);+ ASSERT_NULL(names.targets); /* even removal invalidates the full manifest */++ ASSERT_EQ(+ cbm_gbuf_node_set_properties_json((cbm_gbuf_node_t *)file, "{\"php_imports_complete\":1}"),+ 0);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets);+ ASSERT_EQ(cbm_gbuf_node_set_properties_json((cbm_gbuf_node_t *)file, "{invalid"), 0);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets);+ cbm_pipeline_namespace_map_free(ns);+ free(file_qn);+ cbm_gbuf_free(gb);+ cbm_free_result(r);+ PASS();+}++TEST(ei_php_binding_snapshot_groups_kinds_and_invalidates_failed_rebuild) {+ const char *source =+ "<?php\nnamespace Local;\n"+ "use Lib\\Pkg\\{Thing as Same, function render as Same, const VALUE as Same};\n"+ "class Main { function run(Same $x) { $x->go(); } }\n";+ const char *library =+ "<?php\nnamespace Lib\\Pkg;\n"+ "class Thing { function go() {} }\nfunction render() {}\nconst VALUE = 1;\n";+ CBMFileResult *r =+ cbm_extract_file(source, (int)strlen(source), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ CBMFileResult *lib = cbm_extract_file(library, (int)strlen(library), CBM_LANG_PHP, "p",+ "lib/Thing.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_NOT_NULL(lib);+ ASSERT_EQ(r->imports.count, 3);+ int class_kind = 0, function_kind = 0, const_kind = 0;+ for (int i = 0; i < r->imports.count; i++) {+ ASSERT_STR_EQ(r->imports.items[i].local_name, "Same");+ class_kind += r->imports.items[i].kind == CBM_IMPORT_KIND_DEFAULT;+ function_kind += r->imports.items[i].kind == CBM_IMPORT_KIND_FUNCTION;+ const_kind += r->imports.items[i].kind == CBM_IMPORT_KIND_CONST;+ }+ ASSERT_EQ(class_kind, 1);+ ASSERT_EQ(function_kind, 1);+ ASSERT_EQ(const_kind, 1);+ cbm_gbuf_t *gb = cbm_gbuf_new("p", "/tmp");+ ASSERT_NOT_NULL(gb);+ ASSERT_TRUE(ei_php_seed_result(gb, "p", "main.php", r));+ ASSERT_TRUE(ei_php_seed_result(gb, "p", "lib/Thing.php", lib));+ char *file_qn = cbm_pipeline_fqn_compute("p", "main.php", "__file__");+ char *target_qn = cbm_pipeline_fqn_compute("p", "lib/Thing.php", "__file__");+ ASSERT_NOT_NULL(file_qn);+ ASSERT_NOT_NULL(target_qn);+ const cbm_gbuf_node_t *file = cbm_gbuf_find_by_qn(gb, file_qn);+ ASSERT_NOT_NULL(file);+ CBMFileResult *results[] = {r, lib};+ const char *rels[] = {"main.php", "lib/Thing.php"};+ CBMHashTable *ns = cbm_pipeline_namespace_map_build("p", results, rels, 2);+ ASSERT_NOT_NULL(ns);+ cbm_pipeline_ctx_t ctx = {.project_name = "p", .gbuf = gb};+ CBMHashTable *saved = cbm_pipeline_get_pkgmap();+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, r, "main.php", file_qn, file, ns);+ cbm_pipeline_set_pkgmap(saved);+ cbm_php_vendor_names_t names = {0};+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NOT_NULL(names.targets);+ for (int i = 0; i < r->imports.count; i++)+ ASSERT_STR_EQ(names.targets[i], target_qn);+ ASSERT_TRUE(!cbm_pipeline_php_vendor_bound(&names, "Same"));+ cbm_pipeline_php_vendor_names_free(&names);+ const cbm_gbuf_edge_t **edges = NULL;+ int edge_count = -1;+ ASSERT_EQ(cbm_gbuf_find_edges_by_source_type(gb, file->id, "IMPORTS", &edges, &edge_count), 0);+ ASSERT_EQ(edge_count, 1); /* same target and alias, three represented kinds */+ ASSERT_NOT_NULL(strstr(edges[0]->properties_json, "php_import_bindings"));++ /* A copied File marker cannot certify legacy, malformed or dangling+ * IMPORTS rows. The query succeeds and returns the deliberately bad row. */+ const char *bad_properties[] = {+ "{\"local_name\":\"Same\"}",+ "{\"local_name\":\"Same\",\"php_import_bindings\":[{\"kind\":0}]}",+ edges[0]->properties_json,+ };+ for (int bad = 0; bad < 3; bad++) {+ cbm_gbuf_t *legacy = cbm_gbuf_new("p", "/tmp");+ ASSERT_NOT_NULL(legacy);+ ASSERT_TRUE(ei_php_seed_result(legacy, "p", "main.php", r));+ ASSERT_TRUE(ei_php_seed_result(legacy, "p", "lib/Thing.php", lib));+ const cbm_gbuf_node_t *legacy_file = cbm_gbuf_find_by_qn(legacy, file_qn);+ const cbm_gbuf_node_t *legacy_target = cbm_gbuf_find_by_qn(legacy, target_qn);+ ASSERT_NOT_NULL(legacy_file);+ ASSERT_NOT_NULL(legacy_target);+ ASSERT_EQ(cbm_gbuf_node_set_properties_json((cbm_gbuf_node_t *)legacy_file,+ file->properties_json),+ 0);+ cbm_gbuf_insert_edge(legacy, legacy_file->id,+ bad == 2 ? legacy_target->id + 10000 : legacy_target->id, "IMPORTS",+ bad_properties[bad]);+ const cbm_gbuf_edge_t **bad_edges = NULL;+ int bad_count = 0;+ ASSERT_EQ(cbm_gbuf_find_edges_by_source_type(legacy, legacy_file->id, "IMPORTS", &bad_edges,+ &bad_count),+ 0);+ ASSERT_EQ(bad_count, 1);+ cbm_pipeline_php_vendor_names_build(legacy, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets);+ cbm_gbuf_free(legacy);+ }++ CBMImport duplicates[] = {r->imports.items[0], r->imports.items[0]};+ CBMFileResult malformed = *r;+ malformed.imports.items = duplicates;+ malformed.imports.count = 2;+ cbm_pipeline_set_pkgmap(NULL);+ cbm_pipeline_php_create_import_edges(&ctx, &malformed, "main.php", file_qn, file, ns);+ cbm_pipeline_set_pkgmap(saved);+ ASSERT_NOT_NULL(strstr(file->properties_json, "\"php_imports_complete\":0"));+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", &malformed, &names);+ ASSERT_NULL(names.targets);+ cbm_pipeline_php_vendor_names_build(gb, "p", "main.php", r, &names);+ ASSERT_NULL(names.targets); /* failed rebuild cannot revive old proof */+ cbm_pipeline_namespace_map_free(ns);+ free(file_qn);+ free(target_qn);+ cbm_gbuf_free(gb);+ cbm_free_result(r);+ cbm_free_result(lib);+ PASS();+}++TEST(ei_php_psr4_missing_class_leaves_type_evidence_unknown) {+ EILangFile files[] = {+ {"composer.json",+ "{\"autoload\":{\"psr-4\":{\"App\\\\\":\"app/\",\"Vendor\\\\\":\"missing/\"}}}\n"},+ {"app/Svc.php", "<?php\nnamespace App;\nclass Svc { function go() {} }\n"},+ {"app/Main.php", "<?php\nnamespace App;\nuse Vendor\\Request;\nuse App\\Svc;\n"+ "class Main { function run(Request $r, Svc $s) { $s->go(); } }\n"},+ };+ CBMFileResult *r = cbm_extract_file(files[2].content, (int)strlen(files[2].content),+ CBM_LANG_PHP, "p", files[2].name, 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 2);+ int sites = 0;+ for (int i = 0; i < r->calls.count; i++) {+ const CBMCall *c = &r->calls.items[i];+ sites += c->callee_name && strstr(c->callee_name, "go") && c->enclosing_func_qn &&+ strstr(c->enclosing_func_qn, "Main.run") && c->site_end_byte > c->site_start_byte;+ }+ cbm_free_result(r);+ ASSERT_EQ(sites, 1);+ const char *covered_missing = files[0].content;+ const char *empty_prefix =+ "{\"autoload\":{\"psr-4\":{\"App\\\\\":\"app/\",\"\":\"missing/\"}}}\n";+ /* The baseline resolver also cannot certify a Composer fallback prefix. */+ for (int scenario = 0; scenario < 2; scenario++) {+ files[0].content = scenario == 0 ? covered_missing : empty_prefix;+ EILangProj lp;+ cbm_store_t *store = ei_index_files(&lp, files, 3);+ bool ok = store != NULL;+ cbm_node_t *nodes = NULL;+ int count = 0, file_count = 0;+ if (!store || cbm_store_find_nodes_by_file(store, lp.project, "app/Main.php", &nodes,+ &count) != CBM_STORE_OK) {+ ok = false;+ }+ for (int i = 0; i < count; i++) {+ if (nodes[i].label && strcmp(nodes[i].label, "File") == 0) {+ file_count++;+ ok = nodes[i].properties_json &&+ !strstr(nodes[i].properties_json, "\"php_imports_complete\":1") && ok;+ }+ }+ cbm_store_free_nodes(nodes, count);+ char target[512];+ if (store) {+ ok = ei_import_target_path(store, lp.project, "app/Main.php", "Request", target,+ sizeof(target)) == 0 &&+ ok;+ ok = ei_import_target_path(store, lp.project, "app/Main.php", "Svc", target,+ sizeof(target)) == 1 &&+ strcmp(target, "app/Svc.php") == 0 && ok;+ ok = ei_php_checked_file_edges(store, lp.project, "app/Main.php", "CALLS",+ "app/Svc.php") == 1 &&+ ok;+ }+ ei_cleanup(&lp, store);+ ASSERT_EQ(file_count, 1);+ ASSERT_TRUE(ok);+ }+ PASS();+}+/* ═══════════════════════════════════════════════════════════════════════════* SUITE registration* ═══════════════════════════════════════════════════════════════════════════ */@@ -1963,4 +2392,8 @@ SUITE(edge_imports) {RUN_TEST(ei_php_declared_functions_and_alias_issue1186);RUN_TEST(ei_php_null_namespace_map_keeps_php_candidate_issue1186);RUN_TEST(ei_php_require_path_keeps_generic_resolution_issue1186);+ RUN_TEST(ei_php_vendor_types_never_bind_by_name_issue1186);+ RUN_TEST(ei_php_binding_snapshot_requires_current_complete_evidence);+ RUN_TEST(ei_php_binding_snapshot_groups_kinds_and_invalidates_failed_rebuild);+ RUN_TEST(ei_php_psr4_missing_class_leaves_type_evidence_unknown);}diff --git a/tests/test_parallel.c b/tests/test_parallel.cindex f2eb59681..42c61dd2d 100644--- a/tests/test_parallel.c+++ b/tests/test_parallel.c@@ -17,6 +17,7 @@#include "graph_buffer/graph_buffer.h"#include "discover/discover.h"#include "foundation/platform.h"+#include "foundation/compat_fs.h"#include "foundation/log.h"#include "foundation/mem.h"#include "cbm.h"@@ -4882,7 +4883,381 @@ TEST(lsp_target_node_supports_long_prefixed_qualified_name) {/* ── Suite Registration ──────────────────────────────────────────── */+/* ── PHP vendor-imported types never bind by name (#1186) ─────────── */++/* Foo.php imports `Request` from a vendor namespace no project file declares,+ * so the import stays unresolved. The project has its own class Request+ * (another namespace) and a TypeScript function sendAsync. Every edge from+ * Foo.php that names the vendor Request -- its base class, calls on a+ * Request-typed receiver, the `new`, the type references -- used to bind by+ * name to those project symbols. Svc is imported from a declared project+ * namespace and is the control that must keep resolving. */+static const struct {+ const char *rel;+ CBMLanguage lang;+ const char *src;+} k_php_vendor_files[] = {+ {"lib/Requests/Request.php", CBM_LANG_PHP,+ "<?php\nnamespace App\\Http\\Requests;\n\nclass Request {\n"+ " public function validated() { return 1; }\n"+ " public static function makeIt() { return 2; }\n"+ " public function get($k) { return $k; }\n}\n"},+ {"lib/Services/Svc.php", CBM_LANG_PHP,+ "<?php\nnamespace App\\Services;\n\nclass Svc {\n"+ " public function go() { return 3; }\n"+ " public static function build() { return 4; }\n}\n"},+ {"web/api.ts", CBM_LANG_TYPESCRIPT, "export function sendAsync(x: number) { return x; }\n"},+ {"lib/Integrations/Foo.php", CBM_LANG_PHP,+ "<?php\nnamespace App\\Http\\Integrations;\n\n"+ "use Saloon\\Http\\Request;\nuse App\\Services\\Svc;\n\n"+ "class Foo extends Request {\n"+ " public function run(Request $r, Svc $s) {\n"+ " $r->validated();\n"+ " Request::makeIt();\n"+ " $made = new Request();\n"+ " $s->go();\n"+ " Svc::build();\n"+ " $r->get('id');\n"+ " return $r->sendAsync(1);\n"+ " }\n}\n\n"+ "class Bar extends Svc {\n}\n"},+ {"lib/Integrations/Clients.php", CBM_LANG_PHP,+ "<?php\nnamespace App\\Http\\Integrations;\n"+ "use GuzzleHttp\\Client as GuzzleClient;\nuse Kafka\\Producer as KafkaProducer;\n"+ "class Clients { function run() {\n"+ " GuzzleClient::get('/api/vendor-health');\n"+ " KafkaProducer::publish('vendor-orders', 'payload');\n}\n}\n"},+};+enum { PHP_VENDOR_FILE_COUNT = (int)(sizeof(k_php_vendor_files) / sizeof(k_php_vendor_files[0])) };++typedef struct {+ const cbm_gbuf_t *gbuf;+ const char *type;+ const char *src_rel;+ const char *tgt_rel;+ int count;+ int source_nodes;+ bool query_failed;+} php_file_edge_count_t;++static void php_count_source_edges(const cbm_gbuf_node_t *source, void *ud) {+ php_file_edge_count_t *c = ud;+ if (!source->file_path || strcmp(source->file_path, c->src_rel) != 0)+ return;+ c->source_nodes++;+ const cbm_gbuf_edge_t **edges = NULL;+ int count = 0;+ if (cbm_gbuf_find_edges_by_source_type(c->gbuf, source->id, c->type, &edges, &count) != 0) {+ c->query_failed = true;+ return;+ }+ for (int i = 0; i < count; i++) {+ const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(c->gbuf, edges[i]->target_id);+ if (!target) {+ c->query_failed = true;+ } else if (target->file_path && strcmp(target->file_path, c->tgt_rel) == 0) {+ c->count++;+ }+ }+}++static int php_file_edges(const cbm_gbuf_t *gbuf, const char *type, const char *source,+ const char *target) {+ char *source_qn = cbm_pipeline_fqn_compute("cbm_par_phpvendor", source, "__file__");+ char *target_qn = cbm_pipeline_fqn_compute("cbm_par_phpvendor", target, "__file__");+ const cbm_gbuf_node_t *s = source_qn ? cbm_gbuf_find_by_qn(gbuf, source_qn) : NULL;+ const cbm_gbuf_node_t *t = target_qn ? cbm_gbuf_find_by_qn(gbuf, target_qn) : NULL;+ bool files_exist = s && t && s->label && t->label && strcmp(s->label, "File") == 0 &&+ strcmp(t->label, "File") == 0;+ free(source_qn);+ free(target_qn);+ if (!files_exist)+ return -1;+ php_file_edge_count_t c = {.gbuf = gbuf, .type = type, .src_rel = source, .tgt_rel = target};+ cbm_gbuf_foreach_node(gbuf, php_count_source_edges, &c);+ return c.query_failed || c.source_nodes == 0 ? -1 : c.count;+}++static bool php_vendor_extracted_sites(void) {+ for (int file = 3; file < PHP_VENDOR_FILE_COUNT; file++) {+ const char *source = k_php_vendor_files[file].src;+ CBMFileResult *r =+ cbm_extract_file(source, (int)strlen(source), CBM_LANG_PHP, "cbm_par_phpvendor",+ k_php_vendor_files[file].rel, 0, NULL, NULL);+ if (!r)+ return false;+ bool ok = r->defs.count > 0 && r->imports.count == 2;+ const char *core[] = {"validated", "makeIt", "go", "build", "get", "sendAsync"};+ const char *service[] = {"get", "publish"};+ const char *const *wanted = file == 3 ? core : service;+ int wanted_count = file == 3 ? 6 : 2;+ for (int i = 0; i < wanted_count; i++) {+ int count = 0;+ for (int j = 0; j < r->calls.count; j++) {+ const CBMCall *c = &r->calls.items[j];+ if (!c->callee_name || !c->enclosing_func_qn ||+ strcmp(cbm_pipeline_call_callee_leaf(c->callee_name), wanted[i]) != 0 ||+ c->site_end_byte <= c->site_start_byte || c->site_end_byte > strlen(source))+ continue;+ if (file == 4) {+ const char *arg = i == 0 ? "/api/vendor-health" : "vendor-orders";+ const char *alias = i == 0 ? "GuzzleClient" : "KafkaProducer";+ if (!c->first_string_arg || strcmp(c->first_string_arg, arg) != 0 ||+ !strstr(c->callee_name, alias))+ continue;+ }+ count++;+ }+ ok = count == 1 && ok;+ }+ cbm_free_result(r);+ if (!ok)+ return false;+ }+ return true;+}++static bool php_vendor_service_edge(const cbm_gbuf_t *gb, const char *type, const char *name) {+ const cbm_gbuf_node_t *source = find_unique_callable_node_by_tail(gb, "Clients.run");+ if (!source)+ return false;+ const cbm_gbuf_edge_t **edges = NULL;+ int count = 0;+ if (cbm_gbuf_find_edges_by_source_type(gb, source->id, type, &edges, &count) != 0 || count != 1)+ return false;+ const cbm_gbuf_node_t *target = cbm_gbuf_find_by_id(gb, edges[0]->target_id);+ return target && target->label && strcmp(target->label, "Route") == 0 &&+ edges[0]->properties_json && strstr(edges[0]->properties_json, name);+}++static void php_vendor_edge_fp(const cbm_gbuf_edge_t *edge, void *ud) {+ if (strcmp(edge->type, "CALLS") == 0 || strcmp(edge->type, "USAGE") == 0 ||+ strcmp(edge->type, "INHERITS") == 0 || strcmp(edge->type, "IMPORTS") == 0 ||+ strcmp(edge->type, "HTTP_CALLS") == 0 || strcmp(edge->type, "ASYNC_CALLS") == 0)+ fp_visit_edge(edge, ud);+}++/* 1 when the graph holds no vendor-named edge and every control edge. */+static int php_vendor_graph_ok(const cbm_gbuf_t *gbuf, const char *driver) {+ static const char *const foo = "lib/Integrations/Foo.php";+ static const char *const req = "lib/Requests/Request.php";+ static const char *const svc = "lib/Services/Svc.php";+ struct {+ const char *type;+ const char *tgt;+ int want_min;+ int want_max;+ } checks[] = {+ {"INHERITS", req, 0, 0}, {"CALLS", req, 0, 0}, {"USAGE", req, 0, 0},+ {"CALLS", "web/api.ts", 0, 0}, {"INHERITS", svc, 1, 1}, {"CALLS", svc, 2, 2},+ {"CALLS", foo, 0, 0}, {"USAGE", svc, 1, 1 << 20},+ };+ int ok = 1;+ for (size_t i = 0; i < sizeof(checks) / sizeof(checks[0]); i++) {+ int got = php_file_edges(gbuf, checks[i].type, foo, checks[i].tgt);+ if (got < checks[i].want_min || got > checks[i].want_max) {+ printf(" [%s] %s Foo.php -> %s: got %d, want %d..%d\n", driver, checks[i].type,+ checks[i].tgt, got, checks[i].want_min, checks[i].want_max);+ ok = 0;+ }+ }+ return ok && php_vendor_service_edge(gbuf, "HTTP_CALLS", "/api/vendor-health") &&+ php_vendor_service_edge(gbuf, "ASYNC_CALLS", "vendor-orders");+}++TEST(parallel_php_vendor_types_never_bind_by_name_issue1186) {+ ASSERT_TRUE(php_vendor_extracted_sites());+ char tmpdir[256];+ snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_par_phpvendor_XXXXXX");+ if (!cbm_mkdtemp(tmpdir)) {+ FAIL("mkdtemp failed");+ }+ char paths[PHP_VENDOR_FILE_COUNT][512];+ cbm_file_info_t files[PHP_VENDOR_FILE_COUNT];+ memset(files, 0, sizeof(files));+ for (int i = 0; i < PHP_VENDOR_FILE_COUNT; i++) {+ snprintf(paths[i], sizeof(paths[i]), "%s/%s", tmpdir, k_php_vendor_files[i].rel);+ char dir[512];+ snprintf(dir, sizeof(dir), "%s", paths[i]);+ *strrchr(dir, '/') = '\0';+ cbm_mkdir_p(dir, 0755);+ FILE *f = fopen(paths[i], "w");+ if (!f) {+ th_rmtree(tmpdir);+ FAIL("fopen failed");+ }+ bool wrote = fputs(k_php_vendor_files[i].src, f) >= 0;+ bool closed = fclose(f) == 0;+ if (!wrote || !closed) {+ th_rmtree(tmpdir);+ FAIL("fixture write failed");+ }+ files[i].path = paths[i];+ files[i].rel_path = (char *)k_php_vendor_files[i].rel;+ files[i].language = k_php_vendor_files[i].lang;+ }++ cbm_gbuf_t *seq = run_sequential_with_lsp_cross_and_mutator(+ "cbm_par_phpvendor", tmpdir, files, PHP_VENDOR_FILE_COUNT, NULL, NULL, true);+ cbm_gbuf_t *par = run_parallel_with_extract_opts_and_mutator(+ "cbm_par_phpvendor", tmpdir, files, PHP_VENDOR_FILE_COUNT, 2, NULL, NULL, NULL, true);+ const size_t saved_budget = cbm_mem_budget();+ const size_t budget = (size_t)1024 * 1024 * 1024;+ cbm_mem_set_budget_for_tests(budget);+ cbm_mem_set_charged_for_tests(budget - budget / 16);+ g_harness_spill = true;+ int cached = -1;+ cbm_gbuf_t *spilled = run_parallel_with_extract_opts_and_mutator(+ "cbm_par_phpvendor", tmpdir, files, PHP_VENDOR_FILE_COUNT, 2, NULL, count_cached_results,+ &cached, true);+ int64_t parked = g_harness_parked;+ g_harness_spill = false;+ cbm_mem_set_charged_for_tests(0);+ cbm_mem_set_budget_for_tests(saved_budget);+ int seq_ok = seq ? php_vendor_graph_ok(seq, "sequential") : 0;+ int par_ok = par ? php_vendor_graph_ok(par, "parallel") : 0;+ int spill_ok = spilled ? php_vendor_graph_ok(spilled, "spilled") : 0;+ graph_fp_t seq_edges = {.gb = seq}, par_edges = {.gb = par};+ graph_fp_t par_all = {0}, spill_all = {0};+ if (seq)+ cbm_gbuf_foreach_edge(seq, php_vendor_edge_fp, &seq_edges);+ if (par) {+ cbm_gbuf_foreach_edge(par, php_vendor_edge_fp, &par_edges);+ par_all = graph_fingerprint(par);+ }+ if (spilled)+ spill_all = graph_fingerprint(spilled);+ bool edge_parity = seq_edges.count > 0 && seq_edges.count == par_edges.count &&+ seq_edges.sum == par_edges.sum && seq_edges.xr == par_edges.xr;+ bool spill_parity = par_all.count > 0 && par_all.count == spill_all.count &&+ par_all.sum == spill_all.sum && par_all.xr == spill_all.xr;+ cbm_gbuf_free(seq);+ cbm_gbuf_free(par);+ cbm_gbuf_free(spilled);+ th_rmtree(tmpdir);+ ASSERT_EQ(cached, 0);+ ASSERT_EQ((int)parked, PHP_VENDOR_FILE_COUNT);+ ASSERT_TRUE(seq_ok);+ ASSERT_TRUE(par_ok);+ ASSERT_TRUE(spill_ok);+ ASSERT_TRUE(edge_parity);+ ASSERT_TRUE(spill_parity);+ PASS();+}++/* A fresh PHP external row replaces stale evidence for its exact occurrence,+ * including an older external row, without clearing a real project invocation+ * of the same method at the next occurrence. Test both old-row orders. */+TEST(parallel_php_external_row_replaces_only_its_exact_occurrence) {+ const char *source = "<?php\nnamespace App;\nuse Vendor\\Http\\Request;\n"+ "use App\\Project\\Request as LocalRequest;\n"+ "class Caller { function run(Request $r, LocalRequest $p) {\n"+ " $r->validated();\n $p->validated();\n}\n}\n";+ const char *project_type = "p.lib.Request.Request";+ CBMLSPDef defs[] = {+ {.qualified_name = project_type,+ .short_name = "Request",+ .label = "Class",+ .def_module_qn = "p.lib.Request",+ .lang = CBM_LANG_PHP},+ {.qualified_name = "p.lib.Request.Request.validated",+ .short_name = "validated",+ .label = "Method",+ .receiver_type = project_type,+ .def_module_qn = "p.lib.Request",+ .lang = CBM_LANG_PHP},+ };+ for (int order = 0; order < 2; order++) {+ CBMFileResult *r = cbm_extract_file(source, (int)strlen(source), CBM_LANG_PHP, "p",+ "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 2);+ const CBMCall *sites[2] = {0};+ int count = 0;+ for (int i = 0; i < r->calls.count; i++) {+ const CBMCall *call = &r->calls.items[i];+ if (call->enclosing_func_qn && strstr(call->enclosing_func_qn, "Caller.run") &&+ call->callee_name &&+ strcmp(cbm_pipeline_call_callee_leaf(call->callee_name), "validated") == 0 &&+ call->site_end_byte > call->site_start_byte) {+ ASSERT_TRUE(count < 2);+ sites[count++] = call;+ }+ }+ ASSERT_EQ(count, 2);+ if (sites[0]->site_start_byte > sites[1]->site_start_byte) {+ const CBMCall *swap = sites[0];+ sites[0] = sites[1];+ sites[1] = swap;+ }+ ASSERT_TRUE(sites[0]->site_end_byte <= sites[1]->site_start_byte);+ CBMResolvedCall stale = {0};+ stale.caller_qn = sites[0]->enclosing_func_qn;+ stale.callee_qn = "p.lib.Request.Request.validated";+ stale.strategy = "test_stale_project";+ stale.confidence = 0.99f;+ stale.kind = CBM_RESOLVED_INVOCATION;+ stale.site_start_byte = sites[0]->site_start_byte;+ stale.site_end_byte = sites[0]->site_end_byte;+ stale.source_origin = sites[0]->source_origin;+ CBMResolvedCall old_external = stale;+ old_external.callee_qn = "Old.Vendor.Request.validated";+ old_external.strategy = "php_external_receiver";+ CBMResolvedCall separate = stale;+ separate.strategy = "test_separate_project";+ separate.site_start_byte = sites[1]->site_start_byte;+ separate.site_end_byte = sites[1]->site_end_byte;+ separate.source_origin = sites[1]->source_origin;+ r->resolved_calls.count = 0;+ cbm_resolvedcall_push(&r->resolved_calls, &r->arena, order ? old_external : stale);+ cbm_resolvedcall_push(&r->resolved_calls, &r->arena, order ? stale : old_external);+ cbm_resolvedcall_push(&r->resolved_calls, &r->arena, separate);+ const char *targets[2] = {0};+ for (int i = 0; i < r->imports.count; i++)+ if (strcmp(r->imports.items[i].local_name, "LocalRequest") == 0)+ targets[i] = "p.lib.Request.__file__";+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ const char *keys[] = {"LocalRequest"};+ const char *vals[] = {project_type};+ cbm_pxc_run_one_with_php_bindings(CBM_LANG_PHP, r, source, (int)strlen(source), "p.main",+ defs, 2, keys, vals, 1, &bindings);+ int external_count = 0, project_count = 0;+ for (int i = 0; i < r->resolved_calls.count; i++) {+ const CBMResolvedCall *row = &r->resolved_calls.items[i];+ if (!row->caller_qn || strcmp(row->caller_qn, sites[0]->enclosing_func_qn) != 0 ||+ row->kind != CBM_RESOLVED_INVOCATION)+ continue;+ if (row->site_start_byte == sites[0]->site_start_byte &&+ row->site_end_byte == sites[0]->site_end_byte &&+ row->source_origin == sites[0]->source_origin) {+ ASSERT_STR_EQ(row->callee_qn, "Vendor.Http.Request.validated");+ ASSERT_STR_EQ(row->strategy, "php_external_receiver");+ external_count++;+ } else if (row->site_start_byte == sites[1]->site_start_byte &&+ row->site_end_byte == sites[1]->site_end_byte &&+ row->source_origin == sites[1]->source_origin) {+ ASSERT_STR_EQ(row->callee_qn, "p.lib.Request.Request.validated");+ project_count++;+ }+ }+ ASSERT_EQ(external_count, 1);+ ASSERT_EQ(project_count, 1);+ const CBMResolvedCall *vendor =+ cbm_pipeline_find_lsp_resolution(&r->resolved_calls, sites[0], false);+ const CBMResolvedCall *project =+ cbm_pipeline_find_lsp_resolution(&r->resolved_calls, sites[1], false);+ ASSERT_NOT_NULL(vendor);+ ASSERT_NOT_NULL(project);+ ASSERT_STR_EQ(vendor->strategy, "php_external_receiver");+ ASSERT_STR_EQ(project->callee_qn, "p.lib.Request.Request.validated");+ cbm_free_result(r);+ }+ PASS();+}+SUITE(parallel) {+ RUN_TEST(parallel_php_external_row_replaces_only_its_exact_occurrence);+ RUN_TEST(parallel_php_vendor_types_never_bind_by_name_issue1186);RUN_TEST(usage_semantic_reference_candidate_trusts_marked_producer);RUN_TEST(lsp_bare_segment_skips_preprocessor_spacing);RUN_TEST(lsp_resolve_qualified_static_call_normalizes_colons);diff --git a/tests/test_php_lsp.c b/tests/test_php_lsp.cindex 906bababc..354d96c75 100644--- a/tests/test_php_lsp.c+++ b/tests/test_php_lsp.c@@ -5310,7 +5310,339 @@ TEST(phplsp_ordinary_same_leaf_calls_join_by_exact_site) {/* ── Suite ─────────────────────────────────────────────────────── */+/* Typed import evidence is separate from the legacy flattened import map.+ * All negative checks below first require a real extracted invocation site. */+#define PHP_VENDOR_REQ "p.lib.Request.Request"+#define PHP_PROJECT_SVC "p.lib.Svc.Svc"+#define PHP_TEST_CLASS(q, n, m, l) \+ {.qualified_name = q, .short_name = n, .label = l, .def_module_qn = m, .lang = CBM_LANG_PHP}+#define PHP_TEST_METHOD(q, n, r, m) \+ {.qualified_name = q, \+ .short_name = n, \+ .label = "Method", \+ .receiver_type = r, \+ .def_module_qn = m, \+ .lang = CBM_LANG_PHP}+static CBMLSPDef php_vendor_test_defs[] = {+ PHP_TEST_CLASS(PHP_VENDOR_REQ, "Request", "p.lib.Request", "Class"),+ PHP_TEST_METHOD(PHP_VENDOR_REQ ".validated", "validated", PHP_VENDOR_REQ, "p.lib.Request"),+ PHP_TEST_METHOD(PHP_VENDOR_REQ ".makeIt", "makeIt", PHP_VENDOR_REQ, "p.lib.Request"),+ PHP_TEST_CLASS(PHP_PROJECT_SVC, "Svc", "p.lib.Svc", "Class"),+ PHP_TEST_METHOD(PHP_PROJECT_SVC ".go", "go", PHP_PROJECT_SVC, "p.lib.Svc"),+ PHP_TEST_CLASS("p.main.Holder", "Holder", "p.main", "Class"),+ PHP_TEST_METHOD("p.main.Holder.declaredRequest", "declaredRequest", "p.main.Holder", "p.main"),+ PHP_TEST_METHOD("p.main.Holder.documentedRequest", "documentedRequest", "p.main.Holder",+ "p.main"),+ PHP_TEST_CLASS("p.lib.Behavior.Behavior", "Behavior", "p.lib.Behavior", "Trait"),+ PHP_TEST_METHOD("p.lib.Behavior.Behavior.traitTap", "traitTap", "p.lib.Behavior.Behavior",+ "p.lib.Behavior"),+ PHP_TEST_CLASS("p.lib.Helpers.render", "render", "p.lib.Helpers", "Function"),+};+#undef PHP_TEST_CLASS+#undef PHP_TEST_METHOD++static const CBMCall *php_vendor_site(const CBMFileResult *r, const char *caller,+ const char *leaf) {+ const CBMCall *found = NULL;+ for (int i = 0; r && i < r->calls.count; i++) {+ const CBMCall *c = &r->calls.items[i];+ if (c->enclosing_func_qn && strstr(c->enclosing_func_qn, caller) && c->callee_name &&+ strcmp(cbm_pipeline_call_callee_leaf(c->callee_name), leaf) == 0 &&+ c->site_end_byte > c->site_start_byte) {+ if (found)+ return NULL;+ found = c;+ }+ }+ return found;+}++static const CBMResolvedCall *php_vendor_row(const CBMResolvedCallArray *out, const CBMCall *site,+ const char *callee) {+ const CBMResolvedCall *found = NULL;+ for (int i = 0; site && i < out->count; i++) {+ const CBMResolvedCall *row = &out->items[i];+ if (row->kind == CBM_RESOLVED_INVOCATION && row->caller_qn && row->callee_qn &&+ strcmp(row->caller_qn, site->enclosing_func_qn) == 0 &&+ row->site_start_byte == site->site_start_byte &&+ row->site_end_byte == site->site_end_byte && strcmp(row->callee_qn, callee) == 0) {+ found = row;+ }+ }+ return found;+}++static int php_vendor_project_request_rows(const CBMResolvedCallArray *out) {+ int count = 0;+ for (int i = 0; i < out->count; i++) {+ const char *qn = out->items[i].callee_qn;+ count += qn && strncmp(qn, PHP_VENDOR_REQ ".", strlen(PHP_VENDOR_REQ) + 1) == 0;+ }+ return count;+}++static void php_vendor_cross(CBMArena *arena, const char *src, CBMResolvedCallArray *out,+ const CBMPHPImportBindings *bindings) {+ const char *names[] = {"Svc"};+ const char *qns[] = {PHP_PROJECT_SVC};+ cbm_run_php_lsp_cross_with_bindings(+ arena, src, (int)strlen(src), "p.main", php_vendor_test_defs,+ (int)(sizeof(php_vendor_test_defs) / sizeof(php_vendor_test_defs[0])), names, qns, 1, NULL,+ out, bindings);+}++TEST(phplsp_vendor_complete_empty_is_distinct_from_unknown) {+ const char *src = "<?php\nnamespace App;\nuse Vendor\\Http\\Request;\n"+ "class Holder { function run(Request $r) { $r->validated(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 1);+ const CBMCall *site = php_vendor_site(r, "Holder.run", "validated");+ ASSERT_NOT_NULL(site);+ const char *targets[] = {NULL};+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ php_vendor_cross(&arena, src, &out, &bindings);+ const CBMResolvedCall *external = php_vendor_row(&out, site, "Vendor.Http.Request.validated");+ ASSERT_NOT_NULL(external);+ ASSERT_STR_EQ(external->strategy, "php_external_receiver");+ ASSERT_TRUE(external->confidence >= CBM_LSP_CONFIDENCE_FLOOR);+ ASSERT_EQ(php_vendor_project_request_rows(&out), 0);+ cbm_arena_destroy(&arena);++ /* Missing/legacy typed evidence must not manufacture an external marker.+ * Retaining this old fallback is a bounded compatibility rule, not proof+ * that the old guessed target describes the vendor class. */+ for (int mode = 0; mode < 3; mode++) {+ cbm_arena_init(&arena);+ memset(&out, 0, sizeof(out));+ bindings.targets = NULL;+ if (mode == 2) {+ cbm_run_php_lsp_cross(+ &arena, src, (int)strlen(src), "p.main", php_vendor_test_defs,+ (int)(sizeof(php_vendor_test_defs) / sizeof(php_vendor_test_defs[0])), NULL, NULL,+ 0, NULL, &out);+ } else {+ php_vendor_cross(&arena, src, &out, mode == 0 ? NULL : &bindings);+ }+ ASSERT_NOT_NULL(php_vendor_row(&out, site, PHP_VENDOR_REQ ".validated"));+ ASSERT_NULL(php_vendor_row(&out, site, "Vendor.Http.Request.validated"));+ cbm_arena_destroy(&arena);+ }+ cbm_free_result(r);+ PASS();+}++TEST(phplsp_vendor_kinds_do_not_erase_external_class_evidence) {+ const char *src =+ "<?php\nnamespace App;\n"+ "use Vendor\\Http\\{Request as Same};\n"+ "use Lib\\Helpers\\{function render as Same, const VALUE as Same};\n"+ "use App\\Services\\Svc;\n"+ "class Holder { function run(Same $r, Svc $s) { $r->validated(); $s->go(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 4);+ const char *targets[4] = {0};+ int classes = 0, functions = 0, constants = 0;+ for (int i = 0; i < r->imports.count; i++) {+ const CBMImport *imp = &r->imports.items[i];+ if (strcmp(imp->local_name, "Same") == 0) {+ classes += imp->kind == CBM_IMPORT_KIND_DEFAULT;+ functions += imp->kind == CBM_IMPORT_KIND_FUNCTION;+ constants += imp->kind == CBM_IMPORT_KIND_CONST;+ if (imp->kind != CBM_IMPORT_KIND_DEFAULT)+ targets[i] = "p.lib.Helpers.__file__";+ } else {+ ASSERT_STR_EQ(imp->local_name, "Svc");+ targets[i] = "p.lib.Svc.__file__";+ }+ }+ ASSERT_EQ(classes, 1);+ ASSERT_EQ(functions, 1);+ ASSERT_EQ(constants, 1);+ const CBMCall *vendor_site = php_vendor_site(r, "Holder.run", "validated");+ const CBMCall *project_site = php_vendor_site(r, "Holder.run", "go");+ ASSERT_NOT_NULL(vendor_site);+ ASSERT_NOT_NULL(project_site);+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ php_vendor_cross(&arena, src, &out, &bindings);+ const CBMResolvedCall *vendor =+ php_vendor_row(&out, vendor_site, "Vendor.Http.Request.validated");+ ASSERT_NOT_NULL(vendor);+ ASSERT_STR_EQ(vendor->strategy, "php_external_receiver");+ ASSERT_NOT_NULL(php_vendor_row(&out, project_site, PHP_PROJECT_SVC ".go"));+ ASSERT_EQ(php_vendor_project_request_rows(&out), 0);+ cbm_arena_destroy(&arena);+ cbm_free_result(r);+ PASS();+}++TEST(phplsp_vendor_classification_precedes_field_and_return_refinement) {+ const char *src = "<?php\nnamespace App;\nuse Vendor\\Http\\Request;\nuse App\\Services\\Svc;\n"+ "/** @property Request $documented */\n"+ "class Holder {\n"+ " public Request $typed;\n"+ " function __construct(public Request $promoted) {}\n"+ " function declaredRequest(): Request { return $this->typed; }\n"+ " /** @return Request */\n"+ " function documentedRequest() { return $this->typed; }\n"+ " function field() { return $this->typed->validated(); }\n"+ " function promotion() { return $this->promoted->validated(); }\n"+ " function declared() { return $this->declaredRequest()->validated(); }\n"+ " function docReturn() { return $this->documentedRequest()->validated(); }\n"+ " function docProperty() { return $this->documented->validated(); }\n"+ " function control(Svc $s) { return $s->go(); }\n}\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 2);+ const char *targets[2] = {0};+ for (int i = 0; i < r->imports.count; i++)+ if (strcmp(r->imports.items[i].local_name, "Svc") == 0)+ targets[i] = "p.lib.Svc.__file__";+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ php_vendor_cross(&arena, src, &out, &bindings);+ const char *callers[] = {"Holder.field", "Holder.promotion", "Holder.declared",+ "Holder.docReturn", "Holder.docProperty"};+ for (size_t i = 0; i < sizeof(callers) / sizeof(callers[0]); i++) {+ const CBMCall *site = php_vendor_site(r, callers[i], "validated");+ ASSERT_NOT_NULL(site);+ const CBMResolvedCall *row = php_vendor_row(&out, site, "Vendor.Http.Request.validated");+ ASSERT_NOT_NULL(row);+ ASSERT_STR_EQ(row->strategy, "php_external_receiver");+ ASSERT_TRUE(row->confidence >= CBM_LSP_CONFIDENCE_FLOOR);+ }+ const CBMCall *control = php_vendor_site(r, "Holder.control", "go");+ ASSERT_NOT_NULL(control);+ ASSERT_NOT_NULL(php_vendor_row(&out, control, PHP_PROJECT_SVC ".go"));+ ASSERT_EQ(php_vendor_project_request_rows(&out), 0);+ cbm_arena_destroy(&arena);+ cbm_free_result(r);+ PASS();+}++TEST(phplsp_vendor_trait_does_not_copy_project_trait_methods) {+ const char *src = "<?php\nnamespace App;\nuse Vendor\\Behavior;\nuse App\\Services\\Svc;\n"+ "class Holder { use Behavior;\n"+ " function run(Svc $s) { $this->traitTap(); $s->go(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 2);+ const CBMCall *site = php_vendor_site(r, "Holder.run", "traitTap");+ const CBMCall *control = php_vendor_site(r, "Holder.run", "go");+ ASSERT_NOT_NULL(site);+ ASSERT_NOT_NULL(control);+ const char *targets[2] = {0};+ for (int i = 0; i < r->imports.count; i++)+ if (strcmp(r->imports.items[i].local_name, "Svc") == 0)+ targets[i] = "p.lib.Svc.__file__";+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ php_vendor_cross(&arena, src, &out, &bindings);+ ASSERT_NULL(php_vendor_row(&out, site, "p.lib.Behavior.Behavior.traitTap"));+ const CBMResolvedCall *copied = php_vendor_row(&out, site, "p.main.Holder.traitTap");+ ASSERT_TRUE(!copied || !copied->strategy || strcmp(copied->strategy, "php_method_typed") != 0);+ ASSERT_NOT_NULL(php_vendor_row(&out, control, PHP_PROJECT_SVC ".go"));+ cbm_arena_destroy(&arena);+ cbm_free_result(r);+ PASS();+}++TEST(phplsp_vendor_function_and_const_do_not_veto_project_class_alias) {+ const char *src =+ "<?php\nnamespace App;\nuse App\\Project\\Request as Same;\n"+ "use Vendor\\Helpers\\{function render as Same, const VALUE as Same};\n"+ "class Holder { function run(Same $r) { $r->validated(); Same::makeIt(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 3);+ const char *targets[3] = {0};+ int class_bindings = 0, other_bindings = 0;+ for (int i = 0; i < r->imports.count; i++) {+ ASSERT_STR_EQ(r->imports.items[i].local_name, "Same");+ if (r->imports.items[i].kind == CBM_IMPORT_KIND_DEFAULT) {+ targets[i] = "p.lib.Request.__file__";+ class_bindings++;+ } else {+ other_bindings++;+ }+ }+ ASSERT_EQ(class_bindings, 1);+ ASSERT_EQ(other_bindings, 2);+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ php_vendor_cross(&arena, src, &out, &bindings);+ const char *methods[] = {"validated", "makeIt"};+ const char *qns[] = {PHP_VENDOR_REQ ".validated", PHP_VENDOR_REQ ".makeIt"};+ for (int i = 0; i < 2; i++) {+ const CBMCall *site = php_vendor_site(r, "Holder.run", methods[i]);+ ASSERT_NOT_NULL(site);+ const CBMResolvedCall *row = php_vendor_row(&out, site, qns[i]);+ ASSERT_NOT_NULL(row);+ ASSERT_TRUE(row->strategy && strcmp(row->strategy, "php_external_receiver") != 0);+ ASSERT_TRUE(row->confidence >= CBM_LSP_CONFIDENCE_FLOOR);+ }+ ASSERT_EQ(php_vendor_project_request_rows(&out), 2);+ cbm_arena_destroy(&arena);+ cbm_free_result(r);+ PASS();+}++TEST(phplsp_project_function_binding_keeps_its_exact_target) {+ const char *src = "<?php\nnamespace App;\nuse function Lib\\Helpers\\render as fmt;\n"+ "class Holder { function run() { fmt(); } }\n";+ CBMFileResult *r =+ cbm_extract_file(src, (int)strlen(src), CBM_LANG_PHP, "p", "main.php", 0, NULL, NULL);+ ASSERT_NOT_NULL(r);+ ASSERT_EQ(r->imports.count, 1);+ ASSERT_EQ(r->imports.items[0].kind, CBM_IMPORT_KIND_FUNCTION);+ const CBMCall *site = php_vendor_site(r, "Holder.run", "fmt");+ ASSERT_NOT_NULL(site);+ const char *targets[] = {"p.lib.Helpers.__file__"};+ CBMPHPImportBindings bindings = {.imports = &r->imports, .targets = targets};+ const char *keys[] = {"fmt"};+ const char *vals[] = {"p.lib.Helpers.render"};+ CBMArena arena;+ cbm_arena_init(&arena);+ CBMResolvedCallArray out = {0};+ cbm_run_php_lsp_cross_with_bindings(+ &arena, src, (int)strlen(src), "p.main", php_vendor_test_defs,+ (int)(sizeof(php_vendor_test_defs) / sizeof(php_vendor_test_defs[0])), keys, vals, 1, NULL,+ &out, &bindings);+ const CBMResolvedCall *row = php_vendor_row(&out, site, "p.lib.Helpers.render");+ ASSERT_NOT_NULL(row);+ ASSERT_TRUE(row->confidence >= CBM_LSP_CONFIDENCE_FLOOR);+ ASSERT_TRUE(row->strategy && strcmp(row->strategy, "php_external_receiver") != 0);+ cbm_arena_destroy(&arena);+ cbm_free_result(r);+ PASS();+}+SUITE(php_lsp) {+ RUN_TEST(phplsp_project_function_binding_keeps_its_exact_target);+ RUN_TEST(phplsp_vendor_function_and_const_do_not_veto_project_class_alias);+ RUN_TEST(phplsp_vendor_complete_empty_is_distinct_from_unknown);+ RUN_TEST(phplsp_vendor_kinds_do_not_erase_external_class_evidence);+ RUN_TEST(phplsp_vendor_classification_precedes_field_and_return_refinement);+ RUN_TEST(phplsp_vendor_trait_does_not_copy_project_trait_methods);+/* Phase 1 baseline regressions */RUN_TEST(phplsp_local_method_via_new_assignment);RUN_TEST(phplsp_local_method_via_typed_param);