MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / incremental_setup

Function incremental_setup

tests/test_incremental.c:219–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217/* ── Setup / Teardown ─────────────────────────────────────────────── */
218
219static int incremental_setup(void) {
220 snprintf(g_tmpdir, sizeof(g_tmpdir), "/tmp/cbm_incr_XXXXXX");
221 if (!cbm_mkdtemp(g_tmpdir))
222 return -1;
223
224 snprintf(g_repodir, sizeof(g_repodir), "%s/fastapi", g_tmpdir);
225
226 /* The fixture is cloned from the network at most once per machine, into a
227 * persistent cache; every run local-clones from there (seconds, offline).
228 * The one-time clone is staged and committed with an atomic rename so a
229 * torn download can never masquerade as a valid cache. */
230 const char *cache_home = getenv("CBM_TEST_FIXTURE_CACHE");
231 char cache_root[512];
232 if (cache_home && cache_home[0]) {
233 snprintf(cache_root, sizeof(cache_root), "%s", cache_home);
234 } else {
235 const char *home = getenv("HOME");
236 if (!home || !home[0])
237 home = ".";
238 snprintf(cache_root, sizeof(cache_root), "%s/.cache/cbm-test-fixtures", home);
239 }
240 char cache_repo[640];
241 snprintf(cache_repo, sizeof(cache_repo), "%s/fastapi-0.99.1", cache_root);
242 char cmd[1600];
243 if (!cbm_is_dir(cache_repo)) {
244 (void)cbm_mkdir_p(cache_root, 0700);
245 char cache_stage[700];
246 snprintf(cache_stage, sizeof(cache_stage), "%s.stage", cache_repo);
247 th_rmtree(cache_stage);
248 snprintf(cmd, sizeof(cmd),
249 "git clone --depth=1 --branch 0.99.1 --quiet "
250 "https://github.com/fastapi/fastapi.git '%s' 2>&1",
251 cache_stage);
252 int fetch_rc = system(cmd);
253 if (fetch_rc != 0 || rename(cache_stage, cache_repo) != 0) {
254 th_rmtree(cache_stage);
255 if (!cbm_is_dir(cache_repo)) {
256 printf(" fixture clone failed (rc=%d) — network offline?\n", fetch_rc);
257 return -1;
258 }
259 }
260 }
261 snprintf(cmd, sizeof(cmd), "git clone --quiet '%s' '%s' 2>&1", cache_repo, g_repodir);
262 int rc = system(cmd);
263 if (rc != 0) {
264 printf(" fixture local clone failed (rc=%d)\n", rc);
265 return -1;
266 }
267 /* Index the same corpus everywhere: CI historically indexed a sparse
268 * checkout without docs/ and tests/ (the assertion thresholds are sized
269 * for it) while local runs indexed the full tree — twice the files for
270 * the identical assertions, and a local/CI divergence. Trimming the two
271 * directories is the portable equivalent of that sparse profile. */
272 char trim[600];
273 snprintf(trim, sizeof(trim), "%s/docs", g_repodir);
274 th_rmtree(trim);
275 snprintf(trim, sizeof(trim), "%s/tests", g_repodir);
276 th_rmtree(trim);

Callers 1

test_incremental.cFile · 0.85

Calls 8

cbm_mkdtempFunction · 0.85
cbm_is_dirFunction · 0.85
cbm_mkdir_pFunction · 0.85
th_rmtreeFunction · 0.85
cbm_resolve_cache_dirFunction · 0.85
cbm_mcp_server_newFunction · 0.85
cbm_mem_rssFunction · 0.85

Tested by

no test coverage detected