Skip to content

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

fix(pipeline): deny-wins-by-value for infra Route extraction (#521)

Martin Vogel04697c632c77
diff --git a/src/pipeline/pipeline.c b/src/pipeline/pipeline.c
index 12eac8b86..61559bf91 100644
--- a/src/pipeline/pipeline.c
+++ b/src/pipeline/pipeline.c
@@ -533,17 +533,51 @@ static void try_upsert_infra_route(cbm_gbuf_t *gbuf, const CBMStringRef *sr, con
cbm_gbuf_upsert_node(gbuf, "Route", sr->value, route_qn, fp, 0, 0, route_props);
}
+/* A URL string_ref that does NOT denote a route the service serves: a value
+ * containing whitespace is a command/sentence with an embedded URL (e.g. a
+ * Docker healthcheck `curl --fail http://... || exit 1`); a NULL key_path is a
+ * context-less/duplicate ref; an upstream/config/healthcheck key is an external
+ * dependency, not an exposed route. (#521) */
+static bool route_sr_denied(const CBMStringRef *sr) {
+ if (!sr->value || strchr(sr->value, ' ')) {
+ return true;
+ }
+ if (!sr->key_path) {
+ return true;
+ }
+ return is_upstream_config_key(sr->key_path);
+}
+
static void cbm_pipeline_extract_infra_routes(cbm_gbuf_t *gbuf, const cbm_file_info_t *files,
CBMFileResult **result_cache, int file_count) {
- for (int i = 0; i < file_count; i++) {
- if (!result_cache[i] || !is_infra_file(files[i].rel_path)) {
- continue;
- }
- for (int si = 0; si < result_cache[i]->string_refs.count; si++) {
- try_upsert_infra_route(gbuf, &result_cache[i]->string_refs.items[si],
- files[i].rel_path);
+ /* DENY-WINS-BY-VALUE: the same URL is often extracted as several string_refs
+ * at different key_path granularities (full path, leaf key, flat). The Route
+ * node is keyed by VALUE, so it would be minted if ANY granularity passed the
+ * per-ref guard — e.g. a denied full path `registries.terraform-registry.url`
+ * is defeated by a sibling leaf `url`. So pass 1 collects every URL value
+ * denied under ANY of its refs; pass 2 mints only values never denied. (#521) */
+ CBMHashTable *denied = cbm_ht_create(16);
+ for (int pass = 0; pass < 2; pass++) {
+ for (int i = 0; i < file_count; i++) {
+ if (!result_cache[i] || !is_infra_file(files[i].rel_path)) {
+ continue;
+ }
+ for (int si = 0; si < result_cache[i]->string_refs.count; si++) {
+ const CBMStringRef *sr = &result_cache[i]->string_refs.items[si];
+ if (sr->kind != CBM_STRREF_URL || !sr->value || !strstr(sr->value, "://")) {
+ continue;
+ }
+ if (pass == 0) {
+ if (denied && route_sr_denied(sr)) {
+ cbm_ht_set(denied, sr->value, (void *)1);
+ }
+ } else if (!denied || !cbm_ht_has(denied, sr->value)) {
+ try_upsert_infra_route(gbuf, sr, files[i].rel_path);
+ }
+ }
}
}
+ cbm_ht_free(denied);
}
/* Run decorator_tags, configlink, and route matching passes. */