@capagents/forgeqe 2.5.0 → 2.5.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/dist/docs-site/docs/index.html +29 -7
- package/dist/docs-site/docs/mobile/index.html +29 -7
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/forgeqe.js +969 -959
- package/dist/web/assets/{Agent-Q7njo1Nn.js → Agent-BMqCDZeZ.js} +1 -1
- package/dist/web/assets/ApiTests-CkxIx6sI.js +2 -0
- package/dist/web/assets/{Chat-QFcqaBtK.js → Chat-BT6yGqKW.js} +3 -3
- package/dist/web/assets/{Data-CYWRWMA2.js → Data-BPtl_mUy.js} +4 -4
- package/dist/web/assets/{Features-CuixPXUj.js → Features-DwHyOoJu.js} +1 -1
- package/dist/web/assets/{Jobs-B88qIb_r.js → Jobs-DW2uXMkv.js} +3 -3
- package/dist/web/assets/{Quality-BIUiBg1X.js → Quality-BeuhtzZi.js} +1 -1
- package/dist/web/assets/Record-EHgUTspl.js +1 -0
- package/dist/web/assets/{Regression-BH1i_yvJ.js → Regression-BDq3BUP_.js} +2 -2
- package/dist/web/assets/{Reports-DnidGC7G.js → Reports-Bapldq1A.js} +2 -2
- package/dist/web/assets/{Response-o9QqBpwk.js → Response-Dh_kxnCt.js} +3 -3
- package/dist/web/assets/Runs-BOi2fP0o.js +2 -0
- package/dist/web/assets/{circle-dashed-CO-RmzsR.js → circle-dashed-C84s5T0C.js} +1 -1
- package/dist/web/assets/{frame-C0RAa-Ev.js → frame-z3iL_6aL.js} +2 -2
- package/dist/web/assets/index-BVw2ygO2.js +26 -0
- package/dist/web/assets/index-CBa29-yG.css +2 -0
- package/dist/web/assets/{markdown-9nLYjAqd.js → markdown-BtqKvAEi.js} +1 -1
- package/dist/web/assets/{sticky-note-BffcGVvl.js → sticky-note-C_NJNONZ.js} +1 -1
- package/dist/web/assets/{trending-up-BbHX2F6j.js → trending-up-DK1wDqic.js} +1 -1
- package/dist/web/index.html +3 -3
- package/docs/MOBILE.md +29 -7
- package/docs/user-guide.html +29 -7
- package/forgeqe.example.yaml +7 -0
- package/package.json +1 -1
- package/py/forgeqe_mobile/cli.py +9 -2
- package/py/forgeqe_mobile/hyperexecute.py +133 -19
- package/py/forgeqe_mobile/maestro.py +45 -3
- package/py/forgeqe_mobile/service.py +51 -14
- package/dist/web/assets/ApiTests-C0ZAAuTl.js +0 -2
- package/dist/web/assets/Record-DnT3bDoJ.js +0 -1
- package/dist/web/assets/Runs-hOT-2g1a.js +0 -2
- package/dist/web/assets/index-BdhUnF_q.css +0 -2
- package/dist/web/assets/index-DBQd0Qgk.js +0 -26
package/py/forgeqe_mobile/cli.py
CHANGED
|
@@ -15,7 +15,7 @@ from typing import List, Optional
|
|
|
15
15
|
from forgeqe_desktop.workflow import WorkflowError, load
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def doctor(appium_url: str, maestro: str) -> dict:
|
|
18
|
+
def doctor(appium_url: str, maestro: str, hyperexecute: Optional[str] = None) -> dict:
|
|
19
19
|
out: dict = {"appium_url": appium_url}
|
|
20
20
|
try:
|
|
21
21
|
req = urllib.request.Request(appium_url.rstrip("/") + "/status", method="GET")
|
|
@@ -30,6 +30,12 @@ def doctor(appium_url: str, maestro: str) -> dict:
|
|
|
30
30
|
out["maestro"] = bool(found)
|
|
31
31
|
if found:
|
|
32
32
|
out["maestro_path"] = found
|
|
33
|
+
if hyperexecute:
|
|
34
|
+
# Maestro on TestMu: TestMu's hyperexecute CLI, which runs the flows instead of a local maestro.
|
|
35
|
+
cli = shutil.which(hyperexecute)
|
|
36
|
+
out["hyperexecute"] = bool(cli)
|
|
37
|
+
if cli:
|
|
38
|
+
out["hyperexecute_path"] = cli
|
|
33
39
|
return out
|
|
34
40
|
|
|
35
41
|
|
|
@@ -47,6 +53,7 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
47
53
|
d = sub.add_parser("doctor", help="whether the Appium server and maestro answer, as JSON")
|
|
48
54
|
d.add_argument("--appium-url", default="http://127.0.0.1:4723")
|
|
49
55
|
d.add_argument("--maestro", default="maestro")
|
|
56
|
+
d.add_argument("--hyperexecute", help="mobile.maestro.testmu.cli, when Maestro runs on TestMu")
|
|
50
57
|
args = parser.parse_args(argv)
|
|
51
58
|
if args.command == "serve":
|
|
52
59
|
from .service import serve
|
|
@@ -64,7 +71,7 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
64
71
|
|
|
65
72
|
print(f"ok: {len(check_flow(args.flow, args.root))} flow files checked")
|
|
66
73
|
return 0
|
|
67
|
-
print(json.dumps(doctor(args.appium_url, args.maestro)))
|
|
74
|
+
print(json.dumps(doctor(args.appium_url, args.maestro, args.hyperexecute)))
|
|
68
75
|
return 0
|
|
69
76
|
except (WorkflowError, ValueError, OSError) as e:
|
|
70
77
|
print(f"error: {e}", file=sys.stderr)
|
|
@@ -14,10 +14,16 @@ argument list. The user and key come from the environment variables the config n
|
|
|
14
14
|
"""
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
import base64
|
|
18
|
+
import json
|
|
17
19
|
import os
|
|
18
20
|
import re
|
|
21
|
+
import secrets
|
|
19
22
|
import shutil
|
|
20
23
|
import subprocess
|
|
24
|
+
import time
|
|
25
|
+
import urllib.parse
|
|
26
|
+
import urllib.request
|
|
21
27
|
import zipfile
|
|
22
28
|
from pathlib import Path
|
|
23
29
|
from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple
|
|
@@ -26,21 +32,23 @@ import yaml
|
|
|
26
32
|
|
|
27
33
|
from forgeqe_desktop.workflow import WorkflowError
|
|
28
34
|
|
|
29
|
-
from .maestro import _junit,
|
|
35
|
+
from .maestro import _junit, command_runs
|
|
30
36
|
|
|
31
37
|
MAESTRO_ON_TESTMU = "2.6.1"
|
|
32
38
|
# The exact downloads TestMu's machine installs, checked before they are unpacked.
|
|
33
39
|
MAESTRO_SHA256 = "3440825f514f537c6a96bcf5de995780c2a4a7f83a43208fdc95d4f1fecfad3b"
|
|
34
40
|
PLATFORM_TOOLS = "35.0.2"
|
|
35
41
|
PLATFORM_TOOLS_SHA256 = "acfdcccb123a8718c46c46c059b2f621140194e5ec1ac9d81715be3d6ab6cd0a"
|
|
36
|
-
DEVICE = re.compile(r"^[A-Za-z0-9 ._*()+-]{1,60}
|
|
37
|
-
REGION = re.compile(r"^[a-z]{2,4}
|
|
38
|
-
LT_APP = re.compile(r"^lt://[A-Za-z0-9]{1,100}
|
|
42
|
+
DEVICE = re.compile(r"^[A-Za-z0-9 ._*()+-]{1,60}\Z")
|
|
43
|
+
REGION = re.compile(r"^[a-z]{2,4}\Z")
|
|
44
|
+
LT_APP = re.compile(r"^lt://[A-Za-z0-9]{1,100}\Z")
|
|
39
45
|
# Flow paths end up on HyperExecute's command line (./run.sh $test), which its shell reads: letters, digits, _ . - /.
|
|
40
|
-
#
|
|
41
|
-
|
|
46
|
+
# No part may be hidden (a name starting with a dot) except Maestro's usual .maestro/ folder at the top: hidden files of
|
|
47
|
+
# the working folder are never sent out of the machine.
|
|
48
|
+
SAFE_PATH = re.compile(r"^(?=.{1,210}\Z)(?!.*\.\.)(?:\.maestro/)?(?:[A-Za-z0-9_][A-Za-z0-9_.-]*/)*[A-Za-z0-9_][A-Za-z0-9_.-]*\.ya?ml\Z")
|
|
42
49
|
ARTIFACTS = "maestro-results"
|
|
43
|
-
|
|
50
|
+
# The job's page: on LambdaTest's domain, or TestMu AI's since the rename.
|
|
51
|
+
_JOB_LINK = re.compile(r"https://hyperexecute\.(?:lambdatest\.com|testmu\.ai)/[^\s'\"]+")
|
|
44
52
|
|
|
45
53
|
# TestMu's own setup for Maestro on HyperExecute (its sample, with Maestro taken from its release instead of an
|
|
46
54
|
# installer piped to a shell, and both downloads pinned to a version and checked against their SHA-256).
|
|
@@ -67,10 +75,12 @@ unzip -q -o maestro.zip
|
|
|
67
75
|
"""
|
|
68
76
|
|
|
69
77
|
RUN_SCRIPT = """#!/bin/bash
|
|
70
|
-
# One flow (its path from discover.txt), with Maestro's JUnit report for HyperExecute.
|
|
71
|
-
|
|
78
|
+
# One flow (its path from discover.txt), with Maestro's JUnit report for HyperExecute. What it prints is kept in
|
|
79
|
+
# MaestroLogs (uploaded with the results), so a run that stops before any command still says why.
|
|
80
|
+
set -o pipefail
|
|
72
81
|
name="$(basename "$1" .yaml)"
|
|
73
|
-
|
|
82
|
+
mkdir -p ./MaestroLogs
|
|
83
|
+
{ adb devices; "$HOME/maestro-cli/maestro/bin/maestro" test "$1" --debug-output ./MaestroLogs --format junit --output "./reports/$name.xml"; } 2>&1 | tee "./MaestroLogs/run-$name.log"
|
|
74
84
|
"""
|
|
75
85
|
|
|
76
86
|
|
|
@@ -114,6 +124,17 @@ def _app(app: Optional[str], project: Path) -> str:
|
|
|
114
124
|
return dest.name
|
|
115
125
|
|
|
116
126
|
|
|
127
|
+
def build_name(build: str) -> str:
|
|
128
|
+
"""The build name TestMu shows (and ForgeQE looks the run's videos up by): letters, digits, space _ . - only."""
|
|
129
|
+
return re.sub(r"[^A-Za-z0-9 _.-]", "_", build)[:100] or "forgeqe"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def discover_command(windows: bool = os.name == "nt") -> str:
|
|
133
|
+
"""The test list for HyperExecute: its CLI runs this here, on this machine, and in static mode the tests are the
|
|
134
|
+
lines it prints (``value`` alone is not read). ``type`` on Windows (cmd and PowerShell), ``cat`` elsewhere."""
|
|
135
|
+
return "type discover.txt" if windows else "cat discover.txt"
|
|
136
|
+
|
|
137
|
+
|
|
117
138
|
def write_project(project: Path, files: Sequence[Tuple[Path, str]], tests: Sequence[str], app: Optional[str], platform: str, settings: Mapping[str, Any], build: str) -> Path:
|
|
118
139
|
"""
|
|
119
140
|
The HyperExecute project: ``files`` (source, path under flows/) keep their layout, so a flow's runFlow paths still
|
|
@@ -126,7 +147,7 @@ def write_project(project: Path, files: Sequence[Tuple[Path, str]], tests: Seque
|
|
|
126
147
|
(project / "flows").mkdir(parents=True)
|
|
127
148
|
for rel in [*(r for _, r in files), *tests]:
|
|
128
149
|
if not SAFE_PATH.match(rel):
|
|
129
|
-
raise WorkflowError(f"flow path {rel!r}: for TestMu, flow files are named with letters, digits, _ . - and / only")
|
|
150
|
+
raise WorkflowError(f"flow path {rel!r}: for TestMu, flow files are named with letters, digits, _ . - and / only, in no hidden folder but .maestro/")
|
|
130
151
|
for src, rel in files:
|
|
131
152
|
dest = (project / "flows" / rel).resolve()
|
|
132
153
|
if (project / "flows").resolve() not in dest.parents:
|
|
@@ -146,7 +167,7 @@ def write_project(project: Path, files: Sequence[Tuple[Path, str]], tests: Seque
|
|
|
146
167
|
"deviceLog": True,
|
|
147
168
|
# An upload's lt:// id is the device's appId; a build file in the project is uploaded by the CLI as appPath.
|
|
148
169
|
**({"appId": app_ref} if LT_APP.match(app_ref) else {"appPath": app_ref}),
|
|
149
|
-
"buildName":
|
|
170
|
+
"buildName": build_name(build),
|
|
150
171
|
"queueTimeout": 600,
|
|
151
172
|
"disableReleaseDevice": True,
|
|
152
173
|
"isRealMobile": bool(settings["real_device"]),
|
|
@@ -166,7 +187,7 @@ def write_project(project: Path, files: Sequence[Tuple[Path, str]], tests: Seque
|
|
|
166
187
|
"framework": {"name": "raw", "args": args},
|
|
167
188
|
"env": {"MAESTRO": True, "MAESTRO_LOGS_DIR": "MaestroLogs", "MAESTRO_CLI_NO_ANALYTICS": "1"},
|
|
168
189
|
"pre": ["chmod +x ./setup.sh ./run.sh", "./setup.sh"],
|
|
169
|
-
"testDiscovery": {"command":
|
|
190
|
+
"testDiscovery": {"command": discover_command(), "value": names, "mode": "static", "type": "raw"},
|
|
170
191
|
"testRunnerCommand": "./run.sh $test",
|
|
171
192
|
"frameworkStatusOnly": True,
|
|
172
193
|
"report": True,
|
|
@@ -202,6 +223,7 @@ def run_hyperexecute(
|
|
|
202
223
|
env: Mapping[str, str],
|
|
203
224
|
timeout: float = 5400,
|
|
204
225
|
run: Callable[..., Any] = subprocess.run,
|
|
226
|
+
fetch_videos: Optional[Callable[..., List[Dict[str, Any]]]] = None,
|
|
205
227
|
) -> Dict[str, Any]:
|
|
206
228
|
"""Run ``tests`` on TestMu through HyperExecute; ``{ok, flows, commands, job, log}`` like run_maestro. HyperExecute
|
|
207
229
|
reports the job as a whole, so each flow carries the job's result; its page has each flow's."""
|
|
@@ -210,6 +232,8 @@ def run_hyperexecute(
|
|
|
210
232
|
if not user or not key:
|
|
211
233
|
raise WorkflowError(f"Maestro on TestMu needs {settings['username_env']} and {settings['access_key_env']} set (your TestMu user name and access key)")
|
|
212
234
|
project = out_dir / "hyperexecute"
|
|
235
|
+
# Each run its own build on TestMu, so its sessions (one per flow, with the video) are found after the job.
|
|
236
|
+
build = build_name(f"{build[:70]} {time.strftime('%Y-%m-%d_%H-%M-%S')}-{secrets.token_hex(2)}")
|
|
213
237
|
cfg = write_project(project, files, tests, app, platform, settings, build)
|
|
214
238
|
args = [settings["cli"], "--user", user, "--key", key, "--config", cfg.name, "--download-artifacts", "--download-artifacts-path", "artifacts", "--force-clean-artifacts"]
|
|
215
239
|
child_env = {k: v for k, v in env.items() if k not in (settings["username_env"], settings["access_key_env"])}
|
|
@@ -226,20 +250,107 @@ def run_hyperexecute(
|
|
|
226
250
|
(out_dir / "hyperexecute.log").write_text(log, encoding="utf-8")
|
|
227
251
|
job = (_JOB_LINK.findall(log) or [""])[-1]
|
|
228
252
|
ok = proc.returncode == 0
|
|
229
|
-
cases, commands = job_results(project / "artifacts")
|
|
253
|
+
cases, commands, runs = job_results(project / "artifacts", with_runs=True)
|
|
230
254
|
flows = cases or [{"name": t, "ok": ok} for t in tests]
|
|
231
|
-
result: Dict[str, Any] = {"ok": ok and all(c["ok"] for c in flows), "flows": flows, "commands": commands, "log": log[-2000:], **({"job": job} if job else {})}
|
|
255
|
+
result: Dict[str, Any] = {"ok": ok and all(c["ok"] for c in flows), "flows": flows, "commands": commands, "log": log[-2000:], **({"job": job} if job else {}), **({"device_runs": runs} if runs > 1 else {})}
|
|
232
256
|
if not result["ok"]:
|
|
233
257
|
failed = [c for c in cases if not c["ok"] and c.get("error")]
|
|
234
258
|
last = [line for line in log.strip().splitlines() if line.strip()][-1:] or [""]
|
|
235
259
|
result["error"] = (failed[0]["error"] if failed else f"HyperExecute exited with {proc.returncode}: {last[0][:500]}") + (f" (job: {job})" if job else "")
|
|
260
|
+
if job:
|
|
261
|
+
try:
|
|
262
|
+
videos = (fetch_videos or job_videos)(build, out_dir, user, key)
|
|
263
|
+
except Exception as e: # noqa: BLE001 - the run's result stands without its recordings
|
|
264
|
+
videos, result["video_error"] = [], str(e).replace(key, "***")[:300]
|
|
265
|
+
if videos:
|
|
266
|
+
result["videos"] = videos
|
|
236
267
|
return result
|
|
237
268
|
|
|
238
269
|
|
|
239
|
-
|
|
240
|
-
|
|
270
|
+
TESTMU_API = "https://mobile-api.lambdatest.com/mobile-automation/api/v1"
|
|
271
|
+
# Where TestMu keeps a session's recording; a video link anywhere else is not fetched.
|
|
272
|
+
_VIDEO_LINK = re.compile(r"^https://[A-Za-z0-9.-]+\.lambdatest\.com/")
|
|
273
|
+
MAX_VIDEO_BYTES = 500 * 1024 * 1024
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _testmu_get(url: str, user: str, key: str) -> Any:
|
|
277
|
+
token = base64.b64encode(f"{user}:{key}".encode()).decode()
|
|
278
|
+
req = urllib.request.Request(url, headers={"Authorization": f"Basic {token}", "Accept": "application/json"})
|
|
279
|
+
with urllib.request.urlopen(req, timeout=30) as r: # noqa: S310 - fixed https host
|
|
280
|
+
return json.loads(r.read().decode("utf-8", errors="replace"))
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _download(url: str, dest: Path) -> None:
|
|
284
|
+
part = dest.with_suffix(".part")
|
|
285
|
+
size = 0
|
|
286
|
+
with urllib.request.urlopen(url, timeout=120) as r, open(part, "wb") as f: # noqa: S310 - checked by _VIDEO_LINK
|
|
287
|
+
while chunk := r.read(1 << 20):
|
|
288
|
+
size += len(chunk)
|
|
289
|
+
if size > MAX_VIDEO_BYTES:
|
|
290
|
+
raise ValueError(f"the video is larger than {MAX_VIDEO_BYTES >> 20} MB")
|
|
291
|
+
f.write(chunk)
|
|
292
|
+
part.replace(dest)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def job_videos(
|
|
296
|
+
build: str,
|
|
297
|
+
out_dir: Path,
|
|
298
|
+
user: str,
|
|
299
|
+
key: str,
|
|
300
|
+
get: Callable[[str, str, str], Any] = _testmu_get,
|
|
301
|
+
download: Callable[[str, Path], None] = _download,
|
|
302
|
+
tries: int = 6,
|
|
303
|
+
pause: float = 5,
|
|
304
|
+
sleep: Callable[[float], None] = time.sleep,
|
|
305
|
+
) -> List[Dict[str, Any]]:
|
|
306
|
+
"""Each flow's recording from a finished job: TestMu keeps one App Automation session per flow and device, under
|
|
307
|
+
the job's build, with its video. Saved as videos/<flow>.mp4 in the run folder, with the session's TestMu page."""
|
|
308
|
+
sessions: List[Mapping[str, Any]] = []
|
|
309
|
+
for attempt in range(tries):
|
|
310
|
+
builds = get(f"{TESTMU_API}/builds?limit=20", user, key).get("data") or []
|
|
311
|
+
found = next((b for b in builds if isinstance(b, Mapping) and b.get("name") == build), None)
|
|
312
|
+
if found:
|
|
313
|
+
sessions = [s for s in get(f"{TESTMU_API}/sessions?build_id={int(found['build_id'])}&limit=50", user, key).get("data") or [] if isinstance(s, Mapping)]
|
|
314
|
+
# A video is ready a little after its session ends.
|
|
315
|
+
if sessions and all(s.get("video_url") for s in sessions):
|
|
316
|
+
break
|
|
317
|
+
if attempt < tries - 1:
|
|
318
|
+
sleep(pause)
|
|
319
|
+
folder = out_dir / "videos"
|
|
320
|
+
out: List[Dict[str, Any]] = []
|
|
321
|
+
used: set = set()
|
|
322
|
+
for s in sessions:
|
|
323
|
+
flow = str(s.get("name") or "flow")
|
|
324
|
+
device = str(s.get("device") or "")
|
|
325
|
+
base = re.sub(r"[^A-Za-z0-9_.-]", "_", Path(flow).stem).lstrip(".-")[:60] or "flow"
|
|
326
|
+
name = base if base not in used else re.sub(r"[^A-Za-z0-9_.-]", "_", f"{base}-{device}")[:80]
|
|
327
|
+
while name in used:
|
|
328
|
+
name += "_"
|
|
329
|
+
used.add(name)
|
|
330
|
+
test_id = str(s.get("test_id") or s.get("session_id") or "")
|
|
331
|
+
entry: Dict[str, Any] = {"flow": flow, "device": device, "status": str(s.get("status_ind") or "")}
|
|
332
|
+
if test_id:
|
|
333
|
+
entry["link"] = f"https://appautomation.lambdatest.com/test?testID={urllib.parse.quote(test_id)}"
|
|
334
|
+
url = s.get("video_url")
|
|
335
|
+
if isinstance(url, str) and _VIDEO_LINK.match(url):
|
|
336
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
337
|
+
try:
|
|
338
|
+
download(url, folder / f"{name}.mp4")
|
|
339
|
+
entry["file"] = f"videos/{name}.mp4"
|
|
340
|
+
except (OSError, ValueError) as e:
|
|
341
|
+
entry["error"] = str(e)[:200]
|
|
342
|
+
out.append(entry)
|
|
343
|
+
return out
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def job_results(artifacts: Path, with_runs: bool = False) -> Any:
|
|
347
|
+
"""The flows' JUnit results and Maestro's command results from a job's downloaded artifacts (zips unpacked).
|
|
348
|
+
|
|
349
|
+
A job on several devices brings back one run of Maestro per device. Their commands are not mixed: the first run
|
|
350
|
+
with a failed command gives the steps their results, else the first run. ``with_runs`` adds how many runs came back.
|
|
351
|
+
"""
|
|
241
352
|
if not artifacts.is_dir():
|
|
242
|
-
return [], []
|
|
353
|
+
return ([], [], 0) if with_runs else ([], [])
|
|
243
354
|
for z in list(artifacts.rglob("*.zip")):
|
|
244
355
|
target = z.with_suffix("")
|
|
245
356
|
try:
|
|
@@ -259,4 +370,7 @@ def job_results(artifacts: Path) -> Tuple[List[Dict[str, Any]], List[Dict[str, A
|
|
|
259
370
|
cases: List[Dict[str, Any]] = []
|
|
260
371
|
for xml in sorted(artifacts.rglob("*.xml")):
|
|
261
372
|
cases += _junit(xml)
|
|
262
|
-
|
|
373
|
+
runs = command_runs(artifacts)
|
|
374
|
+
failed = [r for r in runs if any(c.get("status") == "FAILED" for c in r)]
|
|
375
|
+
commands = (failed or runs or [[]])[0]
|
|
376
|
+
return (cases, commands, len(runs)) if with_runs else (cases, commands)
|
|
@@ -273,13 +273,25 @@ _INTERNAL_COMMANDS = frozenset({"applyConfigurationCommand", "defineVariablesCom
|
|
|
273
273
|
|
|
274
274
|
def command_results(debug_dir: Path) -> List[Dict[str, Any]]:
|
|
275
275
|
"""The status of each command Maestro ran (its debug output's commands-*.json), in order; [] when not written."""
|
|
276
|
-
|
|
276
|
+
return [c for run in command_runs(debug_dir) for c in run]
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def command_runs(debug_dir: Path) -> List[List[Dict[str, Any]]]:
|
|
280
|
+
"""Each Maestro run's command results, one list per folder of debug output: a job on several devices writes one
|
|
281
|
+
folder per device, so their commands are kept apart."""
|
|
282
|
+
runs: Dict[Path, List[Dict[str, Any]]] = {}
|
|
277
283
|
for f in sorted(debug_dir.rglob("commands-*.json")):
|
|
284
|
+
results = runs.setdefault(f.parent, [])
|
|
278
285
|
try:
|
|
279
286
|
doc = json.loads(f.read_text(encoding="utf-8", errors="replace"))
|
|
280
287
|
except ValueError:
|
|
281
288
|
continue
|
|
282
|
-
|
|
289
|
+
entries = doc if isinstance(doc, list) else []
|
|
290
|
+
# Maestro does not write the commands in the order they ran; each one's sequenceNumber gives it.
|
|
291
|
+
seqs = [((e.get("metadata") or {}) if isinstance(e, Mapping) else {}).get("sequenceNumber") for e in entries]
|
|
292
|
+
if entries and all(isinstance(s, int) for s in seqs):
|
|
293
|
+
entries = [e for _, e in sorted(zip(seqs, entries), key=lambda p: p[0])]
|
|
294
|
+
for entry in entries:
|
|
283
295
|
command = entry.get("command") if isinstance(entry, Mapping) else None
|
|
284
296
|
# Maestro's own bookkeeping (the flow's config, its env), not a command of the flow.
|
|
285
297
|
if isinstance(command, Mapping) and set(command) & _INTERNAL_COMMANDS:
|
|
@@ -288,7 +300,37 @@ def command_results(debug_dir: Path) -> List[Dict[str, Any]]:
|
|
|
288
300
|
status = str((meta or {}).get("status") or "").upper()
|
|
289
301
|
err = (meta or {}).get("error")
|
|
290
302
|
results.append({"status": status, **({"error": str(err.get("message") if isinstance(err, Mapping) else err)[:1000]} if err else {})})
|
|
291
|
-
return
|
|
303
|
+
return [r for r in runs.values() if r]
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
# The variables Maestro sets itself on every run: a flow reads them without an env: block.
|
|
307
|
+
MAESTRO_BUILTINS = frozenset({"MAESTRO_FILENAME", "MAESTRO_SHARD_ID", "MAESTRO_SHARD_INDEX", "MAESTRO_DEVICE_UDID"})
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def flow_variables(files: Iterable[str | os.PathLike]) -> Tuple[List[str], List[str]]:
|
|
311
|
+
"""``(used, defined)``: the ``${NAME}`` variables checked flows read, and those their own ``env:`` blocks set."""
|
|
312
|
+
used: List[str] = []
|
|
313
|
+
defined: set = set()
|
|
314
|
+
|
|
315
|
+
def walk(value: Any) -> None:
|
|
316
|
+
if isinstance(value, str):
|
|
317
|
+
for m in _JS_EXPR.finditer(value):
|
|
318
|
+
name = m.group(1).strip()
|
|
319
|
+
if name not in used:
|
|
320
|
+
used.append(name)
|
|
321
|
+
elif isinstance(value, Mapping):
|
|
322
|
+
for k, v in value.items():
|
|
323
|
+
if k == "env" and isinstance(v, Mapping):
|
|
324
|
+
defined.update(str(n) for n in v)
|
|
325
|
+
walk(v)
|
|
326
|
+
elif isinstance(value, list):
|
|
327
|
+
for v in value:
|
|
328
|
+
walk(v)
|
|
329
|
+
|
|
330
|
+
for f in files:
|
|
331
|
+
for doc in yaml.safe_load_all(Path(f).read_text(encoding="utf-8")):
|
|
332
|
+
walk(doc)
|
|
333
|
+
return used, sorted(defined)
|
|
292
334
|
|
|
293
335
|
|
|
294
336
|
def run_maestro(
|
|
@@ -18,7 +18,7 @@ import sys
|
|
|
18
18
|
import threading
|
|
19
19
|
import time
|
|
20
20
|
from pathlib import Path
|
|
21
|
-
from typing import IO, Any, Callable, Dict, List, Mapping, Optional
|
|
21
|
+
from typing import IO, Any, Callable, Dict, Iterable, List, Mapping, Optional
|
|
22
22
|
|
|
23
23
|
import yaml
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ from forgeqe_desktop.visual import image_checker
|
|
|
29
29
|
|
|
30
30
|
from .apps import load_mobile_apps
|
|
31
31
|
from .hyperexecute import run_hyperexecute, testmu_settings
|
|
32
|
-
from .maestro import check_flow, run_maestro, to_flow
|
|
32
|
+
from .maestro import MAESTRO_BUILTINS, check_flow, flow_variables, run_maestro, to_flow
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
def _mobile(req: Mapping[str, Any]) -> Dict[str, Any]:
|
|
@@ -69,10 +69,19 @@ def _maestro_command(mobile: Mapping[str, Any]) -> List[str]:
|
|
|
69
69
|
return list(cmd)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def
|
|
73
|
-
"""
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
def _child_env(req: Mapping[str, Any], keep: Iterable[str] = ()) -> Dict[str, str]:
|
|
73
|
+
"""This process's environment for a program it starts (maestro, hyperexecute), without ForgeQE's own secrets (the
|
|
74
|
+
model's key, service tokens: the request's private_env), except the names in ``keep``."""
|
|
75
|
+
private = req.get("private_env")
|
|
76
|
+
drop = {str(n) for n in private if isinstance(n, str)} if isinstance(private, list) else set()
|
|
77
|
+
drop -= set(keep)
|
|
78
|
+
return {k: v for k, v in os.environ.items() if k not in drop}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _maestro_env(req: Mapping[str, Any], names: List[str], secrets: Mapping[str, str]) -> Dict[str, str]:
|
|
82
|
+
"""The environment for maestro: system settings and listed secrets (not ForgeQE's own), with each secret as
|
|
83
|
+
MAESTRO_<NAME>, the only form a flow can read it in."""
|
|
84
|
+
env = _child_env(req)
|
|
76
85
|
for n in names:
|
|
77
86
|
if secrets.get(n) is not None:
|
|
78
87
|
env[f"MAESTRO_{n}"] = secrets[n]
|
|
@@ -108,14 +117,17 @@ def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, dr
|
|
|
108
117
|
if used:
|
|
109
118
|
raise WorkflowError("this workflow types secrets, which Maestro on TestMu cannot be given safely yet; replay it on TestMu with --driver appium")
|
|
110
119
|
events.log(f"Running {wf['name'] or 'the workflow'} on Maestro on TestMu ({', '.join(testmu['devices'])}).")
|
|
111
|
-
res = (cloud_run or run_hyperexecute)([(flow_file, "flow.yaml")], ["flow.yaml"], spec.app, spec.platform, testmu, out, wf["name"] or wf["app"],
|
|
120
|
+
res = (cloud_run or run_hyperexecute)([(flow_file, "flow.yaml")], ["flow.yaml"], spec.app, spec.platform, testmu, out, wf["name"] or wf["app"], _testmu_env(req, testmu))
|
|
112
121
|
else:
|
|
113
122
|
events.log(f"Running {wf['name'] or 'the workflow'} on Maestro ({flow_file}).")
|
|
114
|
-
res = (maestro_run or run_maestro)(_maestro_command(mobile), [str(flow_file)], out, _maestro_env(used, secrets), device=m.get("device"))
|
|
123
|
+
res = (maestro_run or run_maestro)(_maestro_command(mobile), [str(flow_file)], out, _maestro_env(req, used, secrets), device=m.get("device"))
|
|
115
124
|
steps = _maestro_steps(wf, res.get("commands") or [], res["ok"])
|
|
116
125
|
for s in steps:
|
|
117
126
|
events.emit({"type": "step", **s})
|
|
118
|
-
|
|
127
|
+
_log_videos(events, res)
|
|
128
|
+
if res.get("device_runs"):
|
|
129
|
+
events.log(f"The job ran on {res['device_runs']} devices; the steps show {'the first that failed' if not res['ok'] else 'the first'}, the job's page has each device's.")
|
|
130
|
+
return {**base, "ok": res["ok"], "steps": steps, "heals": [], "flow": str(flow_file), **({"job": res["job"]} if res.get("job") else {}), **({"device_runs": res["device_runs"]} if res.get("device_runs") else {}), **({"videos": res["videos"]} if res.get("videos") else {}), **({"error": res["error"]} if res.get("error") else {})}
|
|
119
131
|
|
|
120
132
|
from forgeqe_desktop.heal import make_heal
|
|
121
133
|
from forgeqe_desktop.models import takes_images
|
|
@@ -164,8 +176,10 @@ def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, dr
|
|
|
164
176
|
|
|
165
177
|
|
|
166
178
|
def _maestro_steps(wf: Mapping[str, Any], commands: List[Mapping[str, Any]], ok: bool) -> List[Dict[str, Any]]:
|
|
167
|
-
"""Each workflow step's result from Maestro's command results
|
|
168
|
-
|
|
179
|
+
"""Each workflow step's result from Maestro's command results, as to_flow writes them: a type step is three Maestro
|
|
180
|
+
commands, and a launch is launchApp then an optional tap for each dismiss target (which never fails the launch)."""
|
|
181
|
+
dismiss = len(wf.get("dismiss") or [])
|
|
182
|
+
per_step = [3 if s["op"] == "type" else 1 + dismiss if s["op"] == "launch" else 1 for s in wf["steps"]]
|
|
169
183
|
if not commands and not ok:
|
|
170
184
|
# No step's result is known (Maestro wrote none, or the job's results did not come back): the run's error says
|
|
171
185
|
# what failed, rather than a step that may have passed.
|
|
@@ -180,6 +194,8 @@ def _maestro_steps(wf: Mapping[str, Any], commands: List[Mapping[str, Any]], ok:
|
|
|
180
194
|
elif not chunk:
|
|
181
195
|
break # Maestro stopped before this step
|
|
182
196
|
else:
|
|
197
|
+
if step["op"] == "launch":
|
|
198
|
+
chunk = chunk[:1]
|
|
183
199
|
failed = [c for c in chunk if c.get("status") == "FAILED"]
|
|
184
200
|
status_ok = not failed and all(c.get("status") in ("COMPLETED", "SKIPPED", "WARNED") for c in chunk)
|
|
185
201
|
error = failed[0].get("error", "failed") if failed else ""
|
|
@@ -286,15 +302,36 @@ def run_flows(req: Mapping[str, Any], events: Events, maestro_run: Optional[Call
|
|
|
286
302
|
name = f"{len(flows)} Maestro flow{'' if len(flows) == 1 else 's'}"
|
|
287
303
|
if testmu:
|
|
288
304
|
spec = _app_of_flows(flows, load_mobile_apps(mobile))
|
|
305
|
+
used, defined = flow_variables(checked)
|
|
306
|
+
unset = [n for n in used if n not in defined and n not in MAESTRO_BUILTINS]
|
|
307
|
+
if unset:
|
|
308
|
+
# Locally a variable can come from the environment (MAESTRO_<NAME>); HyperExecute's machine has none of it.
|
|
309
|
+
raise WorkflowError(f"the flows read ${{{unset[0]}}}, which they do not set in an env: block; Maestro on TestMu cannot be given it yet, so run them with a local maestro")
|
|
289
310
|
events.log(f"Checked {len(checked)} flow file{'' if len(checked) == 1 else 's'}; running {len(flows)} on Maestro on TestMu.")
|
|
290
311
|
# A flow that runs another (runFlow) needs it in the project too: every checked file goes, in its layout.
|
|
291
312
|
real_root = Path(os.path.realpath(root))
|
|
292
313
|
rel = lambda f: Path(os.path.realpath(f)).relative_to(real_root).as_posix() # noqa: E731
|
|
293
|
-
res = (cloud_run or run_hyperexecute)([(Path(f), rel(f)) for f in checked], [rel(f) for f in flows], spec.app, spec.platform, testmu, out, name,
|
|
314
|
+
res = (cloud_run or run_hyperexecute)([(Path(f), rel(f)) for f in checked], [rel(f) for f in flows], spec.app, spec.platform, testmu, out, name, _testmu_env(req, testmu))
|
|
294
315
|
else:
|
|
295
316
|
events.log(f"Checked {len(checked)} flow file{'' if len(checked) == 1 else 's'}; running {len(flows)} on Maestro.")
|
|
296
|
-
res = (maestro_run or run_maestro)(_maestro_command(mobile), [str(Path(f).resolve()) for f in flows], out, _maestro_env(names, secrets), device=m.get("device"))
|
|
297
|
-
|
|
317
|
+
res = (maestro_run or run_maestro)(_maestro_command(mobile), [str(Path(f).resolve()) for f in flows], out, _maestro_env(req, names, secrets), device=m.get("device"))
|
|
318
|
+
_log_videos(events, res)
|
|
319
|
+
return {"mode": "maestro", "ok": res["ok"], "flows": res.get("flows") or [], "checked": checked, "name": name, **({"job": res["job"]} if res.get("job") else {}), **({"videos": res["videos"]} if res.get("videos") else {}), **({"error": res["error"]} if res.get("error") else {})}
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _log_videos(events: Events, res: Mapping[str, Any]) -> None:
|
|
323
|
+
"""Where each flow's TestMu recording was saved (or why not), for the person running it."""
|
|
324
|
+
for v in res.get("videos") or []:
|
|
325
|
+
where = v.get("file") or f"not saved ({v.get('error') or 'TestMu had no video for it'})"
|
|
326
|
+
events.log(f"Video of {v.get('flow')} on {v.get('device') or 'the device'}: {where}{' · ' + v['link'] if v.get('link') else ''}")
|
|
327
|
+
if res.get("video_error"):
|
|
328
|
+
events.log(f"The job's videos could not be fetched from TestMu: {res['video_error']}")
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _testmu_env(req: Mapping[str, Any], testmu: Mapping[str, Any]) -> Dict[str, str]:
|
|
332
|
+
"""The hyperexecute CLI's environment: no ForgeQE secrets, but TestMu's user and key, which run_hyperexecute reads
|
|
333
|
+
(and keeps out of the CLI's own environment)."""
|
|
334
|
+
return _child_env(req, keep=(testmu["username_env"], testmu["access_key_env"]))
|
|
298
335
|
|
|
299
336
|
|
|
300
337
|
def _app_of_flows(flows: List[str], apps: Mapping[str, Any]) -> Any:
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{At as e,Fr as t,G as n,J as r,K as i,Mr as a,Tt as o,Wn as s,X as c,Y as l,Z as u,_t as d,at as f,bt as p,ct as m,dr as h,dt as g,fr as _,ot as v,qt as y,r as b,st as x,t as S,wt as C,xt as w,yt as T}from"./frame-C0RAa-Ev.js";import{t as E}from"./circle-dashed-CO-RmzsR.js";import"./markdown-9nLYjAqd.js";import{C as D,S as O,T as k,i as A,n as j,r as M,t as N}from"./index-DBQd0Qgk.js";import{t as P}from"./when-CHnpLdYw.js";var F=t(a(),1),I=T(),L={passed:`pass`,failed:`fail`,error:`fail`,skipped:`neutral`},R={GET:`text-pass`,POST:`text-accent-fg`,PUT:`text-warn`,PATCH:`text-warn`,DELETE:`text-fail`},ee={run:`a browser run's calls`,openapi:`OpenAPI`,swagger:`Swagger`,wsdl:`WSDL`,graphql:`GraphQL`,proto:`.proto`,case:`a test case`,text:`a description`},z=e=>new Date(e).toLocaleString([],{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});function B({job:t,onStop:n}){let r=(0,F.useRef)(null);(0,F.useEffect)(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[t.lines.length]);let[i,a]={contracts:[`Making contracts`,`Made contracts`],run:[`Running the contracts`,`Ran the contracts`],scenarios:[`Making scenarios`,`Made scenarios`],"run-scenarios":[`Running the scenarios`,`Ran the scenarios`]}[t.kind]??[`Working`,`Done`],o=(t.kind===`run`||t.kind===`run-scenarios`)&&t.exitCode===1;return(0,I.jsxs)(`section`,{"aria-label":t.running?i:a,className:`flex flex-col gap-2 rounded-[14px] border border-line-soft p-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`span`,{className:`flex-1 font-medium`,children:t.running?i:a}),(0,I.jsx)(A,{orb:t.kind===`contracts`?`handing`:t.kind===`scenarios`?`writing`:`working`,tone:t.running?`running`:t.exitCode===0?`pass`:o?`warn`:`fail`,children:t.running?`Working`:t.exitCode===0?`Done`:o?`Some failed`:`Did not finish`}),t.running&&(0,I.jsxs)(g,{onClick:n,className:`border-fail text-fail hover:bg-fail-soft`,children:[(0,I.jsx)(e,{size:14,fill:`currentColor`,"aria-hidden":`true`}),`Stop`]})]}),(0,I.jsx)(`code`,{className:`font-mono text-[12px] text-muted [overflow-wrap:anywhere]`,children:t.command}),(0,I.jsxs)(`details`,{open:t.running,children:[(0,I.jsxs)(`summary`,{className:`cursor-pointer text-sm text-muted`,children:[`Output (`,t.lines.length,` lines)`]}),(0,I.jsx)(`pre`,{ref:r,className:`mt-2 max-h-[300px] overflow-auto rounded-[10px] bg-surface-muted p-3 font-mono text-[12px] leading-relaxed whitespace-pre-wrap text-ink-2`,children:t.lines.join(`
|
|
2
|
-
`)||`Starting…`})]})]})}var V=({m:e})=>(0,I.jsx)(`span`,{className:p(`w-[58px] flex-none font-mono text-[12px] font-semibold`,R[e.toUpperCase()]||`text-ink-2`),children:e.toUpperCase()});function te({c:e,r:t}){let n=Array.isArray(e.expect.status)?e.expect.status.join(` or `):e.expect.status,r=t&&t.status!==`passed`?[t.reason,...t.checks.filter(e=>!e.ok).map(e=>`${e.name}${e.detail?`: ${e.detail}`:``}`)].filter(Boolean).join(` · `):``;return(0,I.jsxs)(`li`,{className:`grid min-h-11 grid-cols-[58px_minmax(0,1fr)_auto] items-center gap-x-3 rounded-[10px] px-3 py-1.5 hover:bg-surface-muted @3xl:grid-cols-[58px_minmax(0,1fr)_200px_auto]`,children:[(0,I.jsx)(V,{m:e.method}),(0,I.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,I.jsx)(`span`,{className:`truncate font-mono text-[13px]`,title:e.protocol===`rest`?e.path:e.name,children:e.protocol===`rest`?e.path:e.name}),r?(0,I.jsx)(`span`,{className:p(`truncate text-[12px]`,t?.status===`skipped`?`text-muted`:`text-fail`),title:r,children:r}):(e.writes||e.needsData?.length)&&(0,I.jsx)(`span`,{className:`truncate text-[12px] text-warn`,children:[e.writes?`Changes data`:``,e.needsData?.length?`Needs real ${e.needsData.join(`, `)}`:``].filter(Boolean).join(` · `)})]}),(0,I.jsx)(`span`,{className:`hidden truncate text-[12px] text-muted @3xl:block`,children:[n?`expects ${n}`:``,e.expect.contentType,e.auth?`${e.auth.type} auth`:``].filter(Boolean).join(` · `)}),(0,I.jsx)(`span`,{className:`flex justify-end`,children:t?(0,I.jsx)(A,{tone:L[t.status],children:t.status===`skipped`?`Skipped`:t.httpStatus?`${t.httpStatus}`:t.status}):(0,I.jsx)(`span`,{className:`text-[12px] text-muted`,children:`Not run`})})]})}function ne({s:e,r:t}){let[n,r]=(0,F.useState)(!1);return(0,I.jsxs)(`li`,{className:`border-t border-line-soft first:border-t-0`,children:[(0,I.jsxs)(`button`,{type:`button`,"aria-expanded":n,onClick:()=>r(!n),className:`flex min-h-[52px] w-full cursor-pointer items-center gap-3 border-0 bg-transparent px-1 py-2 text-left text-ink hover:bg-surface-muted`,children:[(0,I.jsx)(d,{icon:C,size:16,className:`flex-none text-muted`}),(0,I.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,I.jsx)(`span`,{className:`text-sm [overflow-wrap:anywhere]`,children:e.name}),(0,I.jsxs)(`span`,{className:`truncate text-[12px] text-muted`,children:[e.kind,` · `,e.steps.length,` step`,e.steps.length===1?``:`s`,e.cleanup?.length?` · ${e.cleanup.length} cleanup`:``,e.caseId?` · ${e.caseId}`:``]})]}),e.writes&&(0,I.jsx)(A,{tone:`warn`,children:`Changes data`}),t&&(0,I.jsx)(A,{tone:L[t.status],children:t.status.charAt(0).toUpperCase()+t.status.slice(1)})]}),(0,I.jsx)(x,{open:n,children:(0,I.jsxs)(`ol`,{className:`m-0 mb-3 ml-8 flex list-none flex-col gap-1 border-l border-line pl-3 text-sm`,children:[e.steps.map((e,n)=>{let r=t?.steps[n];return(0,I.jsxs)(`li`,{className:`flex flex-col`,children:[(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(V,{m:e.method}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 font-mono text-[12px] [overflow-wrap:anywhere]`,children:e.path}),r&&(0,I.jsx)(A,{tone:L[r.status],children:r.httpStatus?String(r.httpStatus):r.status})]}),(0,I.jsxs)(`span`,{className:`pl-[66px] text-[12px] text-muted`,children:[e.name,e.save&&Object.keys(e.save).length?` · keeps ${Object.keys(e.save).join(`, `)}`:``,e.noAuth?` · without credentials`:``]}),r&&r.checks.some(e=>!e.ok)&&(0,I.jsx)(`span`,{className:`pl-[66px] text-[12px] text-fail`,children:r.checks.filter(e=>!e.ok).map(e=>`${e.name}${e.detail?`: ${e.detail}`:``}`).join(` · `)})]},n)}),e.cleanup?.map((e,t)=>(0,I.jsxs)(`li`,{className:`flex items-center gap-2 text-muted`,children:[(0,I.jsx)(V,{m:e.method}),(0,I.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.path}),(0,I.jsx)(`span`,{className:`text-[12px]`,children:`cleanup`})]},`c${t}`)),t?.reason&&(0,I.jsx)(`li`,{className:`text-[12px] text-fail [overflow-wrap:anywhere]`,children:t.reason})]})})]})}function re({what:e,writes:t,defaultUrl:r,onRun:i,onCancel:a,needsData:o}){let[s,c]=(0,F.useState)(r),[l,u]=(0,F.useState)(!1),[p,m]=(0,F.useState)(!1);return(0,I.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-[12px] border border-accent-line bg-accent-soft p-4`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e}),(0,I.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[`Against`,(0,I.jsx)(n,{value:s,spellCheck:!1,placeholder:`https://qa.example.com/api`,onChange:e=>c(e.target.value),className:`max-w-[480px] bg-bg`})]}),t>0&&(0,I.jsxs)(`span`,{className:`flex items-start gap-3 text-sm`,children:[(0,I.jsx)(f,{checked:l,onChange:u,label:`Also run the calls that change data`}),(0,I.jsxs)(`span`,{className:`flex flex-col`,children:[`Also run the `,t,` call`,t===1?``:`s`,` that change data`,(0,I.jsx)(`span`,{className:`text-[13px] text-warn`,children:`Only on a test environment: they create, change or delete data there.`})]})]}),o?(0,I.jsxs)(`span`,{className:`flex items-center gap-3 text-sm`,children:[(0,I.jsx)(f,{checked:p,onChange:m,label:`Also run calls with made-up values`}),`Also run the `,o,` call`,o===1?``:`s`,` whose values were made up`]}):null,(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,I.jsxs)(g,{variant:`primary`,onClick:()=>i({...s.trim()?{baseUrl:s.trim()}:{},allowWrites:l,includeNeedsData:p}),children:[(0,I.jsx)(d,{icon:y,size:16}),`Run`]}),(0,I.jsx)(g,{onClick:a,children:`Don't run`})]})]})}function ie({open:e,onClose:t,view:a,set:o,onMake:s,busy:c}){let[l,u]=(0,F.useState)(`spec`),[d,m]=(0,F.useState)(``),[h,_]=(0,F.useState)(``),[v,y]=(0,F.useState)(``),[b,x]=(0,F.useState)(!0);(0,F.useEffect)(()=>{e&&(u(o.source.kind===`run`?`run`:`spec`),m(o.source.kind===`run`?``:a.runs[0]?.id??``))},[e,o.source.kind,a.runs]);let S=(e,t,n)=>(0,I.jsxs)(`label`,{className:p(`flex cursor-pointer items-start gap-3 rounded-[12px] border px-3 py-2.5`,l===e?`border-accent bg-accent-soft`:`border-line-soft hover:bg-surface-muted`),children:[(0,I.jsx)(`input`,{type:`radio`,name:`sc-from`,checked:l===e,onChange:()=>u(e),className:`mt-1 size-4 accent-accent`}),(0,I.jsxs)(`span`,{className:`flex flex-col`,children:[(0,I.jsx)(`span`,{className:`text-sm font-medium`,children:t}),(0,I.jsx)(`span`,{className:`text-[13px] text-muted`,children:n})]})]});return(0,I.jsx)(r,{open:e,onClose:t,title:`Make scenarios`,description:`API calls in order, where later calls use values earlier answers gave, added to ${o.name}. Nothing runs until you run them.`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(g,{onClick:t,children:`Cancel`}),(0,I.jsx)(g,{variant:`primary`,disabled:c||l===`cases`&&!h.trim()||l===`text`&&!v.trim(),onClick:()=>s({from:l,...l===`run`&&d?{run:d}:{},...l===`cases`?{cases:h}:{},...l===`text`?{text:v}:{},...l===`spec`?{negative:b}:{}}),children:`Make scenarios`})]}),children:(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 pt-3`,children:[S(`spec`,`From the API description`,`Each resource's lifecycle, browsing, the description's links, and negative cases (no model)`),l===`spec`&&(0,I.jsxs)(`span`,{className:`flex items-center gap-2 pl-10 text-sm`,children:[(0,I.jsx)(f,{checked:b,onChange:x,label:`Negative cases`}),` Negative cases: an id that does not exist, no credentials, an empty body`]}),S(`run`,`From a browser run`,`The calls the application made, in order, with the values passed on (no model)`),l===`run`&&(0,I.jsxs)(i,{"aria-label":`Browser run`,value:d,onChange:e=>m(e.target.value),className:`ml-10 max-w-[440px]`,children:[(0,I.jsx)(`option`,{value:``,children:`The latest run`}),a.runs.map(e=>(0,I.jsxs)(`option`,{value:e.id,children:[e.goal,` · `,w(e.calls,`call`),` · `,z(e.at)]},e.id))]}),S(`cases`,`From test cases`,`One scenario per case, planned by the model against the set's operations`),l===`cases`&&(0,I.jsx)(n,{"aria-label":`Test cases`,value:h,spellCheck:!1,placeholder:`ado:2238, jira:SHOP-12`,onChange:e=>_(e.target.value),className:`ml-10 max-w-[440px]`}),S(`text`,`From a description`,`In plain words, planned by the model; a step no operation does is listed, never invented`),l===`text`&&(0,I.jsx)(n,{"aria-label":`The scenario`,value:v,maxLength:1e3,placeholder:`Create a user, log in, add two items, check out, the total is the sum`,onChange:e=>y(e.target.value),className:`ml-10`})]})})}function H({open:e,onClose:t,view:a,onMake:o,busy:s}){let[c,l]=(0,F.useState)(`spec`),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),[_,v]=(0,F.useState)(``);return(0,F.useEffect)(()=>{e&&(d(a.specs[0]??``),p(``),h(``),v(a.baseUrl??``),l(a.specs.length||!a.runs.length?`spec`:`run`))},[e,a]),(0,I.jsx)(r,{open:e,onClose:t,title:`New contract set`,description:`One contract per operation: an example call and what its answer must have (status, content type, schema, key fields). Making them runs nothing.`,footer:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(g,{onClick:t,children:`Cancel`}),(0,I.jsx)(g,{variant:`primary`,disabled:s||c===`spec`&&!u.trim(),onClick:()=>o({from:c,...c===`spec`?{spec:u.trim()}:f?{run:f}:{},...m.trim()?{name:m.trim()}:{},..._.trim()?{baseUrl:_.trim()}:{}}),children:`Make contracts`})]}),children:(0,I.jsxs)(`div`,{className:`flex flex-col gap-4 pt-3`,children:[(0,I.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 border-0 p-0`,children:[(0,I.jsx)(`legend`,{className:`mb-1.5 text-sm font-medium`,children:`From`}),(0,I.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 text-sm`,children:[(0,I.jsx)(`input`,{type:`radio`,name:`set-from`,checked:c===`spec`,onChange:()=>l(`spec`),className:`size-4 accent-accent`}),`An API description: OpenAPI or Swagger, WSDL, GraphQL, .proto, or grpc://`]}),c===`spec`&&(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5 pl-6`,children:[(0,I.jsx)(n,{"aria-label":`API description`,value:u,spellCheck:!1,list:`spec-files`,placeholder:`https://shop.test/openapi.json, or a file in the project`,onChange:e=>d(e.target.value)}),(0,I.jsx)(`datalist`,{id:`spec-files`,children:a.specs.map(e=>(0,I.jsx)(`option`,{value:e},e))}),a.specs.length>0&&(0,I.jsxs)(`span`,{className:`text-[13px] text-muted`,children:[`In this project: `,a.specs.slice(0,6).join(`, `)]})]}),(0,I.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 text-sm`,children:[(0,I.jsx)(`input`,{type:`radio`,name:`set-from`,checked:c===`run`,onChange:()=>l(`run`),className:`size-4 accent-accent`}),`The calls a browser run saw the application make`]}),c===`run`&&(0,I.jsxs)(i,{"aria-label":`Browser run`,value:f,onChange:e=>p(e.target.value),className:`ml-6 max-w-[440px]`,children:[(0,I.jsx)(`option`,{value:``,children:`The latest run`}),a.runs.map(e=>(0,I.jsxs)(`option`,{value:e.id,children:[e.goal,` · `,w(e.calls,`call`),` · `,z(e.at)]},e.id))]})]}),(0,I.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium`,children:[`Name`,(0,I.jsx)(n,{value:m,maxLength:120,placeholder:`Petstore`,onChange:e=>h(e.target.value)})]}),(0,I.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium`,children:[`Base URL`,(0,I.jsx)(n,{value:_,spellCheck:!1,placeholder:`https://qa.shop.test/api`,onChange:e=>v(e.target.value)}),(0,I.jsxs)(`span`,{className:`text-[13px] font-normal text-muted`,children:[`Where the contracts run when not where they were recorded or described.`,a.headers.length?` Each call sends ${a.headers.join(`, `)} from api.headers in forgeqe.yaml.`:` Credentials go in api.headers in forgeqe.yaml, as references to environment variables.`]})]})]})})}var U=50,ae=e=>e.length>48?`…/${e.split(/[\\/]/).filter(Boolean).slice(-2).join(`/`)}`:e;function W({label:e,last:t,onOpen:n}){if(!t)return(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[13px] text-muted`,children:[(0,I.jsx)(E,{size:14,"aria-hidden":`true`}),e,`: not run yet`]});let r=t.counts.failed+t.counts.error,i=t.counts.passed+r;return(0,I.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1.5 text-[13px] text-ink-2`,children:[r?(0,I.jsx)(s,{size:14,"aria-label":`Failures`,className:`text-fail`}):(0,I.jsx)(k,{size:14,"aria-label":`Passed`,className:`text-pass`}),e,`:`,` `,(0,I.jsxs)(`b`,{className:p(`tabular-nums`,r?`text-fail`:`text-ink`),children:[t.counts.passed,`/`,i,` passed`]}),t.counts.skipped?(0,I.jsxs)(`span`,{className:`text-muted`,children:[`· `,t.counts.skipped,` skipped`]}):null,(0,I.jsxs)(`span`,{className:`text-muted`,children:[`· `,P(t.at)]}),t.report&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>n(t.report),className:`cursor-pointer border-0 bg-transparent p-0 text-[13px] text-accent-fg hover:underline`,children:`· Report`})]})}function G({id:e,view:t,busy:n,act:r,version:i}){let[a,s]=(0,F.useState)(null),[c,f]=(0,F.useState)(``),[m,v]=(0,F.useState)(null),[b,x]=(0,F.useState)(!1),[S,C]=(0,F.useState)(``),[T,E]=(0,F.useState)(`contracts`),[D,k]=(0,F.useState)(``),[A,P]=(0,F.useState)(`all`),[L,R]=(0,F.useState)(0);(0,F.useEffect)(()=>{let t=!1;return h.set(e).then(e=>!t&&(s(e),f(``)),e=>!t&&f(e.message)),()=>{t=!0}},[e,i]),(0,F.useEffect)(()=>{v(null),E(`contracts`),k(``),P(`all`)},[e]),(0,F.useEffect)(()=>R(0),[e,T,D,A]);let B=(0,F.useMemo)(()=>new Map((a?.last.contracts?.results??[]).map(e=>[e.id,e])),[a]),V=(0,F.useMemo)(()=>new Map((a?.last.scenarios?.results??[]).map(e=>[e.id,e])),[a]);if(c)return(0,I.jsx)(`p`,{className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail`,children:c});if(!a)return(0,I.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Loading…`});let H=a.contracts.filter(e=>e.writes).length,G=a.contracts.filter(e=>e.needsData?.length).length,K=a.scenarios??[],q=a.last.contracts,oe=a.last.scenarios,J=t.baseUrl||a.baseUrl||``,Y=async e=>C(await l(e)),se=async e=>{try{let{id:t}=await _.start(`Write the API contracts${e?` and scenarios`:``} of set ${a.id} as tests in the repository: call write_api_tests with set_id ${a.id}${e?` and scenarios ["all"]`:``}. Show me the plan before you write.`,{});location.hash=u(`chats`,t)}catch(e){C(e.message)}},X=e=>{let t=B.get(e.id);return!!t&&(t.status===`failed`||t.status===`error`)},ce=D.toLowerCase().split(/\s+/).filter(Boolean),Z=a.contracts.filter(e=>ce.every(t=>`${e.method} ${e.path} ${e.name}`.toLowerCase().includes(t))),le=[{id:`all`,label:`All`,n:Z.length},{id:`failed`,label:`Failed`,n:Z.filter(X).length,alert:!0},...H?[{id:`writes`,label:`Changes data`,n:Z.filter(e=>e.writes).length}]:[],...q?[{id:`unrun`,label:`Not run`,n:Z.filter(e=>!B.has(e.id)).length}]:[]],Q=[...Z.filter(e=>A===`failed`?X(e):A===`writes`?e.writes:A!==`unrun`||!B.has(e.id))].sort((e,t)=>Number(X(t))-Number(X(e))),$=K.filter(e=>ce.every(t=>e.name.toLowerCase().includes(t)));return(0,I.jsxs)(`section`,{"aria-labelledby":`set-h`,className:`flex min-w-0 flex-1 flex-col gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,I.jsx)(`h2`,{id:`set-h`,className:`m-0 text-[22px] font-semibold tracking-[-0.01em] [overflow-wrap:anywhere]`,children:a.name}),(0,I.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 text-[13px] text-muted`,children:[(0,I.jsxs)(`span`,{children:[`From `,ee[a.source.kind]||a.source.kind,` `,(0,I.jsx)(`span`,{className:`font-mono text-[12px]`,title:a.source.ref,children:ae(a.source.ref)})]}),`· `,(0,I.jsx)(`span`,{children:z(a.createdAt)}),a.baseUrl&&(0,I.jsxs)(I.Fragment,{children:[`· `,(0,I.jsx)(`span`,{className:`font-mono text-[12px] [overflow-wrap:anywhere]`,children:a.baseUrl})]})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(g,{variant:`primary`,size:`sm`,disabled:n||!a.contracts.length,onClick:()=>v(`contracts`),children:[(0,I.jsx)(d,{icon:y,size:15}),`Run contracts`]}),(0,I.jsxs)(g,{size:`sm`,disabled:n||!K.length,onClick:()=>v(`scenarios`),children:[(0,I.jsx)(d,{icon:y,size:15}),`Run scenarios`]}),(0,I.jsxs)(g,{size:`sm`,disabled:n,onClick:()=>x(!0),children:[(0,I.jsx)(O,{size:15,"aria-hidden":`true`}),`Make scenarios`]}),(0,I.jsxs)(g,{size:`sm`,variant:`ghost`,onClick:()=>void se(K.length>0),children:[(0,I.jsx)(d,{icon:o,size:15}),`Write them as tests`]})]}),S&&(0,I.jsx)(`p`,{className:`m-0 text-[13px] text-fail`,children:S}),m===`contracts`&&(0,I.jsx)(re,{what:`Run ${a.contracts.length} contract${a.contracts.length===1?``:`s`}`,writes:H,needsData:G,defaultUrl:J,onCancel:()=>v(null),onRun:e=>{v(null),r(()=>h.run(a.id,e))}}),m===`scenarios`&&(0,I.jsx)(re,{what:`Run ${K.length} scenario${K.length===1?``:`s`}`,writes:K.filter(e=>e.writes).length,defaultUrl:J,onCancel:()=>v(null),onRun:e=>{v(null),r(()=>h.runScenarios(a.id,{...e.baseUrl?{baseUrl:e.baseUrl}:{},allowWrites:e.allowWrites}))}}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-[12px] bg-surface-muted px-4 py-2.5`,children:[(0,I.jsx)(W,{label:`Contracts`,last:q,onOpen:e=>void Y(e)}),K.length>0&&(0,I.jsx)(W,{label:`Scenarios`,last:oe,onOpen:e=>void Y(e)})]}),(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-col rounded-[14px] border border-line-soft bg-bg`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line-soft px-3 py-2.5`,children:[(0,I.jsx)(`div`,{role:`tablist`,"aria-label":`In this set`,className:`flex gap-1 rounded-[10px] bg-surface-strong p-1`,children:[[`contracts`,`Contracts`,a.contracts.length],[`scenarios`,`Scenarios`,K.length]].map(([e,t,n])=>(0,I.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":T===e,onClick:()=>E(e),className:p(`inline-flex min-h-8 cursor-pointer items-center gap-1.5 rounded-[7px] border-0 px-3 text-sm font-medium`,T===e?`bg-bg text-ink shadow-sm`:`bg-transparent text-muted hover:text-ink`),children:[t,(0,I.jsx)(`span`,{className:`text-[12px] text-muted tabular-nums`,children:n})]},e))}),(0,I.jsx)(M,{id:`api-search`,label:T===`contracts`?`Find a call`:`Find a scenario`,placeholder:T===`contracts`?`Find a call by its path`:`Find a scenario`,value:D,onChange:k})]}),T===`contracts`?(0,I.jsxs)(I.Fragment,{children:[le.length>1&&(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2.5`,children:(0,I.jsx)(N,{items:le,value:A,onChange:P})}),(0,I.jsxs)(`ul`,{"aria-label":`Contracts`,className:`@container m-0 flex list-none flex-col p-1.5`,children:[Q.length===0&&(0,I.jsx)(`li`,{className:`px-3 py-4 text-sm text-muted`,children:a.contracts.length?`Nothing matches.`:`This set has no contracts.`}),Q.slice(L*U,L*U+U).map(e=>(0,I.jsx)(te,{c:e,r:B.get(e.id)},e.id))]}),(0,I.jsx)(j,{page:L,size:U,total:Q.length,onPage:R,label:`Pages of contracts`,children:a.skipped?.length?(0,I.jsxs)(`span`,{title:a.skipped.join(`; `),children:[` · `,w(a.skipped.length,`operation`),` left out`]}):null})]}):K.length?(0,I.jsxs)(`ul`,{"aria-label":`Scenarios`,className:`m-0 flex list-none flex-col px-3 py-1.5`,children:[$.length===0&&(0,I.jsx)(`li`,{className:`py-4 text-sm text-muted`,children:`Nothing matches.`}),$.map(e=>(0,I.jsx)(ne,{s:e,r:V.get(e.id)},e.id))]}):(0,I.jsxs)(`div`,{className:`flex flex-col items-start gap-2 px-4 py-5`,children:[(0,I.jsx)(`span`,{className:`text-sm text-muted`,children:`No scenarios yet. A scenario chains calls end to end, each using what the one before answered.`}),(0,I.jsxs)(g,{size:`sm`,disabled:n,onClick:()=>x(!0),children:[(0,I.jsx)(O,{size:15,"aria-hidden":`true`}),`Make scenarios`]})]})]}),(0,I.jsx)(ie,{open:b,onClose:()=>x(!1),view:t,set:a,busy:n,onMake:e=>{x(!1),r(()=>h.scenarios(a.id,e))}})]})}function K({sub:e}){let[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(!1),[l,d]=(0,F.useState)(!1),f=(0,F.useCallback)(()=>{h.view().then(e=>{n(e),i(``)},e=>i(e.message))},[]);(0,F.useEffect)(f,[f]);let _=!!t?.job?.running;(0,F.useEffect)(()=>{if(!_)return;let e=setInterval(f,1500);return()=>clearInterval(e)},[_,f]);let y=async e=>{o(!0),i(``);try{await e(),f()}catch(e){i(e.message)}finally{o(!1)}},x=e?decodeURIComponent(e):``,C=t?.sets.find(e=>e.id===x)||t?.sets[0],T=`${t?.job?.endedAt??``}|${C?.at??``}`,[A,j]=(0,F.useState)(``),N=(t?.sets??[]).filter(e=>A.toLowerCase().split(/\s+/).filter(Boolean).every(t=>e.name.toLowerCase().includes(t)));return(0,I.jsxs)(`div`,{className:`flex min-h-screen flex-col`,children:[(0,I.jsx)(b,{}),(0,I.jsxs)(`main`,{className:p(S,`@container flex-auto gap-4`),children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(v,{pixel:c[`api-tests`],size:`lg`}),(0,I.jsx)(`h1`,{className:`m-0 flex-1 text-[26px] font-semibold tracking-[-0.01em]`,children:`API tests`}),(0,I.jsxs)(g,{variant:`primary`,disabled:!t||_,onClick:()=>d(!0),children:[(0,I.jsx)(O,{size:16,"aria-hidden":`true`}),`New contract set`]})]}),(0,I.jsx)(`p`,{className:`m-0 max-w-[74ch] text-sm leading-relaxed text-muted`,children:`REST, GraphQL, SOAP and gRPC, tested straight against the API with no browser and no model. A contract is one call and what its answer must have; a scenario chains calls end to end.`}),r&&(0,I.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:r}),!t&&!r&&(0,I.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}),t?.job&&(0,I.jsx)(B,{job:t.job,onStop:()=>y(()=>h.stop())}),t&&(t.sets.length?(0,I.jsxs)(`div`,{className:`flex flex-col gap-6 @2xl:flex-row @2xl:items-start @2xl:gap-8`,children:[(0,I.jsxs)(`nav`,{"aria-label":`Contract sets`,className:`flex min-w-0 flex-col gap-2 @2xl:sticky @2xl:top-6 @2xl:w-[280px] @2xl:flex-none`,children:[(0,I.jsxs)(`span`,{className:`px-1 text-[13px] font-medium text-muted`,children:[`Contract sets (`,t.sets.length,`)`]}),t.sets.length>6&&(0,I.jsx)(M,{id:`set-search`,label:`Find a set`,value:A,onChange:j,className:`flex-none`}),(0,I.jsxs)(`ul`,{className:`m-0 flex max-h-[60vh] list-none flex-col overflow-y-auto p-0 @2xl:max-h-[calc(100vh-240px)]`,children:[N.length===0&&(0,I.jsx)(`li`,{className:`px-3 py-3 text-sm text-muted`,children:`Nothing matches.`}),N.map(e=>{let n=e.last?.contracts,r=!!n&&n.counts.failed+n.counts.error>0;return(0,I.jsx)(`li`,{children:(0,I.jsxs)(`a`,{href:u(`api-tests`,encodeURIComponent(e.id)),"aria-current":C?.id===e.id?`page`:void 0,className:p(`flex min-h-12 items-center gap-2.5 rounded-[10px] px-3 py-1.5 text-ink no-underline`,C?.id===e.id?`bg-surface-strong hover:text-ink`:`hover:bg-surface-muted hover:text-ink`),children:[t?.job?.running&&t.job.target===e.id?(0,I.jsx)(m,{state:`working`,label:`Working on it`,px:16}):n?r?(0,I.jsx)(s,{size:16,"aria-label":`Failures`,className:`flex-none text-fail`}):(0,I.jsx)(k,{size:16,"aria-label":`Passed`,className:`flex-none text-pass`}):(0,I.jsx)(E,{size:16,"aria-label":`Not run`,className:`flex-none text-muted`}),(0,I.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,I.jsx)(`span`,{className:`truncate text-[14px] font-medium`,children:e.name}),(0,I.jsxs)(`span`,{className:`truncate text-[12px] text-muted`,children:[w(e.contracts,`contract`),e.scenarios?` · ${w(e.scenarios,`scenario`)}`:``,n?` · ${n.counts.passed}/${n.counts.passed+n.counts.failed+n.counts.error} passed`:``]})]}),(0,I.jsx)(`span`,{className:`flex-none text-[12px] text-muted tabular-nums`,children:P(e.at)})]})},e.id)})]})]}),C&&(0,I.jsx)(G,{id:C.id,view:t,busy:a||_,act:y,version:T})]}):(0,I.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-[18px] border border-line p-6`,children:[(0,I.jsx)(D,{size:24,"aria-hidden":`true`,className:`text-muted`}),(0,I.jsxs)(`p`,{className:`m-0 max-w-[62ch] leading-relaxed text-ink-2`,children:[`No API contracts yet. Make a set from your OpenAPI, Swagger, WSDL, GraphQL or .proto description`,t.runs.length?`, or from the ${w(t.runs[0].calls,`call`)} the run "${t.runs[0].goal}" saw`:``,`.`]}),(0,I.jsx)(g,{onClick:()=>d(!0),children:`New contract set`})]}))]}),t&&(0,I.jsx)(H,{open:l,onClose:()=>d(!1),view:t,busy:a||_,onMake:e=>y(async()=>{await h.contracts(e),d(!1)})})]})}export{K as ApiTests};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{An as e,At as t,Cr as n,Fn as r,Fr as i,G as a,K as o,Kn as s,Mr as c,Tt as l,Wn as u,X as d,Y as f,Z as p,Zt as m,_t as h,ar as g,at as _,bt as v,ct as y,dt as b,fr as x,hn as S,in as C,ot as w,qt as T,r as E,st as ee,t as D,wn as O,xt as k,yt as A}from"./frame-C0RAa-Ev.js";import{t as j}from"./markdown-9nLYjAqd.js";import{t as M}from"./sticky-note-BffcGVvl.js";import{O as te,T as N,b as P,h as ne,i as F,m as re,n as ie,r as ae,t as oe}from"./index-DBQd0Qgk.js";import{n as I,t as se}from"./when-CHnpLdYw.js";var L={name:`circle-dot`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};L.node;var ce=g(L),R={name:`crosshair`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`22`,x2:`18`,y1:`12`,y2:`12`,key:`l9bcsi`}],[`line`,{x1:`6`,x2:`2`,y1:`12`,y2:`12`,key:`13hhkx`}],[`line`,{x1:`12`,x2:`12`,y1:`6`,y2:`2`,key:`10w3f3`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`18`,key:`15g9kq`}]]};R.node;var le=g(R),z={name:`dot`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]};z.node;var ue=g(z),B={name:`hourglass`,size:24,node:[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]};B.node;var V=g(B),H={name:`keyboard`,size:24,node:[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]};H.node;var U=g(H),W={name:`mouse-pointer-click`,size:24,node:[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]};W.node;var G=g(W),K={name:`pause`,size:24,node:[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]};K.node;var de=g(K),q={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]};q.node;var fe=g(q),J={name:`variable`,size:24,node:[[`path`,{d:`M8 21s-4-3-4-9 4-9 4-9`,key:`uto9ud`}],[`path`,{d:`M16 3s4 3 4 9-4 9-4 9`,key:`4w2vsq`}],[`line`,{x1:`15`,x2:`9`,y1:`9`,y2:`15`,key:`f7djnv`}],[`line`,{x1:`9`,x2:`15`,y1:`9`,y2:`15`,key:`1shsy8`}]]};J.node;var Y=g(J),X=i(c(),1),Z=A(),pe={navigate:S,back:te,click:G,dblclick:G,input:U,press:U,select:C,upload:fe,expect:N,wait_for:V,capture:Y,note:M,launch:T,double_click:G,type:U,keys:U},me=e=>pe[e]||(e.startsWith(`expect`)?N:ue),he=new Set([`starting`,`recording`,`paused`,`stopping`]);function ge(e,t){let n=Math.max(0,Math.round(((t?Date.parse(t):Date.now())-Date.parse(e))/1e3));return n<3600?`${Math.floor(n/60)}:${String(n%60).padStart(2,`0`)}`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}async function _e(e){let{id:t}=await x.start(`Turn the recording in ${e} into a test: call write_test with run_dir ${e}. Show me the plan before you write.`,{});location.hash=p(`chats`,t)}async function Q(e){let{id:t}=await x.start(`Replay the desktop workflow ${e}: call desktop_replay with workflow ${e}, and tell me how each step went.`,{});location.hash=p(`chats`,t)}function ve({s:e,live:t,onDelete:n}){let r=me(e.op);return(0,Z.jsxs)(`li`,{className:`group flex min-h-[44px] items-start gap-3 border-t border-line-soft py-2 first:border-t-0`,children:[(0,Z.jsx)(`span`,{className:`w-6 flex-none pt-0.5 text-right text-[13px] text-muted tabular-nums`,children:e.n}),(0,Z.jsx)(r,{size:16,"aria-hidden":`true`,className:v(`mt-0.5 flex-none`,e.op.startsWith(`expect`)?`text-pass`:`text-muted`)}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`text-sm [overflow-wrap:anywhere]`,children:e.text}),(e.note||e.dynamic||e.inferred||e.case_step)&&(0,Z.jsxs)(`span`,{className:`flex flex-wrap gap-x-2 text-[12px] text-muted`,children:[e.case_step?(0,Z.jsxs)(`span`,{children:[`case step `,e.case_step]}):null,e.dynamic&&(0,Z.jsx)(`span`,{children:`value changes between runs`}),e.inferred&&(0,Z.jsx)(`span`,{children:`added by ForgeQE`}),e.note&&(0,Z.jsxs)(`span`,{className:`[overflow-wrap:anywhere]`,children:[`note: `,e.note]})]})]}),t&&e.n>1&&(0,Z.jsx)(b,{variant:`icon`,size:`icon`,"aria-label":`Delete step ${e.n}`,onClick:n,className:`size-8 flex-none opacity-60 group-hover:opacity-100`,children:(0,Z.jsx)(ne,{size:15,"aria-hidden":`true`})})]})}function ye({s:e,send:n,busy:i}){let[o,s]=(0,X.useState)(``),[,c]=(0,X.useState)(0);(0,X.useEffect)(()=>{let e=setInterval(()=>c(e=>e+1),1e3);return()=>clearInterval(e)},[]);let u=(0,X.useRef)(null);(0,X.useEffect)(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[e.log.length]);let d=e.kind===`desktop`,f=e.state===`paused`,p=e.log.at(-1)?.level===`warn`&&/press Stop again/i.test(e.log.at(-1).text),m=Math.max(0,...e.steps.map(e=>e.case_step||0)),g=(t,r,a,o)=>(0,Z.jsxs)(b,{disabled:i||e.state===`starting`,onClick:()=>n({cmd:t}),title:o,children:[(0,Z.jsx)(a,{size:16,"aria-hidden":`true`}),r]},t);return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3 rounded-[14px] border border-line-soft px-4 py-3`,children:[f?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`size-3 flex-none rounded-full bg-warn`}):(0,Z.jsx)(y,{state:e.state===`starting`?`waiting`:e.state===`stopping`?`working`:`recording`,px:20}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-[1_1_260px] flex-col gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`font-medium [overflow-wrap:anywhere]`,children:e.name}),(0,Z.jsxs)(`span`,{className:`truncate text-[13px] text-muted`,children:[e.state===`starting`?d?`Starting ${e.app}…`:`Opening the browser…`:e.state===`stopping`?`Saving the workflow…`:f?`Paused: what you do now is not recorded`:`Recording`,` · `,ge(e.startedAt),` ·`,` `,d?`${e.app}, a desktop app`:e.url]})]}),!d&&(0,Z.jsxs)(b,{disabled:i||e.state===`starting`,onClick:()=>n({cmd:`pause`}),children:[f?(0,Z.jsx)(h,{icon:T,size:16}):(0,Z.jsx)(de,{size:16,"aria-hidden":`true`}),f?`Resume`:`Pause`]}),(0,Z.jsxs)(b,{disabled:i||e.state===`stopping`,onClick:()=>n({cmd:`stop`,...p?{force:!0}:{}}),className:`border-fail bg-fail text-white hover:bg-fail hover:text-white hover:opacity-90`,children:[(0,Z.jsx)(t,{size:14,fill:`currentColor`,"aria-hidden":`true`}),p?`Stop anyway`:`Stop and save`]})]}),d?(0,Z.jsxs)(`p`,{className:`m-0 rounded-[12px] bg-accent-soft px-4 py-3 text-sm leading-relaxed text-ink-2`,children:[e.app,` is open on this computer: do the steps in it. Only clicks and keys in its own windows are recorded; password fields are saved as secret names, never as what you type. In the app, `,(0,Z.jsx)(`strong`,{children:`Ctrl+Shift+F11`}),` over a control adds a check of what it shows, and `,(0,Z.jsx)(`strong`,{children:`Ctrl+Shift+F12`}),` or closing the app stops.`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`details`,{className:`rounded-[12px] bg-accent-soft px-4 py-2.5 text-sm text-ink-2`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer`,children:`Do the steps in the browser on this computer. Keys in the page…`}),(0,Z.jsxs)(`p`,{className:`m-0 mt-2 leading-relaxed`,children:[`The Recorder panel in the page does the same as these buttons; in the page, `,e.leader,` then a letter: `,(0,Z.jsx)(`strong`,{children:`A`}),` check, `,(0,Z.jsx)(`strong`,{children:`V`}),` keep a value, `,(0,Z.jsx)(`strong`,{children:`W`}),` wait for, `,(0,Z.jsx)(`strong`,{children:`D`}),` test data, `,(0,Z.jsx)(`strong`,{children:`N`}),` note,`,` `,(0,Z.jsx)(`strong`,{children:`P`}),` pause, `,(0,Z.jsx)(`strong`,{children:`Z`}),` undo, `,(0,Z.jsx)(`strong`,{children:`S`}),` stop.`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,role:`toolbar`,"aria-label":`Recorder`,children:[g(`assert`,`Check an element`,le,`Pick an element in the page to check`),g(`variable`,`Keep a value`,Y,`Pick an element whose text later steps use`),g(`wait`,`Wait for`,V,`Pick an element the test waits for`),g(`data`,`Test data`,r,`The last value you typed becomes test data`),g(`note`,`Note`,M,`A note for the step, for whoever reads the test`),g(`undo`,`Undo`,re,`Remove the last step`)]}),(0,Z.jsxs)(`form`,{className:`flex flex-wrap gap-2`,onSubmit:e=>{e.preventDefault(),o.trim()&&(n({cmd:`chat`,text:o.trim()}),s(``))},children:[(0,Z.jsx)(`label`,{htmlFor:`rec-check`,className:`sr-only`,children:`Describe a check`}),(0,Z.jsx)(a,{id:`rec-check`,value:o,maxLength:2e3,placeholder:`Describe a check: the total shows "$40.00", or note: …`,onChange:e=>s(e.target.value),className:`min-w-0 flex-[1_1_320px]`}),(0,Z.jsxs)(b,{type:`submit`,variant:`primary`,disabled:i||!o.trim()||e.state===`starting`,children:[(0,Z.jsx)(h,{icon:l,size:16}),`Add`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-5`,children:[(0,Z.jsxs)(`section`,{"aria-labelledby":`rec-steps`,className:`flex min-w-0 flex-[999_1_420px] flex-col gap-2 rounded-[14px] border border-line-soft px-4 py-3`,children:[(0,Z.jsxs)(`h2`,{id:`rec-steps`,className:`m-0 flex items-center gap-2 text-base font-semibold`,children:[(0,Z.jsx)(h,{icon:C,size:18,className:`text-accent-fg`}),`Steps`,(0,Z.jsx)(`span`,{className:`text-sm font-normal text-muted`,children:e.summary})]}),e.steps.length?(0,Z.jsx)(`ol`,{className:`m-0 flex list-none flex-col p-0`,"aria-live":`polite`,children:e.steps.map(e=>(0,Z.jsx)(ve,{s:e,live:!d,onDelete:()=>n({cmd:`delete`,n:e.n})},`${e.n}-${e.text}`))}):(0,Z.jsx)(`p`,{className:`m-0 py-2 text-sm text-muted`,children:e.state===`starting`?d?`Starting ${e.app}…`:`Opening the browser…`:`Nothing yet: do the first step in ${d?e.app:`the browser`}.`})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_300px] flex-col gap-5`,children:[e.case&&(0,Z.jsxs)(`section`,{"aria-labelledby":`rec-case`,className:`flex flex-col gap-2 rounded-[14px] border border-line-soft px-4 py-3`,children:[(0,Z.jsxs)(`h2`,{id:`rec-case`,className:`m-0 flex items-center gap-2 text-base font-semibold`,children:[(0,Z.jsx)(h,{icon:C,size:18,className:`text-accent-fg`}),e.case.id]}),(0,Z.jsxs)(`p`,{className:`m-0 text-[13px] text-muted`,children:[e.case.title,`. Each step you record belongs to the case step you are on: pick one to record it.`]}),(0,Z.jsx)(`ol`,{className:`m-0 flex list-none flex-col p-0`,children:e.case.steps.map(t=>{let r=e.steps.some(e=>e.case_step===t.n);return(0,Z.jsx)(`li`,{className:`border-t border-line-soft first:border-t-0`,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:i,"aria-current":t.n===m?`step`:void 0,onClick:()=>n({cmd:`case_step`,n:t.n}),className:v(`flex w-full cursor-pointer items-start gap-2 rounded-[10px] border-0 bg-transparent px-2 py-2 text-left text-sm text-ink hover:bg-surface-muted`,t.n===m&&`bg-accent-soft`),children:[r?(0,Z.jsx)(N,{size:16,"aria-hidden":`true`,className:`mt-0.5 flex-none text-pass`}):(0,Z.jsx)(`span`,{className:`mt-0.5 w-4 flex-none text-center text-[12px] text-muted`,children:t.n}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Z.jsx)(`span`,{className:`[overflow-wrap:anywhere]`,children:t.action}),t.expected&&(0,Z.jsxs)(`span`,{className:`text-[12px] text-muted [overflow-wrap:anywhere]`,children:[`Expect: `,t.expected]})]})]})},t.n)})}),(0,Z.jsx)(b,{disabled:i,onClick:()=>n({cmd:`case_next`}),className:`self-start`,children:`Next case step`})]}),(0,Z.jsxs)(`section`,{"aria-labelledby":`rec-log`,className:`flex flex-col gap-2 rounded-[14px] border border-line-soft px-4 py-3`,children:[(0,Z.jsx)(`h2`,{id:`rec-log`,className:`m-0 text-base font-semibold`,children:`What the recorder says`}),(0,Z.jsx)(`div`,{ref:u,className:`flex max-h-[280px] flex-col gap-1 overflow-auto text-[13px]`,"aria-live":`polite`,children:e.log.length?e.log.map((e,t)=>(0,Z.jsx)(`p`,{className:v(`m-0 [overflow-wrap:anywhere]`,e.level===`warn`?`text-warn`:e.level===`error`?`text-fail`:`text-ink-2`),children:e.text},t)):(0,Z.jsxs)(`p`,{className:`m-0 text-muted`,children:[`Waiting for `,d?`the app`:`the browser`,`…`]})})]})]})]})]})}function be({s:t}){let n=t.result,[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(!1);if(!n)return null;let s=t.kind===`desktop`;return(0,Z.jsxs)(`section`,{"aria-labelledby":`rec-result`,className:`flex flex-col gap-3 rounded-[14px] border border-line-soft p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h2`,{id:`rec-result`,className:`m-0 flex-1 text-base font-semibold [overflow-wrap:anywhere]`,children:t.name}),(0,Z.jsx)(F,{tone:n.ok?`pass`:`fail`,children:n.ok?`Recorded`:`Not recorded`})]}),(0,Z.jsxs)(`p`,{className:`m-0 text-sm text-ink-2`,children:[n.ok?n.summary||t.summary:n.error||`Nothing was recorded.`,` `,t.endedAt&&(0,Z.jsxs)(`span`,{className:`text-muted`,children:[`· `,ge(t.startedAt,t.endedAt)]})]}),n.ok&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-sm`,children:[(0,Z.jsx)(F,{tone:`neutral`,icon:!1,children:k(t.steps.length,`step`)}),(0,Z.jsxs)(F,{tone:n.checks?`pass`:`warn`,children:[n.checks,` check`,n.checks===1?``:`s`]}),n.variables.length>0&&(0,Z.jsxs)(F,{tone:`neutral`,icon:!1,children:[`kept: `,n.variables.join(`, `)]}),n.testData.length>0&&(0,Z.jsxs)(F,{tone:`neutral`,icon:!1,children:[`test data: `,n.testData.join(`, `)]})]}),!s&&n.secrets.length>0&&(0,Z.jsxs)(`p`,{className:`m-0 text-sm text-ink-2`,children:[`The test reads`,` `,n.secrets.map((e,t)=>(0,Z.jsxs)(`span`,{children:[t?`, `:``,(0,Z.jsx)(`code`,{className:`font-mono text-[13px]`,children:e})]},e)),` `,`from the environment: what you typed there was not saved. Set `,n.secrets.length===1?`it`:`them`,` before the test runs.`]}),n.caseGaps.length>0&&(0,Z.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5 text-sm text-warn`,children:n.caseGaps.map(e=>(0,Z.jsxs)(`li`,{children:[`No check for case step `,e.n,`: expects “`,e.expected,`”`]},e.n))}),(n.notes??[]).length>0&&(0,Z.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5 text-sm text-ink-2`,children:n.notes.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))}),n.skipped.length>0&&(0,Z.jsx)(`ul`,{className:`m-0 flex flex-col gap-1 pl-5 text-sm text-muted`,children:n.skipped.map((e,t)=>(0,Z.jsxs)(`li`,{children:[`Not recorded: `,e.action,`: `,e.reason]},t))}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s&&n.workflow&&(0,Z.jsxs)(b,{variant:`primary`,disabled:a,onClick:async()=>{o(!0);try{await Q(n.workflow)}catch(e){i(e.message),o(!1)}},children:[(0,Z.jsx)(P,{size:16,"aria-hidden":`true`}),`Replay it`]}),s&&n.report&&(0,Z.jsxs)(b,{onClick:async()=>i(await f(n.report)),children:[(0,Z.jsx)(h,{icon:e,size:16}),`Open the report`]}),!s&&n.ok&&(0,Z.jsxs)(b,{variant:`primary`,disabled:a,onClick:async()=>{o(!0);try{await _e(t.runDir)}catch(e){i(e.message),o(!1)}},children:[(0,Z.jsx)(h,{icon:l,size:16}),`Write a test from it`]}),!s&&n.ok&&(0,Z.jsxs)(b,{onClick:async()=>i(await f(`${t.runDir}/trace.md`)),children:[(0,Z.jsx)(h,{icon:O,size:16}),`Read the steps`]}),(0,Z.jsx)(`span`,{className:`text-sm`,children:(0,Z.jsx)(j,{path:s&&n.workflow?n.workflow:t.runDir})}),r&&(0,Z.jsx)(`span`,{className:`text-[13px] text-fail`,children:r})]})]})}function xe({view:e,busy:t,onStart:n}){let[r,i]=(0,X.useState)(e.session?.kind===`desktop`&&e.desktop.available?`desktop`:`web`),[c,l]=(0,X.useState)(e.desktop.apps[0]??``),[u,d]=(0,X.useState)(e.apps[0]?.name??``),[f,h]=(0,X.useState)(``),[g,y]=(0,X.useState)(``),[x,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(e.environment??``),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),A=r===`desktop`?e.desktop.available&&!!c:u?!0:/^https?:\/\/\S+$/i.test(f.trim()),j=r===`web`||e.environments.length>1;return(0,Z.jsxs)(`form`,{"aria-labelledby":`rec-new`,className:`flex flex-col gap-3 rounded-[14px] border border-line-soft bg-bg p-4`,onSubmit:t=>{if(t.preventDefault(),A){if(r===`desktop`)return n({kind:`desktop`,app:c,...g.trim()?{name:g.trim()}:{},...w&&w!==e.environment?{env:w}:{}});n({...u?{app:u}:{url:f.trim()},...g.trim()?{name:g.trim()}:{},...x.trim()?{case:x.trim()}:{},...w&&w!==e.environment?{env:w}:{},signedIn:E})}},children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`h2`,{id:`rec-new`,className:`m-0 flex-1 text-base font-semibold`,children:`New recording`}),(0,Z.jsx)(`div`,{role:`radiogroup`,"aria-label":`What to record`,className:`flex gap-1 rounded-[10px] bg-surface-strong p-1`,children:[[`web`,`Web page`,S,!0],[`desktop`,`Desktop app`,m,e.desktop.available]].map(([t,n,a,o])=>(0,Z.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r===t,disabled:!o,title:o?void 0:e.desktop.reason||`Windows only.`,onClick:()=>i(t),className:v(`inline-flex min-h-8 cursor-pointer items-center gap-1.5 rounded-[7px] border-0 px-3 text-sm font-medium disabled:cursor-not-allowed disabled:opacity-50`,r===t?`bg-bg text-ink shadow-sm`:`bg-transparent text-muted hover:text-ink`),children:[(0,Z.jsx)(a,{size:14,"aria-hidden":`true`}),n]},t))})]}),(0,Z.jsxs)(`div`,{className:`grid gap-2 @2xl:grid-cols-[minmax(0,1.2fr)_minmax(0,1fr)_auto]`,children:[r===`desktop`?e.desktop.apps.length?(0,Z.jsx)(o,{"aria-label":`App`,value:c,onChange:e=>l(e.target.value),children:e.desktop.apps.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}):(0,Z.jsxs)(`p`,{className:`m-0 self-center text-sm text-muted`,children:[`No desktop apps yet: add one in `,(0,Z.jsx)(`a`,{href:p(`settings`,`environments`),children:`Settings, Environments`}),`.`]}):(0,Z.jsxs)(`div`,{className:`flex min-w-0 gap-2`,children:[e.apps.length>0&&(0,Z.jsxs)(o,{"aria-label":`Start on`,value:u,onChange:e=>d(e.target.value),className:v(u?`min-w-0 flex-1`:`w-[150px] flex-none`),children:[e.apps.map(e=>(0,Z.jsxs)(`option`,{value:e.name,children:[e.name,` · `,e.url]},e.name)),(0,Z.jsx)(`option`,{value:``,children:`Another page…`})]}),!u&&(0,Z.jsx)(a,{"aria-label":`Page address`,type:`url`,value:f,spellCheck:!1,placeholder:`https://shop.example.com/`,onChange:e=>h(e.target.value),className:`min-w-0 flex-1`})]}),(0,Z.jsx)(a,{"aria-label":`What the test does`,value:g,maxLength:200,placeholder:`What the test does`,onChange:e=>y(e.target.value)}),(0,Z.jsxs)(b,{type:`submit`,variant:`primary`,disabled:t||!A,children:[(0,Z.jsx)(ce,{size:16,"aria-hidden":`true`}),t?r===`desktop`?`Starting…`:`Opening…`:`Start recording`]})]}),j&&(0,Z.jsxs)(`button`,{type:`button`,"aria-expanded":O,onClick:()=>k(!O),className:`inline-flex cursor-pointer items-center gap-1 self-start border-0 bg-transparent p-0 text-[13px] text-muted hover:text-ink`,children:[(0,Z.jsx)(s,{size:14,"aria-hidden":`true`,className:v(`transition-transform`,O&&`rotate-180`)}),`More options`,!O&&(x||E||w&&w!==e.environment)?(0,Z.jsx)(`span`,{className:`text-accent-fg`,children:`· set`}):null]}),(0,Z.jsx)(ee,{open:O,children:(0,Z.jsxs)(`div`,{className:`grid gap-3 rounded-[12px] bg-surface-muted p-3 @2xl:grid-cols-2`,children:[r===`web`&&(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium`,children:[`Test case `,(0,Z.jsx)(`span`,{className:`-mt-1 text-[12.5px] font-normal text-muted`,children:`Its steps are listed while you record; each one you do is tied to it.`}),(0,Z.jsx)(a,{value:x,spellCheck:!1,placeholder:`SHOP-12, ado:1234 or a file`,onChange:e=>C(e.target.value),className:`bg-bg`})]}),e.environments.length>1&&(r===`desktop`||!!u)&&(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm font-medium`,children:[`Environment`,(0,Z.jsx)(o,{value:w,onChange:e=>T(e.target.value),children:e.environments.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})]}),r===`web`&&e.logins.length>0&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 @2xl:col-span-2`,children:[(0,Z.jsx)(_,{checked:E,onChange:D,label:`Start signed in`}),(0,Z.jsxs)(`span`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:`Start signed in`}),(0,Z.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`With the saved sign-ins (`,e.logins.join(`, `),`). Off: the sign-in is recorded too, its password saved as a variable name, never as typed.`]})]})]})]})}),(0,Z.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:r===`desktop`?`The app starts on this computer; do the steps in it. It is saved as a workflow that replays with no model.`:`A browser opens on this computer with the Recorder panel in the page. A chat turns the recording into a test.`})]})}var $=20;function Se({rows:t}){let[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(`all`),[c,d]=(0,X.useState)(0);if((0,X.useEffect)(()=>d(0),[i,o]),!t.length)return null;let p=i.toLowerCase().split(/\s+/).filter(Boolean),g=t.filter(e=>p.every(t=>`${e.name} ${e.caseId||``} ${e.app||``} ${e.startUrl}`.toLowerCase().includes(t))),_=o===`all`?g:g.filter(e=>e.kind===o),v=_.slice(c*$,c*$+$),y=t.some(e=>e.kind===`desktop`)&&t.some(e=>e.kind===`web`);return(0,Z.jsxs)(`section`,{"aria-labelledby":`rec-list`,className:`flex min-w-0 flex-col gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`h2`,{id:`rec-list`,className:`m-0 mr-2 text-base font-semibold`,children:[`Recordings `,(0,Z.jsx)(`span`,{className:`font-normal text-muted tabular-nums`,children:t.length})]}),(0,Z.jsx)(ae,{id:`rec-search`,label:`Find a recording`,value:i,onChange:a}),y&&(0,Z.jsx)(oe,{items:[{id:`all`,label:`All`,n:g.length},{id:`web`,label:`Web`,n:g.filter(e=>e.kind===`web`).length},{id:`desktop`,label:`Desktop`,n:g.filter(e=>e.kind===`desktop`).length}],value:o,onChange:s})]}),n&&(0,Z.jsx)(`p`,{className:`m-0 text-[13px] text-fail`,children:n}),(0,Z.jsxs)(`div`,{className:`rounded-[14px] border border-line-soft bg-bg`,children:[(0,Z.jsxs)(`ul`,{className:`m-0 list-none p-1.5`,children:[v.length===0&&(0,Z.jsx)(`li`,{className:`px-3 py-4 text-sm text-muted`,children:`Nothing matches.`}),v.map((t,n)=>{let i=I(t.startedAt);return(0,Z.jsxs)(`li`,{className:`contents`,children:[(n===0||I(v[n-1].startedAt)!==i)&&(0,Z.jsx)(`span`,{className:`block px-3 pt-3 pb-1 text-[12px] font-semibold text-muted`,children:i}),(0,Z.jsxs)(`div`,{className:`grid min-h-12 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 rounded-[10px] px-3 py-1.5 hover:bg-surface-muted`,children:[t.ok?(0,Z.jsx)(N,{size:16,"aria-label":`Recorded`,className:`text-pass`}):(0,Z.jsx)(u,{size:16,"aria-label":`Not recorded`,className:`text-fail`}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[t.kind===`desktop`?(0,Z.jsx)(h,{icon:m,size:13,className:`flex-none text-muted`,label:`Desktop app`}):(0,Z.jsx)(h,{icon:S,size:13,className:`flex-none text-muted`,label:`Web page`}),(0,Z.jsx)(`span`,{className:`truncate text-[14px] font-medium`,title:t.name,children:t.name})]}),(0,Z.jsx)(`span`,{className:`truncate text-[12px] text-muted`,children:[k(t.steps,`step`),k(t.checks,`check`),t.caseId,t.app,se(t.startedAt)].filter(Boolean).join(` · `)})]}),(0,Z.jsxs)(`span`,{className:`flex flex-none items-center gap-1`,children:[t.trace&&(0,Z.jsx)(b,{size:`icon`,variant:`icon`,"aria-label":`Read the steps of ${t.name}`,title:`Read the steps`,onClick:async()=>r(await f(t.trace)),children:(0,Z.jsx)(h,{icon:O,size:15})}),t.report&&(0,Z.jsx)(b,{size:`icon`,variant:`icon`,"aria-label":`Open the report of ${t.name}`,title:`Open the report`,onClick:async()=>r(await f(t.report)),children:(0,Z.jsx)(h,{icon:e,size:15})}),t.kind===`desktop`&&t.workflow&&(0,Z.jsxs)(b,{size:`sm`,onClick:()=>Q(t.workflow).catch(e=>r(e.message)),children:[(0,Z.jsx)(P,{size:14,"aria-hidden":`true`}),(0,Z.jsx)(`span`,{className:`hidden @md:inline`,children:`Replay`})]}),t.kind===`web`&&t.ok&&(0,Z.jsxs)(b,{size:`sm`,onClick:()=>_e(t.runDir).catch(e=>r(e.message)),children:[(0,Z.jsx)(h,{icon:l,size:14}),(0,Z.jsx)(`span`,{className:`hidden @md:inline`,children:`Write a test`})]})]})]})]},t.runDir)})]}),(0,Z.jsx)(ie,{page:c,size:$,total:_.length,onPage:d,label:`Pages of recordings`})]})]})}function Ce(){let[e,t]=(0,X.useState)(null),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(!1),s=(0,X.useCallback)(()=>{n.get().then(e=>{t(e),i(``)},e=>i(e.message))},[]);(0,X.useEffect)(s,[s]);let c=!!e?.session&&he.has(e.session.state);(0,X.useEffect)(()=>{if(!c)return;let e=setInterval(s,800);return()=>clearInterval(e)},[c,s]);let l=async e=>{o(!0),i(``);try{t(await e())}catch(e){i(e.message)}finally{o(!1)}},u=e?.session;return(0,Z.jsxs)(`div`,{className:`flex min-h-screen flex-col`,children:[(0,Z.jsx)(E,{}),(0,Z.jsxs)(`main`,{className:v(D,`@container flex-auto gap-4`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(w,{pixel:d.record,size:`lg`}),(0,Z.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:`Record`})]}),(0,Z.jsx)(`p`,{className:`m-0 max-w-[74ch] text-sm leading-relaxed text-muted`,children:`Do a test's steps yourself in a browser or a Windows app ForgeQE opens; each click, entry and check you add is recorded in order.`}),r&&(0,Z.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:r}),!e&&!r&&(0,Z.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}),e&&u&&c&&(0,Z.jsx)(ye,{s:u,busy:a,send:e=>void l(()=>n.command(e))}),e&&!c&&(0,Z.jsxs)(Z.Fragment,{children:[u?.result&&(0,Z.jsx)(be,{s:u}),(0,Z.jsx)(xe,{view:e,busy:a,onStart:e=>void l(()=>n.start(e))}),(0,Z.jsx)(Se,{rows:e.recordings})]})]})]})}export{Ce as Record};
|