android-decrypt-hub 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {android_decrypt_hub-0.2.0/src/android_decrypt_hub.egg-info → android_decrypt_hub-0.2.1}/PKG-INFO +3 -1
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/README.md +2 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/pyproject.toml +1 -1
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/__init__.py +1 -1
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/cli.py +1 -1
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/http_mcp.py +3 -1
- android_decrypt_hub-0.2.1/src/adh/observation.py +38 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/status.py +3 -2
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1/src/android_decrypt_hub.egg-info}/PKG-INFO +3 -1
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/SOURCES.txt +2 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/tests/test_agent_cli.py +71 -71
- android_decrypt_hub-0.2.1/tests/test_observation.py +67 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/LICENSE +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/MANIFEST.in +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/setup.cfg +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/__main__.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/config.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/endpoint.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/adh/stdio.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/dependency_links.txt +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/entry_points.txt +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/requires.txt +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/top_level.txt +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/tests/test_component_build.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/tests/test_config.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/tests/test_endpoint.py +0 -0
- {android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/tests/test_operations.py +0 -0
{android_decrypt_hub-0.2.0/src/android_decrypt_hub.egg-info → android_decrypt_hub-0.2.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: android-decrypt-hub
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Connect to Host ADH Daemon and bridge HTTP MCP to stdio
|
|
5
5
|
Author: DecryptHub
|
|
6
6
|
License: MIT
|
|
@@ -197,6 +197,8 @@ adh tools --json --endpoint http://127.0.0.1:8088
|
|
|
197
197
|
|
|
198
198
|
`status --json` 返回带 `schemaVersion: 1` 和 `checkedAt` 的只读快照,分别列出 `connections` 的服务在线事实及 `targets` 的应用/PID/目标标识;离线地址不会冒充在线目标。状态查询不保存地址、不注入、不启停应用,也不自动升级 CLI。`tools --json` 返回当前目标的真实 MCP 工具说明和参数 schema。先查询状态,再选择本次返回的唯一目标,最后通过现有 `call` 或持久 MCP 连接执行分析;多个候选必须让用户选择。
|
|
199
199
|
|
|
200
|
+
`configuration.source` 为 `explicit` 或 `saved`。显式 `--endpoint` 只检查传入地址,忽略已保存的地址。 桌面端可从同一个本机 stdio MCP 子进程收到有限的已验证使用回报。它不是工具输出,不改变权限、目标选择或调用逻辑;无相应回报时不能认定 AI 已使用。
|
|
201
|
+
|
|
200
202
|
ADH 省略端口时默认连接 8088;`devices --endpoint` 支持临时探测,`call` 收到 MCP 错误或 `isError` 时返回非零退出码。
|
|
201
203
|
|
|
202
204
|
## 开发验证
|
|
@@ -169,6 +169,8 @@ adh tools --json --endpoint http://127.0.0.1:8088
|
|
|
169
169
|
|
|
170
170
|
`status --json` 返回带 `schemaVersion: 1` 和 `checkedAt` 的只读快照,分别列出 `connections` 的服务在线事实及 `targets` 的应用/PID/目标标识;离线地址不会冒充在线目标。状态查询不保存地址、不注入、不启停应用,也不自动升级 CLI。`tools --json` 返回当前目标的真实 MCP 工具说明和参数 schema。先查询状态,再选择本次返回的唯一目标,最后通过现有 `call` 或持久 MCP 连接执行分析;多个候选必须让用户选择。
|
|
171
171
|
|
|
172
|
+
`configuration.source` 为 `explicit` 或 `saved`。显式 `--endpoint` 只检查传入地址,忽略已保存的地址。 桌面端可从同一个本机 stdio MCP 子进程收到有限的已验证使用回报。它不是工具输出,不改变权限、目标选择或调用逻辑;无相应回报时不能认定 AI 已使用。
|
|
173
|
+
|
|
172
174
|
ADH 省略端口时默认连接 8088;`devices --endpoint` 支持临时探测,`call` 收到 MCP 错误或 `isError` 时返回非零退出码。
|
|
173
175
|
|
|
174
176
|
## 开发验证
|
|
@@ -186,7 +186,7 @@ def _cmd_devices(args: argparse.Namespace) -> int:
|
|
|
186
186
|
|
|
187
187
|
def _cmd_status(args: argparse.Namespace) -> int:
|
|
188
188
|
endpoints = [HostEndpoint.from_url(value) for value in args.endpoint] if args.endpoint else load_saved_endpoints()
|
|
189
|
-
data = inventory(endpoints, timeout=args.timeout)
|
|
189
|
+
data = inventory(endpoints, timeout=args.timeout, source="explicit" if args.endpoint else "saved")
|
|
190
190
|
print(json.dumps(data, ensure_ascii=False, indent=2))
|
|
191
191
|
return 0
|
|
192
192
|
|
|
@@ -10,6 +10,7 @@ from urllib.error import HTTPError, URLError
|
|
|
10
10
|
from urllib.request import Request, urlopen
|
|
11
11
|
|
|
12
12
|
from . import __version__
|
|
13
|
+
from .observation import observe_result
|
|
13
14
|
from .endpoint import HostEndpoint
|
|
14
15
|
|
|
15
16
|
|
|
@@ -53,7 +54,8 @@ class MCPHTTPClient:
|
|
|
53
54
|
payload = response.read()
|
|
54
55
|
if response.status in (202, 204) or not payload:
|
|
55
56
|
return None
|
|
56
|
-
|
|
57
|
+
value = json.loads(payload)
|
|
58
|
+
return observe_result(message, value, request.full_url, response.geturl())
|
|
57
59
|
except HTTPError as exc:
|
|
58
60
|
detail = exc.read().decode("utf-8", errors="replace")
|
|
59
61
|
raise MCPTransportError(
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Opt-in, read-only receipt metadata for the owning desktop."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
_META_KEY = "decrypthub/usage"
|
|
9
|
+
_NONCE = re.compile(r"[0-9a-f]{32}")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def observe_result(
|
|
13
|
+
request: Any, response: Any, endpoint: str, response_url: str
|
|
14
|
+
) -> Any:
|
|
15
|
+
"""Stamp the service that answered this tool call, without changing routing."""
|
|
16
|
+
nonce = os.environ.get("DECRYPTHUB_MCP_OBSERVATION", "")
|
|
17
|
+
if not _NONCE.fullmatch(nonce) or not isinstance(request, dict) or request.get("method") != "tools/call":
|
|
18
|
+
return response
|
|
19
|
+
if not isinstance(response, dict) or "error" in response:
|
|
20
|
+
return response
|
|
21
|
+
result = response.get("result")
|
|
22
|
+
if "id" not in request or response.get("id") != request["id"] or not isinstance(result, dict):
|
|
23
|
+
return response
|
|
24
|
+
incoming = result.get("_meta")
|
|
25
|
+
metadata = dict(incoming) if isinstance(incoming, dict) else {}
|
|
26
|
+
# The remote service cannot report on behalf of the local CLI.
|
|
27
|
+
metadata.pop(_META_KEY, None)
|
|
28
|
+
if response_url == endpoint and result.get("isError") is not True and isinstance(result.get("content"), list):
|
|
29
|
+
metadata[_META_KEY] = {
|
|
30
|
+
"schemaVersion": 1,
|
|
31
|
+
"nonce": nonce,
|
|
32
|
+
"component": "adh",
|
|
33
|
+
"target": {"kind": "service", "id": endpoint, "endpoint": endpoint},
|
|
34
|
+
}
|
|
35
|
+
value = {key: item for key, item in result.items() if key != "_meta"}
|
|
36
|
+
if metadata:
|
|
37
|
+
value["_meta"] = metadata
|
|
38
|
+
return {**response, "result": value}
|
|
@@ -10,7 +10,7 @@ from .endpoint import HostEndpoint
|
|
|
10
10
|
from .http_mcp import probe_endpoint
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def inventory(endpoints: list[HostEndpoint], *, timeout: float = 3.0) -> dict[str, Any]:
|
|
13
|
+
def inventory(endpoints: list[HostEndpoint], *, timeout: float = 3.0, source: str = "explicit") -> dict[str, Any]:
|
|
14
14
|
unique = list({endpoint.key: endpoint for endpoint in endpoints}.values())
|
|
15
15
|
with ThreadPoolExecutor(max_workers=max(1, min(8, len(unique)))) as pool:
|
|
16
16
|
checked = list(pool.map(lambda endpoint: probe_endpoint(endpoint, timeout=timeout), unique))
|
|
@@ -29,4 +29,5 @@ def inventory(endpoints: list[HostEndpoint], *, timeout: float = 3.0) -> dict[st
|
|
|
29
29
|
"package": app.get("package"), "pid": app.get("pid"),
|
|
30
30
|
"endpoint": endpoint.mcp_url, "online": online and app.get("online") is True})
|
|
31
31
|
return {"schemaVersion": 1, "component": "adh", "version": __version__,
|
|
32
|
-
"checkedAt": datetime.now(timezone.utc).isoformat(), "connections": connections, "targets": targets
|
|
32
|
+
"checkedAt": datetime.now(timezone.utc).isoformat(), "connections": connections, "targets": targets,
|
|
33
|
+
"configuration": {"source": source, "endpoints": [endpoint.mcp_url for endpoint in checked]}}
|
{android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1/src/android_decrypt_hub.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: android-decrypt-hub
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Connect to Host ADH Daemon and bridge HTTP MCP to stdio
|
|
5
5
|
Author: DecryptHub
|
|
6
6
|
License: MIT
|
|
@@ -197,6 +197,8 @@ adh tools --json --endpoint http://127.0.0.1:8088
|
|
|
197
197
|
|
|
198
198
|
`status --json` 返回带 `schemaVersion: 1` 和 `checkedAt` 的只读快照,分别列出 `connections` 的服务在线事实及 `targets` 的应用/PID/目标标识;离线地址不会冒充在线目标。状态查询不保存地址、不注入、不启停应用,也不自动升级 CLI。`tools --json` 返回当前目标的真实 MCP 工具说明和参数 schema。先查询状态,再选择本次返回的唯一目标,最后通过现有 `call` 或持久 MCP 连接执行分析;多个候选必须让用户选择。
|
|
199
199
|
|
|
200
|
+
`configuration.source` 为 `explicit` 或 `saved`。显式 `--endpoint` 只检查传入地址,忽略已保存的地址。 桌面端可从同一个本机 stdio MCP 子进程收到有限的已验证使用回报。它不是工具输出,不改变权限、目标选择或调用逻辑;无相应回报时不能认定 AI 已使用。
|
|
201
|
+
|
|
200
202
|
ADH 省略端口时默认连接 8088;`devices --endpoint` 支持临时探测,`call` 收到 MCP 错误或 `isError` 时返回非零退出码。
|
|
201
203
|
|
|
202
204
|
## 开发验证
|
{android_decrypt_hub-0.2.0 → android_decrypt_hub-0.2.1}/src/android_decrypt_hub.egg-info/SOURCES.txt
RENAMED
|
@@ -8,6 +8,7 @@ src/adh/cli.py
|
|
|
8
8
|
src/adh/config.py
|
|
9
9
|
src/adh/endpoint.py
|
|
10
10
|
src/adh/http_mcp.py
|
|
11
|
+
src/adh/observation.py
|
|
11
12
|
src/adh/status.py
|
|
12
13
|
src/adh/stdio.py
|
|
13
14
|
src/android_decrypt_hub.egg-info/PKG-INFO
|
|
@@ -20,4 +21,5 @@ tests/test_agent_cli.py
|
|
|
20
21
|
tests/test_component_build.py
|
|
21
22
|
tests/test_config.py
|
|
22
23
|
tests/test_endpoint.py
|
|
24
|
+
tests/test_observation.py
|
|
23
25
|
tests/test_operations.py
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
import subprocess
|
|
5
|
-
import sys
|
|
6
|
-
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
7
|
-
from threading import Thread
|
|
8
|
-
|
|
9
|
-
import pytest
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@pytest.fixture
|
|
13
|
-
def host():
|
|
14
|
-
class Handler(BaseHTTPRequestHandler):
|
|
15
|
-
def log_message(self, *args):
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
def do_GET(self):
|
|
19
|
-
self.send_response(200)
|
|
20
|
-
self.end_headers()
|
|
21
|
-
self.wfile.write(json.dumps({"ok": True, "service": "adhd", "version": "test", "apps": [
|
|
22
|
-
{"package": "com.example.live", "sessionId": "live-session", "pid": 42, "online": True},
|
|
23
|
-
{"package": "com.example.old", "sessionId": "old-session", "pid": 43, "online": False},
|
|
24
|
-
]}).encode())
|
|
25
|
-
|
|
26
|
-
def do_POST(self):
|
|
27
|
-
data = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
|
|
28
|
-
result = {"tools": [{"name": "sessions", "description": "Live sessions", "inputSchema": {"type": "object"}}]} if data["method"] == "tools/list" else {"isError": True, "content": []}
|
|
29
|
-
self.send_response(200)
|
|
30
|
-
self.end_headers()
|
|
31
|
-
self.wfile.write(json.dumps({"jsonrpc": "2.0", "id": data["id"], "result": result}).encode())
|
|
32
|
-
|
|
33
|
-
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
34
|
-
thread = Thread(target=server.serve_forever, daemon=True)
|
|
35
|
-
thread.start()
|
|
36
|
-
yield f"http://127.0.0.1:{server.server_port}"
|
|
37
|
-
server.shutdown()
|
|
38
|
-
server.server_close()
|
|
39
|
-
thread.join()
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def run(tmp_path, *args):
|
|
43
|
-
env = {**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[1] / "src"),
|
|
44
|
-
"ADH_CONFIG_PATH": str(tmp_path / "connections.json"), "PYTHONIOENCODING": "utf-8"}
|
|
45
|
-
return subprocess.run([sys.executable, "-m", "adh", *args], env=env, capture_output=True, text=True, encoding="utf-8", timeout=15)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_status_reads_actual_health_without_saving_or_claiming_an_old_session_online(tmp_path, host):
|
|
49
|
-
result = run(tmp_path, "status", "--endpoint", host, "--json")
|
|
50
|
-
assert result.returncode == 0, result.stderr
|
|
51
|
-
status = json.loads(result.stdout)
|
|
52
|
-
assert status["component"] == "adh" and status["schemaVersion"] == 1
|
|
53
|
-
assert status["connections"][0]["online"] is True
|
|
54
|
-
assert [(row["id"], row["online"]) for row in status["targets"]] == [("live-session", True), ("old-session", False)]
|
|
55
|
-
assert not (tmp_path / "connections.json").exists()
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def test_unreachable_host_is_an_observation_not_a_fake_target(tmp_path):
|
|
59
|
-
result = run(tmp_path, "status", "--endpoint", "127.0.0.1:1", "--timeout", "0.1", "--json")
|
|
60
|
-
assert result.returncode == 0, result.stderr
|
|
61
|
-
status = json.loads(result.stdout)
|
|
62
|
-
assert status["connections"][0]["online"] is False
|
|
63
|
-
assert status["targets"] == []
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def test_tools_returns_real_schema_and_call_failure_has_nonzero_exit(tmp_path, host):
|
|
67
|
-
result = run(tmp_path, "tools", "--endpoint", host, "--json")
|
|
68
|
-
assert result.returncode == 0, result.stderr
|
|
69
|
-
assert json.loads(result.stdout)["tools"][0]["inputSchema"] == {"type": "object"}
|
|
70
|
-
result = run(tmp_path, "call", "failure", "--endpoint", host, "--json")
|
|
71
|
-
assert result.returncode == 1
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
7
|
+
from threading import Thread
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def host():
|
|
14
|
+
class Handler(BaseHTTPRequestHandler):
|
|
15
|
+
def log_message(self, *args):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def do_GET(self):
|
|
19
|
+
self.send_response(200)
|
|
20
|
+
self.end_headers()
|
|
21
|
+
self.wfile.write(json.dumps({"ok": True, "service": "adhd", "version": "test", "apps": [
|
|
22
|
+
{"package": "com.example.live", "sessionId": "live-session", "pid": 42, "online": True},
|
|
23
|
+
{"package": "com.example.old", "sessionId": "old-session", "pid": 43, "online": False},
|
|
24
|
+
]}).encode())
|
|
25
|
+
|
|
26
|
+
def do_POST(self):
|
|
27
|
+
data = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
|
|
28
|
+
result = {"tools": [{"name": "sessions", "description": "Live sessions", "inputSchema": {"type": "object"}}]} if data["method"] == "tools/list" else {"isError": True, "content": []}
|
|
29
|
+
self.send_response(200)
|
|
30
|
+
self.end_headers()
|
|
31
|
+
self.wfile.write(json.dumps({"jsonrpc": "2.0", "id": data["id"], "result": result}).encode())
|
|
32
|
+
|
|
33
|
+
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
34
|
+
thread = Thread(target=server.serve_forever, daemon=True)
|
|
35
|
+
thread.start()
|
|
36
|
+
yield f"http://127.0.0.1:{server.server_port}"
|
|
37
|
+
server.shutdown()
|
|
38
|
+
server.server_close()
|
|
39
|
+
thread.join()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run(tmp_path, *args):
|
|
43
|
+
env = {**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[1] / "src"),
|
|
44
|
+
"ADH_CONFIG_PATH": str(tmp_path / "connections.json"), "PYTHONIOENCODING": "utf-8"}
|
|
45
|
+
return subprocess.run([sys.executable, "-m", "adh", *args], env=env, capture_output=True, text=True, encoding="utf-8", timeout=15)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_status_reads_actual_health_without_saving_or_claiming_an_old_session_online(tmp_path, host):
|
|
49
|
+
result = run(tmp_path, "status", "--endpoint", host, "--json")
|
|
50
|
+
assert result.returncode == 0, result.stderr
|
|
51
|
+
status = json.loads(result.stdout)
|
|
52
|
+
assert status["component"] == "adh" and status["schemaVersion"] == 1
|
|
53
|
+
assert status["connections"][0]["online"] is True
|
|
54
|
+
assert [(row["id"], row["online"]) for row in status["targets"]] == [("live-session", True), ("old-session", False)]
|
|
55
|
+
assert not (tmp_path / "connections.json").exists()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_unreachable_host_is_an_observation_not_a_fake_target(tmp_path):
|
|
59
|
+
result = run(tmp_path, "status", "--endpoint", "127.0.0.1:1", "--timeout", "0.1", "--json")
|
|
60
|
+
assert result.returncode == 0, result.stderr
|
|
61
|
+
status = json.loads(result.stdout)
|
|
62
|
+
assert status["connections"][0]["online"] is False
|
|
63
|
+
assert status["targets"] == []
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_tools_returns_real_schema_and_call_failure_has_nonzero_exit(tmp_path, host):
|
|
67
|
+
result = run(tmp_path, "tools", "--endpoint", host, "--json")
|
|
68
|
+
assert result.returncode == 0, result.stderr
|
|
69
|
+
assert json.loads(result.stdout)["tools"][0]["inputSchema"] == {"type": "object"}
|
|
70
|
+
result = run(tmp_path, "call", "failure", "--endpoint", host, "--json")
|
|
71
|
+
assert result.returncode == 1
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Connection receipts are only produced at a verified local HTTP response."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
from adh.http_mcp import MCPHTTPClient
|
|
7
|
+
from adh.endpoint import HostEndpoint
|
|
8
|
+
from adh.status import inventory
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_status_keeps_configuration_separate_from_live_inventory():
|
|
12
|
+
assert inventory([], source="explicit")["configuration"] == {
|
|
13
|
+
"source": "explicit",
|
|
14
|
+
"endpoints": [],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_receipt_tracks_the_actual_responding_service(monkeypatch):
|
|
19
|
+
a = HostEndpoint.from_url("http://127.0.0.1:49301")
|
|
20
|
+
b = HostEndpoint.from_url("http://127.0.0.1:49302")
|
|
21
|
+
nonce = "9e" * 16
|
|
22
|
+
request = {"jsonrpc": "2.0", "id": 7, "method": "tools/call", "params": {"name": "fixture"}}
|
|
23
|
+
result = {
|
|
24
|
+
"jsonrpc": "2.0",
|
|
25
|
+
"id": 7,
|
|
26
|
+
"result": {
|
|
27
|
+
"content": [{"type": "text", "text": "fixture"}],
|
|
28
|
+
"_meta": {"unrelated": "retained", "decrypthub/usage": {"endpoint": b.mcp_url}},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class Response:
|
|
33
|
+
headers = {}
|
|
34
|
+
status = 200
|
|
35
|
+
url = a.mcp_url
|
|
36
|
+
|
|
37
|
+
def read(self):
|
|
38
|
+
return json.dumps(result).encode()
|
|
39
|
+
|
|
40
|
+
def geturl(self):
|
|
41
|
+
return self.url
|
|
42
|
+
|
|
43
|
+
def __enter__(self):
|
|
44
|
+
return self
|
|
45
|
+
|
|
46
|
+
def __exit__(self, *_args):
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
response = Response()
|
|
50
|
+
monkeypatch.setattr("adh.http_mcp.urlopen", lambda *_a, **_k: response)
|
|
51
|
+
client = MCPHTTPClient(a)
|
|
52
|
+
monkeypatch.delenv("DECRYPTHUB_MCP_OBSERVATION", raising=False)
|
|
53
|
+
assert client.send(request) == result
|
|
54
|
+
monkeypatch.setenv("DECRYPTHUB_MCP_OBSERVATION", nonce)
|
|
55
|
+
received = client.send(request)["result"]["_meta"]
|
|
56
|
+
assert received["unrelated"] == "retained"
|
|
57
|
+
assert received["decrypthub/usage"] == {
|
|
58
|
+
"schemaVersion": 1,
|
|
59
|
+
"nonce": nonce,
|
|
60
|
+
"component": "adh",
|
|
61
|
+
"target": {"kind": "service", "id": a.mcp_url, "endpoint": a.mcp_url},
|
|
62
|
+
}
|
|
63
|
+
response.url = b.mcp_url
|
|
64
|
+
assert client.send(request)["result"]["_meta"] == {"unrelated": "retained"}
|
|
65
|
+
response.url = a.mcp_url
|
|
66
|
+
result["result"]["isError"] = True
|
|
67
|
+
assert client.send(request)["result"]["_meta"] == {"unrelated": "retained"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|