Each preview test starts from a real private index. Restore process state and * remove the fixture even when a deliberately RED check returns failure. */
| 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. */ |
| 4513 | static 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. */ |
no test coverage detected