axor-proxy 0.6.2__tar.gz → 0.7.0__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.
Files changed (38) hide show
  1. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/PKG-INFO +1 -1
  2. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/pyproject.toml +1 -1
  3. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/agent.py +7 -2
  4. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/app.py +34 -11
  5. axor_proxy-0.7.0/tests/test_hosted_demo.py +124 -0
  6. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/.gitignore +0 -0
  7. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/README.md +0 -0
  8. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/__init__.py +0 -0
  9. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/errors.py +0 -0
  10. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/governed.py +0 -0
  11. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/guard.py +0 -0
  12. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/main.py +0 -0
  13. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/mcp.py +0 -0
  14. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/mock_tools.py +0 -0
  15. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/recorder.py +0 -0
  16. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/run_cli.py +0 -0
  17. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/runs.py +0 -0
  18. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/stdio_mcp.py +0 -0
  19. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/stdio_mock.py +0 -0
  20. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/upload.py +0 -0
  21. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/src/axor_proxy/vault.py +0 -0
  22. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_concurrent_runs.py +0 -0
  23. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_control_auth.py +0 -0
  24. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_core_compatibility.py +0 -0
  25. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_examples_hook.py +0 -0
  26. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_governed.py +0 -0
  27. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_governed_proxy.py +0 -0
  28. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_governed_tree.py +0 -0
  29. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_guard.py +0 -0
  30. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_mcp.py +0 -0
  31. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_proxy.py +0 -0
  32. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_run_cli.py +0 -0
  33. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_simulate.py +0 -0
  34. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_stdio_mcp.py +0 -0
  35. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_streaming.py +0 -0
  36. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_upload.py +0 -0
  37. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_vault_colocation.py +0 -0
  38. {axor_proxy-0.6.2 → axor_proxy-0.7.0}/tests/test_vault_injection.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: axor-proxy
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: Observe-only tool proxy: passthrough auth, fault injection, trace recording.
5
5
  Project-URL: Homepage, https://github.com/Bucha11/axor-control-plane
6
6
  Project-URL: Documentation, https://github.com/Bucha11/axor-control-plane#readme
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "axor-proxy"
3
- version = "0.6.2"
3
+ version = "0.7.0"
4
4
  description = "Observe-only tool proxy: passthrough auth, fault injection, trace recording."
5
5
  requires-python = ">=3.12"
6
6
  readme = "README.md"
@@ -41,9 +41,14 @@ def default_claim(faults: list[dict[str, Any]]) -> dict[str, Any]:
41
41
  class ScriptedAgent:
42
42
  """Drives a run to completion over the proxy's own HTTP surface."""
43
43
 
44
- def __init__(self, base_url: str, client: httpx.AsyncClient) -> None:
44
+ def __init__(self, base_url: str, client: httpx.AsyncClient,
45
+ control_token: str | None = None) -> None:
45
46
  self._base = base_url.rstrip("/")
46
47
  self._client = client
48
+ # The claim goes to this proxy's own control surface (/axor/...), which
49
+ # a proxy with AXOR_PROXY_TOKEN guards: without the token the claim was
50
+ # refused and the in-app experiment never finished (QA-002).
51
+ self._control = {"Authorization": f"Bearer {control_token}"} if control_token else {}
47
52
 
48
53
  async def run(
49
54
  self, run_id: str, script: list[dict], claim: dict[str, Any]
@@ -60,6 +65,6 @@ class ScriptedAgent:
60
65
  "X-Axor-Run": run_id},
61
66
  )
62
67
  resp = await self._client.post(
63
- f"{self._base}/axor/runs/{run_id}/claim", json=claim
68
+ f"{self._base}/axor/runs/{run_id}/claim", json=claim, headers=self._control,
64
69
  )
65
70
  return resp.json()
@@ -445,6 +445,28 @@ async def _guarded_call(state: ProxyState, request: Request, tool: str, path: st
445
445
  return Response(upstream.content, status_code=upstream.status_code, headers=headers)
446
446
 
447
447
 
448
+ def _upload_key(state: ProxyState, request: Request) -> str | None:
449
+ """Whose plane workspace a demo node or run lands in: the caller's own
450
+ credential (X-Axor-Upload-Token — the page sends its sign-in token), else
451
+ this proxy's own ingest key. On a hosted plane every workspace is a tenant
452
+ of its own: with the proxy's key the node went to the key's workspace, and
453
+ the person who spawned it never saw it (QA-001)."""
454
+ return request.headers.get("x-axor-upload-token", "").strip() or state.ingest_key
455
+
456
+
457
+ def _upload_refused(exc: httpx.HTTPError) -> JSONResponse:
458
+ """A failed trace upload, said without the plane's internal address: the
459
+ raw exception carried `http://backend:8400/...` to the page (QA-001)."""
460
+ if isinstance(exc, httpx.HTTPStatusError):
461
+ code = exc.response.status_code
462
+ detail = (f"the Control Plane refused the upload (HTTP {code})"
463
+ + (" — sign in again, or check this proxy's AXOR_INGEST_KEY"
464
+ if code in (401, 403) else ""))
465
+ else:
466
+ detail = "the Control Plane could not be reached from the proxy"
467
+ return JSONResponse({"error": "backend_upload_failed", "detail": detail}, status_code=502)
468
+
469
+
448
470
  async def _forward_plain(
449
471
  state: ProxyState, request: Request,
450
472
  upstream_base: Any, # noqa: ANN401 - url or StdioMcpServer
@@ -828,11 +850,18 @@ def create_app(state: ProxyState) -> Starlette:
828
850
  owns = state.agent_client is None
829
851
  client = state.agent_client or httpx.AsyncClient(timeout=30.0)
830
852
  try:
831
- agent = ScriptedAgent(state.self_base_url, client)
853
+ agent = ScriptedAgent(state.self_base_url, client, control_token=state.control_token)
832
854
  result = await agent.run(run.run_id, script, claim)
833
855
  finally:
834
856
  if owns:
835
857
  await client.aclose()
858
+ if isinstance(result, dict) and result.get("error"):
859
+ # The claim was refused: the run did not finish. Answered as a 200
860
+ # it read as "ran, just not uploaded" and the page said so (QA-002).
861
+ return JSONResponse({"error": "claim_refused",
862
+ "detail": "the test could not finish: "
863
+ + str(result.get("detail") or result["error"])},
864
+ status_code=502)
836
865
  return JSONResponse(result)
837
866
 
838
867
  async def submit_claim(request: Request) -> Response:
@@ -907,12 +936,9 @@ def create_app(state: ProxyState) -> Starlette:
907
936
  from axor_proxy.governed import spawn_governed_tree
908
937
 
909
938
  try:
910
- result = await spawn_governed_tree(state.backend_url, state.ingest_key)
939
+ result = await spawn_governed_tree(state.backend_url, _upload_key(state, request))
911
940
  except httpx.HTTPError as exc:
912
- return JSONResponse(
913
- {"error": "backend_upload_failed", "detail": str(exc)},
914
- status_code=502,
915
- )
941
+ return _upload_refused(exc)
916
942
  return JSONResponse(result)
917
943
 
918
944
  async def spawn_governed(request: Request) -> Response:
@@ -929,13 +955,10 @@ def create_app(state: ProxyState) -> Starlette:
929
955
  from axor_proxy.governed import spawn_governed_node
930
956
 
931
957
  try:
932
- result = await spawn_governed_node(state.backend_url, state.ingest_key)
958
+ result = await spawn_governed_node(state.backend_url, _upload_key(state, request))
933
959
  except httpx.HTTPError as exc:
934
960
  # The trace upload failed — say so instead of reporting a live node.
935
- return JSONResponse(
936
- {"error": "backend_upload_failed", "detail": str(exc)},
937
- status_code=502,
938
- )
961
+ return _upload_refused(exc)
939
962
  task = result.pop("_task")
940
963
  node_id = result["node_id"]
941
964
  state.governed[node_id] = task
@@ -0,0 +1,124 @@
1
+ """The demo surfaces on a hosted plane (QA run 2026-11-27).
2
+
3
+ QA-001: a demo node / tree spawned from the page must land in the workspace of
4
+ whoever spawned it — the proxy's own ingest key put it in the key's workspace,
5
+ so on a multi-tenant plane nobody ever saw it — and a refused upload must not
6
+ show the plane's internal address.
7
+ QA-002: the in-app experiment must finish on a proxy that guards its control
8
+ surface (AXOR_PROXY_TOKEN): its scripted agent claimed without the token.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import pathlib
13
+
14
+ import httpx
15
+ import pytest
16
+ from axor_proxy.app import ProxyState, create_app
17
+ from starlette.applications import Starlette
18
+ from starlette.responses import JSONResponse
19
+ from starlette.routing import Route
20
+
21
+ TOKEN = "proxy-control-token"
22
+
23
+
24
+ def _upstream() -> httpx.ASGITransport:
25
+ async def handler(request: object) -> JSONResponse:
26
+ return JSONResponse({"results": [{"content": "real doc"}]})
27
+ return httpx.ASGITransport(
28
+ app=Starlette(routes=[Route("/{path:path}", handler, methods=["GET", "POST"])]))
29
+
30
+
31
+ async def test_the_example_experiment_finishes_on_a_guarded_proxy(
32
+ tmp_path: pathlib.Path) -> None:
33
+ state = ProxyState(tools={"web_search": "http://upstream.test/s"}, trace_dir=tmp_path,
34
+ client=httpx.AsyncClient(transport=_upstream(), base_url="http://upstream.test"),
35
+ control_token=TOKEN)
36
+ app = create_app(state)
37
+ page = httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://proxy.test",
38
+ headers={"Authorization": f"Bearer {TOKEN}"})
39
+ # the scripted agent dials the proxy itself, as an agent does: no token of its own
40
+ state.self_base_url = "http://proxy.test"
41
+ state.agent_client = httpx.AsyncClient(transport=httpx.ASGITransport(app=app),
42
+ base_url="http://proxy.test")
43
+ run_id = (await page.post("/axor/runs", json={
44
+ "scenario": "tool-deprivation",
45
+ "faults": [{"tool": "web_search", "mode": "silent_fail", "probability": 1.0}],
46
+ })).json()["run_id"]
47
+ r = await page.post(f"/axor/runs/{run_id}/simulate", json={})
48
+ assert r.status_code == 200, r.text
49
+ body = r.json()
50
+ assert body.get("error") != "unauthorized", body
51
+ assert body["deviations"] == 1 # the claim reached the proxy and was audited
52
+ assert (await page.get(f"/axor/runs/{run_id}")).json()["completed"] is True
53
+
54
+
55
+ @pytest.fixture
56
+ def spawned(monkeypatch: pytest.MonkeyPatch) -> list[str | None]:
57
+ seen: list[str | None] = []
58
+
59
+ async def fake_node(backend_url: str, ingest_key: str | None = None, **_: object) -> dict:
60
+ seen.append(ingest_key)
61
+
62
+ async def idle() -> None:
63
+ return None
64
+ import asyncio
65
+ return {"node_id": "gov_x", "run_id": "gov_x", "events": 1, "denials": 0,
66
+ "ttl_seconds": 1.0, "_task": asyncio.ensure_future(idle())}
67
+
68
+ async def fake_tree(backend_url: str, ingest_key: str | None = None, **_: object) -> dict:
69
+ seen.append(ingest_key)
70
+ return {"run_id": "tree_x"}
71
+
72
+ monkeypatch.setattr("axor_proxy.governed.spawn_governed_node", fake_node)
73
+ monkeypatch.setattr("axor_proxy.governed.spawn_governed_tree", fake_tree)
74
+ return seen
75
+
76
+
77
+ def _proxy(tmp_path: pathlib.Path) -> httpx.AsyncClient:
78
+ state = ProxyState(tools={}, trace_dir=tmp_path, backend_url="http://backend:8400",
79
+ ingest_key="proxy-own-key")
80
+ return httpx.AsyncClient(transport=httpx.ASGITransport(app=create_app(state)),
81
+ base_url="http://proxy.test")
82
+
83
+
84
+ @pytest.mark.parametrize("route", ["/axor/governed/spawn", "/axor/governed/spawn-tree"])
85
+ async def test_a_demo_spawn_lands_in_the_spawners_workspace(
86
+ tmp_path: pathlib.Path, spawned: list[str | None], route: str) -> None:
87
+ proxy = _proxy(tmp_path)
88
+ assert (await proxy.post(route, headers={"X-Axor-Upload-Token": "user-jwt"})).status_code == 200
89
+ assert (await proxy.post(route)).status_code == 200
90
+ assert spawned == ["user-jwt", "proxy-own-key"] # the caller's, else the proxy's
91
+
92
+
93
+ async def test_a_refused_upload_does_not_show_the_planes_address(
94
+ tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch) -> None:
95
+ async def refused(backend_url: str, ingest_key: str | None = None, **_: object) -> dict:
96
+ req = httpx.Request("POST", "http://backend:8400/v1/ingest/gov_1")
97
+ raise httpx.HTTPStatusError("401", request=req, response=httpx.Response(401, request=req))
98
+
99
+ monkeypatch.setattr("axor_proxy.governed.spawn_governed_node", refused)
100
+ r = await _proxy(tmp_path).post("/axor/governed/spawn")
101
+ assert r.status_code == 502
102
+ detail = r.json()["detail"]
103
+ assert "backend:8400" not in detail and "HTTP 401" in detail
104
+
105
+
106
+ async def test_a_refused_claim_is_a_failed_test_not_a_finished_one(
107
+ tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch) -> None:
108
+ """A refused claim came back as a 200 and the page called it a run that
109
+ "did not upload". It is a test that did not finish, and says why."""
110
+ async def refused(self: object, run_id: str, script: list, claim: dict) -> dict:
111
+ return {"error": "unauthorized", "detail": "this proxy requires a bearer token"}
112
+
113
+ monkeypatch.setattr("axor_proxy.agent.ScriptedAgent.run", refused)
114
+ state = ProxyState(tools={"web_search": "http://upstream.test/s"}, trace_dir=tmp_path,
115
+ client=httpx.AsyncClient(transport=_upstream(), base_url="http://upstream.test"))
116
+ app = create_app(state)
117
+ page = httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://proxy.test")
118
+ state.agent_client = page
119
+ run_id = (await page.post("/axor/runs", json={
120
+ "scenario": "tool-deprivation", "faults": [{"tool": "web_search", "mode": "silent_fail"}],
121
+ })).json()["run_id"]
122
+ r = await page.post(f"/axor/runs/{run_id}/simulate", json={})
123
+ assert r.status_code == 502
124
+ assert r.json()["detail"] == "the test could not finish: this proxy requires a bearer token"
File without changes
File without changes
File without changes