Walk up from the file's parent directory to find the indexed project, then * check whether the file (repo-relative) is listed in its coverage report. * Mirrors ha_resolve_and_query: an MCP error means "not indexed here" → * climb; a valid project with no entry for this file → stop, no output. */
| 625 | * Mirrors ha_resolve_and_query: an MCP error means "not indexed here" → |
| 626 | * climb; a valid project with no entry for this file → stop, no output. */ |
| 627 | static char *ha_resolve_coverage(cbm_mcp_server_t *srv, const char *file_path) { |
| 628 | char dir[4096]; |
| 629 | snprintf(dir, sizeof(dir), "%s", file_path); |
| 630 | if (!ha_strip_last_component(dir)) { |
| 631 | return NULL; /* file directly at a root — nothing to resolve against */ |
| 632 | } |
| 633 | char project_root[4096]; |
| 634 | char *project = |
| 635 | ha_resolve_indexed_project_with_root(srv, dir, project_root, sizeof(project_root)); |
| 636 | if (!project) { |
| 637 | return NULL; |
| 638 | } |
| 639 | char canonical_file[4096]; |
| 640 | bool canonical = ha_canonical_path(file_path, canonical_file, sizeof(canonical_file)); |
| 641 | size_t root_len = strlen(project_root); |
| 642 | const char *rel = canonical && ha_path_contains(project_root, canonical_file) |
| 643 | ? canonical_file + root_len |
| 644 | : NULL; |
| 645 | if (rel && *rel == '/') { |
| 646 | rel++; |
| 647 | } |
| 648 | if (!rel || !rel[0]) { |
| 649 | free(project); |
| 650 | return NULL; |
| 651 | } |
| 652 | |
| 653 | yyjson_mut_doc *adoc = yyjson_mut_doc_new(NULL); |
| 654 | yyjson_mut_val *aroot = adoc ? yyjson_mut_obj(adoc) : NULL; |
| 655 | yyjson_mut_val *paths = adoc ? yyjson_mut_arr(adoc) : NULL; |
| 656 | if (!adoc || !aroot || !paths) { |
| 657 | if (adoc) { |
| 658 | yyjson_mut_doc_free(adoc); |
| 659 | } |
| 660 | free(project); |
| 661 | return NULL; |
| 662 | } |
| 663 | yyjson_mut_doc_set_root(adoc, aroot); |
| 664 | yyjson_mut_obj_add_str(adoc, aroot, "project", project); |
| 665 | yyjson_mut_arr_add_strcpy(adoc, paths, rel); |
| 666 | yyjson_mut_obj_add_val(adoc, aroot, "paths", paths); |
| 667 | yyjson_mut_obj_add_str(adoc, aroot, "format", "json"); |
| 668 | char *args = yyjson_mut_write(adoc, 0, NULL); |
| 669 | yyjson_mut_doc_free(adoc); |
| 670 | free(project); |
| 671 | if (!args) { |
| 672 | return NULL; |
| 673 | } |
| 674 | char *res = cbm_mcp_handle_tool(srv, "check_index_coverage", args); |
| 675 | free(args); |
| 676 | if (!res) { |
| 677 | return NULL; |
| 678 | } |
| 679 | bool is_error = false; |
| 680 | char *context = ha_coverage_context(res, rel, &is_error); |
| 681 | free(res); |
| 682 | return context; |
| 683 | } |
| 684 |
no test coverage detected