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(kustomize): discover `Kustomization` and resolve entries as paths only
Martin Vogel5fe57ea321de
diff --git a/src/discover/language.c b/src/discover/language.cindex b1cd7d938..f7fff9544 100644--- a/src/discover/language.c+++ b/src/discover/language.c@@ -720,6 +720,7 @@ static const filename_entry_t FILENAME_TABLE[] = {{"meson_options.txt", CBM_LANG_MESON},{"kustomization.yaml", CBM_LANG_KUSTOMIZE},{"kustomization.yml", CBM_LANG_KUSTOMIZE},+ {"Kustomization", CBM_LANG_KUSTOMIZE}, /* kustomize's extensionless name *//* Note: FILENAME_TABLE uses case-sensitive strcmp, so mixed-case variants* (e.g. "Kustomization.yaml") are not matched here. They fall through to* CBM_LANG_YAML and are re-classified by cbm_is_kustomize_file() indiff --git a/src/pipeline/pass_pkgmap.c b/src/pipeline/pass_pkgmap.cindex f12dd8d4e..a2014c5d3 100644--- a/src/pipeline/pass_pkgmap.c+++ b/src/pipeline/pass_pkgmap.c@@ -2213,6 +2213,63 @@ cbm_psr4_member_t cbm_pipeline_psr4_member_qn(const cbm_gbuf_t *gbuf, const charreturn *out_qn ? CBM_PSR4_MEMBER_RESOLVED : CBM_PSR4_MEMBER_UNRESOLVED;}+/* A kustomization entry naming a remote base -- a URL, a go-getter host path,+ * an ssh remote or a `?ref=` pin -- lies outside the repository. */+static bool kustomize_remote_entry(const char *entry) {+ static const char *const hosts[] = {"github.com/", "gitlab.com/", "bitbucket.org/", "git@",+ NULL};+ if (strstr(entry, "://") || strstr(entry, "?ref=") || strstr(entry, ".git/")) {+ return true;+ }+ for (int i = 0; hosts[i]; i++) {+ if (strncmp(entry, hosts[i], strlen(hosts[i])) == 0) {+ return true;+ }+ }+ return false;+}++static bool kustomize_file_label(const char *label) {+ return label && (strcmp(label, "Module") == 0 || strcmp(label, "File") == 0);+}++/* A kustomization entry is a path relative to the kustomization's own+ * directory -- a manifest file or a directory -- or a remote base; it never+ * names a symbol. Resolve it exactly or not at all: the name-guess strategies+ * bound a remote base's URL segment `deploy` to a shell function, component+ * paths to Go structs, and an entry's basename to a same-named file beside+ * the importer. */+static const cbm_gbuf_node_t *resolve_kustomize_entry(const cbm_pipeline_ctx_t *ctx,+ const char *source_rel, const char *entry) {+ if (!entry[0] || kustomize_remote_entry(entry)) {+ return NULL;+ }+ /* "x.yaml" and "./x.yaml" name the same file; make every entry relative. */+ bool dotted = entry[0] == '.' && (entry[1] == '/' || (entry[1] == '.' && entry[2] == '/'));+ char rel[PKGMAP_PATH_BUF];+ snprintf(rel, sizeof(rel), "%s%s", dotted ? "" : "./", entry);+ char *path = cbm_pipeline_resolve_relative_import(source_rel, rel);+ if (!path) {+ return NULL;+ }+ const cbm_gbuf_node_t *found = NULL;+ char *qn = cbm_pipeline_fqn_module(ctx->project_name, path);+ const cbm_gbuf_node_t *n = qn ? cbm_gbuf_find_by_qn(ctx->gbuf, qn) : NULL;+ free(qn);+ if (n && kustomize_file_label(n->label)) {+ found = n;+ } else {+ char *fqn = cbm_pipeline_fqn_folder(ctx->project_name, path);+ n = fqn ? cbm_gbuf_find_by_qn(ctx->gbuf, fqn) : NULL;+ free(fqn);+ if (n && n->label && strcmp(n->label, "Folder") == 0) {+ found = n;+ }+ }+ free(path);+ return found;+}+const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_t *ctx,const char *source_rel,const char *source_file_qn,@@ -2222,6 +2279,18 @@ const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_treturn NULL;}+ /* The importing file's language gates the strategies below. */+ const char *src_base = source_rel ? source_rel : "";+ for (const char *pb = src_base; *pb; pb++) {+ if (*pb == '/' || *pb == '\\') {+ src_base = pb + SKIP_ONE;+ }+ }+ const CBMLanguage src_lang = cbm_language_for_filename(src_base);+ if (src_lang == CBM_LANG_KUSTOMIZE) {+ return resolve_kustomize_entry(ctx, source_rel, imp->module_path);+ }+/* Prefer exact header-file nodes for C/C++ includes so same-stem source or* module nodes do not steal the edge target. */const cbm_gbuf_node_t *header_target =@@ -2283,13 +2352,6 @@ const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_t/* Name-guess fallbacks below (Strategy 1b sibling-file, Strategy 3* symbol-name) are gated per importing-file language — see* cbm_import_symbol_fallback_allowed (#1934). */- const char *src_base = source_rel ? source_rel : "";- for (const char *pb = src_base; *pb; pb++) {- if (*pb == '/' || *pb == '\\') {- src_base = pb + SKIP_ONE;- }- }- const CBMLanguage src_lang = cbm_language_for_filename(src_base);const bool symbol_fallback_allowed = cbm_import_symbol_fallback_allowed(src_lang);/* Strategy 1b: sibling-file resolution for build/markup grammars whosediff --git a/tests/test_grammar_probe_f.c b/tests/test_grammar_probe_f.cindex a0673374f..e5e5314c8 100644--- a/tests/test_grammar_probe_f.c+++ b/tests/test_grammar_probe_f.c@@ -512,6 +512,85 @@ TEST(probe_kustomize_imports_after_leading_comment) {PASS();}+/* kustomize also reads an extensionless file named `Kustomization`+ * (kubermatic's addons use it); it was never discovered as a kustomization. */+TEST(probe_kustomize_extensionless_file) {+ static const GpfFile files[] = {+ {"Kustomization",+ "apiVersion: kustomize.config.k8s.io/v1beta1\n"+ "kind: Kustomization\n"+ "resources:\n"+ " - namespace.yaml\n"},+ {"namespace.yaml",+ "apiVersion: v1\n"+ "kind: Namespace\n"+ "metadata:\n"+ " name: addons\n"}+ };+ GpfMetrics m = gpf_metrics_files(files, 2);+ ASSERT_TRUE(m.ok);+ ASSERT_TRUE(m.modules >= 1);+ ASSERT_TRUE(m.imports >= 1);+ PASS();+}++/* A remote base is outside the repository. The import resolver's symbol-name+ * guess walked its URL segments and linked kubermatic's gcp addon to the+ * `deploy` function of hack/ci/deploy.sh. A kustomize entry is a path,+ * never a symbol. */+TEST(probe_kustomize_remote_base_names_no_symbol) {+ static const GpfFile files[] = {+ {"kustomization.yaml",+ "apiVersion: kustomize.config.k8s.io/v1beta1\n"+ "kind: Kustomization\n"+ "resources:\n"+ " - https://github.com/example/csi-driver.git/deploy/kubernetes/base\n"},+ {"hack/deploy.sh",+ "#!/usr/bin/env bash\n"+ "deploy() {\n"+ " echo deploying\n"+ "}\n"},+ /* Same name as the URL's last segment: the sibling lookup's basename+ * candidate must not bind a remote base to it either. */+ {"base.yaml",+ "apiVersion: v1\n"+ "kind: ConfigMap\n"+ "metadata:\n"+ " name: local\n"}+ };+ GpfMetrics m = gpf_metrics_files(files, 3);+ ASSERT_TRUE(m.ok);+ ASSERT_EQ(m.imports, 0);+ PASS();+}++/* Entries are relative to the kustomization's own directory; in a nested+ * overlay they resolve through the sibling lookup, not the repo root. */+TEST(probe_kustomize_nested_sibling_entries) {+ static const GpfFile files[] = {+ {"apps/base/podinfo/kustomization.yaml",+ "apiVersion: kustomize.config.k8s.io/v1beta1\n"+ "kind: Kustomization\n"+ "resources:\n"+ " - namespace.yaml\n"+ " - release.yaml\n"},+ {"apps/base/podinfo/namespace.yaml",+ "apiVersion: v1\n"+ "kind: Namespace\n"+ "metadata:\n"+ " name: podinfo\n"},+ {"apps/base/podinfo/release.yaml",+ "apiVersion: helm.toolkit.fluxcd.io/v2\n"+ "kind: HelmRelease\n"+ "metadata:\n"+ " name: podinfo\n"}+ };+ GpfMetrics m = gpf_metrics_files(files, 3);+ ASSERT_TRUE(m.ok);+ ASSERT_EQ(m.imports, 2);+ PASS();+}+/* The label scan stopped at a leading `---`, so a Service written that way* had no selector and linked to nothing. The workload's name differs from the* selector value, so only the pod-template label can match. */@@ -1643,6 +1722,9 @@ SUITE(grammar_probe_f) {RUN_TEST(probe_k8s_manifest_after_leading_comment);RUN_TEST(probe_kustomize_imports_after_leading_comment);RUN_TEST(probe_k8s_selector_after_leading_separator);+ RUN_TEST(probe_kustomize_extensionless_file);+ RUN_TEST(probe_kustomize_remote_base_names_no_symbol);+ RUN_TEST(probe_kustomize_nested_sibling_entries);/* Nix */RUN_TEST(probe_nix_attrset_node);