102 lines
6.9 KiB
Python
102 lines
6.9 KiB
Python
# #region Tooling.FullFlowMcpProfileMixin [C:3] [TYPE Module] [SEMANTICS test,scenario,execution,mcp]
|
|
# @BRIEF Exercise fresh MCP profiles using only server-issued questions and CAS identities.
|
|
# @INVARIANT All results originate from the real Docker backend API.
|
|
import json
|
|
from functools import partial
|
|
from common import Blocked
|
|
|
|
|
|
# #region Tooling.FullFlowMcpProfileMixin.McpProfileMixin [C:3] [TYPE Class]
|
|
# @BRIEF Keep the bounded verifier state and actual flow operations.
|
|
class McpProfileMixin:
|
|
# #region Tooling.FullFlowMcpProfileMixin.profile [C:3] [TYPE Function]
|
|
# @BRIEF Resolve only questions issued by a fresh external MCP profile.
|
|
def profile(self):
|
|
headers = {"Accept": "application/json, text/event-stream", "Content-Type": "application/json"}
|
|
rpc = partial(self._profile_rpc, headers)
|
|
rpc("mcp-initialize", {"jsonrpc":"2.0", "id":1, "method":"initialize", "params":{
|
|
"protocolVersion":"2025-03-26", "capabilities":{}, "clientInfo":{"name":"docker-full-flow-verifier","version":"1"}}})
|
|
headers["MCP-Protocol-Version"] = "2025-03-26"
|
|
rpc("mcp-initialized", {"jsonrpc":"2.0", "method":"notifications/initialized"})
|
|
unwrap = self._profile_unwrap
|
|
intent = {"environment_id":"full-flow-preprod", "dashboard_id":self.config.get("dashboard_id",1),
|
|
"objective":"Verify filtered sales revenue against approved baseline", "selected_case_ids":["C05"]}
|
|
structured = unwrap(rpc("mcp-propose-real-profile", {"jsonrpc":"2.0", "id":2, "method":"tools/call", "params":{
|
|
"name":"propose_test_pack_profile", "arguments":{"request":intent}}}))
|
|
self.require("mcp-profile-domain-proposal", structured.get("status") != "blocked" and isinstance(structured.get("profile"), dict),
|
|
response=structured)
|
|
profile = structured.get("profile", {})
|
|
coordinate = next((c for c in profile.get("coordinates",[]) if c.get("metric_name") == self.config.get("metric", "total_revenue")), None)
|
|
metric_questions = [q for q in profile.get("unresolved",[]) if q.get("kind") == "needs_metric"]
|
|
for number, question in enumerate(metric_questions, start=3):
|
|
self.require("profile-issued-metric-coordinate", coordinate is not None and coordinate["coordinate_id"] in question["coordinate_ids"])
|
|
request = {**intent, "profile_handle_id":structured["profile_handle_id"],
|
|
"expected_profile_digest":profile["profile_digest"], "expected_cas_version":structured["cas_version"],
|
|
"idempotency_key":"full-flow-metric-"+question["id"], "resolutions":[{
|
|
"unresolved_id":question["id"], "coordinate_id":coordinate["coordinate_id"], "reason":"Actual filtered revenue producer"}]}
|
|
structured = unwrap(rpc("mcp-resolve-issued-metric", {"jsonrpc":"2.0", "id":number, "method":"tools/call", "params":{
|
|
"name":"resolve_test_pack_profile", "arguments":{"request":request}}}))
|
|
profile = structured.get("profile", {})
|
|
baseline_questions = [q for q in profile.get("unresolved",[]) if q.get("kind") == "needs_baseline"]
|
|
for number, question in enumerate(baseline_questions, start=30):
|
|
self.require("profile-issued-baseline-coordinate", coordinate is not None and coordinate["coordinate_id"] in question["coordinate_ids"])
|
|
request = {**intent, "profile_handle_id":structured["profile_handle_id"],
|
|
"expected_profile_digest":profile["profile_digest"], "expected_cas_version":structured["cas_version"],
|
|
"idempotency_key":"full-flow-baseline-"+question["id"], "resolutions":[{
|
|
"kind":"needs_baseline", "unresolved_id":question["id"], "coordinate_id":coordinate["coordinate_id"],
|
|
"baseline_set":"full-flow-sales", "baseline_set_version":"1", "reference_url":self.config["reference_url"],
|
|
"reason":"Exact consumed and Git-published North revenue fixture"}]}
|
|
structured = unwrap(rpc("mcp-resolve-published-baseline", {"jsonrpc":"2.0", "id":number, "method":"tools/call", "params":{
|
|
"name":"resolve_test_pack_profile", "arguments":{"request":request}}}))
|
|
profile = structured.get("profile", {})
|
|
self.require("profile-baseline-selection-staged", bool(profile.get("baseline_selections")) and structured.get("status") == "preview_only")
|
|
self.record("T029a-profile-binding", "BLOCKED", actual_status=structured.get("status"),
|
|
baseline_questions=baseline_questions,
|
|
reason=("Profile selection remains authoring context; runnable baseline producer binding requires T029a"
|
|
if baseline_questions else "Fresh MCP proposal issued no legal needs_metric/needs_baseline question; published baseline locator cannot be submitted"))
|
|
|
|
# #endregion Tooling.FullFlowMcpProfileMixin.profile
|
|
|
|
# #region Tooling.FullFlowMcpProfileMixin.rpc [C:3] [TYPE Function]
|
|
# @BRIEF Validate the actual external JSON-RPC and MCP tool response.
|
|
def _profile_rpc(self, headers, name, payload):
|
|
response = self.client.post("/mcp/", json=payload, headers=headers)
|
|
if response.headers.get("mcp-session-id"):
|
|
headers["Mcp-Session-Id"] = response.headers["mcp-session-id"]
|
|
if not response.content:
|
|
value = {}
|
|
elif "text/event-stream" in response.headers.get("content-type", ""):
|
|
data = [line[6:] for line in response.text.splitlines() if line.startswith("data: ")]
|
|
value = json.loads(data[-1]) if data else {}
|
|
else:
|
|
value = response.json()
|
|
tool_error = value.get("result", {}).get("isError") is True
|
|
self.record(name, "PASS" if response.status_code in (200,202) and "error" not in value and not tool_error else "BLOCKED",
|
|
http_status=response.status_code, response=value)
|
|
if response.status_code not in (200,202) or "error" in value or tool_error:
|
|
raise Blocked(name)
|
|
return value
|
|
|
|
# #endregion Tooling.FullFlowMcpProfileMixin.rpc
|
|
|
|
# #region Tooling.FullFlowMcpProfileMixin.unwrap [C:3] [TYPE Function]
|
|
# @BRIEF Decode structured MCP domain results without hiding tool failures.
|
|
def _profile_unwrap(self, response):
|
|
result = response.get("result", {})
|
|
structured = result.get("structuredContent")
|
|
if not structured:
|
|
content = next((c["text"] for c in result.get("content",[]) if c.get("type") == "text"), "{}")
|
|
try:
|
|
structured = json.loads(content)
|
|
except json.JSONDecodeError:
|
|
self.record("mcp-tool-domain-response", "BLOCKED", error_text=content)
|
|
raise Blocked("MCP tool returned unstructured error text") from None
|
|
return structured
|
|
|
|
# #endregion Tooling.FullFlowMcpProfileMixin.unwrap
|
|
|
|
# #endregion Tooling.FullFlowMcpProfileMixin.McpProfileMixin
|
|
|
|
|
|
# #endregion Tooling.FullFlowMcpProfileMixin
|