Track embedded migrations and verify the deployed schema and binary
This commit is contained in:
@@ -47,7 +47,7 @@ def main():
|
||||
viewer = (STATE / "viewer-a.token").read_text().strip()
|
||||
operator_b = (STATE / "operator-b.token").read_text().strip()
|
||||
asset, agent = str(uuid.uuid4()), str(uuid.uuid4())
|
||||
sql(f"INSERT INTO assets VALUES('{A}','{asset}'); INSERT INTO agent_installations(tenant_id,agent_id,asset_id,certificate_sha256,capabilities) VALUES('{A}','{agent}','{asset}','{secrets.token_hex(32)}','[\"run_script\",\"query_logs\"]');")
|
||||
sql(f"INSERT INTO assets VALUES('{A}','{asset}'); INSERT INTO agent_installations(tenant_id,agent_id,asset_id,certificate_sha256,capabilities) VALUES('{A}','{agent}','{asset}','{secrets.token_hex(32)}','[\"linux.base/1\",\"run_script\",\"query_logs\"]');")
|
||||
base = f"/api/v1/tenants/{A}"
|
||||
try:
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
@@ -120,13 +120,25 @@ def main():
|
||||
check(request("/mcp", "POST", {"jsonrpc": "2.0", "method": "notifications/initialized"}, operator, h)[0] == 202, "MCP initialized notification")
|
||||
result = request("/mcp", "POST", {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}, operator, h)[2]
|
||||
names = [x["name"] for x in result["result"]["tools"]]
|
||||
check(len(names) == 10 and not any("approv" in n or "authoriz" in n for n in names), "ten real MCP tools and no approval tool")
|
||||
check({"tenants.list","inventory.list_devices","inventory.get_device","updates.list_releases","monitoring.get_health","logs.query","operations.plan","operations.submit","jobs.get","jobs.cancel","sessions.request","scripts.list","scripts.publish","scripts.plan"} <= set(names) and not any("approv" in n or "authoriz" in n for n in names), "inventory, operations and script library exposed through MCP with no approval tool")
|
||||
call = {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "inventory.list_devices", "arguments": {"tenant_id": B}}}
|
||||
result = request("/mcp", "POST", call, operator, h)[2]["result"]
|
||||
check(result["isError"] and result["structuredContent"]["code"] == "NOT_FOUND", "MCP enforces same tenant boundary")
|
||||
call["params"] = {"name": "jobs.get", "arguments": {"tenant_id": A, "operation_id": pending["operation_id"]}}
|
||||
result = request("/mcp", "POST", call, operator, h)[2]["result"]["structuredContent"]
|
||||
check(result["approval_state"] == "pending_approval" and result["job_count"] == 0, "MCP jobs.get sees same persisted pending request")
|
||||
library_input = {"name": "contract-" + uuid.uuid4().hex, "expected_version": 0,
|
||||
"interpreter": "posix_sh", "execution_identity": "agent_service", "script_utf8": "printf 'catalog version 1\\n'\n"}
|
||||
call["params"] = {"name": "scripts.publish", "arguments": {"tenant_id": A, "input": library_input}}
|
||||
stored = request("/mcp", "POST", call, operator, h)[2]["result"]["structuredContent"]
|
||||
check(stored["version"] == 1 and stored["script_sha256"] == hashlib.sha256(library_input["script_utf8"].encode()).hexdigest(),
|
||||
"MCP publishes an immutable named revision")
|
||||
selection = {"targets": plan_input["targets"], "schedule": {"not_before": now.isoformat(), "start_before": end.isoformat()},
|
||||
"rollout": plan_input["rollout"], "reason": "library contract", "max_runtime_seconds": 60, "max_output_bytes": 4096}
|
||||
call["params"] = {"name": "scripts.plan", "arguments": {"tenant_id": A, "revision_id": stored["revision_id"], "input": selection}}
|
||||
library_plan = request("/mcp", "POST", call, operator, h)[2]["result"]["structuredContent"]
|
||||
reloaded = request(base + "/operation-plans/" + library_plan["plan_id"], token=operator)[2]
|
||||
check(reloaded["plan_payload"]["script_revision"]["revision_id"] == stored["revision_id"], "WebUI reads the same immutable MCP revision plan")
|
||||
call["params"]={"name":"operations.plan","arguments":{"tenant_id":A,"input":plan_input}}
|
||||
mcp_plan=request("/mcp","POST",call,operator,h)[2]["result"]["structuredContent"]
|
||||
check(mcp_plan["jobs"][0]["asset_id"]==asset,"MCP planning uses same exact DTO and fixed job contract")
|
||||
|
||||
Reference in New Issue
Block a user