Astra: Excel opens from Fusion e-mails without a login; events carry steps (4100070)
Browse files- coworker/api/routes/consultant.py +19 -4
- coworker/platform/agent_studio.py +0 -0
- coworker/platform/links.py +38 -0
- coworker/tests/test_agent_studio.py +155 -135
- web/src/api/openapi.json +61 -1
- web/src/api/schema.d.ts +62 -6
coworker/api/routes/consultant.py
CHANGED
|
@@ -106,12 +106,10 @@ def run_scenarios(run_id: str, request: Request, user: Principal = Depends(requi
|
|
| 106 |
return _scenarios_view(svc, runs, _run(svc, run_id))
|
| 107 |
|
| 108 |
|
| 109 |
-
|
| 110 |
-
def run_test_script(run_id: str, request: Request, user: Principal = Depends(require("read"))):
|
| 111 |
"""The test script as an Excel workbook for offline verification: one row per step (action, expected result),
|
| 112 |
reviewer columns to fill in, and the results once the scenarios have run. Audited as an export."""
|
| 113 |
from ...platform import test_script
|
| 114 |
-
svc, runs = _ctx(request)
|
| 115 |
run = _run(svc, run_id)
|
| 116 |
view = _scenarios_view(svc, runs, run)
|
| 117 |
gate = runs.gate_payload(run_id) if run.get("pending_gate") else None
|
|
@@ -121,12 +119,29 @@ def run_test_script(run_id: str, request: Request, user: Principal = Depends(req
|
|
| 121 |
for i, st in enumerate(R.module_steps(m)):
|
| 122 |
order.setdefault(st["name"], i)
|
| 123 |
data = test_script.build(run, view["scenarios"], failures, area_names=MODULE_NAMES, signoff=_signoff(svc, run_id), step_order=order)
|
| 124 |
-
svc.audit.append("export.test_script", actor=
|
| 125 |
payload={"scenarios": len(view["scenarios"]), "bytes": len(data)})
|
| 126 |
return Response(content=data, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 127 |
headers={"Content-Disposition": f'attachment; filename="test-script-{run_id}.xlsx"', "Cache-Control": "no-store"})
|
| 128 |
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
@router.get("/runs/{run_id}/failures")
|
| 131 |
def run_failures(run_id: str, request: Request, user: Principal = Depends(require("read"))):
|
| 132 |
"""Failed or flaky scenarios in business words: process step, expected vs actual, screenshot ids, suggestion."""
|
|
|
|
| 106 |
return _scenarios_view(svc, runs, _run(svc, run_id))
|
| 107 |
|
| 108 |
|
| 109 |
+
def test_script_xlsx(svc, runs, run_id: str, actor: str) -> Response:
|
|
|
|
| 110 |
"""The test script as an Excel workbook for offline verification: one row per step (action, expected result),
|
| 111 |
reviewer columns to fill in, and the results once the scenarios have run. Audited as an export."""
|
| 112 |
from ...platform import test_script
|
|
|
|
| 113 |
run = _run(svc, run_id)
|
| 114 |
view = _scenarios_view(svc, runs, run)
|
| 115 |
gate = runs.gate_payload(run_id) if run.get("pending_gate") else None
|
|
|
|
| 119 |
for i, st in enumerate(R.module_steps(m)):
|
| 120 |
order.setdefault(st["name"], i)
|
| 121 |
data = test_script.build(run, view["scenarios"], failures, area_names=MODULE_NAMES, signoff=_signoff(svc, run_id), step_order=order)
|
| 122 |
+
svc.audit.append("export.test_script", actor=actor, run_id=run_id, summary=f"{len(view['scenarios'])} scenario(s) to Excel",
|
| 123 |
payload={"scenarios": len(view["scenarios"]), "bytes": len(data)})
|
| 124 |
return Response(content=data, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 125 |
headers={"Content-Disposition": f'attachment; filename="test-script-{run_id}.xlsx"', "Cache-Control": "no-store"})
|
| 126 |
|
| 127 |
|
| 128 |
+
@router.get("/runs/{run_id}/test-script.xlsx")
|
| 129 |
+
def run_test_script(run_id: str, request: Request, user: Principal = Depends(require("read"))):
|
| 130 |
+
svc, runs = _ctx(request)
|
| 131 |
+
return test_script_xlsx(svc, runs, run_id, user.username)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@router.get("/share/runs/{run_id}/test-script.xlsx")
|
| 135 |
+
def shared_test_script(run_id: str, request: Request, exp: int = Query(...), sig: str = Query(..., max_length=80)):
|
| 136 |
+
"""The same workbook from a signed link (platform/links.py) in an e-mail Oracle Fusion sends: no login, this run only,
|
| 137 |
+
read-only, until the link expires."""
|
| 138 |
+
from ...platform import links
|
| 139 |
+
svc, runs = _ctx(request)
|
| 140 |
+
if not links.verify(svc, run_id, "test-script.xlsx", exp, sig):
|
| 141 |
+
raise ApiError(403, "LINK_EXPIRED", "This download link has expired or is not valid. Open the run in Astra, or ask for a new e-mail.")
|
| 142 |
+
return test_script_xlsx(svc, runs, run_id, "signed link (e-mail)")
|
| 143 |
+
|
| 144 |
+
|
| 145 |
@router.get("/runs/{run_id}/failures")
|
| 146 |
def run_failures(run_id: str, request: Request, user: Principal = Depends(require("read"))):
|
| 147 |
"""Failed or flaky scenarios in business words: process step, expected vs actual, screenshot ids, suggestion."""
|
coworker/platform/agent_studio.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
coworker/platform/links.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Download links that work without an Astra login, for the e-mails Oracle Fusion sends: each one is signed for one run
|
| 2 |
+
and one file, read-only, and expires (7 days). The signing key is made once and kept in the vault (vault LINK_SIGNING_KEY,
|
| 3 |
+
or FPT_SECRET_LINK_SIGNING_KEY); changing it ends every link already sent."""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import hashlib
|
| 7 |
+
import hmac
|
| 8 |
+
import secrets
|
| 9 |
+
import time
|
| 10 |
+
|
| 11 |
+
KEY = "LINK_SIGNING_KEY"
|
| 12 |
+
DAYS = 7
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _key(svc) -> bytes:
|
| 16 |
+
k = svc.vault.get(KEY)
|
| 17 |
+
if not k:
|
| 18 |
+
if not hasattr(svc.vault, "set"):
|
| 19 |
+
raise RuntimeError("the vault cannot keep a link signing key; set FPT_SECRET_LINK_SIGNING_KEY")
|
| 20 |
+
k = secrets.token_urlsafe(32)
|
| 21 |
+
svc.vault.set(KEY, k)
|
| 22 |
+
return k.encode()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _mac(svc, run_id: str, what: str, exp: int) -> str:
|
| 26 |
+
return hmac.new(_key(svc), f"{run_id}|{what}|{exp}".encode(), hashlib.sha256).hexdigest()[:40]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def sign(svc, run_id: str, what: str, days: int = DAYS, now: float | None = None) -> str:
|
| 30 |
+
"""The query string (exp=...&sig=...) that opens `what` of `run_id` until it expires."""
|
| 31 |
+
exp = int((now or time.time()) + days * 86400)
|
| 32 |
+
return f"exp={exp}&sig={_mac(svc, run_id, what, exp)}"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def verify(svc, run_id: str, what: str, exp: int, sig: str, now: float | None = None) -> bool:
|
| 36 |
+
if exp < (now or time.time()):
|
| 37 |
+
return False
|
| 38 |
+
return hmac.compare_digest(_mac(svc, run_id, what, exp), str(sig or ""))
|
coworker/tests/test_agent_studio.py
CHANGED
|
@@ -1,135 +1,155 @@
|
|
| 1 |
-
"""Oracle AI Agent Studio drives a test cycle (docs/AGENT_STUDIO.md): an OAuth client gets an invoke-only token; the
|
| 2 |
-
approved synthetic test data starts a run; scripts_ready goes back; the start-testing decision made in Fusion resumes
|
| 3 |
-
the run; results go back; the cycle's test data is tried first by the runner; personal data is refused."""
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import json
|
| 7 |
-
import unittest
|
| 8 |
-
|
| 9 |
-
from coworker.platform.agent_studio import AgentStudio, Courier, validate_test_data, verify_signature, AgentStudioError
|
| 10 |
-
from coworker.tests.test_ai_scenarios import fusion_app
|
| 11 |
-
|
| 12 |
-
TD = {"AP": {"business_unit": "TEST_US_BU", "supplier": ["Test Supplier A", "Test Supplier B"], "currency": "USD"}}
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class TestAgentStudio(unittest.TestCase):
|
| 16 |
-
@classmethod
|
| 17 |
-
def setUpClass(cls):
|
| 18 |
-
cls.app, cls.c, cls.svc, cls.h, cls.pod_id = fusion_app()
|
| 19 |
-
r = cls.c.post("/api/agent-studio/clients", json={"name": "Fusion test pod", "callback_url": "https://fusion.example/cb"},
|
| 20 |
-
headers=cls.h["admin"])
|
| 21 |
-
assert r.status_code == 201, r.text
|
| 22 |
-
cls.client = r.json()
|
| 23 |
-
|
| 24 |
-
def token(self) -> str:
|
| 25 |
-
r = self.c.post("/oauth/token", data={"grant_type": "client_credentials", "client_id": self.client["client_id"],
|
| 26 |
-
"client_secret": self.client["client_secret"], "scope": "patchwise.invoke"})
|
| 27 |
-
self.assertEqual(r.status_code, 200, r.text)
|
| 28 |
-
self.assertEqual(r.json()["scope"], "patchwise.invoke")
|
| 29 |
-
return r.json()["access_token"]
|
| 30 |
-
|
| 31 |
-
def test_a_token_needs_the_right_secret_and_only_invokes(self):
|
| 32 |
-
bad = self.c.post("/oauth/token", data={"grant_type": "client_credentials", "client_id": self.client["client_id"], "client_secret": "nope"})
|
| 33 |
-
self.assertEqual(bad.status_code, 401)
|
| 34 |
-
tok = self.token()
|
| 35 |
-
self.assertEqual(self.c.get("/api/runs", headers={"Authorization": f"Bearer {tok}"}).status_code, 401) # not a person's token
|
| 36 |
-
self.assertEqual(self.c.get("/api/agent-studio/v1/cycles/cyc_none", headers={"Authorization": f"Bearer {tok}"}).status_code, 404)
|
| 37 |
-
self.assertNotIn("secret_hash", json.dumps(self.c.get("/api/agent-studio/clients", headers=self.h["admin"]).json()))
|
| 38 |
-
|
| 39 |
-
def test_test_data_must_be_synthetic_and_approved(self):
|
| 40 |
-
with self.assertRaises(AgentStudioError) as e:
|
| 41 |
-
validate_test_data({"AP": {"supplier": "jane.doe@example.com"}})
|
| 42 |
-
self.assertEqual(e.exception.code, "NOT_SYNTHETIC")
|
| 43 |
-
with self.assertRaises(AgentStudioError):
|
| 44 |
-
validate_test_data({"AP": {"Bad Key": "x"}})
|
| 45 |
-
self.assertEqual(validate_test_data(TD)["AP"]["supplier"], ["Test Supplier A", "Test Supplier B"])
|
| 46 |
-
h = {"Authorization": f"Bearer {self.token()}"}
|
| 47 |
-
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": TD}, headers=h)
|
| 48 |
-
self.assertEqual(r.status_code, 422) # data_approved_by is required
|
| 49 |
-
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": {"AP": {"supplier": "+1 415 555 0100 4411"}}, "data_approved_by": "X"}, headers=h)
|
| 50 |
-
self.assertEqual(r.status_code, 400)
|
| 51 |
-
self.assertEqual(r.json()["code"], "NOT_SYNTHETIC")
|
| 52 |
-
|
| 53 |
-
def test_z_a_cycle_end_to_end(self):
|
| 54 |
-
h = {"Authorization": f"Bearer {self.token()}"}
|
| 55 |
-
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": TD, "data_approved_by": "Priya (Fusion QA)", "areas": ["AP"],
|
| 56 |
-
"correlation_id": "wf-42"}, headers=h)
|
| 57 |
-
self.assertEqual(r.status_code, 202, r.text)
|
| 58 |
-
cyc = r.json()
|
| 59 |
-
self.app.state.runs.drain()
|
| 60 |
-
studio = AgentStudio(self.svc)
|
| 61 |
-
# the runner tries the cycle's synthetic values first
|
| 62 |
-
from coworker.platform.pods import PodRegistry
|
| 63 |
-
reg = PodRegistry(self.svc.db, self.svc.vault, self.svc.cfg, self.svc.egress, self.svc.audit)
|
| 64 |
-
cands = reg.test_data_candidates(self.pod_id, cyc["run_id"])
|
| 65 |
-
self.assertEqual(cands["AP"]["supplier"][:2], ["Test Supplier A", "Test Supplier B"])
|
| 66 |
-
self.assertEqual(reg.test_data_candidates(self.pod_id).get("AP", {}).get("supplier", [None])[0] != "Test Supplier A", True)
|
| 67 |
-
|
| 68 |
-
courier = Courier(self.svc, self.app.state.runs, watch_hours=0)
|
| 69 |
-
courier.studio.watch_runs(self.app.state.runs)
|
| 70 |
-
sent = studio.deliveries()
|
| 71 |
-
ready = next(d for d in sent if d["event"] == "scripts_ready")
|
| 72 |
-
self.assertEqual(ready["payload"]["cycle_id"], cyc["cycle_id"])
|
| 73 |
-
self.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
self.assertEqual(
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
self.
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
self.
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Oracle AI Agent Studio drives a test cycle (docs/AGENT_STUDIO.md): an OAuth client gets an invoke-only token; the
|
| 2 |
+
approved synthetic test data starts a run; scripts_ready goes back; the start-testing decision made in Fusion resumes
|
| 3 |
+
the run; results go back; the cycle's test data is tried first by the runner; personal data is refused."""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import unittest
|
| 8 |
+
|
| 9 |
+
from coworker.platform.agent_studio import AgentStudio, Courier, validate_test_data, verify_signature, AgentStudioError
|
| 10 |
+
from coworker.tests.test_ai_scenarios import fusion_app
|
| 11 |
+
|
| 12 |
+
TD = {"AP": {"business_unit": "TEST_US_BU", "supplier": ["Test Supplier A", "Test Supplier B"], "currency": "USD"}}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestAgentStudio(unittest.TestCase):
|
| 16 |
+
@classmethod
|
| 17 |
+
def setUpClass(cls):
|
| 18 |
+
cls.app, cls.c, cls.svc, cls.h, cls.pod_id = fusion_app()
|
| 19 |
+
r = cls.c.post("/api/agent-studio/clients", json={"name": "Fusion test pod", "callback_url": "https://fusion.example/cb"},
|
| 20 |
+
headers=cls.h["admin"])
|
| 21 |
+
assert r.status_code == 201, r.text
|
| 22 |
+
cls.client = r.json()
|
| 23 |
+
|
| 24 |
+
def token(self) -> str:
|
| 25 |
+
r = self.c.post("/oauth/token", data={"grant_type": "client_credentials", "client_id": self.client["client_id"],
|
| 26 |
+
"client_secret": self.client["client_secret"], "scope": "patchwise.invoke"})
|
| 27 |
+
self.assertEqual(r.status_code, 200, r.text)
|
| 28 |
+
self.assertEqual(r.json()["scope"], "patchwise.invoke")
|
| 29 |
+
return r.json()["access_token"]
|
| 30 |
+
|
| 31 |
+
def test_a_token_needs_the_right_secret_and_only_invokes(self):
|
| 32 |
+
bad = self.c.post("/oauth/token", data={"grant_type": "client_credentials", "client_id": self.client["client_id"], "client_secret": "nope"})
|
| 33 |
+
self.assertEqual(bad.status_code, 401)
|
| 34 |
+
tok = self.token()
|
| 35 |
+
self.assertEqual(self.c.get("/api/runs", headers={"Authorization": f"Bearer {tok}"}).status_code, 401) # not a person's token
|
| 36 |
+
self.assertEqual(self.c.get("/api/agent-studio/v1/cycles/cyc_none", headers={"Authorization": f"Bearer {tok}"}).status_code, 404)
|
| 37 |
+
self.assertNotIn("secret_hash", json.dumps(self.c.get("/api/agent-studio/clients", headers=self.h["admin"]).json()))
|
| 38 |
+
|
| 39 |
+
def test_test_data_must_be_synthetic_and_approved(self):
|
| 40 |
+
with self.assertRaises(AgentStudioError) as e:
|
| 41 |
+
validate_test_data({"AP": {"supplier": "jane.doe@example.com"}})
|
| 42 |
+
self.assertEqual(e.exception.code, "NOT_SYNTHETIC")
|
| 43 |
+
with self.assertRaises(AgentStudioError):
|
| 44 |
+
validate_test_data({"AP": {"Bad Key": "x"}})
|
| 45 |
+
self.assertEqual(validate_test_data(TD)["AP"]["supplier"], ["Test Supplier A", "Test Supplier B"])
|
| 46 |
+
h = {"Authorization": f"Bearer {self.token()}"}
|
| 47 |
+
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": TD}, headers=h)
|
| 48 |
+
self.assertEqual(r.status_code, 422) # data_approved_by is required
|
| 49 |
+
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": {"AP": {"supplier": "+1 415 555 0100 4411"}}, "data_approved_by": "X"}, headers=h)
|
| 50 |
+
self.assertEqual(r.status_code, 400)
|
| 51 |
+
self.assertEqual(r.json()["code"], "NOT_SYNTHETIC")
|
| 52 |
+
|
| 53 |
+
def test_z_a_cycle_end_to_end(self):
|
| 54 |
+
h = {"Authorization": f"Bearer {self.token()}"}
|
| 55 |
+
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": TD, "data_approved_by": "Priya (Fusion QA)", "areas": ["AP"],
|
| 56 |
+
"correlation_id": "wf-42"}, headers=h)
|
| 57 |
+
self.assertEqual(r.status_code, 202, r.text)
|
| 58 |
+
cyc = r.json()
|
| 59 |
+
self.app.state.runs.drain()
|
| 60 |
+
studio = AgentStudio(self.svc)
|
| 61 |
+
# the runner tries the cycle's synthetic values first
|
| 62 |
+
from coworker.platform.pods import PodRegistry
|
| 63 |
+
reg = PodRegistry(self.svc.db, self.svc.vault, self.svc.cfg, self.svc.egress, self.svc.audit)
|
| 64 |
+
cands = reg.test_data_candidates(self.pod_id, cyc["run_id"])
|
| 65 |
+
self.assertEqual(cands["AP"]["supplier"][:2], ["Test Supplier A", "Test Supplier B"])
|
| 66 |
+
self.assertEqual(reg.test_data_candidates(self.pod_id).get("AP", {}).get("supplier", [None])[0] != "Test Supplier A", True)
|
| 67 |
+
|
| 68 |
+
courier = Courier(self.svc, self.app.state.runs, watch_hours=0)
|
| 69 |
+
courier.studio.watch_runs(self.app.state.runs)
|
| 70 |
+
sent = studio.deliveries()
|
| 71 |
+
ready = next(d for d in sent if d["event"] == "scripts_ready")
|
| 72 |
+
self.assertEqual(ready["payload"]["cycle_id"], cyc["cycle_id"])
|
| 73 |
+
self.assertTrue(any(sc["steps"] and {"n", "action", "expected"} <= set(sc["steps"][0]) for sc in ready["payload"]["scenarios"]))
|
| 74 |
+
# the Excel opens from the e-mail without a login: this run only, and not once the link is changed
|
| 75 |
+
from urllib.parse import urlsplit
|
| 76 |
+
xl = urlsplit(ready["payload"]["links"]["excel"])
|
| 77 |
+
self.assertTrue(xl.path.endswith(f"/api/share/runs/{cyc['run_id']}/test-script.xlsx"), xl.path)
|
| 78 |
+
got = self.c.get(f"{xl.path}?{xl.query}")
|
| 79 |
+
self.assertEqual(got.status_code, 200, got.text[:200])
|
| 80 |
+
self.assertTrue(got.content.startswith(b"PK"))
|
| 81 |
+
self.assertEqual(self.c.get(f"{xl.path}?{xl.query[:-2]}00").status_code, 403)
|
| 82 |
+
other = self.svc.db.q("SELECT run_id FROM runs WHERE run_id<>? LIMIT 1", (cyc["run_id"],))
|
| 83 |
+
if other:
|
| 84 |
+
self.assertEqual(self.c.get(f"/api/share/runs/{other[0]['run_id']}/test-script.xlsx?{xl.query}").status_code, 403)
|
| 85 |
+
self.assertEqual(ready["payload"]["correlation_id"], "wf-42")
|
| 86 |
+
self.assertTrue(ready["payload"]["scenarios"])
|
| 87 |
+
self.assertEqual(self.c.get(f"/api/agent-studio/v1/cycles/{cyc['cycle_id']}", headers=h).json()["waiting_for"],
|
| 88 |
+
"approval in Oracle Fusion (start testing)")
|
| 89 |
+
# the same step is reported once
|
| 90 |
+
courier.studio.watch_runs(self.app.state.runs)
|
| 91 |
+
self.assertEqual(sum(1 for d in studio.deliveries() if d["event"] == "scripts_ready"), 1)
|
| 92 |
+
# a signed body: what the Fusion side checks
|
| 93 |
+
key = self.client["signing_key"]
|
| 94 |
+
body = json.dumps(ready["payload"]).encode()
|
| 95 |
+
import hmac, hashlib
|
| 96 |
+
self.assertTrue(verify_signature(key, body, "sha256=" + hmac.new(key.encode(), body, hashlib.sha256).hexdigest()))
|
| 97 |
+
self.assertFalse(verify_signature(key, body, "sha256=00"))
|
| 98 |
+
|
| 99 |
+
# the start-testing decision, made in Fusion
|
| 100 |
+
r = self.c.post(f"/api/agent-studio/v1/cycles/{cyc['cycle_id']}/approval", json={"decision": "approve", "approved_by": "Priya (Fusion QA)"}, headers=h)
|
| 101 |
+
self.assertEqual(r.status_code, 200, r.text)
|
| 102 |
+
self.assertEqual(r.json()["scripts_approved_by"], "Priya (Fusion QA)")
|
| 103 |
+
self.app.state.runs.drain()
|
| 104 |
+
run = self.svc.db.get_run(cyc["run_id"])
|
| 105 |
+
if run["status"] == "waiting_review": # failures wait for a person in Patchwise; the cycle says so
|
| 106 |
+
courier.studio.watch_runs(self.app.state.runs)
|
| 107 |
+
self.assertTrue(any(d["event"] == "failures_need_review" for d in studio.deliveries()))
|
| 108 |
+
else:
|
| 109 |
+
self.assertEqual(run["status"], "completed")
|
| 110 |
+
courier.studio.watch_runs(self.app.state.runs)
|
| 111 |
+
res = next(d for d in studio.deliveries() if d["event"] == "results")
|
| 112 |
+
self.assertIn(res["payload"]["verdict"], ("Ready", "Not ready"))
|
| 113 |
+
sc = res["payload"]["scenarios"] # each scenario's outcome, for the results e-mail
|
| 114 |
+
self.assertTrue(sc and all(s["outcome"] in ("passed", "failed", "flaky", "skipped") for s in sc), sc)
|
| 115 |
+
self.assertTrue(all(s["reason"] == "" for s in sc if s["outcome"] == "passed"))
|
| 116 |
+
approvals = self.svc.db.q("SELECT actor FROM approvals WHERE run_id=? AND gate='approve_cases'", (cyc["run_id"],))
|
| 117 |
+
self.assertTrue(all("(in Oracle Fusion)" in a["actor"] for a in approvals) and approvals)
|
| 118 |
+
|
| 119 |
+
def test_the_supabase_state_archive_keeps_the_clients_and_their_keys(self):
|
| 120 |
+
import io, sqlite3, tarfile, tempfile
|
| 121 |
+
from pathlib import Path
|
| 122 |
+
from coworker.platform import statesync
|
| 123 |
+
blob = statesync.build_archive(Path(self.svc.cfg.home))
|
| 124 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 125 |
+
with tarfile.open(fileobj=io.BytesIO(blob), mode="r:gz") as tar:
|
| 126 |
+
names = tar.getnames()
|
| 127 |
+
tar.extractall(tmp, filter="data")
|
| 128 |
+
from contextlib import closing
|
| 129 |
+
with closing(sqlite3.connect(str(Path(tmp) / "fpt.sqlite"))) as db:
|
| 130 |
+
ids = {r[0] for r in db.execute("SELECT client_id FROM agent_clients")}
|
| 131 |
+
tables = {r[0] for r in db.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'agent_%'")}
|
| 132 |
+
self.assertIn(self.client["client_id"], ids)
|
| 133 |
+
self.assertTrue({"agent_clients", "agent_tokens", "agent_cycles", "agent_callbacks"} <= tables)
|
| 134 |
+
self.assertTrue(any(n.startswith("secrets") for n in names)) # the signing keys (vault)
|
| 135 |
+
|
| 136 |
+
def test_a_signed_link_expires(self):
|
| 137 |
+
from coworker.platform import links
|
| 138 |
+
q = dict(x.split("=") for x in links.sign(self.svc, "r1", "test-script.xlsx", now=1000).split("&"))
|
| 139 |
+
self.assertTrue(links.verify(self.svc, "r1", "test-script.xlsx", int(q["exp"]), q["sig"], now=2000))
|
| 140 |
+
self.assertFalse(links.verify(self.svc, "r1", "test-script.xlsx", int(q["exp"]), q["sig"], now=int(q["exp"]) + 1))
|
| 141 |
+
self.assertFalse(links.verify(self.svc, "r1", "report.pdf", int(q["exp"]), q["sig"], now=2000))
|
| 142 |
+
self.assertFalse(links.verify(self.svc, "r1", "test-script.xlsx", int(q["exp"]) + 86400, q["sig"], now=2000))
|
| 143 |
+
|
| 144 |
+
def test_a_callback_that_fails_is_tried_again_later(self):
|
| 145 |
+
studio = AgentStudio(self.svc)
|
| 146 |
+
did = studio.queue(self.client["client_id"], "https://fusion.example/cb", "stopped", {"status": "failed"})
|
| 147 |
+
studio.deliver_due()
|
| 148 |
+
d = next(x for x in studio.deliveries() if x["delivery_id"] == did)
|
| 149 |
+
self.assertEqual(d["attempts"], 1)
|
| 150 |
+
self.assertIsNone(d["delivered_at"])
|
| 151 |
+
self.assertGreater(d["next_at"], d["created_at"])
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
if __name__ == "__main__":
|
| 155 |
+
unittest.main()
|
web/src/api/openapi.json
CHANGED
|
@@ -5464,6 +5464,7 @@
|
|
| 5464 |
},
|
| 5465 |
"/api/agent-studio/v1/test-data/check": {
|
| 5466 |
"post": {
|
|
|
|
| 5467 |
"operationId": "check_test_data_api_agent_studio_v1_test_data_check_post",
|
| 5468 |
"requestBody": {
|
| 5469 |
"content": {
|
|
@@ -10504,7 +10505,6 @@
|
|
| 10504 |
},
|
| 10505 |
"/api/runs/{run_id}/test-script.xlsx": {
|
| 10506 |
"get": {
|
| 10507 |
-
"description": "The test script as an Excel workbook for offline verification: one row per step (action, expected result),\nreviewer columns to fill in, and the results once the scenarios have run. Audited as an export.",
|
| 10508 |
"operationId": "run_test_script_api_runs__run_id__test_script_xlsx_get",
|
| 10509 |
"parameters": [
|
| 10510 |
{
|
|
@@ -10935,6 +10935,66 @@
|
|
| 10935 |
]
|
| 10936 |
}
|
| 10937 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10938 |
"/api/storage": {
|
| 10939 |
"get": {
|
| 10940 |
"description": "Administrator: what the saved state holds and how the last save went (with the error text), the retention\nsettings and the last clean-up.",
|
|
|
|
| 5464 |
},
|
| 5465 |
"/api/agent-studio/v1/test-data/check": {
|
| 5466 |
"post": {
|
| 5467 |
+
"description": "Also picks up and confirms events for delivery mode pull: {\"pickup\": {\"max\": 1, \"cycle_id\"?}} answers as\n/events/claim, {\"confirm\": [\"dlv_...\"]} as /events/ack. The Fusion tool's checkTestData function then serves the\ncallback workflow too, so the workflow needs no new tool functions.",
|
| 5468 |
"operationId": "check_test_data_api_agent_studio_v1_test_data_check_post",
|
| 5469 |
"requestBody": {
|
| 5470 |
"content": {
|
|
|
|
| 10505 |
},
|
| 10506 |
"/api/runs/{run_id}/test-script.xlsx": {
|
| 10507 |
"get": {
|
|
|
|
| 10508 |
"operationId": "run_test_script_api_runs__run_id__test_script_xlsx_get",
|
| 10509 |
"parameters": [
|
| 10510 |
{
|
|
|
|
| 10935 |
]
|
| 10936 |
}
|
| 10937 |
},
|
| 10938 |
+
"/api/share/runs/{run_id}/test-script.xlsx": {
|
| 10939 |
+
"get": {
|
| 10940 |
+
"description": "The same workbook from a signed link (platform/links.py) in an e-mail Oracle Fusion sends: no login, this run only,\nread-only, until the link expires.",
|
| 10941 |
+
"operationId": "shared_test_script_api_share_runs__run_id__test_script_xlsx_get",
|
| 10942 |
+
"parameters": [
|
| 10943 |
+
{
|
| 10944 |
+
"in": "path",
|
| 10945 |
+
"name": "run_id",
|
| 10946 |
+
"required": true,
|
| 10947 |
+
"schema": {
|
| 10948 |
+
"title": "Run Id",
|
| 10949 |
+
"type": "string"
|
| 10950 |
+
}
|
| 10951 |
+
},
|
| 10952 |
+
{
|
| 10953 |
+
"in": "query",
|
| 10954 |
+
"name": "exp",
|
| 10955 |
+
"required": true,
|
| 10956 |
+
"schema": {
|
| 10957 |
+
"title": "Exp",
|
| 10958 |
+
"type": "integer"
|
| 10959 |
+
}
|
| 10960 |
+
},
|
| 10961 |
+
{
|
| 10962 |
+
"in": "query",
|
| 10963 |
+
"name": "sig",
|
| 10964 |
+
"required": true,
|
| 10965 |
+
"schema": {
|
| 10966 |
+
"maxLength": 80,
|
| 10967 |
+
"title": "Sig",
|
| 10968 |
+
"type": "string"
|
| 10969 |
+
}
|
| 10970 |
+
}
|
| 10971 |
+
],
|
| 10972 |
+
"responses": {
|
| 10973 |
+
"200": {
|
| 10974 |
+
"content": {
|
| 10975 |
+
"application/json": {
|
| 10976 |
+
"schema": {}
|
| 10977 |
+
}
|
| 10978 |
+
},
|
| 10979 |
+
"description": "Successful Response"
|
| 10980 |
+
},
|
| 10981 |
+
"422": {
|
| 10982 |
+
"content": {
|
| 10983 |
+
"application/json": {
|
| 10984 |
+
"schema": {
|
| 10985 |
+
"$ref": "#/components/schemas/HTTPValidationError"
|
| 10986 |
+
}
|
| 10987 |
+
}
|
| 10988 |
+
},
|
| 10989 |
+
"description": "Validation Error"
|
| 10990 |
+
}
|
| 10991 |
+
},
|
| 10992 |
+
"summary": "Shared Test Script",
|
| 10993 |
+
"tags": [
|
| 10994 |
+
"consultant"
|
| 10995 |
+
]
|
| 10996 |
+
}
|
| 10997 |
+
},
|
| 10998 |
"/api/storage": {
|
| 10999 |
"get": {
|
| 11000 |
"description": "Administrator: what the saved state holds and how the last save went (with the error text), the retention\nsettings and the last clean-up.",
|
web/src/api/schema.d.ts
CHANGED
|
@@ -352,7 +352,12 @@ export interface paths {
|
|
| 352 |
};
|
| 353 |
get?: never;
|
| 354 |
put?: never;
|
| 355 |
-
/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
post: operations["check_test_data_api_agent_studio_v1_test_data_check_post"];
|
| 357 |
delete?: never;
|
| 358 |
options?: never;
|
|
@@ -2401,11 +2406,7 @@ export interface paths {
|
|
| 2401 |
path?: never;
|
| 2402 |
cookie?: never;
|
| 2403 |
};
|
| 2404 |
-
/**
|
| 2405 |
-
* Run Test Script
|
| 2406 |
-
* @description The test script as an Excel workbook for offline verification: one row per step (action, expected result),
|
| 2407 |
-
* reviewer columns to fill in, and the results once the scenarios have run. Audited as an export.
|
| 2408 |
-
*/
|
| 2409 |
get: operations["run_test_script_api_runs__run_id__test_script_xlsx_get"];
|
| 2410 |
put?: never;
|
| 2411 |
post?: never;
|
|
@@ -2525,6 +2526,27 @@ export interface paths {
|
|
| 2525 |
patch?: never;
|
| 2526 |
trace?: never;
|
| 2527 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2528 |
"/api/storage": {
|
| 2529 |
parameters: {
|
| 2530 |
query?: never;
|
|
@@ -8774,6 +8796,40 @@ export interface operations {
|
|
| 8774 |
};
|
| 8775 |
};
|
| 8776 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8777 |
storage_api_storage_get: {
|
| 8778 |
parameters: {
|
| 8779 |
query?: never;
|
|
|
|
| 352 |
};
|
| 353 |
get?: never;
|
| 354 |
put?: never;
|
| 355 |
+
/**
|
| 356 |
+
* Check test data before sending it (synthetic, well formed)
|
| 357 |
+
* @description Also picks up and confirms events for delivery mode pull: {"pickup": {"max": 1, "cycle_id"?}} answers as
|
| 358 |
+
* /events/claim, {"confirm": ["dlv_..."]} as /events/ack. The Fusion tool's checkTestData function then serves the
|
| 359 |
+
* callback workflow too, so the workflow needs no new tool functions.
|
| 360 |
+
*/
|
| 361 |
post: operations["check_test_data_api_agent_studio_v1_test_data_check_post"];
|
| 362 |
delete?: never;
|
| 363 |
options?: never;
|
|
|
|
| 2406 |
path?: never;
|
| 2407 |
cookie?: never;
|
| 2408 |
};
|
| 2409 |
+
/** Run Test Script */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2410 |
get: operations["run_test_script_api_runs__run_id__test_script_xlsx_get"];
|
| 2411 |
put?: never;
|
| 2412 |
post?: never;
|
|
|
|
| 2526 |
patch?: never;
|
| 2527 |
trace?: never;
|
| 2528 |
};
|
| 2529 |
+
"/api/share/runs/{run_id}/test-script.xlsx": {
|
| 2530 |
+
parameters: {
|
| 2531 |
+
query?: never;
|
| 2532 |
+
header?: never;
|
| 2533 |
+
path?: never;
|
| 2534 |
+
cookie?: never;
|
| 2535 |
+
};
|
| 2536 |
+
/**
|
| 2537 |
+
* Shared Test Script
|
| 2538 |
+
* @description The same workbook from a signed link (platform/links.py) in an e-mail Oracle Fusion sends: no login, this run only,
|
| 2539 |
+
* read-only, until the link expires.
|
| 2540 |
+
*/
|
| 2541 |
+
get: operations["shared_test_script_api_share_runs__run_id__test_script_xlsx_get"];
|
| 2542 |
+
put?: never;
|
| 2543 |
+
post?: never;
|
| 2544 |
+
delete?: never;
|
| 2545 |
+
options?: never;
|
| 2546 |
+
head?: never;
|
| 2547 |
+
patch?: never;
|
| 2548 |
+
trace?: never;
|
| 2549 |
+
};
|
| 2550 |
"/api/storage": {
|
| 2551 |
parameters: {
|
| 2552 |
query?: never;
|
|
|
|
| 8796 |
};
|
| 8797 |
};
|
| 8798 |
};
|
| 8799 |
+
shared_test_script_api_share_runs__run_id__test_script_xlsx_get: {
|
| 8800 |
+
parameters: {
|
| 8801 |
+
query: {
|
| 8802 |
+
exp: number;
|
| 8803 |
+
sig: string;
|
| 8804 |
+
};
|
| 8805 |
+
header?: never;
|
| 8806 |
+
path: {
|
| 8807 |
+
run_id: string;
|
| 8808 |
+
};
|
| 8809 |
+
cookie?: never;
|
| 8810 |
+
};
|
| 8811 |
+
requestBody?: never;
|
| 8812 |
+
responses: {
|
| 8813 |
+
/** @description Successful Response */
|
| 8814 |
+
200: {
|
| 8815 |
+
headers: {
|
| 8816 |
+
[name: string]: unknown;
|
| 8817 |
+
};
|
| 8818 |
+
content: {
|
| 8819 |
+
"application/json": unknown;
|
| 8820 |
+
};
|
| 8821 |
+
};
|
| 8822 |
+
/** @description Validation Error */
|
| 8823 |
+
422: {
|
| 8824 |
+
headers: {
|
| 8825 |
+
[name: string]: unknown;
|
| 8826 |
+
};
|
| 8827 |
+
content: {
|
| 8828 |
+
"application/json": components["schemas"]["HTTPValidationError"];
|
| 8829 |
+
};
|
| 8830 |
+
};
|
| 8831 |
+
};
|
| 8832 |
+
};
|
| 8833 |
storage_api_storage_get: {
|
| 8834 |
parameters: {
|
| 8835 |
query?: never;
|