ARCH: прикрепить debug MCP discovery
This commit is contained in:
@@ -92,7 +92,72 @@ describe("assistant address lane response runtime adapter", () => {
|
||||
capability_binding_response_guard: expect.objectContaining({
|
||||
schema_version: "assistant_capability_binding_response_guard_v1",
|
||||
applied: false
|
||||
})
|
||||
}),
|
||||
assistant_mcp_discovery_entry_point_v1: null,
|
||||
mcp_discovery_attempted: false,
|
||||
mcp_discovery_hot_runtime_wired: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("attaches MCP discovery summary from predecompose runtime meta without changing the reply", () => {
|
||||
const runtime = runAssistantAddressLaneResponseRuntime({
|
||||
sessionId: "asst-mcp",
|
||||
userMessage: "raw",
|
||||
effectiveAddressUserMessage: "raw",
|
||||
addressLane: {
|
||||
handled: true,
|
||||
reply_text: "answer",
|
||||
reply_type: "partial_coverage",
|
||||
debug: {}
|
||||
},
|
||||
llmPreDecomposeMeta: {
|
||||
mcpDiscoveryRuntimeEntryPoint: {
|
||||
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,
|
||||
answer_draft: { answer_mode: "confirmed_with_bounded_inference" }
|
||||
},
|
||||
reason_codes: ["runtime_entry_point_bridge_executed"]
|
||||
}
|
||||
},
|
||||
knownOrganizations: [],
|
||||
activeOrganization: null,
|
||||
sanitizeOutgoingAssistantText: (text) => String(text ?? ""),
|
||||
buildAddressDebugPayload: () => ({}),
|
||||
buildAddressFollowupOffer: () => null,
|
||||
mergeKnownOrganizations: (items) => items,
|
||||
toNonEmptyString: () => null,
|
||||
appendItem: () => {},
|
||||
getSession: () => ({ session_id: "asst-mcp", updated_at: "", items: [], investigation_state: null } as any),
|
||||
persistSession: () => {},
|
||||
cloneConversation: (items) => items,
|
||||
logEvent: () => {},
|
||||
messageIdFactory: () => "msg-mcp",
|
||||
finalizeAddressTurn: () => ({
|
||||
response: {
|
||||
ok: true
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
expect(runtime.response).toEqual({ ok: true });
|
||||
expect(runtime.debug).toEqual(
|
||||
expect.objectContaining({
|
||||
mcp_discovery_entry_status: "bridge_executed",
|
||||
mcp_discovery_attempted: true,
|
||||
mcp_discovery_bridge_status: "answer_draft_ready",
|
||||
mcp_discovery_answer_mode: "confirmed_with_bounded_inference",
|
||||
mcp_discovery_business_fact_answer_allowed: true,
|
||||
mcp_discovery_hot_runtime_wired: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -154,6 +154,9 @@ describe("assistant debug payload assembler", () => {
|
||||
binding_action: "observe_only"
|
||||
})
|
||||
);
|
||||
expect(payload.assistant_mcp_discovery_entry_point_v1).toBeNull();
|
||||
expect(payload.mcp_discovery_attempted).toBe(false);
|
||||
expect(payload.mcp_discovery_hot_runtime_wired).toBe(false);
|
||||
});
|
||||
|
||||
it("omits optional fields when they are not provided", () => {
|
||||
@@ -188,4 +191,35 @@ describe("assistant debug payload assembler", () => {
|
||||
expect(payload.answer_contract_stage4_v1?.legacy_blocks_present).toContain("Что сломано");
|
||||
expect(payload.answer_contract_stage4_v1?.legacy_blocks_present).toContain("Ограничения");
|
||||
});
|
||||
|
||||
it("attaches MCP discovery entry point summary when runtime meta provides it", () => {
|
||||
const input = baseInput();
|
||||
input.addressRuntimeMetaForDeep = {
|
||||
...input.addressRuntimeMetaForDeep,
|
||||
mcpDiscoveryRuntimeEntryPoint: {
|
||||
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,
|
||||
answer_draft: { answer_mode: "confirmed_with_bounded_inference" }
|
||||
},
|
||||
reason_codes: ["runtime_entry_point_bridge_executed"]
|
||||
}
|
||||
};
|
||||
|
||||
const payload = buildDeepAnalysisDebugPayload(input);
|
||||
|
||||
expect(payload.mcp_discovery_entry_status).toBe("bridge_executed");
|
||||
expect(payload.mcp_discovery_attempted).toBe(true);
|
||||
expect(payload.mcp_discovery_bridge_status).toBe("answer_draft_ready");
|
||||
expect(payload.mcp_discovery_answer_mode).toBe("confirmed_with_bounded_inference");
|
||||
expect(payload.mcp_discovery_business_fact_answer_allowed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
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,
|
||||
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_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_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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user