import { describe, expect, it } from "vitest"; import { attachAssistantMcpDiscoveryDebug } from "../src/services/assistantMcpDiscoveryDebugAttachment"; function entryPointContract(overrides: Record = {}) { 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_ranking", catalog_chain_template_matches: ["value_flow_ranking", "value_flow"], catalog_chain_template_alignment: { alignment_status: "selected_matches_top", top_chain_template_match: "value_flow_ranking", selected_chain_template_rank: 1, selected_chain_is_catalog_template: true, selected_chain_in_catalog_matches: true, selected_chain_matches_top: true } }, 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(false); expect(debug.mcp_discovery_bridge_status).toBe("answer_draft_ready"); expect(debug.mcp_discovery_selected_chain_id).toBe("value_flow_ranking"); expect(debug.mcp_discovery_catalog_chain_template_matches).toEqual(["value_flow_ranking", "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_ranking"); expect(debug.mcp_discovery_catalog_chain_selected_matches_top).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_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_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); }); });