@capagents/forgeqe 2.9.0 → 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.
Files changed (123) hide show
  1. package/HOW_TO_USE.md +250 -22
  2. package/dist/docs-site/docs/desktop/index.html +45 -1
  3. package/dist/docs-site/docs/index.html +261 -4
  4. package/dist/docs-site/docs/search.js +1 -1
  5. package/dist/forgeqe.js +1671 -1623
  6. package/dist/web/assets/Agent-BNWcLTrm.js +4 -0
  7. package/dist/web/assets/ApiTests-CZFzjMKc.js +10 -0
  8. package/dist/web/assets/Browse-CeiK4X_V.js +2 -0
  9. package/dist/web/assets/{Chat-BcFP0BbA.js → Chat-BqXSNxV2.js} +3 -3
  10. package/dist/web/assets/CommandPalette-VSEzjRS1.js +1 -0
  11. package/dist/web/assets/Compare-Bjh-qB8C.js +1 -0
  12. package/dist/web/assets/Cost-BRtni21m.js +1 -0
  13. package/dist/web/assets/Data-Bzn351xU.js +6 -0
  14. package/dist/web/assets/Evidence-eM1ZsFF-.js +1 -0
  15. package/dist/web/assets/{Explore-Dw8S6DG1.js → Explore-D07Qbzyq.js} +2 -2
  16. package/dist/web/assets/Features-DFwuL5cN.js +1 -0
  17. package/dist/web/assets/Flags-pxSAu21R.js +2 -0
  18. package/dist/web/assets/Flaky-BdfqCR6j.js +1 -0
  19. package/dist/web/assets/ForceGraph-DC7NzeR4.js +1 -0
  20. package/dist/web/assets/Impact-CfnvrPzq.js +3 -0
  21. package/dist/web/assets/Jobs-CIKpgvcv.js +5 -0
  22. package/dist/web/assets/KindPage-OyYE9NU7.js +6 -0
  23. package/dist/web/assets/Migration-BQA6MOPN.js +2 -0
  24. package/dist/web/assets/Product-DNe8RV_H.js +7 -0
  25. package/dist/web/assets/Production-ClEiFS1u.js +1 -0
  26. package/dist/web/assets/Quality-BZnQcbb2.js +1 -0
  27. package/dist/web/assets/Readiness-Dk2KZZm4.js +1 -0
  28. package/dist/web/assets/Record-CSapdwkr.js +2 -0
  29. package/dist/web/assets/Regression-C7bZ5sSE.js +5 -0
  30. package/dist/web/assets/Reports-BWtgbiVp.js +2 -0
  31. package/dist/web/assets/{Response-DGl2R0A-.js → Response-DyvlQXek.js} +2 -2
  32. package/dist/web/assets/RunDiff-DWV5qdHx.js +1 -0
  33. package/dist/web/assets/{Runs-CkNWhAhe.js → Runs-CET6zwQu.js} +2 -2
  34. package/dist/web/assets/Steps-DUG1BKJb.js +2 -0
  35. package/dist/web/assets/TestCases-DyicRSqL.js +1 -0
  36. package/dist/web/assets/TestData-D2aWG3dq.js +2 -0
  37. package/dist/web/assets/TestDebt-DobUiGTz.js +1 -0
  38. package/dist/web/assets/Tosca-DvTni6va.js +3 -0
  39. package/dist/web/assets/WhatsNew-B3xewvk5.js +1 -0
  40. package/dist/web/assets/dataParts-rU9wRwfo.js +3 -0
  41. package/dist/web/assets/families-DWrv-fcS.js +1 -0
  42. package/dist/web/assets/filters-BDJYWuRV.js +1 -0
  43. package/dist/web/assets/fold-BgITvJex.js +1 -0
  44. package/dist/web/assets/frame-Dn34zQXO.js +4 -0
  45. package/dist/web/assets/index-BiMUTOBo.js +45 -0
  46. package/dist/web/assets/index-CGfii-zv.css +2 -0
  47. package/dist/web/assets/logos-C067hMmF.js +1 -0
  48. package/dist/web/assets/palette-Br50dJuQ.js +1 -0
  49. package/dist/web/assets/parts-CbA0h_uO.js +1 -0
  50. package/dist/web/assets/productParts-BxQnjrHo.js +1 -0
  51. package/dist/web/assets/qualityParts-Cn74cNyX.js +1 -0
  52. package/dist/web/assets/rows-X8lfgK8j.js +1 -0
  53. package/dist/web/assets/segmented-mcjXGwLg.js +1 -0
  54. package/dist/web/assets/{thread-BeaLQ_f4.js → thread-Bamx8xqR.js} +2 -2
  55. package/dist/web/assets/usePageChat-B-vpiXQ6.js +1 -0
  56. package/dist/web/index.html +4 -3
  57. package/docs/DESKTOP.md +48 -1
  58. package/docs/user-guide.html +261 -4
  59. package/package.json +1 -1
  60. package/prompts/README.md +1 -0
  61. package/prompts/impact-reader.md +8 -9
  62. package/prompts/tosca-assistant.md +47 -0
  63. package/prompts/tosca.md +3 -1
  64. package/py/forgeqe_desktop/agentdesktop_driver.py +57 -7
  65. package/py/forgeqe_desktop/handhooks.py +71 -22
  66. package/py/forgeqe_desktop/handrecord.py +7 -1
  67. package/py/forgeqe_desktop/heal.py +24 -2
  68. package/py/forgeqe_desktop/memory.py +54 -4
  69. package/py/forgeqe_desktop/pywinauto_driver.py +210 -12
  70. package/py/forgeqe_desktop/replay.py +10 -2
  71. package/py/forgeqe_desktop/service.py +9 -2
  72. package/py/forgeqe_desktop/ufo_runner.py +101 -1
  73. package/py/forgeqe_mobile/service.py +4 -1
  74. package/py/forgeqe_tosca/__init__.py +11 -1
  75. package/py/forgeqe_tosca/app.py +168 -0
  76. package/py/forgeqe_tosca/db.py +131 -0
  77. package/py/forgeqe_tosca/files.py +74 -0
  78. package/py/forgeqe_tosca/ntir.py +357 -5
  79. package/py/forgeqe_tosca/render.py +38 -0
  80. package/py/forgeqe_tosca/tsu.py +110 -0
  81. package/skills/tosca-knowledge/SKILL.md +14 -3
  82. package/skills/tosca-knowledge/references/api.md +54 -0
  83. package/dist/web/assets/Agent-BGwHbXbc.js +0 -4
  84. package/dist/web/assets/ApiTests-DSnZHRlF.js +0 -10
  85. package/dist/web/assets/Browse-Dx3pHGuG.js +0 -2
  86. package/dist/web/assets/CommandPalette-v6mqHZnU.js +0 -1
  87. package/dist/web/assets/Cost-C9LZdx1p.js +0 -1
  88. package/dist/web/assets/Data-DvbaOc9e.js +0 -6
  89. package/dist/web/assets/Evidence-Y1AeSzh5.js +0 -1
  90. package/dist/web/assets/Features-CjrVraBE.js +0 -1
  91. package/dist/web/assets/Flags-C_Qm0078.js +0 -2
  92. package/dist/web/assets/Flaky-DYgN586D.js +0 -1
  93. package/dist/web/assets/ForceGraph-CEH86-Z0.js +0 -1
  94. package/dist/web/assets/Impact-dBPp7aM2.js +0 -3
  95. package/dist/web/assets/Jobs-CSyN6YRx.js +0 -5
  96. package/dist/web/assets/KindPage-BQl-5bcd.js +0 -6
  97. package/dist/web/assets/Migration-COly7O-T.js +0 -2
  98. package/dist/web/assets/Product-7mM8tcxH.js +0 -7
  99. package/dist/web/assets/Production-De5CCUoP.js +0 -1
  100. package/dist/web/assets/Quality-Q_iqj3fk.js +0 -1
  101. package/dist/web/assets/Readiness-kU9kum_I.js +0 -1
  102. package/dist/web/assets/Record-CIhINuEz.js +0 -2
  103. package/dist/web/assets/Regression-CMQnH7dN.js +0 -5
  104. package/dist/web/assets/Reports-dUOe6_vN.js +0 -2
  105. package/dist/web/assets/RunDiff-BVRRIz3m.js +0 -1
  106. package/dist/web/assets/TestCases-exR7hRWd.js +0 -1
  107. package/dist/web/assets/TestData-yVPMg9kw.js +0 -2
  108. package/dist/web/assets/TestDebt-C3sM6cH0.js +0 -1
  109. package/dist/web/assets/Tosca-Bcalg1JU.js +0 -2
  110. package/dist/web/assets/WhatsNew-EFSt6xx2.js +0 -1
  111. package/dist/web/assets/dataParts-D33u08WR.js +0 -3
  112. package/dist/web/assets/families-Btjss8bN.js +0 -1
  113. package/dist/web/assets/frame-D3IhgCFt.js +0 -4
  114. package/dist/web/assets/index-D5sya6FK.css +0 -2
  115. package/dist/web/assets/index-v-k_CVn7.js +0 -45
  116. package/dist/web/assets/logos-CfpaNwbY.js +0 -1
  117. package/dist/web/assets/palette-X7hU78Wy.js +0 -1
  118. package/dist/web/assets/parts-B7YrlR3a.js +0 -1
  119. package/dist/web/assets/productParts-CAxyMnWJ.js +0 -1
  120. package/dist/web/assets/qualityParts-CN9JVKZN.js +0 -1
  121. package/dist/web/assets/rows-IEP4Jvfi.js +0 -1
  122. package/dist/web/assets/segmented-DBqHvZW3.js +0 -1
  123. package/dist/web/assets/usePageChat-D_3KsqBU.js +0 -1
@@ -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)}