Set up: create project, index it through MCP (production flow) */
| 97 | |
| 98 | /* Set up: create project, index it through MCP (production flow) */ |
| 99 | static int integration_setup(void) { |
| 100 | if (create_test_project() != 0) |
| 101 | return -1; |
| 102 | |
| 103 | /* Derive project name (same logic the pipeline uses) */ |
| 104 | g_project = cbm_project_name_from_path(g_tmpdir); |
| 105 | if (!g_project) |
| 106 | return -1; |
| 107 | |
| 108 | /* Build db path for direct store queries (pipeline writes here) */ |
| 109 | const char *home = getenv("HOME"); |
| 110 | if (!home) |
| 111 | home = "/tmp"; |
| 112 | snprintf(g_dbpath, sizeof(g_dbpath), "%s/.cache/codebase-memory-mcp/%s.db", home, g_project); |
| 113 | |
| 114 | /* Ensure cache dir exists */ |
| 115 | char cache_dir[512]; |
| 116 | snprintf(cache_dir, sizeof(cache_dir), "%s/.cache/codebase-memory-mcp", home); |
| 117 | cbm_mkdir(cache_dir); |
| 118 | |
| 119 | /* Remove stale db from previous test runs */ |
| 120 | unlink(g_dbpath); |
| 121 | |
| 122 | /* Create MCP server, then index through it (production flow): |
| 123 | * 1. Server starts with in-memory store |
| 124 | * 2. index_repository closes in-memory store |
| 125 | * 3. Pipeline runs → dumps to ~/.cache/.../<project>.db |
| 126 | * 4. Server reopens from that db |
| 127 | * This exercises the exact same path as real usage. */ |
| 128 | g_srv = cbm_mcp_server_new(NULL); |
| 129 | if (!g_srv) |
| 130 | return -1; |
| 131 | |
| 132 | /* Index our temp project via MCP tool handler */ |
| 133 | char args[512]; |
| 134 | snprintf(args, sizeof(args), "{\"repo_path\":\"%s\"}", g_tmpdir); |
| 135 | char *resp = cbm_mcp_handle_tool(g_srv, "index_repository", args); |
| 136 | if (!resp) |
| 137 | return -1; |
| 138 | |
| 139 | /* Verify indexing succeeded */ |
| 140 | bool ok = strstr(resp, "indexed") != NULL; |
| 141 | free(resp); |
| 142 | return ok ? 0 : -1; |
| 143 | } |
| 144 | |
| 145 | static void integration_teardown(void) { |
| 146 | if (g_srv) { |
no test coverage detected