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.

Emit INFRA_MAPS for HCL scheduler + k8s selectors, ASYNC_CALLS for SQS struct args

Martin Vogelb30fe13de10c
diff --git a/internal/cbm/extract_calls.c b/internal/cbm/extract_calls.c
index 407005da6..5bb7e9b73 100644
--- a/internal/cbm/extract_calls.c
+++ b/internal/cbm/extract_calls.c
@@ -880,6 +880,25 @@ static bool is_url_or_topic_keyword(const char *key) {
return false;
}
+// Check if a struct-field name identifies a queue/topic target. Cloud SDKs pass
+// the destination via a composite-literal input struct rather than a bare string
+// arg (e.g. Go `SendMessageInput{QueueUrl: ...}`, `PublishInput{TopicArn: ...}`).
+// Case-insensitive so QueueUrl/QueueURL/queue_url all match.
+static bool is_queue_topic_field(const char *key) {
+ static const char *fields[] = {"QueueUrl", "QueueURL", "TopicArn", "TopicARN",
+ "QueueName", "TopicName", "QueueArn", "QueueARN",
+ "Destination", NULL};
+ if (!key || !key[0]) {
+ return false;
+ }
+ for (int i = 0; fields[i]; i++) {
+ if (strcasecmp(key, fields[i]) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
// Extract string value from a node (literal or constant reference).
static const char *extract_string_value(CBMExtractCtx *ctx, TSNode val_node) {
const char *vk = ts_node_type(val_node);
@@ -897,6 +916,73 @@ static const char *extract_string_value(CBMExtractCtx *ctx, TSNode val_node) {
return NULL;
}
+// Recover a queue/topic identity from a Go composite-literal input struct, e.g.
+// &sqs.SendMessageInput{QueueUrl: queueUrl, MessageBody: body}
+// sns.PublishInput{TopicArn: "arn:aws:sns:..."}
+// The dispatch target is carried by a struct field (QueueUrl/TopicArn/...), not a
+// bare string arg, so the async edge would otherwise degrade to a plain CALLS.
+// Returns the field's value: the string-literal content when present, else the
+// referenced identifier text (which still names the queue/topic for edge formation).
+static const char *extract_composite_queue_field(CBMExtractCtx *ctx, TSNode node) {
+ // Unwrap a pointer-of-composite: `&Type{...}` is a unary_expression whose
+ // operand is the composite_literal.
+ if (strcmp(ts_node_type(node), "unary_expression") == 0) {
+ TSNode operand = ts_node_child_by_field_name(node, TS_FIELD("operand"));
+ if (ts_node_is_null(operand)) {
+ return NULL;
+ }
+ node = operand;
+ }
+ if (strcmp(ts_node_type(node), "composite_literal") != 0) {
+ return NULL;
+ }
+ TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body"));
+ if (ts_node_is_null(body)) {
+ body = cbm_find_child_by_kind(node, "literal_value");
+ }
+ if (ts_node_is_null(body)) {
+ return NULL;
+ }
+ uint32_t nc = ts_node_named_child_count(body);
+ for (uint32_t i = 0; i < nc; i++) {
+ TSNode el = ts_node_named_child(body, i);
+ if (strcmp(ts_node_type(el), "keyed_element") != 0) {
+ continue;
+ }
+ // keyed_element children: key then value. Each side may be wrapped in a
+ // literal_element; unwrap to the underlying identifier/literal.
+ uint32_t ec = ts_node_named_child_count(el);
+ if (ec < PAIR_LEN) {
+ continue;
+ }
+ TSNode key_n = ts_node_named_child(el, 0);
+ TSNode val_n = ts_node_named_child(el, 1);
+ if (strcmp(ts_node_type(key_n), "literal_element") == 0 &&
+ ts_node_named_child_count(key_n) > 0) {
+ key_n = ts_node_named_child(key_n, 0);
+ }
+ if (strcmp(ts_node_type(val_n), "literal_element") == 0 &&
+ ts_node_named_child_count(val_n) > 0) {
+ val_n = ts_node_named_child(val_n, 0);
+ }
+ char *key = cbm_node_text(ctx->arena, key_n, ctx->source);
+ if (!is_queue_topic_field(key)) {
+ continue;
+ }
+ const char *resolved = extract_string_value(ctx, val_n);
+ if (resolved && resolved[0]) {
+ return resolved;
+ }
+ // Value is a variable/expression (no constant value); use its source text
+ // as the queue/topic identity so the async edge still forms.
+ char *raw = cbm_node_text(ctx->arena, val_n, ctx->source);
+ if (raw && raw[0]) {
+ return raw;
+ }
+ }
+ return NULL;
+}
+
// Try to extract URL/topic from a keyword_argument or pair node.
static const char *extract_keyword_url(CBMExtractCtx *ctx, TSNode arg) {
TSNode key_node = ts_node_child_by_field_name(arg, TS_FIELD("name"));
@@ -952,6 +1038,16 @@ static const char *extract_url_or_topic_arg(CBMExtractCtx *ctx, TSNode args) {
continue;
}
+ /* Cloud SDK dispatch via input struct: the queue/topic target is a field
+ * of a composite literal (Go `&sqs.SendMessageInput{QueueUrl: ...}`), not
+ * a bare string arg. Recover it so the async edge forms. */
+ if (strcmp(ak, "composite_literal") == 0 || strcmp(ak, "unary_expression") == 0) {
+ const char *val = extract_composite_queue_field(ctx, arg);
+ if (val) {
+ return val;
+ }
+ }
+
if (ai < MAX_POSITIONAL_SCAN) {
const char *val = extract_positional_url(ctx, arg, ak);
if (val) {
diff --git a/internal/cbm/extract_unified.c b/internal/cbm/extract_unified.c
index 0b9c1d46e..3c22a44e9 100644
--- a/internal/cbm/extract_unified.c
+++ b/internal/cbm/extract_unified.c
@@ -552,24 +552,46 @@ static void scan_yaml_for_infra_bindings(CBMExtractCtx *ctx, TSNode root) {
* where one is a source key (topic, queue_name) and another is a
* target key (uri, push_endpoint). Handles nested blocks like
* push_config { push_endpoint = "..." }. */
-// Extract a string value from an HCL attribute value node
-// (quoted_template/template_literal/string_lit).
+// Extract a string value from an HCL attribute value node. The tree-sitter-hcl
+// grammar wraps the literal: attribute → (identifier)(expression → literal_value
+// → string_lit → template_literal). Descend through the expression/literal_value
+// wrappers to reach the actual string token before reading it.
static char *extract_hcl_string_val(CBMArena *a, TSNode val_node, const char *source) {
- const char *vk = ts_node_type(val_node);
- if (strcmp(vk, "quoted_template") != 0 && strcmp(vk, "template_literal") != 0 &&
- strcmp(vk, "string_lit") != 0) {
+ enum { HCL_MAX_UNWRAP = 5 };
+ for (int depth = 0; depth < HCL_MAX_UNWRAP; depth++) {
+ const char *vk = ts_node_type(val_node);
+ if (strcmp(vk, "expression") == 0 || strcmp(vk, "literal_value") == 0) {
+ if (ts_node_named_child_count(val_node) == 0) {
+ return NULL;
+ }
+ val_node = ts_node_named_child(val_node, 0);
+ continue;
+ }
+ if (strcmp(vk, "quoted_template") == 0 || strcmp(vk, "template_literal") == 0 ||
+ strcmp(vk, "string_lit") == 0) {
+ char *val = cbm_node_text(a, val_node, source);
+ return strip_yaml_quotes(a, val);
+ }
return NULL;
}
- char *val = cbm_node_text(a, val_node, source);
- return strip_yaml_quotes(a, val);
+ return NULL;
+}
+
+// The tree-sitter-hcl grammar nests a block's attributes/sub-blocks inside a
+// `body` child rather than directly under the block. Return that body node so
+// scanners iterate the right level; fall back to the block itself if no body.
+static TSNode hcl_block_body(TSNode block) {
+ TSNode body = cbm_find_child_by_kind(block, "body");
+ return ts_node_is_null(body) ? block : body;
}
// Scan a nested HCL block for target keys (push_endpoint, uri, etc.).
static void scan_hcl_nested_block_targets(CBMExtractCtx *ctx, TSNode block, const char **targets,
int *n_targets) {
- uint32_t bnc = ts_node_named_child_count(block);
+ TSNode body = hcl_block_body(block);
+ uint32_t bnc = ts_node_named_child_count(body);
for (uint32_t bi = 0; bi < bnc; bi++) {
- TSNode bchild = ts_node_named_child(block, bi);
+ TSNode bchild = ts_node_named_child(body, bi);
if (strcmp(ts_node_type(bchild), "attribute") != 0) {
continue;
}
@@ -589,6 +611,48 @@ static void scan_hcl_nested_block_targets(CBMExtractCtx *ctx, TSNode block, cons
}
}
+/* A scheduler/cron job has no topic/queue source key — its identity is the
+ * resource itself, and the binding target is the job's invocation endpoint
+ * (uri / http_target / pubsub_target). Detect such a block by its first label
+ * (resource type, e.g. "google_cloud_scheduler_job") and return the job's
+ * synthetic source name (its second label / resource name), or NULL if the
+ * block is not a scheduler job. Sets *broker_out to the scheduler broker id. */
+static const char *hcl_scheduler_source(CBMExtractCtx *ctx, TSNode block, const char **broker_out) {
+ const char *first_label = NULL;
+ const char *last_label = NULL;
+ uint32_t cc = ts_node_named_child_count(block);
+ for (uint32_t i = 0; i < cc; i++) {
+ TSNode ch = ts_node_named_child(block, i);
+ if (strcmp(ts_node_type(ch), "string_lit") != 0) {
+ continue;
+ }
+ TSNode lit = cbm_find_child_by_kind(ch, "template_literal");
+ if (ts_node_is_null(lit)) {
+ continue;
+ }
+ char *label = cbm_node_text(ctx->arena, lit, ctx->source);
+ if (!label || !label[0]) {
+ continue;
+ }
+ if (!first_label) {
+ first_label = label;
+ }
+ last_label = label;
+ }
+ if (!first_label) {
+ return NULL;
+ }
+ /* google_cloud_scheduler_job, aws_cloudwatch_event_rule (cron), etc. */
+ if (strstr(first_label, "scheduler") || strstr(first_label, "schedule") ||
+ strstr(first_label, "cron")) {
+ if (broker_out) {
+ *broker_out = "cloud_scheduler";
+ }
+ return last_label ? last_label : first_label;
+ }
+ return NULL;
+}
+
static void scan_hcl_block_for_bindings(CBMExtractCtx *ctx, TSNode block) {
const char *sources[MAX_INFRA_BINDINGS] = {NULL};
const char *source_keys[MAX_INFRA_BINDINGS] = {NULL};
@@ -596,9 +660,10 @@ static void scan_hcl_block_for_bindings(CBMExtractCtx *ctx, TSNode block) {
const char *targets[MAX_INFRA_BINDINGS] = {NULL};
int n_targets = 0;
- uint32_t nc = ts_node_named_child_count(block);
+ TSNode body = hcl_block_body(block);
+ uint32_t nc = ts_node_named_child_count(body);
for (uint32_t i = 0; i < nc; i++) {
- TSNode child = ts_node_named_child(block, i);
+ TSNode child = ts_node_named_child(body, i);
const char *ck = ts_node_type(child);
if (strcmp(ck, "attribute") == 0) {
@@ -630,6 +695,29 @@ static void scan_hcl_block_for_bindings(CBMExtractCtx *ctx, TSNode block) {
}
}
+ /* Scheduler/cron jobs carry no topic/queue source key — the resource itself
+ * is the source. If we found an invocation target (uri/http_target) but no
+ * explicit source key, synthesize the source from the scheduler resource so
+ * the job→endpoint binding (INFRA_MAPS) still forms. */
+ if (n_sources == 0 && n_targets > 0) {
+ const char *sched_broker = NULL;
+ const char *sched_src = hcl_scheduler_source(ctx, block, &sched_broker);
+ if (sched_src) {
+ for (int ti = 0; ti < n_targets; ti++) {
+ if (!targets[ti]) {
+ continue;
+ }
+ CBMInfraBinding ib = {
+ .source_name = sched_src,
+ .target_url = targets[ti],
+ .broker = sched_broker ? sched_broker : "cloud_scheduler",
+ };
+ cbm_infrabinding_push(&ctx->result->infra_bindings, ctx->arena, ib);
+ }
+ return;
+ }
+ }
+
emit_infra_bindings(ctx, sources, source_keys, n_sources, targets, n_targets);
}
diff --git a/src/pipeline/pass_k8s.c b/src/pipeline/pass_k8s.c
index b6a953142..5b6b9cf96 100644
--- a/src/pipeline/pass_k8s.c
+++ b/src/pipeline/pass_k8s.c
@@ -147,12 +147,233 @@ static void handle_kustomize(cbm_pipeline_ctx_t *ctx, const char *path, const ch
cbm_log_info("pass.k8s.kustomize", "file", rel_path, "imports", itoa_k8s(import_count));
}
+/* ── K8s cross-manifest label-selector matching ──────────────────────
+ * A Service routes traffic to the workload Pods whose labels match the
+ * Service's spec.selector. We record, per manifest, the Resource node id plus
+ * its selector label-values (Services) and pod label-values (workloads), then
+ * after all manifests are processed connect each Service to the workload(s) it
+ * targets via an INFRA_MAPS edge. This models the runtime traffic path the same
+ * way k8s itself resolves Service → Endpoints by label.
+ *
+ * Matching is by label *value*: a Service selector `app: frontend` matches a
+ * workload that either carries the pod label value "frontend" OR is named
+ * "frontend" (the ubiquitous app==name convention, used when the pod template
+ * omits explicit labels). */
+enum { K8S_MAX_LABELS = 16, K8S_MAX_RECORDS = 512, K8S_LABEL_LEN = 128 };
+
+typedef struct {
+ int64_t node_id;
+ char name[K8S_LABEL_LEN];
+ bool is_service;
+ bool is_workload;
+ char selector_vals[K8S_MAX_LABELS][K8S_LABEL_LEN]; /* Service spec.selector values */
+ int n_selector;
+ char label_vals[K8S_MAX_LABELS][K8S_LABEL_LEN]; /* workload pod-template label values */
+ int n_label;
+} k8s_record_t;
+
+typedef struct {
+ k8s_record_t *items;
+ int count;
+ int cap;
+} k8s_record_array_t;
+
+/* Count leading-space indentation of a line (tabs are invalid YAML indent). */
+static int k8s_indent(const char *line) {
+ int n = 0;
+ while (line[n] == ' ') {
+ n++;
+ }
+ return n;
+}
+
+/* Split `key: value` (already de-indented). Returns 1 if a key was found; fills
+ * key/val (val empty when the key opens a nested block). */
+static int k8s_split_kv(const char *t, char *key, size_t key_sz, char *val, size_t val_sz) {
+ key[0] = '\0';
+ val[0] = '\0';
+ if (t[0] == '#' || t[0] == '-' || t[0] == '\0') {
+ return 0;
+ }
+ const char *colon = strchr(t, ':');
+ if (!colon) {
+ return 0;
+ }
+ size_t klen = (size_t)(colon - t);
+ if (klen == 0 || klen >= key_sz) {
+ return 0;
+ }
+ memcpy(key, t, klen);
+ key[klen] = '\0';
+ const char *v = colon + 1;
+ while (*v == ' ' || *v == '\t') {
+ v++;
+ }
+ size_t vn = 0;
+ while (v[vn] && v[vn] != '\r' && v[vn] != '\n' && v[vn] != '#' && vn + 1 < val_sz) {
+ val[vn] = v[vn];
+ vn++;
+ }
+ /* trim trailing space */
+ while (vn > 0 && (val[vn - 1] == ' ' || val[vn - 1] == '\t')) {
+ vn--;
+ }
+ val[vn] = '\0';
+ /* strip surrounding quotes */
+ if (vn >= 2 && (val[0] == '"' || val[0] == '\'') && val[vn - 1] == val[0]) {
+ memmove(val, val + 1, vn - 2);
+ val[vn - 2] = '\0';
+ }
+ return 1;
+}
+
+static void k8s_add_val(char dst[][K8S_LABEL_LEN], int *n, const char *v) {
+ if (*n >= K8S_MAX_LABELS || !v || !v[0]) {
+ return;
+ }
+ snprintf(dst[*n], K8S_LABEL_LEN, "%s", v);
+ (*n)++;
+}
+
+/* Scan a single-document k8s manifest's text for the resource name, selector
+ * label-values (Service) and pod-template label-values (workload). A small
+ * indentation path-stack distinguishes spec.selector from
+ * spec.template.metadata.labels and from top-level metadata.name. */
+static void k8s_scan_labels(const char *source, k8s_record_t *rec) {
+ enum { PATH_MAX = 12 };
+ struct {
+ int indent;
+ char key[64];
+ } stack[PATH_MAX];
+ int depth = 0;
+ bool got_name = false;
+
+ const char *p = source;
+ while (p && *p) {
+ const char *eol = strchr(p, '\n');
+ size_t len = eol ? (size_t)(eol - p) : strlen(p);
+ char line[CBM_SZ_512];
+ size_t cp = len < sizeof(line) - 1 ? len : sizeof(line) - 1;
+ memcpy(line, p, cp);
+ line[cp] = '\0';
+
+ /* End of first YAML document — stop (one Resource per file). */
+ const char *trimmed = line;
+ while (*trimmed == ' ') {
+ trimmed++;
+ }
+ if (strncmp(trimmed, "---", 3) == 0 && line == trimmed) {
+ break;
+ }
+
+ if (trimmed[0] && trimmed[0] != '#') {
+ int ind = k8s_indent(line);
+ while (depth > 0 && stack[depth - 1].indent >= ind) {
+ depth--;
+ }
+ char key[64];
+ char val[K8S_LABEL_LEN];
+ if (k8s_split_kv(trimmed, key, sizeof(key), val, sizeof(val))) {
+ /* Build the current dotted path for context decisions. */
+ bool under_selector =
+ (depth >= 1 && strcmp(stack[depth - 1].key, "selector") == 0);
+ bool under_labels = (depth >= 1 && strcmp(stack[depth - 1].key, "labels") == 0);
+ bool under_metadata =
+ (depth >= 1 && strcmp(stack[depth - 1].key, "metadata") == 0);
+
+ if (val[0] == '\0') {
+ /* Block-opening key: push onto the path stack. */
+ if (depth < PATH_MAX) {
+ stack[depth].indent = ind;
+ snprintf(stack[depth].key, sizeof(stack[depth].key), "%s", key);
+ depth++;
+ }
+ } else {
+ /* Leaf key: value. */
+ if (ind == 0 && strcmp(key, "kind") == 0) {
+ rec->is_service = (strcmp(val, "Service") == 0);
+ rec->is_workload =
+ (strcmp(val, "Deployment") == 0 || strcmp(val, "StatefulSet") == 0 ||
+ strcmp(val, "DaemonSet") == 0 || strcmp(val, "ReplicaSet") == 0 ||
+ strcmp(val, "ReplicationController") == 0 || strcmp(val, "Pod") == 0 ||
+ strcmp(val, "Job") == 0 || strcmp(val, "CronJob") == 0);
+ } else if (!got_name && under_metadata && strcmp(key, "name") == 0) {
+ snprintf(rec->name, sizeof(rec->name), "%s", val);
+ got_name = true;
+ } else if (under_selector) {
+ /* Service spec.selector matchLabels values. */
+ k8s_add_val(rec->selector_vals, &rec->n_selector, val);
+ } else if (under_labels) {
+ /* Pod-template / metadata labels values. */
+ k8s_add_val(rec->label_vals, &rec->n_label, val);
+ }
+ }
+ }
+ }
+
+ if (!eol) {
+ break;
+ }
+ p = eol + 1;
+ }
+}
+
+/* True if any of the service's selector values matches the workload. */
+static bool k8s_selector_matches(const k8s_record_t *svc, const k8s_record_t *wl) {
+ for (int s = 0; s < svc->n_selector; s++) {
+ const char *sv = svc->selector_vals[s];
+ if (!sv[0]) {
+ continue;
+ }
+ if (wl->name[0] && strcmp(sv, wl->name) == 0) {
+ return true;
+ }
+ for (int l = 0; l < wl->n_label; l++) {
+ if (strcmp(sv, wl->label_vals[l]) == 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/* After all manifests are recorded, connect each Service to the workload(s) its
+ * selector targets via an INFRA_MAPS edge (Service Resource → workload Resource). */
+static void k8s_link_selectors(cbm_pipeline_ctx_t *ctx, const k8s_record_array_t *recs) {
+ int edges = 0;
+ for (int i = 0; i < recs->count; i++) {
+ const k8s_record_t *svc = &recs->items[i];
+ if (!svc->is_service || svc->n_selector == 0 || svc->node_id <= 0) {
+ continue;
+ }
+ for (int j = 0; j < recs->count; j++) {
+ const k8s_record_t *wl = &recs->items[j];
+ if (i == j || !wl->is_workload || wl->node_id <= 0) {
+ continue;
+ }
+ if (k8s_selector_matches(svc, wl)) {
+ char props[CBM_SZ_256];
+ snprintf(props, sizeof(props),
+ "{\"kind\":\"selector\",\"service\":\"%s\",\"workload\":\"%s\"}",
+ svc->name, wl->name);
+ cbm_gbuf_insert_edge(ctx->gbuf, svc->node_id, wl->node_id, "INFRA_MAPS", props);
+ edges++;
+ }
+ }
+ }
+ if (edges > 0) {
+ cbm_log_info("pass.k8s.selectors", "linked", itoa_k8s(edges));
+ }
+}
+
/* ── K8s manifest handler ────────────────────────────────────────── */
/* source/src_len are the already-read file bytes (caller retains ownership and
- * must free after this call returns). */
+ * must free after this call returns). When `rec` is non-NULL it is populated
+ * with the first Resource's node id, name and label/selector values for later
+ * cross-manifest selector matching. */
static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *path, const char *rel_path,
- const char *source, int src_len) {
+ const char *source, int src_len, k8s_record_t *rec) {
(void)path; /* retained for symmetry; source is always provided now */
int resource_count = 0;
@@ -185,11 +406,21 @@ static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *path, const
cbm_gbuf_insert_edge(ctx->gbuf, file_node->id, node_id, "DEFINES", "{}");
}
+ /* Capture the first Resource for cross-manifest selector matching. */
+ if (rec && rec->node_id <= 0 && node_id > 0) {
+ rec->node_id = node_id;
+ }
+
resource_count++;
}
cbm_free_result(res);
+ /* Record selector / pod-label values for later Service → workload linking. */
+ if (rec && rec->node_id > 0) {
+ k8s_scan_labels(source, rec);
+ }
+
cbm_log_info("pass.k8s.manifest", "file", rel_path, "resources", itoa_k8s(resource_count));
}
@@ -400,8 +631,14 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
int manifest_count = 0;
int helm_count = 0;
+ /* Collect per-manifest selector/label records for cross-manifest matching. */
+ k8s_record_array_t recs = {0};
+ recs.items = calloc(K8S_MAX_RECORDS, sizeof(*recs.items));
+ recs.cap = recs.items ? K8S_MAX_RECORDS : 0;
+
for (int i = 0; i < file_count; i++) {
if (cbm_pipeline_check_cancel(ctx)) {
+ free(recs.items);
return CBM_NOT_FOUND;
}
@@ -438,7 +675,12 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
* pass and contain no "Resource" definitions. Pass the already-
* read source buffer so handle_k8s_manifest does not re-read. */
(void)cached; /* cached YAML result intentionally discarded */
- handle_k8s_manifest(ctx, path, rel, source, src_len);
+ k8s_record_t *rec =
+ (recs.count < recs.cap) ? &recs.items[recs.count] : NULL;
+ handle_k8s_manifest(ctx, path, rel, source, src_len, rec);
+ if (rec && rec->node_id > 0) {
+ recs.count++;
+ }
manifest_count++;
}
free(source);
@@ -446,6 +688,10 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
}
}
+ /* Connect Services to the workloads their selectors target (INFRA_MAPS). */
+ k8s_link_selectors(ctx, &recs);
+ free(recs.items);
+
cbm_log_info("pass.done", "pass", "k8s", "kustomize", itoa_k8s(kustomize_count), "manifests",
itoa_k8s(manifest_count));
(void)helm_count;
diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.c
index 4b02de9cd..cdf5a3cc4 100644
--- a/src/pipeline/pipeline.c
+++ b/src/pipeline/pipeline.c
@@ -391,13 +391,25 @@ static int process_one_infra_binding(cbm_gbuf_t *gbuf, const CBMInfraBinding *ib
snprintf(topic_route_qn, sizeof(topic_route_qn), "__route__%s__%s",
ib->broker ? ib->broker : "async", ib->source_name);
const cbm_gbuf_node_t *topic_route = cbm_gbuf_find_by_qn(gbuf, topic_route_qn);
- if (!topic_route) {
- return 0;
+ int64_t topic_route_id;
+ if (topic_route) {
+ topic_route_id = topic_route->id;
+ } else {
+ /* The config file IS the declaration that the topic/queue/schedule exists;
+ * upsert its Route node so the binding maps even when no code-side dispatch
+ * call created the node first (e.g. a standalone scheduler/subscription
+ * manifest). */
+ topic_route_id =
+ cbm_gbuf_upsert_node(gbuf, "Route", ib->source_name, topic_route_qn, rel_path, 0, 0,
+ ib->broker ? ib->broker : "async");
+ if (topic_route_id <= 0) {
+ return 0;
+ }
}
char props[CBM_SZ_512];
snprintf(props, sizeof(props), "{\"broker\":\"%s\",\"topic\":\"%s\",\"endpoint\":\"%s\"}",
ib->broker ? ib->broker : "async", ib->source_name, ib->target_url);
- cbm_gbuf_insert_edge(gbuf, topic_route->id, url_route_id, "INFRA_MAPS", props);
+ cbm_gbuf_insert_edge(gbuf, topic_route_id, url_route_id, "INFRA_MAPS", props);
return SKIP_ONE;
}
@@ -564,6 +576,14 @@ static int run_sequential_pipeline(cbm_pipeline_t *p, cbm_pipeline_ctx_t *ctx,
rc = CBM_NOT_FOUND;
}
}
+ /* Consume infra bindings (YAML/HCL topic/queue/scheduler → endpoint) so
+ * INFRA_MAPS edges also form on the sequential path, not just the parallel
+ * one. process_one_infra_binding self-creates the topic Route node when no
+ * code-side dispatch created it (e.g. a standalone scheduler manifest). */
+ if (seq_cache && rc == 0) {
+ cbm_pipeline_extract_infra_routes(p->gbuf, files, seq_cache, file_count);
+ cbm_pipeline_process_infra_bindings(p->gbuf, files, seq_cache, file_count);
+ }
if (seq_cache) {
for (int i = 0; i < file_count; i++) {
if (seq_cache[i]) {