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

Function dm_preview_fixture

tests/test_doc_mentions.c:4513–4548  ·  view source on GitHub ↗

Each preview test starts from a real private index. Restore process state and * remove the fixture even when a deliberately RED check returns failure. */

Source from the content-addressed store, hash-verified

4511/* Each preview test starts from a real private index. Restore process state and
4512 * remove the fixture even when a deliberately RED check returns failure. */
4513static int dm_preview_fixture(int (*check)(const char *db, const char *project)) {
4514 char tmp[256] = "/tmp/cbm_dm_preview_XXXXXX";
4515 if (!cbm_mkdtemp(tmp)) {
4516 return 1;
4517 }
4518 char repo[400], cache_dir[400], db[1024];
4519 snprintf(repo, sizeof(repo), "%s/repo", tmp);
4520 snprintf(cache_dir, sizeof(cache_dir), "%s/cache", tmp);
4521 dm_write_resolver_fixture(repo);
4522 cbm_mkdir_p(cache_dir, 0700);
4523 char *project = cbm_project_name_from_path(repo);
4524 const char *saved = getenv("CBM_CACHE_DIR");
4525 char *saved_copy = saved ? strdup(saved) : NULL;
4526 if (!project || (saved && !saved_copy)) {
4527 free(project);
4528 free(saved_copy);
4529 th_rmtree(tmp);
4530 return 1;
4531 }
4532 snprintf(db, sizeof(db), "%s/%s.db", cache_dir, project);
4533 cbm_setenv("CBM_CACHE_DIR", cache_dir, 1);
4534 int rc = dm_index(repo, db, NULL);
4535 if (rc == 0) {
4536 rc = check(db, project);
4537 }
4538 if (saved_copy) {
4539 cbm_setenv("CBM_CACHE_DIR", saved_copy, 1);
4540 } else {
4541 cbm_unsetenv("CBM_CACHE_DIR");
4542 }
4543 free(saved_copy);
4544 dm_unlink_db(db);
4545 free(project);
4546 th_rmtree(tmp);
4547 return rc;
4548}
4549
4550/* Return the actual MCP envelope, including structuredContent for JSON, so a
4551 * test exercises both transport boundaries instead of a formatter in isolation. */

Callers 1

Calls 10

cbm_mkdtempFunction · 0.85
cbm_mkdir_pFunction · 0.85
th_rmtreeFunction · 0.85
cbm_setenvFunction · 0.85
dm_indexFunction · 0.85
cbm_unsetenvFunction · 0.85
dm_unlink_dbFunction · 0.85
checkFunction · 0.70

Tested by

no test coverage detected