Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(helm): Chart.yaml dependencies -> DEPENDS_ON edges + values.yaml top-level keys

Martin Vogel1b308ec8646c
diff --git a/internal/cbm/extract_defs.c b/internal/cbm/extract_defs.c
index e38de8718..99aae339e 100644
--- a/internal/cbm/extract_defs.c
+++ b/internal/cbm/extract_defs.c
@@ -3297,11 +3297,72 @@ static void walk_variables_iter(CBMExtractCtx *ctx, TSNode root, const CBMLangSp
}
}
+// True if the file's basename is values.yaml / values.yml (Helm values, #338).
+static bool is_helm_values_file(const char *rel) {
+ if (!rel) {
+ return false;
+ }
+ const char *b = strrchr(rel, '/');
+ b = b ? b + 1 : rel;
+ return strcmp(b, "values.yaml") == 0 || strcmp(b, "values.yml") == 0;
+}
+
+// Extract ONLY top-level keys of a YAML document (no leaf explosion). Used for
+// Helm values.yaml so each chart's tunables surface as a handful of structured
+// Variables instead of one node per nested leaf (#338).
+static void extract_yaml_toplevel_keys(CBMExtractCtx *ctx, TSNode root) {
+ CBMArena *a = ctx->arena;
+ // Descend stream -> document -> block_node down to the first block_mapping.
+ TSNode bm = {0};
+ TSNode cur = root;
+ for (int depth = 0; depth < 6 && ts_node_is_null(bm); depth++) {
+ uint32_t n = ts_node_child_count(cur);
+ TSNode next = {0};
+ bool have_next = false;
+ for (uint32_t i = 0; i < n; i++) {
+ TSNode ch = ts_node_child(cur, i);
+ const char *ck = ts_node_type(ch);
+ if (strcmp(ck, "block_mapping") == 0) {
+ bm = ch;
+ break;
+ }
+ if (!have_next && (strcmp(ck, "document") == 0 || strcmp(ck, "block_node") == 0)) {
+ next = ch;
+ have_next = true;
+ }
+ }
+ if (!ts_node_is_null(bm) || !have_next) {
+ break;
+ }
+ cur = next;
+ }
+ if (ts_node_is_null(bm)) {
+ return;
+ }
+ uint32_t n = ts_node_named_child_count(bm);
+ for (uint32_t i = 0; i < n; i++) {
+ TSNode pair = ts_node_named_child(bm, i);
+ if (strcmp(ts_node_type(pair), "block_mapping_pair") != 0) {
+ continue;
+ }
+ TSNode key = ts_node_child_by_field_name(pair, TS_FIELD("key"));
+ if (!ts_node_is_null(key)) {
+ push_var_def(ctx, cbm_node_text(a, key, ctx->source), pair);
+ }
+ }
+}
+
static void extract_variables(CBMExtractCtx *ctx, TSNode root, const CBMLangSpec *spec) {
if (!spec->variable_node_types || !spec->variable_node_types[0]) {
return;
}
+ // Helm values.yaml: only top-level keys, not the per-leaf flood.
+ if (ctx->language == CBM_LANG_YAML && is_helm_values_file(ctx->rel_path)) {
+ extract_yaml_toplevel_keys(ctx, root);
+ return;
+ }
+
// Config languages with nested structure: use recursive walk
if (ctx->language == CBM_LANG_YAML || ctx->language == CBM_LANG_TOML ||
ctx->language == CBM_LANG_INI || ctx->language == CBM_LANG_JSON) {
diff --git a/src/pipeline/pass_infrascan.c b/src/pipeline/pass_infrascan.c
index d15004b05..a9b2418fd 100644
--- a/src/pipeline/pass_infrascan.c
+++ b/src/pipeline/pass_infrascan.c
@@ -1227,3 +1227,103 @@ char *cbm_infra_qn(const char *project_name, const char *rel_path, const char *i
free(base);
return strdup(result);
}
+
+/* ── Helm Chart.yaml parser (#338) ───────────────────────────────── */
+
+/* Copy the scalar value following a "key:" up to end-of-line into out,
+ * trimming surrounding whitespace, optional quotes, and trailing comments. */
+static void helm_copy_scalar(const char *s, const char *eol, char *out, size_t cap) {
+ while (s < eol && (*s == ' ' || *s == '\t')) {
+ s++;
+ }
+ char quote = 0;
+ if (s < eol && (*s == '"' || *s == '\'')) {
+ quote = *s;
+ s++;
+ }
+ const char *e = s;
+ while (e < eol) {
+ if (quote) {
+ if (*e == quote) {
+ break;
+ }
+ } else if (*e == ' ' || *e == '\t' || *e == '#' || *e == '\r') {
+ break;
+ }
+ e++;
+ }
+ size_t n = (size_t)(e - s);
+ if (n >= cap) {
+ n = cap - 1;
+ }
+ memcpy(out, s, n);
+ out[n] = '\0';
+}
+
+/* Match "key:" at the start of a content pointer; return value start or NULL. */
+static const char *helm_match_key(const char *content, const char *eol, const char *key) {
+ size_t kl = strlen(key);
+ if ((size_t)(eol - content) < kl + 1) {
+ return NULL;
+ }
+ if (strncmp(content, key, kl) != 0 || content[kl] != ':') {
+ return NULL;
+ }
+ return content + kl + 1;
+}
+
+int cbm_parse_helm_chart(const char *source, cbm_helm_chart_t *out) {
+ if (!source || !out) {
+ return -1;
+ }
+ out->chart_name[0] = '\0';
+ out->dep_count = 0;
+
+ bool in_deps = false;
+ const char *p = source;
+ while (*p) {
+ const char *eol = strchr(p, '\n');
+ if (!eol) {
+ eol = p + strlen(p);
+ }
+ int indent = 0;
+ const char *content = p;
+ while (content < eol && *content == ' ') {
+ content++;
+ indent++;
+ }
+ if (content < eol && *content != '#') {
+ if (indent == 0) {
+ /* New top-level key ends any dependencies block. */
+ in_deps = (helm_match_key(content, eol, "dependencies") != NULL);
+ const char *nv = helm_match_key(content, eol, "name");
+ if (!in_deps && nv && out->chart_name[0] == '\0') {
+ helm_copy_scalar(nv, eol, out->chart_name, CBM_HELM_NAME_MAX);
+ }
+ } else if (in_deps) {
+ /* List item: optional leading "- ", then look for name:. */
+ const char *q = content;
+ if (*q == '-') {
+ q++;
+ while (q < eol && *q == ' ') {
+ q++;
+ }
+ }
+ const char *nv = helm_match_key(q, eol, "name");
+ if (nv && out->dep_count < CBM_HELM_MAX_DEPS) {
+ char buf[CBM_HELM_NAME_MAX];
+ helm_copy_scalar(nv, eol, buf, CBM_HELM_NAME_MAX);
+ if (buf[0]) {
+ memcpy(out->deps[out->dep_count], buf, CBM_HELM_NAME_MAX);
+ out->dep_count++;
+ }
+ }
+ }
+ }
+ if (*eol == '\0') {
+ break;
+ }
+ p = eol + 1;
+ }
+ return (out->chart_name[0] || out->dep_count > 0) ? 0 : -1;
+}
diff --git a/src/pipeline/pass_k8s.c b/src/pipeline/pass_k8s.c
index 383c57cf8..9322f46df 100644
--- a/src/pipeline/pass_k8s.c
+++ b/src/pipeline/pass_k8s.c
@@ -193,6 +193,53 @@ static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *path, const
cbm_log_info("pass.k8s.manifest", "file", rel_path, "resources", itoa_k8s(resource_count));
}
+/* ── Helm chart handler ──────────────────────────────────────────── */
+
+static bool is_helm_chart_file(const char *base) {
+ return strcmp(base, "Chart.yaml") == 0 || strcmp(base, "Chart.yml") == 0;
+}
+
+/* Emit a Chart node for a Chart.yaml and a DEPENDS_ON edge to a (shared,
+ * deduplicated) Chart node per declared dependency (#338). */
+static void handle_helm_chart(cbm_pipeline_ctx_t *ctx, const char *rel_path, const char *source) {
+ cbm_helm_chart_t hc;
+ if (cbm_parse_helm_chart(source, &hc) != 0) {
+ return;
+ }
+
+ const char *cname = hc.chart_name[0] ? hc.chart_name : k8s_basename(rel_path);
+ char *chart_qn = cbm_infra_qn(ctx->project_name, rel_path, "helm-chart", NULL);
+ if (!chart_qn) {
+ return;
+ }
+ int64_t chart_id = cbm_gbuf_upsert_node(ctx->gbuf, "Chart", cname, chart_qn, rel_path, SKIP_ONE,
+ 0, "{\"source\":\"helm\"}");
+ free(chart_qn);
+
+ char *file_qn = cbm_pipeline_fqn_compute(ctx->project_name, rel_path, "__file__");
+ const cbm_gbuf_node_t *file_node = file_qn ? cbm_gbuf_find_by_qn(ctx->gbuf, file_qn) : NULL;
+ if (file_node && chart_id > 0) {
+ cbm_gbuf_insert_edge(ctx->gbuf, file_node->id, chart_id, "DEFINES", "{}");
+ }
+ free(file_qn);
+
+ int dep_edges = 0;
+ for (int i = 0; i < hc.dep_count && chart_id > 0; i++) {
+ /* Stable per-project QN so multiple charts depending on the same chart
+ * link to one shared dependency node. */
+ char dep_qn[CBM_SZ_512];
+ snprintf(dep_qn, sizeof(dep_qn), "%s.__helm_dep__.%s", ctx->project_name, hc.deps[i]);
+ int64_t dep_id =
+ cbm_gbuf_upsert_node(ctx->gbuf, "Chart", hc.deps[i], dep_qn, rel_path, SKIP_ONE, 0,
+ "{\"source\":\"helm\",\"external\":true}");
+ if (dep_id > 0) {
+ cbm_gbuf_insert_edge(ctx->gbuf, chart_id, dep_id, "DEPENDS_ON", "{}");
+ dep_edges++;
+ }
+ }
+ cbm_log_info("pass.k8s.helm", "file", rel_path, "deps", itoa_k8s(dep_edges));
+}
+
/* ── Pass entry point ────────────────────────────────────────────── */
int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files, int file_count) {
@@ -202,6 +249,7 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
int kustomize_count = 0;
int manifest_count = 0;
+ int helm_count = 0;
for (int i = 0; i < file_count; i++) {
if (cbm_pipeline_check_cancel(ctx)) {
@@ -224,7 +272,10 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
int src_len = 0;
char *source = k8s_read_file(path, &src_len);
if (source) {
- if (cbm_is_k8s_manifest(base, source)) {
+ if (is_helm_chart_file(base)) {
+ handle_helm_chart(ctx, rel, source);
+ helm_count++;
+ } else if (cbm_is_k8s_manifest(base, source)) {
/* Always re-extract with CBM_LANG_K8S regardless of any cached
* result: cached results were produced during the parallel YAML
* pass and contain no "Resource" definitions. Pass the already-
@@ -240,5 +291,6 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
cbm_log_info("pass.done", "pass", "k8s", "kustomize", itoa_k8s(kustomize_count), "manifests",
itoa_k8s(manifest_count));
+ (void)helm_count;
return 0;
}
diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h
index 6259892fc..d785455dc 100644
--- a/src/pipeline/pipeline_internal.h
+++ b/src/pipeline/pipeline_internal.h
@@ -343,6 +343,18 @@ int cbm_parse_shell_source(const char *source, cbm_shell_result_t *out);
/* Parse a Terraform file from source text. Returns 0 if parsed, -1 if empty. */
int cbm_parse_terraform_source(const char *source, cbm_terraform_result_t *out);
+/* Helm Chart.yaml parse result: chart name + dependency chart names (#338). */
+enum { CBM_HELM_MAX_DEPS = 128, CBM_HELM_NAME_MAX = 128 };
+typedef struct {
+ char chart_name[CBM_HELM_NAME_MAX];
+ char deps[CBM_HELM_MAX_DEPS][CBM_HELM_NAME_MAX];
+ int dep_count;
+} cbm_helm_chart_t;
+
+/* Parse a Helm Chart.yaml: top-level `name:` and `dependencies:` list names.
+ * Returns 0 if parsed (name or deps found), -1 otherwise. */
+int cbm_parse_helm_chart(const char *source, cbm_helm_chart_t *out);
+
/* Build an infrastructure QN. Caller must free the returned string. */
char *cbm_infra_qn(const char *project_name, const char *rel_path, const char *infra_type,
const char *service_name);
diff --git a/tests/test_extraction.c b/tests/test_extraction.c
index 797c5929a..bc6b27951 100644
--- a/tests/test_extraction.c
+++ b/tests/test_extraction.c
@@ -299,6 +299,29 @@ TEST(extract_helm_templates_issue338) {
PASS();
}
+/* --- Helm values.yaml: top-level keys only, no leaf flood (#338) --- */
+TEST(extract_helm_values_toplevel_issue338) {
+ CBMFileResult *r = extract("image:\n"
+ " repository: nginx\n"
+ " tag: latest\n"
+ "replicaCount: 3\n"
+ "service:\n"
+ " port: 80\n",
+ CBM_LANG_YAML, "chart", "values.yaml");
+ ASSERT_NOT_NULL(r);
+ ASSERT_FALSE(r->has_error);
+ ASSERT(has_def(r, "Variable", "image"));
+ ASSERT(has_def(r, "Variable", "replicaCount"));
+ ASSERT(has_def(r, "Variable", "service"));
+ /* Nested leaf keys must NOT explode into separate nodes. */
+ ASSERT(!has_def(r, "Variable", "repository"));
+ ASSERT(!has_def(r, "Variable", "tag"));
+ ASSERT(!has_def(r, "Variable", "port"));
+ ASSERT_EQ(count_defs_with_label(r, "Variable"), 3);
+ cbm_free_result(r);
+ PASS();
+}
+
/* --- Java --- */
TEST(java_class) {
CBMFileResult *r = extract(
@@ -2577,6 +2600,7 @@ SUITE(extraction) {
RUN_TEST(extract_cfscript_issue38);
RUN_TEST(extract_cfml_tag_issue38);
RUN_TEST(extract_helm_templates_issue338);
+ RUN_TEST(extract_helm_values_toplevel_issue338);
/* OOP */
RUN_TEST(java_class);
diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c
index 0dbe9fb93..69ff13353 100644
--- a/tests/test_pipeline.c
+++ b/tests/test_pipeline.c
@@ -572,7 +572,7 @@ TEST(githistory_coupling_carries_last_co_change) {
{files_old, 2, 1700000000LL}, /* oldest a.go/b.go co-change */
{files_other, 2, 1750000000LL}, /* unrelated pair */
{files_mid, 2, 1720000000LL},
- {files_new, 2, 1800000000LL}, /* newest a.go/b.go co-change */
+ {files_new, 2, 1800000000LL}, /* newest a.go/b.go co-change */
};
cbm_change_coupling_t results[16];
@@ -581,10 +581,9 @@ TEST(githistory_coupling_carries_last_co_change) {
bool found_ab = false;
for (int i = 0; i < n; i++) {
- bool is_ab = (strcmp(results[i].file_a, "a.go") == 0 &&
- strcmp(results[i].file_b, "b.go") == 0) ||
- (strcmp(results[i].file_a, "b.go") == 0 &&
- strcmp(results[i].file_b, "a.go") == 0);
+ bool is_ab =
+ (strcmp(results[i].file_a, "a.go") == 0 && strcmp(results[i].file_b, "b.go") == 0) ||
+ (strcmp(results[i].file_a, "b.go") == 0 && strcmp(results[i].file_b, "a.go") == 0);
if (!is_ab) {
continue;
}
@@ -3297,6 +3296,37 @@ TEST(infra_parse_terraform_empty) {
PASS();
}
+/* ── Helm Chart.yaml dependency parsing (#338) ──────────────────── */
+
+TEST(helm_parse_chart_dependencies_issue338) {
+ const char *src = "apiVersion: v2\n"
+ "name: mychart\n"
+ "version: 1.0.0\n"
+ "dependencies:\n"
+ " - name: postgresql\n"
+ " repository: https://charts.bitnami.com/bitnami\n"
+ " version: 12.x.x\n"
+ " - name: redis\n"
+ " repository: https://charts.bitnami.com/bitnami\n"
+ "maintainers:\n"
+ " - name: alice\n"; /* not a dependency — outside the block */
+ cbm_helm_chart_t hc;
+ ASSERT_EQ(cbm_parse_helm_chart(src, &hc), 0);
+ ASSERT_STR_EQ(hc.chart_name, "mychart");
+ ASSERT_EQ(hc.dep_count, 2);
+ ASSERT_STR_EQ(hc.deps[0], "postgresql");
+ ASSERT_STR_EQ(hc.deps[1], "redis");
+ PASS();
+}
+
+TEST(helm_parse_chart_no_deps_issue338) {
+ cbm_helm_chart_t hc;
+ ASSERT_EQ(cbm_parse_helm_chart("name: solo\nversion: 0.1.0\n", &hc), 0);
+ ASSERT_STR_EQ(hc.chart_name, "solo");
+ ASSERT_EQ(hc.dep_count, 0);
+ PASS();
+}
+
/* ── Infrascan: infra QN helper ─────────────────────────────────── */
/* ── Function Registry / Resolver tests ─────────────────────────── */
@@ -5491,6 +5521,8 @@ SUITE(pipeline) {
RUN_TEST(infra_parse_terraform_full);
RUN_TEST(infra_parse_terraform_variables_only);
RUN_TEST(infra_parse_terraform_empty);
+ RUN_TEST(helm_parse_chart_dependencies_issue338);
+ RUN_TEST(helm_parse_chart_no_deps_issue338);
/* Infrascan: QN helper */
RUN_TEST(infra_qn_helper);
/* Infrascan: pipeline integration */