Build the success portion of the index_repository response. * Returns true when status should be "degraded" (#334 plausibility gate). */
| 7448 | /* Build the success portion of the index_repository response. |
| 7449 | * Returns true when status should be "degraded" (#334 plausibility gate). */ |
| 7450 | static bool build_index_success_response(cbm_mcp_server_t *srv, yyjson_mut_doc *doc, |
| 7451 | yyjson_mut_val *root, const char *project_name, |
| 7452 | const char *repo_path, bool persistence, cbm_pipeline_t *p, |
| 7453 | char **excluded_dirs, int excluded_count, |
| 7454 | const cbm_file_error_t *file_errors, int file_error_count, |
| 7455 | const char *logfile) { |
| 7456 | add_excluded_summary(doc, root, excluded_dirs, excluded_count); |
| 7457 | add_not_indexed_files_summary(doc, root, p); |
| 7458 | |
| 7459 | int exp_nodes = -1; |
| 7460 | int exp_edges = -1; |
| 7461 | cbm_pipeline_get_committed_counts(p, &exp_nodes, &exp_edges); |
| 7462 | |
| 7463 | const double ratio = cbm_dump_verify_min_ratio(); |
| 7464 | const int min_floor = CBM_DUMP_VERIFY_MIN_FLOOR; |
| 7465 | |
| 7466 | cbm_store_t *store = resolve_store(srv, project_name); |
| 7467 | if (!store || !add_persisted_failure_summaries(doc, root, store, project_name, logfile)) { |
| 7468 | add_skipped_summary(doc, root, file_errors, file_error_count, logfile); |
| 7469 | add_parse_partial_summary(doc, root, file_errors, file_error_count); |
| 7470 | } |
| 7471 | int nodes = 0; |
| 7472 | int edges = 0; |
| 7473 | bool degraded = false; |
| 7474 | |
| 7475 | if (!store) { |
| 7476 | degraded = true; |
| 7477 | } else { |
| 7478 | nodes = cbm_store_count_nodes(store, project_name); |
| 7479 | edges = cbm_store_count_edges(store, project_name); |
| 7480 | if (nodes < 0) { |
| 7481 | degraded = true; |
| 7482 | nodes = 0; |
| 7483 | edges = edges >= 0 ? edges : 0; |
| 7484 | } else if (cbm_dump_verify_is_degraded(exp_nodes, nodes, ratio, min_floor)) { |
| 7485 | (void)cbm_store_checkpoint(store); |
| 7486 | int nodes2 = cbm_store_count_nodes(store, project_name); |
| 7487 | int edges2 = cbm_store_count_edges(store, project_name); |
| 7488 | if (nodes2 >= 0) { |
| 7489 | nodes = nodes2; |
| 7490 | } |
| 7491 | if (edges2 >= 0) { |
| 7492 | edges = edges2; |
| 7493 | } |
| 7494 | degraded = cbm_dump_verify_is_degraded(exp_nodes, nodes, ratio, min_floor); |
| 7495 | } |
| 7496 | } |
| 7497 | |
| 7498 | yyjson_mut_obj_add_int(doc, root, "nodes", nodes); |
| 7499 | yyjson_mut_obj_add_int(doc, root, "edges", edges); |
| 7500 | if (exp_nodes >= 0) { |
| 7501 | yyjson_mut_obj_add_int(doc, root, "expected_nodes", exp_nodes); |
| 7502 | yyjson_mut_obj_add_int(doc, root, "expected_edges", exp_edges); |
| 7503 | } |
| 7504 | |
| 7505 | if (degraded) { |
| 7506 | if (!store) { |
| 7507 | yyjson_mut_obj_add_str(doc, root, "hint", |
no test coverage detected