Merge pull request #3102 from DeusData/fix/semantic-index-version-14

fix(pipeline): an index built before the config references rebuilds once
This commit is contained in:
Martin Vogel
2026-11-27 04:45:59 +01:00
committed by GitHub
2 changed files with 153 additions and 1 deletions
+10 -1
View File
@@ -1849,8 +1849,17 @@ int cbm_pipeline_build_fresh_semantic_manifest(cbm_pipeline_t *p, const char *pr
* directories name and HANDLES its Route (extract_nextjs.c). An index
* built before has none of these Routes for its unchanged route files,
* so it rebuilds once on upgrade.
* 14: a config file REFERENCES_FILE the files it names: a Dockerfile's COPY
* and ADD sources {via:copy|add}, a compose service's bind mounts,
* env_file, configs and secrets, a Terraform block's file() family, a
* workflow's local actions and reusable workflows {via:uses}, a
* kustomization's generator files and configurations; and a Make rule
* DEPENDS_ON {via:prerequisite} the rules of its makefile that its
* prerequisites name (pass_docker.c, pass_ci.c, pass_terraform.c,
* pass_k8s.c, pass_shell.c). An index built before has none of these
* edges for its unchanged config files, so it rebuilds once on upgrade.
* The unresolved-call coverage threshold remains independent. */
enum { CBM_SEMANTIC_INDEX_VERSION = 13 };
enum { CBM_SEMANTIC_INDEX_VERSION = 14 };
typedef struct {
cbm_gbuf_t *gbuf;
+143
View File
@@ -5750,6 +5750,148 @@ TEST(incremental_make_prerequisite_follows_edits) {
PASS();
}
/* Version 14 of the semantic index: an index built before the config
* references holds none of them for its unchanged files. One tree with every
* kind: a Dockerfile's COPY source, a compose bind mount, a Terraform file(),
* a workflow's local action, a kustomization's generator file and a Make
* prerequisite. The published index is put back to what version 13 wrote (its
* stamp, and none of those edges); with nothing in the tree changed the next
* index rebuilds in full, draws them all again and stamps the current
* version, and the one after it is a no-op. */
TEST(pipeline_config_references_semantic_upgrade) {
char tmp[256];
snprintf(tmp, sizeof(tmp), "/tmp/cbm_cfgup_XXXXXX");
if (!cbm_mkdtemp(tmp)) {
FAIL("tmpdir");
}
write_temp_file(tmp, "Dockerfile", "FROM alpine:3.20\nCOPY entry.sh /entry.sh\n");
write_temp_file(tmp, "entry.sh", "#!/bin/sh\necho entry\n");
write_temp_file(tmp, "compose.yaml", "services:\n"
" web:\n"
" image: nginx:1.27\n"
" volumes:\n"
" - ./nginx.conf:/etc/nginx/nginx.conf\n");
write_temp_file(tmp, "nginx.conf", "worker_processes 1;\n");
write_temp_file(tmp, "infra/main.tf",
"locals {\n"
" settings = file(\"${path.module}/settings.properties\")\n"
"}\n");
write_temp_file(tmp, "infra/settings.properties", "first = 1\n");
write_temp_file(tmp, ".github/workflows/ci.yml", "name: ci\n"
"on: [push]\n"
"jobs:\n"
" build:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: ./.github/actions/setup\n");
write_temp_file(tmp, ".github/actions/setup/action.yml",
"name: setup\nruns:\n using: composite\n steps: []\n");
write_temp_file(tmp, "deploy/kustomization.yaml",
"apiVersion: kustomize.config.k8s.io/v1beta1\n"
"kind: Kustomization\n"
"resources:\n"
" - deployment.yaml\n"
"configMapGenerator:\n"
" - name: app-config\n"
" files:\n"
" - app.properties\n");
write_temp_file(tmp, "deploy/deployment.yaml", "apiVersion: apps/v1\n"
"kind: Deployment\n"
"metadata:\n"
" name: app\n"
"spec:\n"
" replicas: 1\n");
write_temp_file(tmp, "deploy/app.properties", "first = 1\n");
write_temp_file(tmp, "Makefile", "all: build\n\techo all\n\nbuild:\n\techo build\n");
char db_path[512];
snprintf(db_path, sizeof(db_path), "%s/cfgup.db", tmp);
static const char refs[] =
"SELECT COUNT(*) FROM edges WHERE type='REFERENCES_FILE' AND "
"json_extract(properties,'$.via') IN ('copy','volume','file','uses','configMapGenerator')";
static const char kinds[] =
"SELECT COUNT(DISTINCT json_extract(properties,'$.via')) FROM edges WHERE "
"type='REFERENCES_FILE' AND json_extract(properties,'$.via') IN "
"('copy','volume','file','uses','configMapGenerator')";
static const char deps[] = "SELECT COUNT(*) FROM edges WHERE type='DEPENDS_ON' AND "
"json_extract(properties,'$.via')='prerequisite'";
static const char all_nodes[] = "SELECT COUNT(*) FROM nodes";
static const char all_edges[] = "SELECT COUNT(*) FROM edges";
int rc_full = k8s_inc_index(tmp, db_path);
int refs_full = k8s_inc_count(db_path, refs);
int kinds_full = k8s_inc_count(db_path, kinds);
int deps_full = k8s_inc_count(db_path, deps);
int nodes_full = k8s_inc_count(db_path, all_nodes);
int edges_full = k8s_inc_count(db_path, all_edges);
/* Put the published index back to what version 13 wrote. */
cbm_store_t *store = cbm_store_open_path(db_path);
ASSERT_NOT_NULL(store);
cbm_coverage_row_t *coverage_rows = NULL;
int coverage_count = 0;
ASSERT_EQ(cbm_store_coverage_get(store, "k8sinc", &coverage_rows, &coverage_count),
CBM_STORE_OK);
cbm_coverage_meta_t meta = {0};
ASSERT_EQ(cbm_store_coverage_meta_get(store, "k8sinc", &meta), CBM_STORE_OK);
cbm_coverage_meta_t old_meta = meta;
old_meta.coverage_version = 13;
ASSERT_EQ(
cbm_store_coverage_replace_ex(store, "k8sinc", coverage_rows, coverage_count, &old_meta),
CBM_STORE_OK);
cbm_store_free_coverage(coverage_rows, coverage_count);
cbm_store_coverage_meta_clear(&meta);
ASSERT_EQ(cbm_store_exec(store,
"DELETE FROM edges WHERE (type='REFERENCES_FILE' AND "
"json_extract(properties,'$.via') IN "
"('copy','volume','file','uses','configMapGenerator')) OR "
"(type='DEPENDS_ON' AND "
"json_extract(properties,'$.via')='prerequisite');"),
CBM_STORE_OK);
cbm_store_close(store);
int refs_13 = k8s_inc_count(db_path, refs);
int deps_13 = k8s_inc_count(db_path, deps);
/* Nothing in the tree changed: only the version says the index is stale. */
int rc_upgrade = k8s_inc_index(tmp, db_path);
cbm_incremental_route_t upgrade_route = cbm_pipeline_incremental_test_last_route();
int refs_upgrade = k8s_inc_count(db_path, refs);
int kinds_upgrade = k8s_inc_count(db_path, kinds);
int deps_upgrade = k8s_inc_count(db_path, deps);
int nodes_upgrade = k8s_inc_count(db_path, all_nodes);
int edges_upgrade = k8s_inc_count(db_path, all_edges);
store = cbm_store_open_path(db_path);
ASSERT_NOT_NULL(store);
cbm_coverage_meta_t new_meta = {0};
ASSERT_EQ(cbm_store_coverage_meta_get(store, "k8sinc", &new_meta), CBM_STORE_OK);
int stored_version = new_meta.coverage_version;
cbm_store_coverage_meta_clear(&new_meta);
cbm_store_close(store);
int rc_again = k8s_inc_index(tmp, db_path);
cbm_incremental_route_t again_route = cbm_pipeline_incremental_test_last_route();
int refs_again = k8s_inc_count(db_path, refs);
th_rmtree(tmp);
ASSERT_EQ(rc_full, 0);
ASSERT_EQ(refs_full, 5);
ASSERT_EQ(kinds_full, 5); /* one of each kind */
ASSERT_EQ(deps_full, 1);
ASSERT_EQ(refs_13, 0);
ASSERT_EQ(deps_13, 0);
ASSERT_EQ(rc_upgrade, 0);
ASSERT_EQ(upgrade_route, CBM_INCREMENTAL_ROUTE_FORCED_FULL);
ASSERT_EQ(refs_upgrade, 5);
ASSERT_EQ(kinds_upgrade, 5);
ASSERT_EQ(deps_upgrade, 1);
ASSERT_EQ(nodes_upgrade, nodes_full);
ASSERT_EQ(edges_upgrade, edges_full);
ASSERT_EQ(stored_version, CBM_SEMANTIC_INDEX_VERSION);
ASSERT_EQ(rc_again, 0);
ASSERT_EQ(again_route, CBM_INCREMENTAL_ROUTE_NOOP);
ASSERT_EQ(refs_again, 5);
ASSERT_GTE(CBM_SEMANTIC_INDEX_VERSION, 14);
PASS();
}
/* Deleting the only script requesting a URL leaves no Route behind -- a full
* index never makes one without an edge; the Route a kept script requests
* stays. `legacy`: through the full-load route, else closure repair. Returns
@@ -38560,6 +38702,7 @@ SUITE(pipeline_semantic_manifest_repro) {
RUN_TEST(incremental_local_action_pair_deleted_takes_the_full_route);
RUN_TEST(incremental_kustomize_file_reference_follows_its_file);
RUN_TEST(incremental_make_prerequisite_follows_edits);
RUN_TEST(pipeline_config_references_semantic_upgrade);
RUN_TEST(incremental_script_request_to_compose_service_keeps_host);
RUN_TEST(incremental_deleted_dockerfile_drops_its_image);
RUN_TEST(incremental_dockerfile_edit_keeps_build_edges);