@capagents/forgeqe 2.8.9 → 2.9.1
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.
- package/HOW_TO_USE.md +250 -22
- package/dist/docs-site/docs/desktop/index.html +45 -1
- package/dist/docs-site/docs/index.html +335 -4
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/forgeqe.js +2077 -2022
- package/dist/template.html +66 -66
- package/dist/web/THIRD_PARTY_NOTICES.md +455 -0
- package/dist/web/assets/Agent-BNWcLTrm.js +4 -0
- package/dist/web/assets/ApiTests-CZFzjMKc.js +10 -0
- package/dist/web/assets/Browse-CeiK4X_V.js +2 -0
- package/dist/web/assets/Chat-BqXSNxV2.js +3 -0
- package/dist/web/assets/CommandPalette-VSEzjRS1.js +1 -0
- package/dist/web/assets/Compare-Bjh-qB8C.js +1 -0
- package/dist/web/assets/Cost-BRtni21m.js +1 -0
- package/dist/web/assets/Data-Bzn351xU.js +6 -0
- package/dist/web/assets/Evidence-eM1ZsFF-.js +1 -0
- package/dist/web/assets/Explore-D07Qbzyq.js +2 -0
- package/dist/web/assets/Features-DFwuL5cN.js +1 -0
- package/dist/web/assets/Flags-pxSAu21R.js +2 -0
- package/dist/web/assets/Flaky-BdfqCR6j.js +1 -0
- package/dist/web/assets/ForceGraph-DC7NzeR4.js +1 -0
- package/dist/web/assets/Impact-CfnvrPzq.js +3 -0
- package/dist/web/assets/Jobs-CIKpgvcv.js +5 -0
- package/dist/web/assets/KindPage-OyYE9NU7.js +6 -0
- package/dist/web/assets/Migration-BQA6MOPN.js +2 -0
- package/dist/web/assets/Product-DNe8RV_H.js +7 -0
- package/dist/web/assets/Production-ClEiFS1u.js +1 -0
- package/dist/web/assets/Quality-BZnQcbb2.js +1 -0
- package/dist/web/assets/Readiness-Dk2KZZm4.js +1 -0
- package/dist/web/assets/Record-CSapdwkr.js +2 -0
- package/dist/web/assets/Regression-C7bZ5sSE.js +5 -0
- package/dist/web/assets/Reports-BWtgbiVp.js +2 -0
- package/dist/web/assets/Response-DyvlQXek.js +4 -0
- package/dist/web/assets/RunDiff-DWV5qdHx.js +1 -0
- package/dist/web/assets/Runs-CET6zwQu.js +2 -0
- package/dist/web/assets/Steps-DUG1BKJb.js +2 -0
- package/dist/web/assets/TestCases-DyicRSqL.js +1 -0
- package/dist/web/assets/TestData-D2aWG3dq.js +2 -0
- package/dist/web/assets/TestDebt-DobUiGTz.js +1 -0
- package/dist/web/assets/Tosca-DvTni6va.js +3 -0
- package/dist/web/assets/WhatsNew-B3xewvk5.js +1 -0
- package/dist/web/assets/dataParts-rU9wRwfo.js +3 -0
- package/dist/web/assets/families-DWrv-fcS.js +1 -0
- package/dist/web/assets/filters-BDJYWuRV.js +1 -0
- package/dist/web/assets/fold-BgITvJex.js +1 -0
- package/dist/web/assets/frame-Dn34zQXO.js +4 -0
- package/dist/web/assets/index-BiMUTOBo.js +45 -0
- package/dist/web/assets/index-CGfii-zv.css +2 -0
- package/dist/web/assets/line-icons-CQ-3V8ax.js +1 -0
- package/dist/web/assets/logos-C067hMmF.js +1 -0
- package/dist/web/assets/palette-Br50dJuQ.js +1 -0
- package/dist/web/assets/parts-CbA0h_uO.js +1 -0
- package/dist/web/assets/productParts-BxQnjrHo.js +1 -0
- package/dist/web/assets/qualityParts-Cn74cNyX.js +1 -0
- package/dist/web/assets/rows-X8lfgK8j.js +1 -0
- package/dist/web/assets/segmented-mcjXGwLg.js +1 -0
- package/dist/web/assets/thread-Bamx8xqR.js +5 -0
- package/dist/web/assets/usePageChat-B-vpiXQ6.js +1 -0
- package/dist/web/index.html +5 -3
- package/docs/DESKTOP.md +48 -1
- package/docs/user-guide.html +335 -4
- package/evals/evidence/build/README.md +20 -0
- package/evals/evidence/build/base/package.json +1 -0
- package/evals/evidence/build/base/src/index.ts +1 -0
- package/evals/evidence/build/base/src/pricing.ts +22 -0
- package/evals/evidence/build/base/tests/discount.test.ts +6 -0
- package/evals/evidence/build/base/tests/legacy.test.ts +7 -0
- package/evals/evidence/build/base/tests/pricing.test.ts +10 -0
- package/evals/evidence/build/cases/build-broken/after/src/pricing.ts +22 -0
- package/evals/evidence/build/cases/build-broken/case.json +13 -0
- package/evals/evidence/build/cases/fixes-legacy/after/src/pricing.ts +22 -0
- package/evals/evidence/build/cases/fixes-legacy/case.json +11 -0
- package/evals/evidence/build/cases/flaky-test/after/tests/flaky.test.ts +11 -0
- package/evals/evidence/build/cases/flaky-test/case.json +11 -0
- package/evals/evidence/build/cases/good-feature/after/src/index.ts +1 -0
- package/evals/evidence/build/cases/good-feature/after/src/pricing.ts +28 -0
- package/evals/evidence/build/cases/good-feature/after/tests/bulk.test.ts +7 -0
- package/evals/evidence/build/cases/good-feature/case.json +17 -0
- package/evals/evidence/build/cases/new-test-fails/after/src/index.ts +1 -0
- package/evals/evidence/build/cases/new-test-fails/after/src/pricing.ts +27 -0
- package/evals/evidence/build/cases/new-test-fails/after/tests/coupon.test.ts +6 -0
- package/evals/evidence/build/cases/new-test-fails/case.json +19 -0
- package/evals/evidence/build/cases/regression/after/src/pricing.ts +23 -0
- package/evals/evidence/build/cases/regression/case.json +13 -0
- package/evals/evidence/build/cases/test-removed/case.json +14 -0
- package/forgeqe.example.yaml +2 -0
- package/package.json +2 -1
- package/prompts/README.md +1 -0
- package/prompts/impact-reader.md +8 -9
- package/prompts/tosca-assistant.md +47 -0
- package/prompts/tosca.md +3 -1
- package/py/forgeqe_desktop/agentdesktop_driver.py +57 -7
- package/py/forgeqe_desktop/handhooks.py +71 -22
- package/py/forgeqe_desktop/handrecord.py +7 -1
- package/py/forgeqe_desktop/heal.py +24 -2
- package/py/forgeqe_desktop/memory.py +54 -4
- package/py/forgeqe_desktop/pywinauto_driver.py +210 -12
- package/py/forgeqe_desktop/replay.py +10 -2
- package/py/forgeqe_desktop/service.py +9 -2
- package/py/forgeqe_desktop/ufo_runner.py +101 -1
- package/py/forgeqe_engine/browser.py +309 -31
- package/py/forgeqe_engine/browserdoctor.py +255 -0
- package/py/forgeqe_engine/browserlaunch.py +271 -0
- package/py/forgeqe_engine/capture.py +20 -4
- package/py/forgeqe_engine/cli.py +26 -0
- package/py/forgeqe_engine/logins.py +1 -1
- package/py/forgeqe_engine/pwlaunch.mjs +61 -0
- package/py/forgeqe_engine/recordsession.py +1 -1
- package/py/forgeqe_engine/service.py +1 -1
- package/py/forgeqe_mobile/service.py +4 -1
- package/py/forgeqe_tosca/__init__.py +11 -1
- package/py/forgeqe_tosca/app.py +168 -0
- package/py/forgeqe_tosca/db.py +131 -0
- package/py/forgeqe_tosca/files.py +74 -0
- package/py/forgeqe_tosca/ntir.py +357 -5
- package/py/forgeqe_tosca/render.py +38 -0
- package/py/forgeqe_tosca/tsu.py +110 -0
- package/skills/tosca-knowledge/SKILL.md +14 -3
- package/skills/tosca-knowledge/references/api.md +54 -0
- package/dist/web/assets/Agent-CHliM9aG.js +0 -4
- package/dist/web/assets/ApiTests-DcGDtIjl.js +0 -10
- package/dist/web/assets/Browse-DWZgEdaB.js +0 -1
- package/dist/web/assets/Chat-DVolc6Rs.js +0 -3
- package/dist/web/assets/CommandPalette-CdwjRIsa.js +0 -1
- package/dist/web/assets/Cost-BifpK_Ac.js +0 -1
- package/dist/web/assets/Data-Crk0ef8O.js +0 -6
- package/dist/web/assets/Evidence-EYGofupD.js +0 -1
- package/dist/web/assets/Explore-DtqBRQi7.js +0 -2
- package/dist/web/assets/Features-B_ZtQEtR.js +0 -1
- package/dist/web/assets/Flags-DCLSg8Na.js +0 -2
- package/dist/web/assets/Flaky-HpgrkJIF.js +0 -1
- package/dist/web/assets/ForceGraph-Dm4VEUjO.js +0 -1
- package/dist/web/assets/Impact-CyzbgGih.js +0 -3
- package/dist/web/assets/Jobs-CbTd9csb.js +0 -5
- package/dist/web/assets/KindPage-cfP76U_9.js +0 -6
- package/dist/web/assets/Migration-va16JqtB.js +0 -2
- package/dist/web/assets/Product-D0iY6orX.js +0 -7
- package/dist/web/assets/Production-CBUb6wZJ.js +0 -1
- package/dist/web/assets/Quality-OMhrUKTU.js +0 -1
- package/dist/web/assets/Readiness-B64Rxahv.js +0 -1
- package/dist/web/assets/Record-B_JXq6Dv.js +0 -2
- package/dist/web/assets/Regression-2blJAX7v.js +0 -5
- package/dist/web/assets/Reports-DCgjGdw4.js +0 -2
- package/dist/web/assets/Response-BtMM8nqx.js +0 -4
- package/dist/web/assets/RunDiff-KuUVRuQI.js +0 -1
- package/dist/web/assets/Runs-zHDZ-rSo.js +0 -2
- package/dist/web/assets/TestCases-B1j2Oelt.js +0 -1
- package/dist/web/assets/TestData-CZSynoi-.js +0 -2
- package/dist/web/assets/TestDebt-DEdIBwdb.js +0 -1
- package/dist/web/assets/Tosca-BcuaHsQC.js +0 -2
- package/dist/web/assets/WhatsNew-CjvX6DNo.js +0 -1
- package/dist/web/assets/dataParts-BImZKYEu.js +0 -3
- package/dist/web/assets/families-q4nF1Fqo.js +0 -1
- package/dist/web/assets/frame-eAHxqKfn.js +0 -4
- package/dist/web/assets/index-COTk3Bz-.js +0 -45
- package/dist/web/assets/index-DvuGI8X3.css +0 -2
- package/dist/web/assets/logos-DEPdha9g.js +0 -1
- package/dist/web/assets/parts-CVdJRIxI.js +0 -1
- package/dist/web/assets/productParts-CqY4Zs7J.js +0 -1
- package/dist/web/assets/qualityParts-BcrXEQ9B.js +0 -1
- package/dist/web/assets/segmented-BJECij_J.js +0 -1
- package/dist/web/assets/thread-Cuvu0HhP.js +0 -5
- package/dist/web/assets/usePageChat-Bz7fuynu.js +0 -1
|
@@ -172,7 +172,7 @@ class RecordSession:
|
|
|
172
172
|
|
|
173
173
|
brand.install()
|
|
174
174
|
stored = load_sessions(logins) if self.payload.get("signed_in") else None
|
|
175
|
-
candidates = [{**c, "storage_state": stored} if stored else c for c in local_launch_candidates(headless=False, choice=self.payload.get("local_browser"))]
|
|
175
|
+
candidates = [{**c, "storage_state": stored} if stored else c for c in local_launch_candidates(headless=False, choice=self.payload.get("local_browser"), method=self.payload.get("launch"), port=self.payload.get("attach_port"))]
|
|
176
176
|
self.browser, self.launch = await start_local_browser(
|
|
177
177
|
candidates,
|
|
178
178
|
make=lambda kw: Browser(**kw),
|
|
@@ -1127,7 +1127,7 @@ async def run_browser_task(req: RunRequest, emit: Emit, cancel_event: asyncio.Ev
|
|
|
1127
1127
|
emit({"type": "log", "level": "warn", "text": f"{browser_name(failed)} did not start ({reason}); trying {browser_name(nxt)}"})
|
|
1128
1128
|
|
|
1129
1129
|
browser, browser_kw = await start_local_browser(
|
|
1130
|
-
[{**c, **extra} for c in local_launch_candidates(headless=headless, choice=browser_cfg.get("local_browser"))],
|
|
1130
|
+
[{**c, **extra} for c in local_launch_candidates(headless=headless, choice=browser_cfg.get("local_browser"), method=browser_cfg.get("launch"), port=browser_cfg.get("attach_port"))],
|
|
1131
1131
|
make=lambda kw: Browser(**kw),
|
|
1132
1132
|
on_fallback=_fell_back,
|
|
1133
1133
|
)
|
|
@@ -142,7 +142,7 @@ def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, dr
|
|
|
142
142
|
if os.environ.get(n) is None:
|
|
143
143
|
raise WorkflowError(f"secret {n} is not set: the workflow types it (set {n} in the environment or .env, or in the credential store)")
|
|
144
144
|
driver = (driver_factory or (lambda: appium_driver(mobile)))()
|
|
145
|
-
heal = make_heal(_model(req, events, model_factory), driver, log=events.log, images=takes_images(req.get("llm") or {})) if req.get("heal") else None
|
|
145
|
+
heal = make_heal(_model(req, events, model_factory), driver, log=events.log, images=takes_images(req.get("llm") or {}), steps=wf["steps"]) if req.get("heal") else None
|
|
146
146
|
# A control that an earlier heal found is used again without the model (memory heals/<app>.json).
|
|
147
147
|
heal = remembered_heal(AppMemory.from_request(req, "mobile"), wf["app"], driver, heal, log=events.log)
|
|
148
148
|
shots = bool(mobile.get("screenshots", True))
|
|
@@ -169,6 +169,9 @@ def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, dr
|
|
|
169
169
|
should_stop=stop.is_set,
|
|
170
170
|
compare_image=image_checker(workflow_file, out, update=bool(req.get("update_baselines"))),
|
|
171
171
|
)
|
|
172
|
+
settle = getattr(heal, "settle", None)
|
|
173
|
+
if settle is not None:
|
|
174
|
+
settle(result.ok)
|
|
172
175
|
steps = []
|
|
173
176
|
for s in result.steps:
|
|
174
177
|
shot = f"steps/{s.index:03d}.png"
|
|
@@ -38,7 +38,7 @@ def read(path: Path, test_attributes: Optional[List[str]] = None, skip_modules:
|
|
|
38
38
|
if m is None:
|
|
39
39
|
continue
|
|
40
40
|
case = {**tc, "id": _case_id(tc["name"], used)}
|
|
41
|
-
cases.append(ntir.build(m, case, idx.engines, tsu.route_of))
|
|
41
|
+
cases.append(ntir.build(m, case, idx.engines, tsu.route_of, idx.api, idx.controls))
|
|
42
42
|
by_id = {c["source"]["test_case"]["surrogate"]: c["source"]["test_case"]["id"] for c in cases}
|
|
43
43
|
suites = [{"name": s["name"], "folders": s["folders"], "cases": [by_id[x] for x in s["cases"] if x in by_id]} for s in idx.suites]
|
|
44
44
|
return {"file": Path(path).name, "project": idx.project, "entities": idx.entity_count, "engines": idx.engines, "cases": cases, "suites": suites}
|
|
@@ -58,12 +58,22 @@ def summary(result: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
58
58
|
env.setdefault(e["name"], e)
|
|
59
59
|
cases.append({
|
|
60
60
|
"id": c["source"]["test_case"]["id"], "name": c["source"]["test_case"]["name"],
|
|
61
|
+
# Tosca's own unique id (the test case's surrogate): stays when it is renamed or moved.
|
|
62
|
+
"uid": c["source"]["test_case"].get("surrogate", ""),
|
|
61
63
|
"folders": c["source"]["test_case"]["folders"], "area": c["source"]["test_case"].get("area", []),
|
|
62
64
|
"suites": c["source"]["test_case"].get("suites", []), "route": c["route"], "routes": c["routes"],
|
|
63
65
|
"steps": r["counts"]["steps"], "actions": r["counts"]["actions"], "asserts": r["counts"]["asserts"],
|
|
64
66
|
"unsupported": r["counts"]["unsupported"], "warnings": len(r["warnings"]),
|
|
67
|
+
# Read-only database queries the target's database client runs (db.py).
|
|
68
|
+
"db": r["counts"].get("db", 0),
|
|
69
|
+
# Read-only file and Excel checks (files.py), which the test makes with the target's own code.
|
|
70
|
+
"files": r["counts"].get("files", 0),
|
|
71
|
+
# Runs of desktop or mobile steps in a web or API test, each a small workflow the test replays (ntir.py).
|
|
72
|
+
**({"parts": sorted({p["engine"] for p in c["parts"]})} if c.get("parts") else {}),
|
|
65
73
|
"pages": [p["id"] for p in c["pages"]], "env": [e["name"] for e in c["config"]["env"]],
|
|
66
74
|
"base_url": c["config"]["base_url"],
|
|
75
|
+
# A desktop or mobile case as a ForgeQE workflow (app.py): its engine, steps (launch and close aside), steps left out.
|
|
76
|
+
**({"workflow": {"engine": c["workflow"]["engine"], "steps": len(c["workflow"]["steps"]) - 2, "skipped": len(c["workflow"]["skipped"])}} if c.get("workflow") else {}),
|
|
67
77
|
})
|
|
68
78
|
pages: Dict[str, Dict[str, Any]] = {}
|
|
69
79
|
for c in result["cases"]:
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Tosca desktop and mobile test cases as ForgeQE workflows (forgeqe-desktop-v1, forgeqe-mobile-v1), by code.
|
|
2
|
+
|
|
3
|
+
Tosca finds a desktop control by its UI Automation properties and a mobile one by its resource id, accessibility id,
|
|
4
|
+
text or class: the same properties ForgeQE's workflows find controls by. So a case whose steps are all desktop (or all
|
|
5
|
+
mobile) steps becomes a workflow step by step, with no model: each step's control as a target, each value as text, a
|
|
6
|
+
secret as {{secret:NAME}} and test data as {{name}}. A step a workflow cannot do (a condition, a loop, a buffer, a
|
|
7
|
+
Tosca expression, an engine whose controls UI Automation cannot find, such as SAP GUI or Java Swing) is left out and
|
|
8
|
+
said, with why, so a person adds it.
|
|
9
|
+
|
|
10
|
+
The workflow is data: ForgeQE's TypeScript writes it as YAML and its replay checks it again (forgeqe_desktop.workflow).
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
# Desktop engines whose controls UI Automation finds (pywinauto, agent-desktop). SAP GUI scripting ids, Java Swing
|
|
18
|
+
# (the Java Access Bridge), Delphi and PowerBuilder controls are not UI Automation controls ForgeQE can name.
|
|
19
|
+
UIA_ENGINE = re.compile(r"(uia|automation|dotnet|\.net|wpf|winforms|win32|windows|desktop)", re.I)
|
|
20
|
+
NOT_UIA = re.compile(r"(sap|java|swing|delphi|powerbuilder)", re.I)
|
|
21
|
+
|
|
22
|
+
# Tosca's technical properties for a control, by what ForgeQE's targets call them (first found wins).
|
|
23
|
+
TARGET_KEYS = {
|
|
24
|
+
"automation_id": ("AutomationId", "AutomationID", "automationid", "resource-id", "resource_id", "ResourceId",
|
|
25
|
+
"accessibility id", "accessibilityId", "AccessibilityId", "identifier"),
|
|
26
|
+
"name": ("Name", "name", "content-desc", "ContentDesc", "text", "Text", "label", "Label"),
|
|
27
|
+
"control_type": ("ControlType", "LocalizedControlType", "class", "Class", "type", "Type"),
|
|
28
|
+
"class_name": ("ClassName", "classname"),
|
|
29
|
+
}
|
|
30
|
+
# Desktop keys a workflow takes, and named keys of each (forgeqe_desktop.workflow NAMED_KEYS, MOBILE_KEYS).
|
|
31
|
+
DESKTOP_KEYS = {"Enter": "enter", "Tab": "tab", "Escape": "esc", "Space": "space", "Backspace": "backspace", "Delete": "delete",
|
|
32
|
+
"Insert": "insert", "Home": "home", "End": "end", "PageUp": "pageup", "PageDown": "pagedown", "ArrowUp": "up",
|
|
33
|
+
"ArrowDown": "down", "ArrowLeft": "left", "ArrowRight": "right", **{f"F{n}": f"f{n}" for n in range(1, 13)}}
|
|
34
|
+
DESKTOP_MODIFIERS = {"Control": "ctrl", "Shift": "shift", "Alt": "alt"}
|
|
35
|
+
MOBILE_KEYS = {"Enter": "enter", "Tab": "tab", "Delete": "delete", "Backspace": "delete"}
|
|
36
|
+
TEXT_MAX = 2000
|
|
37
|
+
VAR = re.compile(r"^[A-Za-z_][A-Za-z0-9_]{0,63}$")
|
|
38
|
+
SECRET_VAR = re.compile(r"^[A-Z][A-Z0-9_]{1,63}$")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def app_target(route: str, engine: str, raw: Dict[str, Any]) -> Tuple[Optional[Dict[str, Any]], str]:
|
|
42
|
+
"""The workflow target of a Tosca control, or None and why."""
|
|
43
|
+
if route == "desktop" and (NOT_UIA.search(engine or "") or not UIA_ENGINE.search(engine or "")):
|
|
44
|
+
return None, f"engine '{engine}': ForgeQE's desktop replay finds controls by UI Automation, which this engine's controls are not"
|
|
45
|
+
out: Dict[str, Any] = {}
|
|
46
|
+
for key, names in TARGET_KEYS.items():
|
|
47
|
+
for n in names:
|
|
48
|
+
v = raw.get(n)
|
|
49
|
+
if isinstance(v, str) and v.strip() and "{{" not in v and "}}" not in v and len(v) <= 300 and "\n" not in v:
|
|
50
|
+
out[key] = v.strip()
|
|
51
|
+
break
|
|
52
|
+
if route == "mobile":
|
|
53
|
+
out.pop("class_name", None)
|
|
54
|
+
if not out.get("automation_id") and not out.get("name"):
|
|
55
|
+
return None, "Tosca recorded no automation id or name for this control"
|
|
56
|
+
return out, ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _text(value: Any) -> Tuple[Optional[str], str]:
|
|
60
|
+
"""A step's value as workflow text: a literal, {{secret:NAME}} or {{name}}; else None and why."""
|
|
61
|
+
if not isinstance(value, dict):
|
|
62
|
+
return None, "no value"
|
|
63
|
+
if "literal" in value:
|
|
64
|
+
t = str(value["literal"])
|
|
65
|
+
if "{{" in t or "}}" in t or "\n" in t or len(t) > TEXT_MAX:
|
|
66
|
+
return None, "the value has {{ or }}, a line break, or is too long for a workflow"
|
|
67
|
+
return t, ""
|
|
68
|
+
if "env" in value and SECRET_VAR.match(str(value["env"])):
|
|
69
|
+
return "{{secret:%s}}" % value["env"], ""
|
|
70
|
+
if "data" in value:
|
|
71
|
+
name = re.sub(r"[^A-Za-z0-9_]+", "_", str(value["data"])).strip("_")
|
|
72
|
+
if VAR.match(name):
|
|
73
|
+
return "{{%s}}" % name, ""
|
|
74
|
+
if "var" in value:
|
|
75
|
+
return None, f"it reads the Tosca buffer '{value['var']}', which a workflow has no place for"
|
|
76
|
+
if "expr" in value:
|
|
77
|
+
return None, f"it needs the Tosca expression {value['expr']} worked out"
|
|
78
|
+
return None, "its value is made of parts a workflow cannot join"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _keys(route: str, key: str) -> Optional[str]:
|
|
82
|
+
"""A Tosca key or chord ("Control+s", "Enter") as a workflow's keys, or None."""
|
|
83
|
+
if route == "mobile":
|
|
84
|
+
return MOBILE_KEYS.get(key)
|
|
85
|
+
parts = key.split("+")
|
|
86
|
+
mods = [DESKTOP_MODIFIERS.get(p) for p in parts[:-1]]
|
|
87
|
+
last = parts[-1]
|
|
88
|
+
named = DESKTOP_KEYS.get(last) or (last.lower() if len(last) == 1 and last.isalnum() else None)
|
|
89
|
+
if any(m is None for m in mods) or not named:
|
|
90
|
+
return None
|
|
91
|
+
return "+".join([*mods, named]) # type: ignore[list-item]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _step(route: str, n: Dict[str, Any]) -> Tuple[Optional[Dict[str, Any]], str]:
|
|
95
|
+
"""One NTIR node as a workflow step, or None and why."""
|
|
96
|
+
kind, op = n.get("kind"), n.get("op")
|
|
97
|
+
if kind == "wait":
|
|
98
|
+
secs = min(60.0, max(0.1, (n.get("ms") or 0) / 1000))
|
|
99
|
+
return {"op": "wait", "seconds": round(secs, 1)}, ""
|
|
100
|
+
if kind == "unsupported":
|
|
101
|
+
if str(n.get("module") or "").startswith("TBox "):
|
|
102
|
+
return None, f"the Tosca TBox module '{n['module']}': a workflow has no step for it"
|
|
103
|
+
return None, n.get("reason") or "a step Tosca's reader could not map"
|
|
104
|
+
if kind not in ("action", "assert"):
|
|
105
|
+
what = {"if": "a condition", "loop": "a loop", "store": "a value read into a buffer", "set_var": "a Tosca buffer set"}.get(kind, f"a {kind} step")
|
|
106
|
+
return None, f"{what}: a workflow has none"
|
|
107
|
+
target = n.get("app_target")
|
|
108
|
+
if not target:
|
|
109
|
+
return None, n.get("app_reason") or "no control to act on"
|
|
110
|
+
tap = "tap" if route == "mobile" else "click"
|
|
111
|
+
if kind == "action":
|
|
112
|
+
if op == "click":
|
|
113
|
+
mods = n.get("modifiers") or {}
|
|
114
|
+
if mods.get("double"):
|
|
115
|
+
return {"op": "double_tap" if route == "mobile" else "double_click", "target": target}, ""
|
|
116
|
+
if mods:
|
|
117
|
+
return None, "a right-click or a click held down: a workflow has only clicks and double-clicks"
|
|
118
|
+
return {"op": tap, "target": target}, ""
|
|
119
|
+
if op == "fill":
|
|
120
|
+
text, why = _text(n.get("value"))
|
|
121
|
+
return ({"op": "type", "target": target, "text": text}, "") if text is not None else (None, why)
|
|
122
|
+
if op in ("check", "uncheck"):
|
|
123
|
+
return {"op": tap, "target": target}, ""
|
|
124
|
+
if op == "press":
|
|
125
|
+
keys = _keys(route, str(n.get("key") or ""))
|
|
126
|
+
return ({"op": "keys", "keys": keys}, "") if keys else (None, f"the key {n.get('key')} is not one a workflow presses")
|
|
127
|
+
if op == "select" and route == "desktop":
|
|
128
|
+
opt = n.get("option") or {}
|
|
129
|
+
if "label" in opt and isinstance(opt["label"], str) and "{{" not in opt["label"]:
|
|
130
|
+
return {"op": "select", "target": target, "value": opt["label"]}, ""
|
|
131
|
+
return None, "a choice by its position: a workflow picks one by its text"
|
|
132
|
+
return None, f"the action '{op}' has no workflow step"
|
|
133
|
+
# Checks: the control's text, or that it is there or gone.
|
|
134
|
+
if op in ("text", "value") and n.get("match", "exact") == "exact":
|
|
135
|
+
text, why = _text(n.get("expected"))
|
|
136
|
+
return ({"op": "expect", "target": target, "text": text}, "") if text is not None else (None, why)
|
|
137
|
+
if op in ("visible", "attached"):
|
|
138
|
+
return {"op": "wait_for", "target": target}, ""
|
|
139
|
+
if op in ("hidden", "detached"):
|
|
140
|
+
return {"op": "wait_for", "target": target, "gone": True}, ""
|
|
141
|
+
return None, f"the check '{op}'{' (contains)' if n.get('match') == 'contains' else ''} has no workflow step"
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _walk(nodes: List[Dict[str, Any]]):
|
|
145
|
+
for n in nodes:
|
|
146
|
+
if n.get("kind") == "group":
|
|
147
|
+
yield from _walk(n.get("body") or [])
|
|
148
|
+
else:
|
|
149
|
+
yield n
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def workflow_of(route: str, body: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
153
|
+
"""The case's workflow steps (launch first, close last) and the steps left out, with why."""
|
|
154
|
+
steps: List[Dict[str, Any]] = [{"op": "launch"}]
|
|
155
|
+
skipped: List[Dict[str, Any]] = []
|
|
156
|
+
for n in _walk(body):
|
|
157
|
+
s, why = _step(route, n)
|
|
158
|
+
anchor = n.get("tosca") or {}
|
|
159
|
+
if s is None:
|
|
160
|
+
skipped.append({"node": n.get("id", ""), "step": anchor.get("step", ""), "element": anchor.get("element", ""), "reason": why})
|
|
161
|
+
continue
|
|
162
|
+
s["note"] = f"tosca: {n.get('id', '')} {anchor.get('step', '')}".strip()[:200]
|
|
163
|
+
steps.append(s)
|
|
164
|
+
steps.append({"op": "close"})
|
|
165
|
+
variables = sorted({m for s in steps for v in (s.get("text"), s.get("value")) if isinstance(v, str) for m in re.findall(r"\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}", v)})
|
|
166
|
+
secrets = sorted({m for s in steps for v in (s.get("text"),) if isinstance(v, str) for m in re.findall(r"\{\{secret:([A-Z][A-Z0-9_]*)\}\}", v)})
|
|
167
|
+
return {"engine": route, "format": "forgeqe-mobile-v1" if route == "mobile" else "forgeqe-desktop-v1", "steps": steps,
|
|
168
|
+
"skipped": skipped, "variables": variables, "secrets": secrets}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Tosca database steps as read-only queries the converted test runs with the target's own database client.
|
|
2
|
+
|
|
3
|
+
A Tosca database module's step sets an SQL statement and checks cells of its result (or reads one into a buffer). Only
|
|
4
|
+
a statement that reads is converted: one SELECT (or WITH ... SELECT), no second statement, nothing that changes data or
|
|
5
|
+
the schema, runs a procedure or writes a table (SELECT ... INTO). Anything else, and a statement not written in the
|
|
6
|
+
export (a buffer, a configuration parameter), stays a marked spot for a person. The statement and the checks are data in
|
|
7
|
+
the agent's brief (render.py quotes them); the test connects with the connection string ForgeQE passes it as
|
|
8
|
+
TOSCA_DB_URL, from the database of Settings a person picked on Review, never one written in the export.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from typing import Any, Dict, List, Optional
|
|
14
|
+
|
|
15
|
+
DATABASE_ENGINE = re.compile(r"(database|^db|db$|sql)", re.I)
|
|
16
|
+
NOT_DATABASE = re.compile(r"(excel|file|tdm|testdata|csv)", re.I)
|
|
17
|
+
SQL_ATTR = re.compile(r"^(sql( ?statement| ?query| ?command)?|statement|query|command ?text|select)$", re.I)
|
|
18
|
+
CONNECTION_ATTR = re.compile(r"(connection|dsn|data ?source|server|database|provider|user|password)", re.I)
|
|
19
|
+
WRITES = re.compile(r"\b(insert|update|delete|merge|drop|alter|create|truncate|grant|revoke|exec|execute|call|into|replace|upsert|lock|attach|pragma|copy|load|vacuum|set)\b", re.I)
|
|
20
|
+
ROW = re.compile(r"^row\s*(\d{1,4})$", re.I)
|
|
21
|
+
MAX_SQL = 4000
|
|
22
|
+
# A Tosca value in a statement: a buffer, a configuration parameter, test data or a parameter of its block.
|
|
23
|
+
TOKEN = re.compile(r"\{(B|CP|XL|PL)\[([^\[\]{}]{1,200})\]\}")
|
|
24
|
+
MAX_PARAMS = 20
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def bind(b: Any, raw: str, element: str) -> Optional[Dict[str, Any]]:
|
|
28
|
+
"""A statement whose Tosca values become bound parameters (:p1, :p2, ...), each value as data; None when a value
|
|
29
|
+
sits inside quotes (binding it would change the statement) or anything else in braces is left."""
|
|
30
|
+
params: List[Dict[str, Any]] = []
|
|
31
|
+
out: List[str] = []
|
|
32
|
+
last = 0
|
|
33
|
+
for m in TOKEN.finditer(raw):
|
|
34
|
+
before = raw[: m.start()]
|
|
35
|
+
if before.count("'") % 2 == 1 or before.count('"') % 2 == 1 or len(params) >= MAX_PARAMS:
|
|
36
|
+
return None
|
|
37
|
+
out.append(raw[last:m.start()])
|
|
38
|
+
name = f"p{len(params) + 1}"
|
|
39
|
+
value, _ = b.value(m.group(0), None, element)
|
|
40
|
+
params.append({"name": name, "value": value})
|
|
41
|
+
out.append(f":{name}")
|
|
42
|
+
last = m.end()
|
|
43
|
+
out.append(raw[last:])
|
|
44
|
+
text = "".join(out)
|
|
45
|
+
if "{" in text or "}" in text:
|
|
46
|
+
return None
|
|
47
|
+
return {"sql": text, "params": params}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def is_database(engine: str) -> bool:
|
|
51
|
+
return bool(DATABASE_ENGINE.search(engine or "")) and not NOT_DATABASE.search(engine or "")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def read_only(sql: str) -> Optional[str]:
|
|
55
|
+
"""The statement, cleaned, when it only reads; else None."""
|
|
56
|
+
if not isinstance(sql, str) or len(sql) > MAX_SQL:
|
|
57
|
+
return None
|
|
58
|
+
text = re.sub(r"/\*.*?\*/", " ", sql, flags=re.S)
|
|
59
|
+
text = re.sub(r"--[^\n]*", " ", text)
|
|
60
|
+
text = " ".join(text.split()).rstrip(";").strip()
|
|
61
|
+
if not text or ";" in text or not re.match(r"^(select|with)\b", text, re.I) or WRITES.search(text):
|
|
62
|
+
return None
|
|
63
|
+
# Quoted text is data, but a keyword in it still makes the statement suspect: keep the rule simple and strict.
|
|
64
|
+
return text
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _column(element: str, path: List[str]) -> Dict[str, Any]:
|
|
68
|
+
"""The result cell an attribute names: its column, and its row (1 unless a Row N attribute is above it)."""
|
|
69
|
+
col = re.sub(r"^column\s+", "", element.strip(), flags=re.I)
|
|
70
|
+
row = 1
|
|
71
|
+
for p in path:
|
|
72
|
+
m = ROW.match(p.strip())
|
|
73
|
+
if m:
|
|
74
|
+
row = int(m.group(1))
|
|
75
|
+
return {"column": col[:200], "row": row}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def query_node(b: Any, step: str, s: Dict[str, Any], module: str) -> Dict[str, Any]:
|
|
79
|
+
"""One database step: a {kind: db} node, or a marked spot (unsupported) with why."""
|
|
80
|
+
sql_raw: Optional[str] = None
|
|
81
|
+
params: List[Dict[str, Any]] = []
|
|
82
|
+
checks: List[Dict[str, Any]] = []
|
|
83
|
+
stores: List[Dict[str, Any]] = []
|
|
84
|
+
# The step's anchor: its statement's action, or its first that is not the connection (whose value may hold a password).
|
|
85
|
+
acts = s.get("actions") or []
|
|
86
|
+
plain = [a for a in acts if not CONNECTION_ATTR.search(a.get("element") or "")]
|
|
87
|
+
first = next((a for a in plain if SQL_ATTR.match((a.get("element") or "").strip())), plain[0] if plain else {"element": "", "mode": "", "value": ""})
|
|
88
|
+
|
|
89
|
+
def spot(reason: str) -> Dict[str, Any]:
|
|
90
|
+
node = b.unsupported(step, first, reason, module)
|
|
91
|
+
node["engine"] = "data"
|
|
92
|
+
return node
|
|
93
|
+
|
|
94
|
+
for a in acts:
|
|
95
|
+
el = a.get("element") or ""
|
|
96
|
+
mode = a.get("mode", "")
|
|
97
|
+
if SQL_ATTR.match(el.strip()) and mode in ("set", "input"):
|
|
98
|
+
resolved = a.get("value_resolved")
|
|
99
|
+
raw = a.get("value") or ""
|
|
100
|
+
if "{" in raw:
|
|
101
|
+
bound = bind(b, raw, el)
|
|
102
|
+
if bound is None:
|
|
103
|
+
return spot(f"a database step whose statement has a Tosca value inside quotes, or a token ForgeQE cannot bind (module '{module}'): a person codes it here")
|
|
104
|
+
sql_raw, params = bound["sql"], bound["params"]
|
|
105
|
+
elif resolved and resolved != raw:
|
|
106
|
+
return spot(f"a database step whose statement is not written in the export (module '{module}'): a person codes it here")
|
|
107
|
+
else:
|
|
108
|
+
sql_raw = raw
|
|
109
|
+
continue
|
|
110
|
+
if CONNECTION_ATTR.search(el):
|
|
111
|
+
continue # The connection is Settings' database, picked on Review, never the export's.
|
|
112
|
+
cell = _column(el, (a.get("locator") or {}).get("path") or [])
|
|
113
|
+
if mode in ("verify", "waitFor"):
|
|
114
|
+
val = b.pick(a.get("value") or "", a.get("value_resolved"))
|
|
115
|
+
match = "exact"
|
|
116
|
+
if isinstance(val, str) and (val.startswith("*") or val.endswith("*")):
|
|
117
|
+
match, val = "contains", val.strip("*")
|
|
118
|
+
expected, _ = b.value(val, None, el)
|
|
119
|
+
checks.append({**cell, "expected": expected, "match": match})
|
|
120
|
+
elif mode == "bufferRead":
|
|
121
|
+
stores.append({**cell, "var": a.get("value") or a.get("explicit_name") or el})
|
|
122
|
+
if sql_raw is None:
|
|
123
|
+
return spot(f"a database step with no SQL statement ForgeQE can read (module '{module}'): a person codes it here")
|
|
124
|
+
sql = read_only(sql_raw)
|
|
125
|
+
if sql is None:
|
|
126
|
+
return spot(f"a database step that changes data or is not one SELECT (module '{module}'): converted tests only read, so a person codes it here")
|
|
127
|
+
b.counts["db"] = b.counts.get("db", 0) + 1
|
|
128
|
+
b.counts["actions"] += 1
|
|
129
|
+
b.counts["asserts"] += len(checks)
|
|
130
|
+
return {"kind": "db", "id": b.node_id(), "op": "query", "sql": sql, **({"params": params} if params else {}), "checks": checks, "stores": stores, "module": module,
|
|
131
|
+
"engine": "data", "tosca": b.anchor(step, first, False)}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Tosca file and Excel steps as read-only checks the converted test makes with the target's own code.
|
|
2
|
+
|
|
3
|
+
A Tosca file step (a TBox file module: a file's existence, its text, two text files compared) or an Excel step (a
|
|
4
|
+
workbook's sheet and cells, Tosca's Excel engine) becomes a check the test makes on the file: its path as Tosca wrote
|
|
5
|
+
it (data, quoted in the brief), what it reads and what it expects. Only reading is converted, as with database steps:
|
|
6
|
+
a step that writes, copies, moves, renames, creates or deletes a file, or sets a cell, stays a marked spot for a
|
|
7
|
+
person. The file is found by its name, among the files the test downloaded or in the folder TOSCA_FILES_DIR names,
|
|
8
|
+
never at the Tosca machine's own path.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from typing import Any, Dict, List
|
|
14
|
+
|
|
15
|
+
FILE_MODULE = re.compile(r"(file|folder|directory|excel|csv|workbook|spreadsheet)", re.I)
|
|
16
|
+
FILE_ENGINE = re.compile(r"(excel|file|csv)", re.I)
|
|
17
|
+
WRITES = re.compile(r"(delete|remove|write|copy|move|rename|create|save|append|clear|overwrite|upload|unzip|zip|extract|replace)", re.I)
|
|
18
|
+
# What a step may set: where the file is and how to read it, never a value written into it.
|
|
19
|
+
WHERE = re.compile(r"^(path|file|file ?name|file ?path|folder|directory|sheet|sheet ?name|worksheet|workbook|encoding|cell|cell ?address|range|row|column|line|search|pattern|text to find|file ?1|file ?2|expected ?file|actual ?file)$", re.I)
|
|
20
|
+
TOSCA_FILES_DIR = "TOSCA_FILES_DIR"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_file_step(module: str, engine: str) -> bool:
|
|
24
|
+
if module.startswith("TBox "):
|
|
25
|
+
return bool(FILE_MODULE.search(module))
|
|
26
|
+
return bool(FILE_ENGINE.search(engine or ""))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def file_node(b: Any, step: str, s: Dict[str, Any], module: str) -> Dict[str, Any]:
|
|
30
|
+
"""One file or Excel step: a {kind: file} node of what it reads and checks, or a marked spot with why."""
|
|
31
|
+
acts = s.get("actions") or []
|
|
32
|
+
first = acts[0] if acts else {"element": "", "mode": "", "value": ""}
|
|
33
|
+
excel = bool(re.search(r"(excel|workbook|spreadsheet|xls)", f"{module} {b.engines.get(module, '')}", re.I))
|
|
34
|
+
|
|
35
|
+
def spot(reason: str) -> Dict[str, Any]:
|
|
36
|
+
node = b.unsupported(step, first, reason, module)
|
|
37
|
+
node["engine"] = "data"
|
|
38
|
+
return node
|
|
39
|
+
|
|
40
|
+
if WRITES.search(module):
|
|
41
|
+
return spot(f"a file step that changes files (module '{module}'): converted tests only read, so a person codes it here")
|
|
42
|
+
where: List[Dict[str, Any]] = []
|
|
43
|
+
checks: List[Dict[str, Any]] = []
|
|
44
|
+
stores: List[Dict[str, Any]] = []
|
|
45
|
+
for a in acts:
|
|
46
|
+
el = (a.get("element") or "").strip()
|
|
47
|
+
mode = a.get("mode", "")
|
|
48
|
+
if mode in ("set", "input", "optionalSet"):
|
|
49
|
+
val = (a.get("value") or "").strip()
|
|
50
|
+
if WRITES.search(el) or WRITES.search(val if el.lower() in ("operation", "action", "mode") else ""):
|
|
51
|
+
return spot(f"a file step that changes files (module '{module}', {el}): converted tests only read, so a person codes it here")
|
|
52
|
+
if not WHERE.match(el):
|
|
53
|
+
return spot(f"a file step that sets '{el}' (module '{module}'): converted tests only read, so a person codes it here")
|
|
54
|
+
value, _ = b.value(a.get("value") or "", a.get("value_resolved"), el)
|
|
55
|
+
where.append({"name": el[:200], "value": value})
|
|
56
|
+
elif mode in ("verify", "waitFor"):
|
|
57
|
+
val = b.pick(a.get("value") or "", a.get("value_resolved"))
|
|
58
|
+
match = "exact"
|
|
59
|
+
if isinstance(val, str) and (val.startswith("*") or val.endswith("*")):
|
|
60
|
+
match, val = "contains", val.strip("*")
|
|
61
|
+
expected, _ = b.value(val, None, el)
|
|
62
|
+
checks.append({"name": el[:200], "property": (a.get("property") or "")[:100], "expected": expected, "match": match})
|
|
63
|
+
elif mode == "bufferRead":
|
|
64
|
+
stores.append({"name": el[:200], "var": a.get("value") or a.get("explicit_name") or el})
|
|
65
|
+
else:
|
|
66
|
+
return spot(f"unknown ActionMode '{mode}' on a file step (module '{module}')")
|
|
67
|
+
if not checks and not stores:
|
|
68
|
+
return spot(f"a file step that checks nothing (module '{module}'): a person codes it here")
|
|
69
|
+
b.counts["files"] = b.counts.get("files", 0) + 1
|
|
70
|
+
b.counts["actions"] += 1
|
|
71
|
+
b.counts["asserts"] += len(checks)
|
|
72
|
+
b.env.setdefault(TOSCA_FILES_DIR, {"name": TOSCA_FILES_DIR, "from": "Tosca file steps: the folder their files are in", "secret": False})
|
|
73
|
+
return {"kind": "file", "id": b.node_id(), "op": "excel" if excel else "file", "module": module, "where": where, "checks": checks,
|
|
74
|
+
"stores": stores, "engine": "data", "tosca": b.anchor(step, first, False)}
|