| 496 | } |
| 497 | |
| 498 | static cbm_test_impact_status_t te_answer(te_ctx_t *c, cbm_test_result_t **out) { |
| 499 | cbm_test_result_rule_match_t *matches = |
| 500 | cbm_arena_calloc(&c->arena, (size_t)(c->match_count + 1) * sizeof(*matches)); |
| 501 | if (!matches) { |
| 502 | return CBM_TEST_IMPACT_OOM; |
| 503 | } |
| 504 | for (int i = 0; i < c->match_count; i++) { |
| 505 | matches[i] = (cbm_test_result_rule_match_t){.rule_index = c->matches[i].rule_index, |
| 506 | .target_resolved = c->matches[i].resolved}; |
| 507 | } |
| 508 | cbm_test_result_receipt_t receipt; |
| 509 | cbm_test_result_evidence_reason_t graph_reason = CBM_TEST_RESULT_EVIDENCE_PROVIDER_UNAVAILABLE; |
| 510 | te_receipt(c, &receipt, &graph_reason); |
| 511 | cbm_test_result_comparison_t comparison = !c->changes || !c->diff_complete |
| 512 | ? CBM_TEST_RESULT_COMPARISON_UNAVAILABLE |
| 513 | : c->has_changes ? CBM_TEST_RESULT_COMPARISON_CHANGED |
| 514 | : CBM_TEST_RESULT_COMPARISON_EMPTY; |
| 515 | if (comparison == CBM_TEST_RESULT_COMPARISON_UNAVAILABLE && c->fallback_count == 0 && |
| 516 | !te_fallback(c, CBM_TEST_RESULT_FALLBACK_GIT_UNAVAILABLE, "the change is not complete")) { |
| 517 | return CBM_TEST_IMPACT_OOM; |
| 518 | } |
| 519 | bool with_selection = c->selection && comparison == CBM_TEST_RESULT_COMPARISON_CHANGED; |
| 520 | cbm_test_result_input_t input = { |
| 521 | .comparison = comparison, |
| 522 | .selection = with_selection ? c->selection : NULL, |
| 523 | .model = with_selection ? c->model : NULL, |
| 524 | .policy = comparison == CBM_TEST_RESULT_COMPARISON_EMPTY ? NULL : c->policy, |
| 525 | .inventory_complete = c->snapshot_ok, |
| 526 | .activation_complete = c->activation_complete, |
| 527 | .matched_rules = comparison == CBM_TEST_RESULT_COMPARISON_EMPTY ? NULL : matches, |
| 528 | .matched_rule_count = |
| 529 | comparison == CBM_TEST_RESULT_COMPARISON_EMPTY ? 0 : (size_t)c->match_count, |
| 530 | .fallbacks = c->fallbacks, |
| 531 | .fallback_count = (size_t)c->fallback_count, |
| 532 | .warnings = c->warnings, |
| 533 | .warning_count = (size_t)c->warning_count, |
| 534 | .receipt = &receipt}; |
| 535 | cbm_test_result_limits_t limits = {.max_input_bytes = (uint64_t)1 << 30, |
| 536 | .max_items = (uint64_t)1 << 26, |
| 537 | .max_alloc_bytes = (size_t)1 << 30, |
| 538 | .max_output_bytes = (size_t)256 << 20}; |
| 539 | cbm_test_result_status_t status = cbm_test_result_build(&input, &limits, NULL, NULL, out); |
| 540 | if (status == CBM_TEST_RESULT_OOM) { |
| 541 | return CBM_TEST_IMPACT_OOM; |
| 542 | } |
| 543 | if (status != CBM_TEST_RESULT_OK) { |
| 544 | char text[64]; |
| 545 | snprintf(text, sizeof(text), "result codec status %d", (int)status); |
| 546 | te_note(c, text); |
| 547 | return CBM_TEST_IMPACT_INVALID; |
| 548 | } |
| 549 | return CBM_TEST_IMPACT_OK; |
| 550 | } |
| 551 | |
| 552 | /* ── The request ─────────────────────────────────────────────────── */ |
| 553 |
no test coverage detected