Astra: regression by default for Fusion cycles (1756857)
Browse files- coworker/api/routes/agent_studio.py +2 -0
- coworker/config.py +2 -0
- coworker/graph/nodes/ai_scenarios.py +28 -2
- coworker/platform/agent_studio.py +7 -1
- coworker/tests/test_agent_studio.py +3 -0
- coworker/tests/test_regression_flows.py +57 -0
- docs/AGENT_STUDIO.md +1 -0
- web/src/api/openapi.json +13 -0
- web/src/api/schema.d.ts +5 -0
coworker/api/routes/agent_studio.py
CHANGED
|
@@ -80,6 +80,8 @@ class CycleIn(BaseModel):
|
|
| 80 |
release: str | None = Field(None, description="the quarterly update under test, e.g. 26B")
|
| 81 |
callback_url: str | None = Field(None, description="where Patchwise reports back; the client's callback address otherwise")
|
| 82 |
correlation_id: str | None = Field(None, max_length=120, description="the Fusion workflow's own id, echoed in every callback")
|
|
|
|
|
|
|
| 83 |
generated_by: str | None = None
|
| 84 |
masked: bool | None = None
|
| 85 |
validated: bool | None = None
|
|
|
|
| 80 |
release: str | None = Field(None, description="the quarterly update under test, e.g. 26B")
|
| 81 |
callback_url: str | None = Field(None, description="where Patchwise reports back; the client's callback address otherwise")
|
| 82 |
correlation_id: str | None = Field(None, max_length=120, description="the Fusion workflow's own id, echoed in every callback")
|
| 83 |
+
depth: str | None = Field(None, max_length=20, description="regression (default: every scenario and an end-to-end flow per "
|
| 84 |
+
"business process), standard or smoke")
|
| 85 |
generated_by: str | None = None
|
| 86 |
masked: bool | None = None
|
| 87 |
validated: bool | None = None
|
coworker/config.py
CHANGED
|
@@ -136,6 +136,8 @@ class Settings(BaseSettings):
|
|
| 136 |
fusion_screens_per_area: int = Field(8, validation_alias=_alias("fpt_fusion_screens_per_area", "fusion_screens_per_area"))
|
| 137 |
# per area, the AI designs fusion_ai_scenarios plus one per change the update switches on by itself, up to this
|
| 138 |
fusion_ai_scenarios_max: int = Field(12, validation_alias=_alias("fpt_fusion_ai_scenarios_max", "fusion_ai_scenarios_max"))
|
|
|
|
|
|
|
| 139 |
# browsers working at once on a Fusion pod (screen reading, dry runs, test runs) and areas the AI designs at once.
|
| 140 |
# Fusion's own server is the slow part, so a small server still runs about 3 well; 1 = one at a time
|
| 141 |
fusion_workers: int = Field(3, validation_alias=_alias("fpt_fusion_workers", "fusion_workers"))
|
|
|
|
| 136 |
fusion_screens_per_area: int = Field(8, validation_alias=_alias("fpt_fusion_screens_per_area", "fusion_screens_per_area"))
|
| 137 |
# per area, the AI designs fusion_ai_scenarios plus one per change the update switches on by itself, up to this
|
| 138 |
fusion_ai_scenarios_max: int = Field(12, validation_alias=_alias("fpt_fusion_ai_scenarios_max", "fusion_ai_scenarios_max"))
|
| 139 |
+
# regression (depth full): end-to-end flows per area, one per business process, at most this many (0: none)
|
| 140 |
+
fusion_regression_flows: int = Field(3, validation_alias=_alias("fpt_fusion_regression_flows", "fusion_regression_flows"))
|
| 141 |
# browsers working at once on a Fusion pod (screen reading, dry runs, test runs) and areas the AI designs at once.
|
| 142 |
# Fusion's own server is the slow part, so a small server still runs about 3 well; 1 = one at a time
|
| 143 |
fusion_workers: int = Field(3, validation_alias=_alias("fpt_fusion_workers", "fusion_workers"))
|
coworker/graph/nodes/ai_scenarios.py
CHANGED
|
@@ -246,6 +246,28 @@ def _design_flows(svc, run_id: str, all_screens: dict[str, list[dict]], research
|
|
| 246 |
_note(svc, run_id, f"{f['name']}: {len(intents)} end-to-end flow(s) designed across {', '.join(f['areas'])}.")
|
| 247 |
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
# ====================================================================== writing
|
| 250 |
def write_ai_scenarios(state, svc, library: list[dict]) -> dict:
|
| 251 |
"""{"cases": [test cases for drafts whose dry run passed], "drafts": [every AI draft with its result]}; {} when the
|
|
@@ -310,8 +332,12 @@ def write_ai_scenarios(state, svc, library: list[dict]) -> dict:
|
|
| 310 |
return
|
| 311 |
with lock:
|
| 312 |
all_screens[area] = screens
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
workers = max(1, min(int(svc.cfg.fusion_workers or 1), len(areas) or 1))
|
| 317 |
with ThreadPoolExecutor(max_workers=workers, thread_name_prefix=f"design-{run_id[-6:]}") as ex:
|
|
|
|
| 246 |
_note(svc, run_id, f"{f['name']}: {len(intents)} end-to-end flow(s) designed across {', '.join(f['areas'])}.")
|
| 247 |
|
| 248 |
|
| 249 |
+
def _design_area_flows(svc, run_id: str, area: str, processes: list[str], changes: list, screens: list[dict], titles: list[str],
|
| 250 |
+
example: str, taken: set[str], drafts: list[dict], placeholders: list[str], lock=None) -> None:
|
| 251 |
+
"""Regression (depth full): one end-to-end flow for each business process of the area, start to finish across its
|
| 252 |
+
screens (create the document, then find it and act on it), so each process is tested whole, not one screen at a time."""
|
| 253 |
+
n = max(0, min(int(svc.cfg.fusion_regression_flows or 0), len(processes)))
|
| 254 |
+
if not n or len(screens) < 2:
|
| 255 |
+
return
|
| 256 |
+
asks = [f"{p_}: one end-to-end flow through this process, start to finish, across these screens" for p_ in processes[:n]]
|
| 257 |
+
try:
|
| 258 |
+
intents = step_writer.design_scenarios(svc, area, asks, changes, screens, count=n, run_id=run_id, existing_titles=titles)
|
| 259 |
+
except Exception as e: # noqa: BLE001
|
| 260 |
+
_note(svc, run_id, f"{area}: the AI model could not design end-to-end flows for regression ({type(e).__name__}).", module=area)
|
| 261 |
+
return
|
| 262 |
+
intents = [i for i in intents if i.get("designed_by") in (Route.FRONTIER.value, Route.LOCAL.value) and len(i.get("flow") or []) > 1]
|
| 263 |
+
if not intents:
|
| 264 |
+
_note(svc, run_id, f"{area}: no end-to-end flow was designed for regression this time.", module=area)
|
| 265 |
+
return
|
| 266 |
+
_write_intents(svc, run_id, area, intents, screens, example, taken, drafts, placeholders, lock)
|
| 267 |
+
_note(svc, run_id, f"{area}: {len(intents)} end-to-end flow(s) for regression: " + "; ".join(i["title"] for i in intents)[:300] + ".",
|
| 268 |
+
module=area)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
# ====================================================================== writing
|
| 272 |
def write_ai_scenarios(state, svc, library: list[dict]) -> dict:
|
| 273 |
"""{"cases": [test cases for drafts whose dry run passed], "drafts": [every AI draft with its result]}; {} when the
|
|
|
|
| 332 |
return
|
| 333 |
with lock:
|
| 334 |
all_screens[area] = screens
|
| 335 |
+
placeholders = step_writer.area_placeholders(area, svc.cfg.home, reg.test_data_keys(pod_id, area, run_id))
|
| 336 |
+
_write_intents(svc, run_id, area, intents, screens, example, taken, drafts, placeholders, lock)
|
| 337 |
+
if state.get("depth") == "full": # the area's business processes first (Fusion's catalog), then the library's
|
| 338 |
+
flows = list(dict.fromkeys(list(cat.get("processes") or []) + step_writer.area_processes(area)))
|
| 339 |
+
_design_area_flows(svc, run_id, area, flows, changes, screens, titles + [i["title"] for i in intents], example, taken,
|
| 340 |
+
drafts, placeholders, lock)
|
| 341 |
|
| 342 |
workers = max(1, min(int(svc.cfg.fusion_workers or 1), len(areas) or 1))
|
| 343 |
with ThreadPoolExecutor(max_workers=workers, thread_name_prefix=f"design-{run_id[-6:]}") as ex:
|
coworker/platform/agent_studio.py
CHANGED
|
@@ -38,6 +38,7 @@ SCOPE = "patchwise.invoke"
|
|
| 38 |
TOKEN_TTL_S = 3600
|
| 39 |
TOKEN_PREFIX = "pwa_"
|
| 40 |
EVENTS = ("scripts_ready", "failures_need_review", "results", "stopped", "patch_update")
|
|
|
|
| 41 |
MAX_ATTEMPTS = 6
|
| 42 |
STOPPED = ("failed", "killed", "cancelled", "interrupted")
|
| 43 |
|
|
@@ -431,7 +432,12 @@ class AgentStudio:
|
|
| 431 |
callback = _check_url(body.get("callback_url"), "callback address") or client.get("callback_url")
|
| 432 |
# a full browser run as the action-only test user; a server set to quick simulations (tests, trials) simulates
|
| 433 |
mode = "stub" if self.svc.cfg.playwright_mode == "stub" else "live"
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
if body.get("release"):
|
| 436 |
try:
|
| 437 |
reg.update(pod["id"], {"release": str(body["release"]).upper()}, f"agent-studio:{client['client_id']}")
|
|
|
|
| 38 |
TOKEN_TTL_S = 3600
|
| 39 |
TOKEN_PREFIX = "pwa_"
|
| 40 |
EVENTS = ("scripts_ready", "failures_need_review", "results", "stopped", "patch_update")
|
| 41 |
+
DEPTHS = {"regression": "full", "full": "full", "standard": "standard", "smoke": "smoke"}
|
| 42 |
MAX_ATTEMPTS = 6
|
| 43 |
STOPPED = ("failed", "killed", "cancelled", "interrupted")
|
| 44 |
|
|
|
|
| 432 |
callback = _check_url(body.get("callback_url"), "callback address") or client.get("callback_url")
|
| 433 |
# a full browser run as the action-only test user; a server set to quick simulations (tests, trials) simulates
|
| 434 |
mode = "stub" if self.svc.cfg.playwright_mode == "stub" else "live"
|
| 435 |
+
# regression by default: every approved scenario of each area, every priority, plus an end-to-end flow per business
|
| 436 |
+
# process; "standard" (the patch's P1s and changed scenarios) or "smoke" when Fusion asks for less
|
| 437 |
+
depth = DEPTHS.get(str(body.get("depth") or "regression").strip().lower())
|
| 438 |
+
if not depth:
|
| 439 |
+
raise AgentStudioError("BAD_DEPTH", "depth is regression, standard or smoke")
|
| 440 |
+
inputs = {"pod_id": pod["id"], "modules": areas, "playwright_mode": mode, "depth": depth, "via": f"agent-studio:{client['client_id']}"}
|
| 441 |
if body.get("release"):
|
| 442 |
try:
|
| 443 |
reg.update(pod["id"], {"release": str(body["release"]).upper()}, f"agent-studio:{client['client_id']}")
|
coworker/tests/test_agent_studio.py
CHANGED
|
@@ -49,6 +49,8 @@ class TestAgentStudio(unittest.TestCase):
|
|
| 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()}"}
|
|
@@ -57,6 +59,7 @@ class TestAgentStudio(unittest.TestCase):
|
|
| 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
|
|
|
|
| 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 |
+
r = self.c.post("/api/agent-studio/v1/cycles", json={"test_data": TD, "data_approved_by": "X", "depth": "everything"}, headers=h)
|
| 53 |
+
self.assertEqual((r.status_code, r.json()["code"]), (400, "BAD_DEPTH"))
|
| 54 |
|
| 55 |
def test_z_a_cycle_end_to_end(self):
|
| 56 |
h = {"Authorization": f"Bearer {self.token()}"}
|
|
|
|
| 59 |
self.assertEqual(r.status_code, 202, r.text)
|
| 60 |
cyc = r.json()
|
| 61 |
self.app.state.runs.drain()
|
| 62 |
+
self.assertEqual(self.app.state.runs.state(cyc["run_id"]).get("depth"), "full") # regression unless Fusion asks for less
|
| 63 |
studio = AgentStudio(self.svc)
|
| 64 |
# the runner tries the cycle's synthetic values first
|
| 65 |
from coworker.platform.pods import PodRegistry
|
coworker/tests/test_regression_flows.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regression (depth full): besides its usual scenarios, each area gets one end-to-end flow per business process, start
|
| 2 |
+
to finish across its screens; single-screen answers are not counted as flows, and a model failure is noted, not fatal."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import unittest
|
| 6 |
+
from types import SimpleNamespace
|
| 7 |
+
from unittest import mock
|
| 8 |
+
|
| 9 |
+
from coworker.graph.nodes import ai_scenarios
|
| 10 |
+
from coworker.llm.base import Route
|
| 11 |
+
|
| 12 |
+
SCREENS = [{"task": "Create Transfer"}, {"task": "Manage Transfers"}, {"task": "Reconcile Statement"}]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def svc(flows=3):
|
| 16 |
+
return SimpleNamespace(cfg=SimpleNamespace(fusion_regression_flows=flows))
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class TestRegressionFlows(unittest.TestCase):
|
| 20 |
+
def run_flows(self, answer, flows=3, processes=("Bank statements", "Reconciliation", "Cash positioning", "Transfers")):
|
| 21 |
+
notes, written = [], []
|
| 22 |
+
design = mock.Mock(side_effect=answer) if isinstance(answer, Exception) else mock.Mock(return_value=answer)
|
| 23 |
+
with mock.patch.object(ai_scenarios.step_writer, "design_scenarios", design), \
|
| 24 |
+
mock.patch.object(ai_scenarios, "_write_intents", lambda *a, **k: written.extend(a[3])), \
|
| 25 |
+
mock.patch.object(ai_scenarios, "_note", lambda s, rid, text, **k: notes.append(text)):
|
| 26 |
+
ai_scenarios._design_area_flows(svc(flows), "r", "CM", list(processes), [], SCREENS, ["Old title"], "", set(), [], [])
|
| 27 |
+
return design, written, notes
|
| 28 |
+
|
| 29 |
+
def test_one_flow_per_business_process(self):
|
| 30 |
+
fr = Route.FRONTIER.value
|
| 31 |
+
answer = [{"title": "Statement to reconciliation", "task": "Create Transfer", "flow": ["Create Transfer", "Reconcile Statement"], "designed_by": fr},
|
| 32 |
+
{"title": "One screen only", "task": "Manage Transfers", "flow": [], "designed_by": fr},
|
| 33 |
+
{"title": "Fallback", "task": "Create Transfer", "flow": ["Create Transfer", "Manage Transfers"], "designed_by": "baseline"}]
|
| 34 |
+
design, written, notes = self.run_flows(answer)
|
| 35 |
+
kw = design.call_args
|
| 36 |
+
self.assertEqual(kw.kwargs["count"], 3) # at most FPT_FUSION_REGRESSION_FLOWS
|
| 37 |
+
self.assertEqual(len(kw.args[2]), 3)
|
| 38 |
+
self.assertTrue(kw.args[2][0].startswith("Bank statements: one end-to-end flow"))
|
| 39 |
+
self.assertEqual(kw.kwargs["existing_titles"], ["Old title"])
|
| 40 |
+
self.assertEqual([i["title"] for i in written], ["Statement to reconciliation"]) # real multi-screen flows only
|
| 41 |
+
self.assertIn("1 end-to-end flow(s) for regression", notes[0])
|
| 42 |
+
|
| 43 |
+
def test_off_or_one_screen_designs_nothing(self):
|
| 44 |
+
design, written, _ = self.run_flows([], flows=0)
|
| 45 |
+
design.assert_not_called()
|
| 46 |
+
with mock.patch.object(ai_scenarios.step_writer, "design_scenarios") as d:
|
| 47 |
+
ai_scenarios._design_area_flows(svc(), "r", "CM", ["Bank statements"], [], SCREENS[:1], [], "", set(), [], [])
|
| 48 |
+
d.assert_not_called()
|
| 49 |
+
|
| 50 |
+
def test_a_model_failure_is_a_note(self):
|
| 51 |
+
_, written, notes = self.run_flows(RuntimeError("down"))
|
| 52 |
+
self.assertEqual(written, [])
|
| 53 |
+
self.assertIn("could not design end-to-end flows", notes[0])
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
unittest.main()
|
docs/AGENT_STUDIO.md
CHANGED
|
@@ -86,6 +86,7 @@ POST /cycles
|
|
| 86 |
| `data_approved_by` | required: who approved the data in Fusion |
|
| 87 |
| `areas` | defaults to the test data's areas. Areas the pod cannot test are skipped and listed in `skipped_areas`; the cycle is refused (`BAD_TEST_DATA`) only when none can be tested |
|
| 88 |
| `package` | optional: the approved test data package of the V3.6 workflows (up to 2 MB). Kept with the cycle; its `package_id` is in the response and admins read it at `GET /api/agent-studio/cycles/{cycle_id}/package` |
|
|
|
|
| 89 |
| `environment` | the Patchwise test environment's name; defaults to the default Fusion pod |
|
| 90 |
| `callback_url` | defaults to the client's callback address |
|
| 91 |
| `correlation_id` | your workflow's id, echoed in every callback |
|
|
|
|
| 86 |
| `data_approved_by` | required: who approved the data in Fusion |
|
| 87 |
| `areas` | defaults to the test data's areas. Areas the pod cannot test are skipped and listed in `skipped_areas`; the cycle is refused (`BAD_TEST_DATA`) only when none can be tested |
|
| 88 |
| `package` | optional: the approved test data package of the V3.6 workflows (up to 2 MB). Kept with the cycle; its `package_id` is in the response and admins read it at `GET /api/agent-studio/cycles/{cycle_id}/package` |
|
| 89 |
+
| `depth` | `regression` (default): every approved scenario of each area, every priority, plus one end-to-end flow per business process of the area (at most `FPT_FUSION_REGRESSION_FLOWS`, 3) and the cross-area flows (Procure-to-Pay ...) when all their areas are tested. `standard`: the patch's P1 scenarios and the ones its changes touch. `smoke`: the quickest check. Anything else is refused (`BAD_DEPTH`) |
|
| 90 |
| `environment` | the Patchwise test environment's name; defaults to the default Fusion pod |
|
| 91 |
| `callback_url` | defaults to the client's callback address |
|
| 92 |
| `correlation_id` | your workflow's id, echoed in every callback |
|
web/src/api/openapi.json
CHANGED
|
@@ -699,6 +699,19 @@
|
|
| 699 |
"title": "Data Approved By",
|
| 700 |
"type": "string"
|
| 701 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
"environment": {
|
| 703 |
"anyOf": [
|
| 704 |
{
|
|
|
|
| 699 |
"title": "Data Approved By",
|
| 700 |
"type": "string"
|
| 701 |
},
|
| 702 |
+
"depth": {
|
| 703 |
+
"anyOf": [
|
| 704 |
+
{
|
| 705 |
+
"maxLength": 20,
|
| 706 |
+
"type": "string"
|
| 707 |
+
},
|
| 708 |
+
{
|
| 709 |
+
"type": "null"
|
| 710 |
+
}
|
| 711 |
+
],
|
| 712 |
+
"description": "regression (default: every scenario and an end-to-end flow per business process), standard or smoke",
|
| 713 |
+
"title": "Depth"
|
| 714 |
+
},
|
| 715 |
"environment": {
|
| 716 |
"anyOf": [
|
| 717 |
{
|
web/src/api/schema.d.ts
CHANGED
|
@@ -2927,6 +2927,11 @@ export interface components {
|
|
| 2927 |
* @description who approved the test data in Fusion
|
| 2928 |
*/
|
| 2929 |
data_approved_by: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2930 |
/**
|
| 2931 |
* Environment
|
| 2932 |
* @description the Patchwise test environment's name; the default Fusion one otherwise
|
|
|
|
| 2927 |
* @description who approved the test data in Fusion
|
| 2928 |
*/
|
| 2929 |
data_approved_by: string;
|
| 2930 |
+
/**
|
| 2931 |
+
* Depth
|
| 2932 |
+
* @description regression (default: every scenario and an end-to-end flow per business process), standard or smoke
|
| 2933 |
+
*/
|
| 2934 |
+
depth?: string | null;
|
| 2935 |
/**
|
| 2936 |
* Environment
|
| 2937 |
* @description the Patchwise test environment's name; the default Fusion one otherwise
|