Astra: pre-flight before Fusion browser runs; edge cases in scenario design (bd47ba3)
Browse files
coworker/graph/nodes/execute.py
CHANGED
|
@@ -209,6 +209,7 @@ def finish_attempt(state, svc, plan: dict, res: dict | None) -> dict:
|
|
| 209 |
|
| 210 |
def executor(state, config, svc) -> dict:
|
| 211 |
plan = plan_attempt(state, svc)
|
|
|
|
| 212 |
for tries in (1, 2): # a browser-level failure (nothing ran) is tried once more, then fails the run clearly
|
| 213 |
try:
|
| 214 |
res = run_planned(plan, svc) if plan["ids"] else None
|
|
@@ -235,6 +236,22 @@ def executor(state, config, svc) -> dict:
|
|
| 235 |
return finish_attempt(state, svc, plan, res)
|
| 236 |
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
# ====================================================================== self_heal
|
| 239 |
def parse_locator(message: str) -> tuple[str, str] | None:
|
| 240 |
for m in LOCATOR_RE.finditer(message or ""):
|
|
|
|
| 209 |
|
| 210 |
def executor(state, config, svc) -> dict:
|
| 211 |
plan = plan_attempt(state, svc)
|
| 212 |
+
preflight_or_stop(state, svc, plan)
|
| 213 |
for tries in (1, 2): # a browser-level failure (nothing ran) is tried once more, then fails the run clearly
|
| 214 |
try:
|
| 215 |
res = run_planned(plan, svc) if plan["ids"] else None
|
|
|
|
| 236 |
return finish_attempt(state, svc, plan, res)
|
| 237 |
|
| 238 |
|
| 239 |
+
def preflight_or_stop(state, svc, plan: dict) -> None:
|
| 240 |
+
"""The first attempt of a browser run on a Fusion pod checks its runner, sign-in and test data before any browser
|
| 241 |
+
starts (platform/preflight.py): a run that cannot work stops in seconds with the reason."""
|
| 242 |
+
pid = svc.fusion_pod_id(plan["run_id"]) if plan["ids"] and plan["mode"] == "live" and plan["attempt"] == 0 else None
|
| 243 |
+
if pid is None:
|
| 244 |
+
return
|
| 245 |
+
from ...platform import preflight
|
| 246 |
+
areas = sorted({c["module"] for c in state.get("test_cases") or []})
|
| 247 |
+
results = preflight.check(svc, pid, plan["run_id"], areas)
|
| 248 |
+
bad = preflight.problems(results)
|
| 249 |
+
svc.db.add_event(plan["run_id"], "executor", "preflight", {"ok": not bad, "checks": results})
|
| 250 |
+
if bad:
|
| 251 |
+
from ...platform.failures import ExecutionError
|
| 252 |
+
raise ExecutionError("Pre-flight check failed, no browser was started: " + " ".join(bad))
|
| 253 |
+
|
| 254 |
+
|
| 255 |
# ====================================================================== self_heal
|
| 256 |
def parse_locator(message: str) -> tuple[str, str] | None:
|
| 257 |
for m in LOCATOR_RE.finditer(message or ""):
|
coworker/llm/prompts/design_scenarios.md
CHANGED
|
@@ -31,8 +31,22 @@ Rules:
|
|
| 31 |
the screens cannot show (other products, AI agents, reports, integrations, setup).
|
| 32 |
- Also propose at least one P1 scenario of the area's core process on these screens even when no change touches it
|
| 33 |
(a regression check that the everyday flow still works after the update); leave its `change_id` empty.
|
| 34 |
-
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
- Titles are short, specific and in plain business language. No ids, names, amounts or URLs that are not in the input.
|
| 37 |
- When the input has `existing_scenarios_do_not_repeat`, those scenarios already exist: every scenario you propose must
|
| 38 |
check something DIFFERENT from all of them (not the same flow with other words). Never return one of those titles.
|
|
|
|
| 31 |
the screens cannot show (other products, AI agents, reports, integrations, setup).
|
| 32 |
- Also propose at least one P1 scenario of the area's core process on these screens even when no change touches it
|
| 33 |
(a regression check that the everyday flow still works after the update); leave its `change_id` empty.
|
| 34 |
+
- Test like a senior QA tester, not only the happy path. After the changes and the core flow, cover the edge cases the
|
| 35 |
+
screen's fields, buttons and menus make testable, choosing different ones each time:
|
| 36 |
+
- a required field left empty (one at a time) is refused;
|
| 37 |
+
- invalid values: zero or negative amounts, a date in the future or far past, text in a number field, too many decimals;
|
| 38 |
+
- boundaries: the smallest and a very large amount, the longest text a field takes, amounts that must add up exactly
|
| 39 |
+
(lines equal to the header, a one-cent difference);
|
| 40 |
+
- duplicates: the same document number twice, the same document saved twice;
|
| 41 |
+
- state changes: act on a document twice (validate, cancel, then try again), change a validated document and check
|
| 42 |
+
it needs validating again, cancel and check nothing was saved;
|
| 43 |
+
- defaults: what Fusion fills in from a choice (supplier -> site, terms; business unit -> currency) and that changing
|
| 44 |
+
the choice changes them;
|
| 45 |
+
- search: find the document just created by its number, and a search that should find nothing.
|
| 46 |
+
At least half of the scenarios that are not change coverage must be `negative` or edge cases (P3).
|
| 47 |
+
- Say in `why` (one sentence) which change it covers, or that it is a regression check, or which edge case it tests.
|
| 48 |
+
P1 = core flow a business cannot work without, or a change switched on by the update; P2 = important variant;
|
| 49 |
+
P3 = edge case.
|
| 50 |
- Titles are short, specific and in plain business language. No ids, names, amounts or URLs that are not in the input.
|
| 51 |
- When the input has `existing_scenarios_do_not_repeat`, those scenarios already exist: every scenario you propose must
|
| 52 |
check something DIFFERENT from all of them (not the same flow with other words). Never return one of those titles.
|
coworker/platform/preflight.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pre-flight: before a Fusion run starts its browsers, the things it needs are checked in seconds, so a run that
|
| 2 |
+
cannot work stops with the reason instead of spending its browser time failing.
|
| 3 |
+
|
| 4 |
+
Checks, read-only: the remote browser runner answers and has the scenario files its step specs read (tests/cases); the
|
| 5 |
+
pod accepts the test user (the pod's connection test); every area of the run has test data. Each result is
|
| 6 |
+
{name, ok, detail}; `problems` lists the failed ones' details."""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def runner_check(svc) -> dict | None:
|
| 11 |
+
"""The remote runner's /healthz, or None when browsers run on this server."""
|
| 12 |
+
from ..adapters.remote_runner import runner_for
|
| 13 |
+
rt = runner_for(svc)
|
| 14 |
+
if rt is None:
|
| 15 |
+
return None
|
| 16 |
+
base = rt[0]
|
| 17 |
+
try:
|
| 18 |
+
r = svc.egress.service_request("remote_runner", "GET", base + "/healthz", allowed_base=base, log_body={"preflight": True},
|
| 19 |
+
timeout=20)
|
| 20 |
+
h = r.json() if r.status_code == 200 else {}
|
| 21 |
+
except Exception as e: # noqa: BLE001 - unreachable: reported, never raised
|
| 22 |
+
return {"name": "runner", "ok": False, "detail": f"The browser runner at {base} does not answer ({type(e).__name__})."}
|
| 23 |
+
if not h.get("ok") or not h.get("automation"):
|
| 24 |
+
return {"name": "runner", "ok": False, "detail": f"The browser runner at {base} is not ready (no token or no test code)."}
|
| 25 |
+
if h.get("cases") is False:
|
| 26 |
+
return {"name": "runner", "ok": False, "detail": f"The browser runner at {base} has no scenario files (tests/cases): "
|
| 27 |
+
"update it with deploy/runner/sync.sh."}
|
| 28 |
+
return {"name": "runner", "ok": True, "detail": f"Browser runner ready (version {h.get('version') or 'unknown'})."}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def check(svc, pod_id: int, run_id: str, areas: list[str]) -> list[dict]:
|
| 32 |
+
from .pods import PodRegistry
|
| 33 |
+
reg = PodRegistry(svc.db, svc.vault, svc.cfg, svc.egress, svc.audit)
|
| 34 |
+
out: list[dict] = []
|
| 35 |
+
r = runner_check(svc)
|
| 36 |
+
if r is not None:
|
| 37 |
+
out.append(r)
|
| 38 |
+
sign_in = [c for c in reg.fusion_checks(reg.get(pod_id))]
|
| 39 |
+
failed = next((c for c in sign_in if not c["ok"]), None)
|
| 40 |
+
out.append(failed or {"name": "fusion", "ok": True, "detail": sign_in[-1]["detail"] if sign_in else "Oracle Fusion answers."})
|
| 41 |
+
cands = reg.test_data_candidates(pod_id, run_id)
|
| 42 |
+
missing = [a for a in areas if not cands.get(a.upper())]
|
| 43 |
+
out.append({"name": "test_data", "ok": not missing, "detail":
|
| 44 |
+
f"No test data for {', '.join(missing)} on this pod: run Discover on the Test environments page, or set it there."
|
| 45 |
+
if missing else f"Test data for {', '.join(areas)}."})
|
| 46 |
+
return out
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def problems(results: list[dict]) -> list[str]:
|
| 50 |
+
return [r["detail"] for r in results if not r["ok"]]
|
coworker/tests/test_preflight.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pre-flight (platform/preflight.py): a Fusion browser run checks its runner, sign-in and test data before any browser
|
| 2 |
+
starts, and stops in seconds with the reason when one is missing. Seen on a real run: a runner without its scenario
|
| 3 |
+
files failed three times, each after a browser start."""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import unittest
|
| 7 |
+
from unittest import mock
|
| 8 |
+
|
| 9 |
+
from coworker.graph.nodes import execute
|
| 10 |
+
from coworker.platform import preflight
|
| 11 |
+
from coworker.platform.failures import ExecutionError
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Resp:
|
| 15 |
+
def __init__(self, status: int, body: dict):
|
| 16 |
+
self.status_code, self._body = status, body
|
| 17 |
+
|
| 18 |
+
def json(self):
|
| 19 |
+
return self._body
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def svc_with(health: dict | Exception | None):
|
| 23 |
+
svc = mock.MagicMock()
|
| 24 |
+
svc.cfg.remote_runner_url = "" if health is None else "https://runner.example"
|
| 25 |
+
svc.vault.get.return_value = "token-123456"
|
| 26 |
+
if isinstance(health, Exception):
|
| 27 |
+
svc.egress.service_request.side_effect = health
|
| 28 |
+
elif health is not None:
|
| 29 |
+
svc.egress.service_request.return_value = Resp(200, health)
|
| 30 |
+
return svc
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def reg_with(sign_in_ok=True, cands=None):
|
| 34 |
+
reg = mock.MagicMock()
|
| 35 |
+
reg.fusion_checks.return_value = [{"name": "address", "ok": True, "detail": "found"},
|
| 36 |
+
{"name": "sign_in", "ok": sign_in_ok, "detail": "Signed in as fin_impl." if sign_in_ok else "HTTP 401"}]
|
| 37 |
+
reg.test_data_candidates.return_value = {"AP": {"business_unit": ["BU One"]}} if cands is None else cands
|
| 38 |
+
return reg
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class TestPreflight(unittest.TestCase):
|
| 42 |
+
def run_check(self, svc, reg, areas=("AP",)):
|
| 43 |
+
with mock.patch("coworker.platform.pods.PodRegistry", return_value=reg):
|
| 44 |
+
return preflight.check(svc, 2, "run-1", list(areas))
|
| 45 |
+
|
| 46 |
+
def test_all_ready(self):
|
| 47 |
+
res = self.run_check(svc_with({"ok": True, "automation": True, "cases": True, "version": "abc"}), reg_with())
|
| 48 |
+
self.assertEqual(preflight.problems(res), [])
|
| 49 |
+
self.assertEqual([r["name"] for r in res], ["runner", "fusion", "test_data"])
|
| 50 |
+
|
| 51 |
+
def test_each_missing_thing_is_named(self):
|
| 52 |
+
cases = [
|
| 53 |
+
(svc_with({"ok": True, "automation": True, "cases": False}), reg_with(), "no scenario files"),
|
| 54 |
+
(svc_with(OSError("refused")), reg_with(), "does not answer"),
|
| 55 |
+
(svc_with({"ok": False, "automation": True}), reg_with(), "not ready"),
|
| 56 |
+
(svc_with(None), reg_with(sign_in_ok=False), "HTTP 401"),
|
| 57 |
+
(svc_with(None), reg_with(cands={}), "No test data for AP"),
|
| 58 |
+
]
|
| 59 |
+
for svc, reg, needle in cases:
|
| 60 |
+
self.assertTrue(any(needle in p for p in preflight.problems(self.run_check(svc, reg))), needle)
|
| 61 |
+
|
| 62 |
+
def test_a_run_that_cannot_work_stops_before_any_browser(self):
|
| 63 |
+
svc = mock.MagicMock()
|
| 64 |
+
svc.fusion_pod_id.return_value = 2
|
| 65 |
+
plan = {"run_id": "run-1", "ids": ["AP-FUS-001"], "mode": "live", "attempt": 0}
|
| 66 |
+
state = {"test_cases": [{"id": "AP-FUS-001", "module": "AP"}]}
|
| 67 |
+
bad = [{"name": "runner", "ok": False, "detail": "The browser runner has no scenario files."}]
|
| 68 |
+
with mock.patch.object(preflight, "check", return_value=bad), mock.patch.object(execute, "run_planned") as run:
|
| 69 |
+
with mock.patch.object(execute, "plan_attempt", return_value=plan), self.assertRaises(ExecutionError) as e:
|
| 70 |
+
execute.executor(state, {}, svc)
|
| 71 |
+
run.assert_not_called()
|
| 72 |
+
self.assertIn("no browser was started", str(e.exception))
|
| 73 |
+
kinds = [c.args[2] for c in svc.db.add_event.call_args_list]
|
| 74 |
+
self.assertIn("preflight", kinds)
|
| 75 |
+
|
| 76 |
+
def test_retries_and_simulations_skip_it(self):
|
| 77 |
+
svc = mock.MagicMock()
|
| 78 |
+
svc.fusion_pod_id.return_value = 2
|
| 79 |
+
with mock.patch.object(preflight, "check") as chk:
|
| 80 |
+
execute.preflight_or_stop({}, svc, {"run_id": "r", "ids": ["X"], "mode": "live", "attempt": 1})
|
| 81 |
+
execute.preflight_or_stop({}, svc, {"run_id": "r", "ids": ["X"], "mode": "stub", "attempt": 0})
|
| 82 |
+
chk.assert_not_called()
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
unittest.main()
|