NODEDC_1C/llm_normalizer/backend/tests/assistantMcpDiscoveryDebugA...

174 lines
8.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { attachAssistantMcpDiscoveryDebug } from "../src/services/assistantMcpDiscoveryDebugAttachment";
function entryPointContract(overrides: Record<string, unknown> = {}) {
return {
schema_version: "assistant_mcp_discovery_runtime_entry_point_v1",
policy_owner: "assistantMcpDiscoveryRuntimeEntryPoint",
entry_status: "bridge_executed",
hot_runtime_wired: false,
discovery_attempted: true,
turn_input: { adapter_status: "ready" },
bridge: {
bridge_status: "answer_draft_ready",
user_facing_response_allowed: true,
business_fact_answer_allowed: true,
requires_user_clarification: false,
planner: {
selected_chain_id: "value_flow",
evidence_plan: {
schema_version: "assistant_evidence_planner_v1",
policy_owner: "assistantEvidencePlanner",
planner_status: "ready_for_execution",
selected_chain_id: "value_flow",
evidence_axes: {
missing_axes: []
},
coverage_gate: {
expected_coverage: "confirmed_coverage"
},
answer_contract: {
answer_mode: "confirmed_business_answer"
}
},
catalog_chain_template_matches: ["value_flow"],
catalog_chain_template_alignment: {
alignment_status: "selected_matches_top",
top_chain_template_match: "value_flow",
selected_chain_template_rank: 1,
selected_chain_is_catalog_template: true,
selected_chain_in_catalog_matches: true,
selected_chain_matches_top: true
}
},
route_candidate: {
schema_version: "assistant_mcp_route_candidate_v1",
policy_owner: "assistantMcpDiscoveryRuntimeBridge",
candidate_status: "ready_for_reviewed_execution",
selected_chain_id: "value_flow",
selected_chain_summary: "Measure value flow",
nearest_catalog_chain_template: "value_flow",
catalog_alignment_status: "selected_matches_top",
business_fact_family: "value_flow",
action_family: "turnover",
proof_expectation: "coverage_checked_fact",
evidence_plan_status: "ready_for_execution",
evidence_answer_mode: "confirmed_business_answer",
evidence_expected_coverage: "confirmed_coverage",
required_axes: ["organization", "period"],
provided_axes: ["organization", "period"],
missing_axes: [],
executable_now: true,
enablement_reason: null,
recommended_next_action: "Execute through the reviewed runtime bridge and truth gate.",
forbidden_overclaim_flags: ["no_unchecked_fact_totals"]
},
execution_handoff: {
schema_version: "assistant_mcp_discovery_execution_handoff_v1",
policy_owner: "assistantMcpDiscoveryExecutionHandoff",
handoff_status: "ready_for_guarded_response",
selected_chain_id: "value_flow",
route_candidate_status: "ready_for_reviewed_execution",
evidence_answer_mode: "confirmed_business_answer",
evidence_expected_coverage: "confirmed_coverage",
pilot_status: "executed",
answer_mode: "confirmed_with_bounded_inference",
mcp_execution_performed: true,
allowed_hot_chain: true,
can_use_guarded_response: true,
must_keep_internal_mechanics_hidden: true,
reason_codes: ["execution_handoff_guarded_response_ready"]
},
answer_draft: {
answer_mode: "confirmed_with_bounded_inference"
}
},
reason_codes: ["runtime_entry_point_bridge_executed"],
...overrides
};
}
describe("assistant MCP discovery debug attachment", () => {
it("attaches a validated entry point contract and exposes summary flags", () => {
const debug = attachAssistantMcpDiscoveryDebug(
{ trace_id: "trace-1" },
{ addressRuntimeMeta: { mcpDiscoveryRuntimeEntryPoint: entryPointContract() } }
);
expect(debug.assistant_mcp_discovery_entry_point_v1?.schema_version).toBe(
"assistant_mcp_discovery_runtime_entry_point_v1"
);
expect(debug.mcp_discovery_entry_status).toBe("bridge_executed");
expect(debug.mcp_discovery_attempted).toBe(true);
expect(debug.mcp_discovery_hot_runtime_wired).toBe(true);
expect(debug.mcp_discovery_bridge_status).toBe("answer_draft_ready");
expect(debug.mcp_discovery_selected_chain_id).toBe("value_flow");
expect(debug.mcp_discovery_evidence_plan_status).toBe("ready_for_execution");
expect(debug.mcp_discovery_evidence_plan_answer_mode).toBe("confirmed_business_answer");
expect(debug.mcp_discovery_evidence_plan_expected_coverage).toBe("confirmed_coverage");
expect(debug.mcp_discovery_evidence_plan_missing_axes).toEqual([]);
expect(debug.mcp_discovery_catalog_chain_template_matches).toEqual(["value_flow"]);
expect(debug.mcp_discovery_catalog_chain_alignment_status).toBe("selected_matches_top");
expect(debug.mcp_discovery_catalog_chain_top_match).toBe("value_flow");
expect(debug.mcp_discovery_catalog_chain_selected_matches_top).toBe(true);
expect(debug.mcp_discovery_route_candidate_status).toBe("ready_for_reviewed_execution");
expect(debug.mcp_discovery_route_candidate_fact_family).toBe("value_flow");
expect(debug.mcp_discovery_route_candidate_action_family).toBe("turnover");
expect(debug.mcp_discovery_route_candidate_evidence_plan_status).toBe("ready_for_execution");
expect(debug.mcp_discovery_route_candidate_evidence_answer_mode).toBe("confirmed_business_answer");
expect(debug.mcp_discovery_route_candidate_evidence_expected_coverage).toBe("confirmed_coverage");
expect(debug.mcp_discovery_route_candidate_missing_axes).toEqual([]);
expect(debug.mcp_discovery_route_candidate_provided_axes).toEqual(["organization", "period"]);
expect(debug.mcp_discovery_route_candidate_executable_now).toBe(true);
expect(debug.mcp_discovery_route_candidate_next_action).toBe(
"Execute through the reviewed runtime bridge and truth gate."
);
expect(debug.mcp_discovery_execution_handoff_status).toBe("ready_for_guarded_response");
expect(debug.mcp_discovery_execution_handoff_allowed_hot_chain).toBe(true);
expect(debug.mcp_discovery_execution_handoff_can_use_guarded_response).toBe(true);
expect(debug.mcp_discovery_answer_mode).toBe("confirmed_with_bounded_inference");
expect(debug.mcp_discovery_business_fact_answer_allowed).toBe(true);
expect(debug.mcp_discovery_user_facing_response_allowed).toBe(true);
expect(debug.mcp_discovery_requires_clarification).toBe(false);
});
it("keeps safe null flags when no validated entry point exists", () => {
const debug = attachAssistantMcpDiscoveryDebug(
{ trace_id: "trace-1" },
{ addressRuntimeMeta: { mcpDiscoveryRuntimeEntryPoint: { schema_version: "wrong" } } }
);
expect(debug.assistant_mcp_discovery_entry_point_v1).toBeNull();
expect(debug.mcp_discovery_entry_status).toBeNull();
expect(debug.mcp_discovery_attempted).toBe(false);
expect(debug.mcp_discovery_hot_runtime_wired).toBe(false);
expect(debug.mcp_discovery_bridge_status).toBeNull();
expect(debug.mcp_discovery_selected_chain_id).toBeNull();
expect(debug.mcp_discovery_evidence_plan_v1).toBeNull();
expect(debug.mcp_discovery_evidence_plan_status).toBeNull();
expect(debug.mcp_discovery_evidence_plan_answer_mode).toBeNull();
expect(debug.mcp_discovery_evidence_plan_expected_coverage).toBeNull();
expect(debug.mcp_discovery_evidence_plan_missing_axes).toEqual([]);
expect(debug.mcp_discovery_catalog_chain_template_matches).toEqual([]);
expect(debug.mcp_discovery_catalog_chain_alignment_status).toBeNull();
expect(debug.mcp_discovery_catalog_chain_top_match).toBeNull();
expect(debug.mcp_discovery_catalog_chain_selected_matches_top).toBe(false);
expect(debug.mcp_discovery_route_candidate_v1).toBeNull();
expect(debug.mcp_discovery_route_candidate_status).toBeNull();
expect(debug.mcp_discovery_route_candidate_evidence_plan_status).toBeNull();
expect(debug.mcp_discovery_route_candidate_evidence_answer_mode).toBeNull();
expect(debug.mcp_discovery_route_candidate_evidence_expected_coverage).toBeNull();
expect(debug.mcp_discovery_route_candidate_missing_axes).toEqual([]);
expect(debug.mcp_discovery_route_candidate_provided_axes).toEqual([]);
expect(debug.mcp_discovery_route_candidate_executable_now).toBe(false);
expect(debug.mcp_discovery_execution_handoff_v1).toBeNull();
expect(debug.mcp_discovery_execution_handoff_status).toBeNull();
expect(debug.mcp_discovery_execution_handoff_allowed_hot_chain).toBe(false);
expect(debug.mcp_discovery_execution_handoff_can_use_guarded_response).toBe(false);
expect(debug.mcp_discovery_answer_mode).toBeNull();
expect(debug.mcp_discovery_business_fact_answer_allowed).toBe(false);
expect(debug.mcp_discovery_user_facing_response_allowed).toBe(false);
expect(debug.mcp_discovery_requires_clarification).toBe(false);
});
});