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(incremental): a Kubernetes edit rebuilds what it reaches
Martin Vogel092c0d22c248
diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.cindex bc3beb7e6..a11f82356 100644--- a/src/pipeline/pipeline_incremental.c+++ b/src/pipeline/pipeline_incremental.c@@ -2343,6 +2343,59 @@ static const char *closure_add_variant_partners(cbm_store_t *store, const char *return decline;}+/* Kubernetes inputs reach past their own file (pass_k8s.c): a kustomization+ * decides which manifests deploy together and in which namespace, a+ * Chart.yaml links other charts, and a manifest's Services select workloads+ * in other files of its bundle. The repair re-runs the K8s pass over its plan+ * only, so a delta touching any of them -- a file that held objects, or holds+ * them now -- declines to the full rebuild. Returns the reason, or NULL. */+static const char *closure_k8s_decline(cbm_store_t *store, const char *project,+ const char *repo_path, char **paths, int n_changed,+ int n_deleted) {+ for (int i = 0; i < n_changed + n_deleted; i++) {+ const char *rel = paths[i];+ const char *slash = strrchr(rel, '/');+ const char *base = slash ? slash + SKIP_ONE : rel;+ if (cbm_is_kustomize_file(base) || strcmp(base, "Kustomization") == 0) {+ return "k8s_bundle_input_changed";+ }+ if (strcmp(base, "Chart.yaml") == 0 || strcmp(base, "Chart.yml") == 0) {+ return "helm_chart_changed";+ }+ cbm_node_t *nodes = NULL;+ int count = 0;+ if (cbm_store_find_nodes_by_file(store, project, rel, &nodes, &count) != CBM_STORE_OK) {+ return "k8s_lookup_failed";+ }+ bool held = false;+ for (int j = 0; j < count && !held; j++) {+ held = nodes[j].label && strcmp(nodes[j].label, "Resource") == 0;+ }+ cbm_store_free_nodes(nodes, count);+ if (held) {+ return "k8s_manifest_changed";+ }+ const char *ext = strrchr(base, '.');+ if (i < n_changed && ext && (strcmp(ext, ".yaml") == 0 || strcmp(ext, ".yml") == 0)) {+ enum { K8S_PEEK = 4096 };+ char path[CBM_SZ_4K];+ snprintf(path, sizeof(path), "%s/%s", repo_path, rel);+ char head[K8S_PEEK + SKIP_ONE];+ size_t n = 0;+ FILE *f = cbm_fopen(path, "rb");+ if (f) {+ n = fread(head, SKIP_ONE, K8S_PEEK, f);+ (void)fclose(f);+ }+ head[n] = '\0';+ if (cbm_is_k8s_manifest(base, head)) {+ return "k8s_manifest_changed";+ }+ }+ }+ return NULL;+}+/* Decide whether this manifest delta is closure-repairable, and if so build* the plan. Returns 1 with *plan filled, or 0 (decline → FULL) with the* reason logged. Every early exit declines; nothing here mutates state. */@@ -2465,6 +2518,11 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *pgoto done;}}+ decline = closure_k8s_decline(store, project, cbm_pipeline_repo_path(p), changed_paths,+ n_changed, n_deleted);+ if (decline) {+ goto done;+ }/* Load the previous generation's surfaces and probe the changed files'* fresh ones. Missing rows fail closed. */diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex f666f993c..f955f9822 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -3347,6 +3347,81 @@ TEST(pipeline_staged_publish_commits_below_full_sync_issue1419) {PASS();}+/* Kubernetes inputs reach past their own file: a Service selects a workload+ * in another file of its bundle, and a kustomization decides the namespace+ * of every object it builds. The closure repair re-runs the K8s pass over+ * its plan only, so editing either must still leave the graph a fresh index+ * builds. */+static int k8s_inc_index(const char *repo, const char *db) {+ cbm_pipeline_t *p = cbm_pipeline_new(repo, db, CBM_MODE_FULL);+ if (!p) {+ return -1;+ }+ (void)cbm_pipeline_set_project_name(p, "k8sinc");+ cbm_pipeline_set_persistence(p, false);+ int rc = cbm_pipeline_run(p);+ cbm_pipeline_free(p);+ return rc;+}++static int k8s_inc_count(const char *db_path, const char *sql) {+ sqlite3 *db = NULL;+ int n = -1;+ if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READONLY, NULL) == SQLITE_OK) {+ sqlite3_stmt *stmt = NULL;+ if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK &&+ sqlite3_step(stmt) == SQLITE_ROW) {+ n = sqlite3_column_int(stmt, 0);+ }+ sqlite3_finalize(stmt);+ }+ sqlite3_close(db);+ return n;+}++TEST(incremental_k8s_edits_reach_other_files) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_k8sinc_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "kustomization.yaml", "resources:\n - svc.yaml\n - deploy.yaml\n");+ write_temp_file(tmp, "svc.yaml",+ "apiVersion: v1\nkind: Service\nmetadata:\n name: db\nspec:\n"+ " selector:\n app: db\n");+ write_temp_file(tmp, "deploy.yaml",+ "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: db\nspec:\n"+ " template:\n metadata:\n labels:\n app: db\n");+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/k8sinc.db", tmp);+ static const char links[] = "SELECT COUNT(*) FROM edges WHERE type='INFRA_MAPS'";+ static const char shop[] = "SELECT COUNT(*) FROM nodes WHERE label='Resource' AND "+ "json_extract(properties,'$.obj_key')='apps/Deployment/shop/db'";++ int rc_full = k8s_inc_index(tmp, db_path);+ int links_full = k8s_inc_count(db_path, links);+ /* the Service's file changes, the Deployment's does not */+ write_temp_file(tmp, "svc.yaml",+ "apiVersion: v1\nkind: Service\nmetadata:\n name: db\nspec:\n"+ " selector:\n app: db\n# edited\n");+ int rc_svc = k8s_inc_index(tmp, db_path);+ int links_after_svc = k8s_inc_count(db_path, links);+ /* the build gains a namespace: deploy.yaml's object lives in it now */+ write_temp_file(tmp, "kustomization.yaml",+ "namespace: shop\nresources:\n - svc.yaml\n - deploy.yaml\n");+ int rc_kust = k8s_inc_index(tmp, db_path);+ int shop_after_kust = k8s_inc_count(db_path, shop);+ th_rmtree(tmp);++ ASSERT_EQ(rc_full, 0);+ ASSERT_EQ(links_full, 1);+ ASSERT_EQ(rc_svc, 0);+ ASSERT_EQ(links_after_svc, 1);+ ASSERT_EQ(rc_kust, 0);+ ASSERT_EQ(shop_after_kust, 1);+ PASS();+}+/* SQL DDL becomes first-class Table/View nodes wired into FROM/JOIN lineage,* while the shared name registry must NOT leak those relations into other* languages' textual resolution: a Python call or identifier sharing the@@ -18970,6 +19045,7 @@ SUITE(pipeline_semantic_manifest_repro) {RUN_TEST(incremental_downgrade_preserves_scope_and_artifact_across_change_noop_delete);RUN_TEST(pipeline_incremental_repoints_call_reference_without_stale_edge);RUN_TEST(pipeline_staged_publish_commits_below_full_sync_issue1419);+ RUN_TEST(incremental_k8s_edits_reach_other_files);RUN_TEST(pipeline_sql_lineage_and_relation_isolation);RUN_TEST(pipeline_incremental_sql_table_rename_drops_stale_lineage);RUN_TEST(pipeline_dbt_jinja_lineage);