| 141 | /* ── Query-time configuration: the merge base's (M-4) ────────────── */ |
| 142 | |
| 143 | bool te_config(te_ctx_t *c) { |
| 144 | const char *path = c->rq->config_path; |
| 145 | char file[4200] = ""; |
| 146 | bool optional = false; |
| 147 | if (!path) { |
| 148 | snprintf(file, sizeof(file), "%s/merge-base-config.json", c->work_dir); |
| 149 | path = file; |
| 150 | optional = true; |
| 151 | cbm_git_blob_t blob; |
| 152 | cbm_git_facts_error_t error; |
| 153 | static const char name[] = ".codebase-memory.json"; |
| 154 | cbm_git_blob_status_t found = cbm_git_facts_read_blob( |
| 155 | c->facts, CBM_GIT_REV_MERGE_BASE, name, sizeof(name) - 1, &blob, &error); |
| 156 | if (found == CBM_GIT_BLOB_ERROR) { |
| 157 | return te_fallback(c, CBM_TEST_RESULT_FALLBACK_CONFIG_INVALID, |
| 158 | "the merge base's .codebase-memory.json could not be read") && |
| 159 | false; |
| 160 | } |
| 161 | if (found == CBM_GIT_BLOB_FOUND) { |
| 162 | FILE *f = cbm_fopen(file, "wb"); |
| 163 | bool ok = f && fwrite(blob.bytes.data, 1, blob.bytes.length, f) == blob.bytes.length; |
| 164 | if (f) { |
| 165 | ok = fclose(f) == 0 && ok; |
| 166 | } |
| 167 | if (!ok) { |
| 168 | return te_fallback(c, CBM_TEST_RESULT_FALLBACK_CONFIG_INVALID, |
| 169 | "the merge base's configuration could not be staged") && |
| 170 | false; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | c->config = cbm_test_config_load(path, optional); |
| 175 | if (optional) { |
| 176 | (void)cbm_unlink(file); /* only the merge-base copy staged above */ |
| 177 | } |
| 178 | if (!c->config) { |
| 179 | return te_fallback(c, CBM_TEST_RESULT_FALLBACK_CONFIG_INVALID, |
| 180 | "the test_impact configuration is invalid") && |
| 181 | false; |
| 182 | } |
| 183 | c->policy = cbm_test_policy_new(c->config); |
| 184 | if (!c->policy) { |
| 185 | return te_fallback(c, CBM_TEST_RESULT_FALLBACK_POLICY_UNAVAILABLE, |
| 186 | "the test_impact rules are invalid") && |
| 187 | false; |
| 188 | } |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | /* ── Classification of the changed paths ─────────────────────────── */ |
| 193 |
no test coverage detected