fusiontest 0.2.48__tar.gz → 0.2.49__tar.gz
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.
- {fusiontest-0.2.48 → fusiontest-0.2.49}/PKG-INFO +2 -1
- {fusiontest-0.2.48 → fusiontest-0.2.49}/README.md +1 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/cli.py +131 -6
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/action_model.py +4 -1
- fusiontest-0.2.49/fusiontest/core/evidence.py +147 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/runner.py +33 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/secrets.py +6 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/desktop/playwright_adapter.py +166 -3
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/PKG-INFO +2 -1
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/SOURCES.txt +1 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/pyproject.toml +1 -1
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/agent/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/agent/mcp_server.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/agent/verify.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/security.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/sites/shop/bugs.js +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/sites/shop/help.html +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/sites/shop/index.html +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/billing-security-spa.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/billing-security.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/diffs/order-retry.diff +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/diffs/sale-banner.diff +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/diffs/stock-check.diff +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/shop-hard.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/shop-intent.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/app_errors.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/bugs.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/goal_verifier.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/promise_checker.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/replay.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/reproduce.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/shared_traces.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/discovery/goal_generator.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/discovery/intent.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/browser_auth.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/checks.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/config.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/engine.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/security/findings.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/requires.txt +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.48 → fusiontest-0.2.49}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fusiontest
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.49
|
|
4
4
|
Summary: AI-powered UI testing for mobile and desktop — by FusionLeap.io
|
|
5
5
|
Author-email: FusionLeap <hello@fusionleap.io>
|
|
6
6
|
License: MIT
|
|
@@ -108,6 +108,7 @@ what passes as regression goals. See [docs/coding-agents.md](docs/coding-agents.
|
|
|
108
108
|
| Multi-provider LLMs | Groq, Claude, Gemini, OpenAI or local Ollama, with automatic fallback |
|
|
109
109
|
| Safe secrets | `{{PASSWORD}}` placeholders — the AI never sees values, which are only typed on allowed sites |
|
|
110
110
|
| Guardrails | Invalid-action checks, loop detection, backtracking, no-progress detection |
|
|
111
|
+
| Run evidence | Web & Electron: a video of the run, a Playwright trace per failed goal, and console and network errors, in the report and the dashboard |
|
|
111
112
|
| Reporting | JSON reports, dashboard uploads, failure screenshots, Slack, GitHub Actions annotations, webhooks |
|
|
112
113
|
| Platforms | Web (Playwright), Electron, Android & iOS (Appium), Windows, macOS |
|
|
113
114
|
|
|
@@ -27,6 +27,7 @@ what passes as regression goals. See [docs/coding-agents.md](docs/coding-agents.
|
|
|
27
27
|
| Multi-provider LLMs | Groq, Claude, Gemini, OpenAI or local Ollama, with automatic fallback |
|
|
28
28
|
| Safe secrets | `{{PASSWORD}}` placeholders — the AI never sees values, which are only typed on allowed sites |
|
|
29
29
|
| Guardrails | Invalid-action checks, loop detection, backtracking, no-progress detection |
|
|
30
|
+
| Run evidence | Web & Electron: a video of the run, a Playwright trace per failed goal, and console and network errors, in the report and the dashboard |
|
|
30
31
|
| Reporting | JSON reports, dashboard uploads, failure screenshots, Slack, GitHub Actions annotations, webhooks |
|
|
31
32
|
| Platforms | Web (Playwright), Electron, Android & iOS (Appium), Windows, macOS |
|
|
32
33
|
|
|
@@ -13,6 +13,7 @@ Commands:
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import json
|
|
16
|
+
import shutil
|
|
16
17
|
import sys
|
|
17
18
|
import time
|
|
18
19
|
from pathlib import Path
|
|
@@ -26,6 +27,7 @@ from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
|
26
27
|
from rich.table import Table
|
|
27
28
|
|
|
28
29
|
from fusiontest import __version__
|
|
30
|
+
from fusiontest.core import evidence as _evidence
|
|
29
31
|
|
|
30
32
|
console = Console()
|
|
31
33
|
|
|
@@ -33,6 +35,7 @@ console = Console()
|
|
|
33
35
|
# safe to commit or cache in CI so later runs can replay.
|
|
34
36
|
DEFAULT_TRACE_DIR = ".fusiontest/traces"
|
|
35
37
|
DEFAULT_SCREENSHOT_DIR = ".fusiontest/screenshots"
|
|
38
|
+
DEFAULT_EVIDENCE_DIR = ".fusiontest/evidence"
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
@click.group()
|
|
@@ -86,8 +89,11 @@ def _judge_note(backend: str, judge: str) -> str:
|
|
|
86
89
|
@click.option("--judge", type=click.Choice(["gpt4o", "claude", "gemini", "groq", "ollama"]),
|
|
87
90
|
default=None, help="Model that judges pass/fail (default: FUSIONTEST_JUDGE, else "
|
|
88
91
|
"Claude or OpenAI when its key is set, else --backend)")
|
|
92
|
+
@click.option("--evidence", "evidence_mode", type=click.Choice(["failures", "all", "off"]), default=None,
|
|
93
|
+
help="Web and Electron: record a video of the run, a trace per goal, and console and "
|
|
94
|
+
"network errors. 'failures' (default) keeps the video and traces only for what failed")
|
|
89
95
|
def run(goal, goal_file, platform, app, url, locale, backend, headless, output, config_file,
|
|
90
|
-
replay, trace_dir, reverify_every, deploy, judge):
|
|
96
|
+
replay, trace_dir, reverify_every, deploy, judge, evidence_mode):
|
|
91
97
|
"""Run a FusionTest test — provide goals via --goal or --file."""
|
|
92
98
|
|
|
93
99
|
_load_env()
|
|
@@ -142,8 +148,20 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
142
148
|
+ _judge_note(backend, judge) + f" · Locale: [cyan]{locale}[/cyan]",
|
|
143
149
|
border_style="blue",
|
|
144
150
|
))
|
|
151
|
+
# Run evidence (video, traces, console and network errors): web and Electron.
|
|
152
|
+
evidence_cfg = cfg.get("evidence") or {}
|
|
153
|
+
evidence_mode = evidence_mode or evidence_cfg.get("mode") or _evidence.DEFAULT_MODE
|
|
154
|
+
if evidence_mode not in _evidence.MODES:
|
|
155
|
+
console.print(f"[red]evidence.mode must be one of: {', '.join(_evidence.MODES)}[/red]")
|
|
156
|
+
sys.exit(1)
|
|
157
|
+
evidence_dir = None
|
|
158
|
+
if evidence_mode != "off" and platform in ("playwright", "electron"):
|
|
159
|
+
from datetime import datetime, timezone
|
|
160
|
+
evidence_dir = (Path(evidence_cfg.get("dir", DEFAULT_EVIDENCE_DIR))
|
|
161
|
+
/ datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ"))
|
|
162
|
+
|
|
145
163
|
# Build adapter
|
|
146
|
-
adapter = _build_adapter(platform, app, url, headless)
|
|
164
|
+
adapter = _build_adapter(platform, app, url, headless, evidence_dir=evidence_dir)
|
|
147
165
|
|
|
148
166
|
# Build runner — enable step logging when an API key is present so every
|
|
149
167
|
# (goal, screen, action, outcome) tuple is captured for training-data.
|
|
@@ -198,6 +216,7 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
198
216
|
# retried in a fresh browser before it's reported as a regression.
|
|
199
217
|
deploy=deploy or _deploy_from_env(),
|
|
200
218
|
fresh_adapter=(lambda: _build_adapter(platform, app, url, True)) if platform == "playwright" else None,
|
|
219
|
+
evidence_mode=evidence_mode,
|
|
201
220
|
)
|
|
202
221
|
runner = FusionTestRunner(adapter, runner_cfg)
|
|
203
222
|
|
|
@@ -249,6 +268,8 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
249
268
|
finally:
|
|
250
269
|
progress.stop()
|
|
251
270
|
|
|
271
|
+
_finish_evidence(adapter, result, evidence_mode, evidence_dir)
|
|
272
|
+
|
|
252
273
|
# Failure screenshots: saved next to the project, shown in the results.
|
|
253
274
|
shot_dir = Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR))
|
|
254
275
|
shots = _save_screenshots(result, shot_dir)
|
|
@@ -256,6 +277,7 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
256
277
|
|
|
257
278
|
# Print results table, then Slack / GitHub annotations if configured
|
|
258
279
|
_print_results(result, shots, bug_shots)
|
|
280
|
+
_print_evidence(result, evidence_dir)
|
|
259
281
|
_notify(result)
|
|
260
282
|
|
|
261
283
|
# Save JSON report locally
|
|
@@ -270,6 +292,8 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
270
292
|
_upload_screenshots(uploaded_run_id, shots)
|
|
271
293
|
if bug_shots:
|
|
272
294
|
_upload_screenshots(uploaded_run_id, bug_shots, kind="bug")
|
|
295
|
+
if uploaded_run_id and result.video and evidence_cfg.get("upload", True):
|
|
296
|
+
_upload_video(uploaded_run_id, Path(result.video))
|
|
273
297
|
|
|
274
298
|
# Upload step telemetry (best-effort, non-blocking)
|
|
275
299
|
if _api_key and _step_log_tmp:
|
|
@@ -842,6 +866,92 @@ def _upload_screenshots(run_id: str, shots: dict[int, Path], kind: str = "goal")
|
|
|
842
866
|
console.print(f"[dim]{stored} {what} screenshot(s) attached to the run (kept 30 days).[/dim]")
|
|
843
867
|
|
|
844
868
|
|
|
869
|
+
def _finish_evidence(adapter, result, mode: str, evidence_dir: Path | None) -> None:
|
|
870
|
+
"""Close the browser so the video is written, then keep or delete it."""
|
|
871
|
+
finish = getattr(adapter, "finish_evidence", None)
|
|
872
|
+
if finish is None or evidence_dir is None:
|
|
873
|
+
return
|
|
874
|
+
try:
|
|
875
|
+
video = finish()
|
|
876
|
+
except Exception as e: # noqa: BLE001 — never fail a run over evidence
|
|
877
|
+
console.print(f"[yellow]Warning:[/yellow] Could not save the run's video: {e}")
|
|
878
|
+
return
|
|
879
|
+
if video is None:
|
|
880
|
+
return
|
|
881
|
+
if _evidence.keeps_video(mode, result.success):
|
|
882
|
+
target = evidence_dir / "run.webm"
|
|
883
|
+
try:
|
|
884
|
+
video.replace(target)
|
|
885
|
+
except OSError:
|
|
886
|
+
target = video
|
|
887
|
+
result.video = str(target)
|
|
888
|
+
else:
|
|
889
|
+
video.unlink(missing_ok=True)
|
|
890
|
+
shutil.rmtree(evidence_dir / "video", ignore_errors=True)
|
|
891
|
+
if evidence_dir.exists() and not any(evidence_dir.iterdir()):
|
|
892
|
+
evidence_dir.rmdir()
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
def _print_evidence(result, evidence_dir: Path | None) -> None:
|
|
896
|
+
traces = [(i, s.evidence.trace) for i, s in enumerate(result.steps) if s.evidence and s.evidence.trace]
|
|
897
|
+
problems = sum(len(s.evidence.console) + len(s.evidence.network)
|
|
898
|
+
for s in result.steps if s.evidence and not s.success)
|
|
899
|
+
if not traces and not result.video and not problems:
|
|
900
|
+
return
|
|
901
|
+
console.print("\n[bold]Evidence[/bold]")
|
|
902
|
+
if result.video:
|
|
903
|
+
console.print(f" video: {escape(result.video)}", soft_wrap=True)
|
|
904
|
+
for i, trace in traces:
|
|
905
|
+
console.print(f" {i + 1}. trace: {escape(trace)}", soft_wrap=True)
|
|
906
|
+
if traces:
|
|
907
|
+
console.print(" [dim]Open a trace with: playwright show-trace <file>[/dim]")
|
|
908
|
+
for i, step in enumerate(result.steps):
|
|
909
|
+
if step.success or step.evidence is None:
|
|
910
|
+
continue
|
|
911
|
+
for e in step.evidence.console[:5]:
|
|
912
|
+
console.print(f" {i + 1}. [dim]console {e.level}:[/dim] {escape(e.text)}", soft_wrap=True)
|
|
913
|
+
for e in step.evidence.network[:5]:
|
|
914
|
+
what = str(e.status) if e.status else e.failure
|
|
915
|
+
console.print(f" {i + 1}. [dim]network:[/dim] {escape(e.method)} {escape(e.url)} → {escape(what)}",
|
|
916
|
+
soft_wrap=True)
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
def _without_trace(step: dict) -> dict:
|
|
920
|
+
ev = step.get("evidence")
|
|
921
|
+
if not ev or "trace" not in ev:
|
|
922
|
+
return step
|
|
923
|
+
return {**step, "evidence": {k: v for k, v in ev.items() if k != "trace"}}
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
def _upload_video(run_id: str, path: Path) -> None:
|
|
927
|
+
"""Attach the run's video to the uploaded run (best effort; kept 30 days,
|
|
928
|
+
and the org's screenshot setting covers it too)."""
|
|
929
|
+
import os
|
|
930
|
+
|
|
931
|
+
import httpx
|
|
932
|
+
|
|
933
|
+
size = path.stat().st_size if path.exists() else 0
|
|
934
|
+
if not size:
|
|
935
|
+
return
|
|
936
|
+
if size > _VIDEO_MAX_BYTES:
|
|
937
|
+
console.print(f"[dim]Video not uploaded: {size // (1024 * 1024)} MB is over the "
|
|
938
|
+
f"{_VIDEO_MAX_BYTES // (1024 * 1024)} MB limit (it's kept locally).[/dim]")
|
|
939
|
+
return
|
|
940
|
+
api_url = os.getenv("FUSIONTEST_API_URL", "https://api.fusiontest.fusionleap.io")
|
|
941
|
+
headers = {"Authorization": f"Bearer {os.getenv('FUSIONTEST_API_KEY', '')}", "Content-Type": "video/webm"}
|
|
942
|
+
try:
|
|
943
|
+
resp = httpx.post(f"{api_url}/api/runs/{run_id}/video", content=path.read_bytes(),
|
|
944
|
+
headers=headers, timeout=120)
|
|
945
|
+
resp.raise_for_status()
|
|
946
|
+
if resp.json().get("stored"):
|
|
947
|
+
console.print("[dim]Video attached to the run (kept 30 days).[/dim]")
|
|
948
|
+
except Exception as e: # noqa: BLE001 — never fail a run over a video
|
|
949
|
+
console.print(f"[yellow]Warning:[/yellow] Could not upload the video: {e}")
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
_VIDEO_MAX_BYTES = 50 * 1024 * 1024
|
|
953
|
+
|
|
954
|
+
|
|
845
955
|
def _load_env() -> None:
|
|
846
956
|
"""Load .env from the directory the command runs in (or a parent).
|
|
847
957
|
|
|
@@ -1339,6 +1449,17 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, max_cost, m
|
|
|
1339
1449
|
Path(summary_md).write_text(
|
|
1340
1450
|
_bench_markdown(summaries, runs, spend_line, bug_summaries, bug_runs), encoding="utf-8")
|
|
1341
1451
|
|
|
1452
|
+
# A suite × backend where every case errored measured nothing (a rejected API
|
|
1453
|
+
# key, no credits, an outage). Results are still written and uploaded so the
|
|
1454
|
+
# dashboard shows the gap, but the run fails so it doesn't go unnoticed.
|
|
1455
|
+
unmeasured = ([f"{sm.suite} × {sm.backend}" for sm in summaries if sm.cases and not sm.evaluated]
|
|
1456
|
+
+ [f"{sm.suite} × {sm.backend}" for sm in bug_summaries
|
|
1457
|
+
if sm.errors and not sm.variants])
|
|
1458
|
+
if unmeasured:
|
|
1459
|
+
console.print(f"[red]✗ Nothing measured for {', '.join(unmeasured)}: every case errored. "
|
|
1460
|
+
"Check the errors above (API key, credits, provider outage).[/red]")
|
|
1461
|
+
sys.exit(1)
|
|
1462
|
+
|
|
1342
1463
|
if min_accuracy is not None:
|
|
1343
1464
|
below = [sm for sm in summaries if sm.accuracy < min_accuracy or sm.false_pass]
|
|
1344
1465
|
if below:
|
|
@@ -1778,10 +1899,11 @@ def _is_ollama_running() -> bool:
|
|
|
1778
1899
|
return False
|
|
1779
1900
|
|
|
1780
1901
|
|
|
1781
|
-
def _build_adapter(platform: str, app: str | None, url: str | None, headless: bool
|
|
1902
|
+
def _build_adapter(platform: str, app: str | None, url: str | None, headless: bool,
|
|
1903
|
+
evidence_dir: Path | None = None):
|
|
1782
1904
|
if platform == "playwright":
|
|
1783
1905
|
from fusiontest.desktop.playwright_adapter import PlaywrightAdapter
|
|
1784
|
-
adapter = PlaywrightAdapter(browser_type="chromium", headless=headless)
|
|
1906
|
+
adapter = PlaywrightAdapter(browser_type="chromium", headless=headless, evidence_dir=evidence_dir)
|
|
1785
1907
|
adapter.start(url=url)
|
|
1786
1908
|
return adapter
|
|
1787
1909
|
|
|
@@ -1790,7 +1912,7 @@ def _build_adapter(platform: str, app: str | None, url: str | None, headless: bo
|
|
|
1790
1912
|
console.print("[red]--app is required for electron platform[/red]")
|
|
1791
1913
|
sys.exit(1)
|
|
1792
1914
|
from fusiontest.desktop.playwright_adapter import PlaywrightAdapter
|
|
1793
|
-
adapter = PlaywrightAdapter(electron_app_path=app, headless=headless)
|
|
1915
|
+
adapter = PlaywrightAdapter(electron_app_path=app, headless=headless, evidence_dir=evidence_dir)
|
|
1794
1916
|
adapter.start()
|
|
1795
1917
|
return adapter
|
|
1796
1918
|
|
|
@@ -1958,6 +2080,7 @@ def _save_report(result, path: str) -> None:
|
|
|
1958
2080
|
"total_duration_seconds": result.total_duration_seconds,
|
|
1959
2081
|
"steps": [s.to_dict() for s in result.steps],
|
|
1960
2082
|
"bugs_detected": [b.to_dict() for b in result.bugs_detected],
|
|
2083
|
+
**({"video": result.video} if result.video else {}),
|
|
1961
2084
|
}
|
|
1962
2085
|
with open(path, "w") as f:
|
|
1963
2086
|
json.dump(data, f, indent=2)
|
|
@@ -1989,7 +2112,9 @@ def _upload_report(result) -> str | None:
|
|
|
1989
2112
|
"status": result.status,
|
|
1990
2113
|
"stability_score": result.stability_score,
|
|
1991
2114
|
"total_duration_seconds": result.total_duration_seconds,
|
|
1992
|
-
|
|
2115
|
+
# Traces stay on this machine (they hold cookies and headers), and so
|
|
2116
|
+
# do local paths.
|
|
2117
|
+
"steps": [_without_trace(s.to_dict()) for s in result.steps],
|
|
1993
2118
|
"bugs_detected": [b.to_dict() for b in result.bugs_detected],
|
|
1994
2119
|
}
|
|
1995
2120
|
|
|
@@ -700,7 +700,10 @@ class LLMCaller:
|
|
|
700
700
|
from google.genai import types as genai_types
|
|
701
701
|
client = genai.Client(
|
|
702
702
|
api_key=api_key,
|
|
703
|
-
|
|
703
|
+
# v1beta: google-genai 3.x defaults to v1, where some models
|
|
704
|
+
# (gemini-2.5-flash) reject system instructions.
|
|
705
|
+
http_options=genai_types.HttpOptions(
|
|
706
|
+
api_version="v1beta", timeout=LLM_REQUEST_TIMEOUT_SECONDS * 1000), # ms
|
|
704
707
|
)
|
|
705
708
|
|
|
706
709
|
else:
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""
|
|
2
|
+
fusiontest.core.evidence — what happened during a goal, kept so a person can
|
|
3
|
+
check the verdict themselves.
|
|
4
|
+
|
|
5
|
+
Adapters that can record (Playwright: web and Electron) capture, per goal:
|
|
6
|
+
|
|
7
|
+
console the page's console errors and warnings
|
|
8
|
+
network requests that failed or got a 4xx/5xx answer
|
|
9
|
+
trace a Playwright trace of the goal (open with `playwright show-trace`)
|
|
10
|
+
|
|
11
|
+
and one video of the whole run, with the second each goal started at so a
|
|
12
|
+
viewer can jump to it.
|
|
13
|
+
|
|
14
|
+
Unlike app_errors (near-certain bugs, ADR-009), these are raw observations:
|
|
15
|
+
a 404 for a missing avatar or a console warning is evidence, not a bug.
|
|
16
|
+
|
|
17
|
+
Secrets: console text and network URLs are redacted, and URLs lose their
|
|
18
|
+
query string and fragment (tokens often live there). Trace files are scrubbed
|
|
19
|
+
of secret values too, but they still hold cookies, request headers and
|
|
20
|
+
screenshots, so they stay on the machine that ran the test and are never
|
|
21
|
+
uploaded. The video shows the screen as a user would see it (password fields
|
|
22
|
+
masked), the same as failure screenshots.
|
|
23
|
+
|
|
24
|
+
Modes (`--evidence`, config `evidence.mode`):
|
|
25
|
+
failures keep traces of failed goals, and the video only if a goal failed
|
|
26
|
+
all keep everything
|
|
27
|
+
off record nothing
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import logging
|
|
33
|
+
import os
|
|
34
|
+
import zipfile
|
|
35
|
+
from dataclasses import dataclass, field
|
|
36
|
+
from pathlib import Path
|
|
37
|
+
from urllib.parse import urlsplit
|
|
38
|
+
|
|
39
|
+
logger = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
MODES = ("failures", "all", "off")
|
|
42
|
+
DEFAULT_MODE = "failures"
|
|
43
|
+
|
|
44
|
+
# Per goal, so a page that logs in a loop can't bloat the report.
|
|
45
|
+
MAX_ENTRIES = 50
|
|
46
|
+
MAX_TEXT = 500
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class ConsoleEntry:
|
|
51
|
+
level: str # error | warning
|
|
52
|
+
text: str
|
|
53
|
+
page: str # path of the page it was logged on
|
|
54
|
+
|
|
55
|
+
def to_dict(self) -> dict:
|
|
56
|
+
return {"level": self.level, "text": self.text, "page": self.page}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True)
|
|
60
|
+
class NetworkEntry:
|
|
61
|
+
method: str
|
|
62
|
+
url: str # scheme://host/path — no query or fragment
|
|
63
|
+
status: int # 0 when the request failed without an answer
|
|
64
|
+
failure: str # e.g. "net::ERR_CONNECTION_REFUSED"; "" when it got an answer
|
|
65
|
+
resource: str # document | xhr | fetch | script | image | …
|
|
66
|
+
|
|
67
|
+
def to_dict(self) -> dict:
|
|
68
|
+
return {"method": self.method, "url": self.url, "status": self.status,
|
|
69
|
+
"failure": self.failure, "resource": self.resource}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class GoalEvidence:
|
|
74
|
+
console: list[ConsoleEntry] = field(default_factory=list)
|
|
75
|
+
network: list[NetworkEntry] = field(default_factory=list)
|
|
76
|
+
dropped: int = 0 # entries over MAX_ENTRIES, not kept
|
|
77
|
+
trace: str = "" # local path of the goal's trace zip, if kept
|
|
78
|
+
video_start: float | None = None # seconds into the run's video
|
|
79
|
+
|
|
80
|
+
def to_dict(self) -> dict:
|
|
81
|
+
data: dict = {
|
|
82
|
+
"console": [e.to_dict() for e in self.console],
|
|
83
|
+
"network": [e.to_dict() for e in self.network],
|
|
84
|
+
}
|
|
85
|
+
if self.dropped:
|
|
86
|
+
data["dropped"] = self.dropped
|
|
87
|
+
if self.trace:
|
|
88
|
+
data["trace"] = self.trace
|
|
89
|
+
if self.video_start is not None:
|
|
90
|
+
data["video_start"] = round(self.video_start, 1)
|
|
91
|
+
return data
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def clean_url(url: str) -> str:
|
|
95
|
+
"""The URL without query string, fragment or credentials."""
|
|
96
|
+
parts = urlsplit(url)
|
|
97
|
+
if not parts.scheme or not parts.hostname:
|
|
98
|
+
return parts.path or url.split("?", 1)[0].split("#", 1)[0]
|
|
99
|
+
host = parts.hostname + (f":{parts.port}" if parts.port else "")
|
|
100
|
+
return f"{parts.scheme}://{host}{parts.path or '/'}"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def clip(text: str) -> str:
|
|
104
|
+
text = " ".join(text.split())
|
|
105
|
+
return text if len(text) <= MAX_TEXT else text[: MAX_TEXT - 1] + "…"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def keeps_trace(mode: str, passed: bool) -> bool:
|
|
109
|
+
return mode == "all" or (mode == "failures" and not passed)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def keeps_video(mode: str, run_passed: bool) -> bool:
|
|
113
|
+
return mode == "all" or (mode == "failures" and not run_passed)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def scrub_trace(path: Path, secrets: list[str]) -> None:
|
|
117
|
+
"""Replace secret values in the text files of a trace zip, in place.
|
|
118
|
+
|
|
119
|
+
Playwright traces log typed values ("fill" parameters) and DOM snapshots
|
|
120
|
+
with field values. Screenshots inside the trace can't be scrubbed — one
|
|
121
|
+
more reason traces stay local.
|
|
122
|
+
"""
|
|
123
|
+
values = sorted({s for s in secrets if s}, key=len, reverse=True)
|
|
124
|
+
if not values or not path.exists():
|
|
125
|
+
return
|
|
126
|
+
needles: list[tuple[bytes, bytes]] = []
|
|
127
|
+
for value in values:
|
|
128
|
+
for form in {value, value.replace("\\", "\\\\").replace('"', '\\"')}:
|
|
129
|
+
needles.append((form.encode(), b"***"))
|
|
130
|
+
tmp = path.with_suffix(".scrub.zip")
|
|
131
|
+
try:
|
|
132
|
+
with zipfile.ZipFile(path) as src, zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) as dst:
|
|
133
|
+
for info in src.infolist():
|
|
134
|
+
data = src.read(info)
|
|
135
|
+
if not _is_image(info.filename):
|
|
136
|
+
for needle, repl in needles:
|
|
137
|
+
data = data.replace(needle, repl)
|
|
138
|
+
dst.writestr(info, data)
|
|
139
|
+
os.replace(tmp, path)
|
|
140
|
+
except Exception as exc: # noqa: BLE001 — a bad trace must not fail a run
|
|
141
|
+
logger.warning("Could not scrub trace %s, deleting it: %s", path, exc)
|
|
142
|
+
tmp.unlink(missing_ok=True)
|
|
143
|
+
path.unlink(missing_ok=True)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _is_image(name: str) -> bool:
|
|
147
|
+
return name.lower().endswith((".jpeg", ".jpg", ".png", ".webp"))
|
|
@@ -22,6 +22,7 @@ from typing import Protocol, runtime_checkable
|
|
|
22
22
|
from urllib.parse import urlsplit
|
|
23
23
|
|
|
24
24
|
from fusiontest.core import bugs
|
|
25
|
+
from fusiontest.core import evidence as run_evidence
|
|
25
26
|
from fusiontest.core.action_model import (
|
|
26
27
|
VISION_BACKENDS,
|
|
27
28
|
Action,
|
|
@@ -111,6 +112,9 @@ class StepResult:
|
|
|
111
112
|
# The judge's last reason for its verdict on this goal (ADR-010), for
|
|
112
113
|
# reports that explain a pass as well as a failure.
|
|
113
114
|
judge_reason: str = ""
|
|
115
|
+
# Console and network problems, the trace and where the goal starts in the
|
|
116
|
+
# run's video (fusiontest.core.evidence), from adapters that record them.
|
|
117
|
+
evidence: run_evidence.GoalEvidence | None = None
|
|
114
118
|
|
|
115
119
|
def to_dict(self) -> dict:
|
|
116
120
|
"""JSON-safe form for reports and the API (screenshots excluded)."""
|
|
@@ -128,6 +132,7 @@ class StepResult:
|
|
|
128
132
|
"verifier": self.verifier_tokens.to_dict(),
|
|
129
133
|
},
|
|
130
134
|
"mode": self.mode,
|
|
135
|
+
**({"evidence": self.evidence.to_dict()} if self.evidence is not None else {}),
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
|
|
@@ -150,6 +155,8 @@ class RunResult:
|
|
|
150
155
|
# LLM answers per "backend:model" (action model + verifier) — which
|
|
151
156
|
# providers actually did the work after fallbacks.
|
|
152
157
|
llm_calls: dict[str, int] = field(default_factory=dict)
|
|
158
|
+
# Local path of the run's video (fusiontest.core.evidence), once kept.
|
|
159
|
+
video: str = ""
|
|
153
160
|
|
|
154
161
|
@property
|
|
155
162
|
def errored(self) -> bool:
|
|
@@ -257,6 +264,9 @@ class RunnerConfig:
|
|
|
257
264
|
# (fresh_adapter) and reported as a regression only if it fails again.
|
|
258
265
|
deploy: str = ""
|
|
259
266
|
retry_regressions: bool = True
|
|
267
|
+
# Which goal traces to keep, from adapters that record evidence:
|
|
268
|
+
# "failures" (default), "all" or "off" (fusiontest.core.evidence).
|
|
269
|
+
evidence_mode: str = run_evidence.DEFAULT_MODE
|
|
260
270
|
|
|
261
271
|
|
|
262
272
|
# ── Runner ─────────────────────────────────────────────────────────────────────
|
|
@@ -418,6 +428,7 @@ class FusionTestRunner:
|
|
|
418
428
|
watchdog.start()
|
|
419
429
|
|
|
420
430
|
app_closed = False
|
|
431
|
+
self._begin_evidence()
|
|
421
432
|
try:
|
|
422
433
|
step_result = self._execute_goal(goal, safe_goal, goal_url, resolver)
|
|
423
434
|
except AdapterClosed as exc:
|
|
@@ -450,6 +461,7 @@ class FusionTestRunner:
|
|
|
450
461
|
step_result.error = (
|
|
451
462
|
f"goal_timeout: exceeded {self.config.max_goal_seconds}s wall-clock limit"
|
|
452
463
|
)
|
|
464
|
+
step_result.evidence = self._end_evidence(i - 1, step_result, resolver)
|
|
453
465
|
result.steps.append(step_result)
|
|
454
466
|
|
|
455
467
|
if not step_result.success:
|
|
@@ -810,6 +822,27 @@ class FusionTestRunner:
|
|
|
810
822
|
|
|
811
823
|
# ── Record & replay (ADR-007 Phase 2) ──────────────────────────────────────
|
|
812
824
|
|
|
825
|
+
def _begin_evidence(self) -> None:
|
|
826
|
+
begin = getattr(self.adapter, "begin_goal_evidence", None)
|
|
827
|
+
if begin is None or self.config.evidence_mode == "off":
|
|
828
|
+
return
|
|
829
|
+
try:
|
|
830
|
+
begin()
|
|
831
|
+
except Exception as exc: # noqa: BLE001 — evidence must never fail a run
|
|
832
|
+
logger.debug("Could not start collecting evidence: %s", exc)
|
|
833
|
+
|
|
834
|
+
def _end_evidence(self, index: int, step: StepResult,
|
|
835
|
+
resolver: SecretResolver) -> run_evidence.GoalEvidence | None:
|
|
836
|
+
end = getattr(self.adapter, "end_goal_evidence", None)
|
|
837
|
+
if end is None or self.config.evidence_mode == "off":
|
|
838
|
+
return None
|
|
839
|
+
try:
|
|
840
|
+
return end(index, run_evidence.keeps_trace(self.config.evidence_mode, step.success),
|
|
841
|
+
redact=resolver.redact, secrets=resolver.sensitive_values)
|
|
842
|
+
except Exception as exc: # noqa: BLE001 — evidence must never fail a run
|
|
843
|
+
logger.debug("Could not collect evidence: %s", exc)
|
|
844
|
+
return None
|
|
845
|
+
|
|
813
846
|
def _execute_goal(
|
|
814
847
|
self, goal: str, safe_goal: str, goal_url: str, resolver: SecretResolver
|
|
815
848
|
) -> StepResult:
|
|
@@ -99,6 +99,12 @@ class SecretResolver:
|
|
|
99
99
|
result = result.replace(secret, "***")
|
|
100
100
|
return result
|
|
101
101
|
|
|
102
|
+
@property
|
|
103
|
+
def sensitive_values(self) -> list[str]:
|
|
104
|
+
"""The secret values resolved so far, for scrubbing files that can't
|
|
105
|
+
go through redact() line by line (e.g. trace archives)."""
|
|
106
|
+
return list(self._sensitive)
|
|
107
|
+
|
|
102
108
|
def has_templates(self, text: str) -> bool:
|
|
103
109
|
"""True if *text* contains any {{VAR}} placeholders."""
|
|
104
110
|
return bool(_TEMPLATE_RE.search(text))
|
|
@@ -17,8 +17,10 @@ import asyncio
|
|
|
17
17
|
import logging
|
|
18
18
|
import os
|
|
19
19
|
import re
|
|
20
|
+
import time
|
|
21
|
+
from pathlib import Path
|
|
20
22
|
|
|
21
|
-
from fusiontest.core import app_errors
|
|
23
|
+
from fusiontest.core import app_errors, evidence
|
|
22
24
|
from fusiontest.core.action_model import Action
|
|
23
25
|
from fusiontest.core.netguard import EgressProxy
|
|
24
26
|
from fusiontest.core.runner import AdapterClosed
|
|
@@ -154,10 +156,17 @@ class PlaywrightAdapter:
|
|
|
154
156
|
viewport: dict | None = None,
|
|
155
157
|
electron_app_path: str | None = None,
|
|
156
158
|
block_private_networks: bool = False,
|
|
159
|
+
evidence_dir: str | Path | None = None,
|
|
160
|
+
record_traces: bool = True,
|
|
157
161
|
):
|
|
158
162
|
"""block_private_networks: route all browser traffic through an
|
|
159
163
|
EgressProxy that refuses private/internal addresses (server-side runs
|
|
160
|
-
on user-supplied URLs). Off for local runs, which test localhost apps.
|
|
164
|
+
on user-supplied URLs). Off for local runs, which test localhost apps.
|
|
165
|
+
|
|
166
|
+
evidence_dir: record a video of the session and a trace per goal there,
|
|
167
|
+
and collect console and network problems (fusiontest.core.evidence).
|
|
168
|
+
record_traces=False records the video and logs only (server-side runs:
|
|
169
|
+
traces hold cookies and never leave the machine)."""
|
|
161
170
|
self.browser_type = browser_type
|
|
162
171
|
self.headless = headless
|
|
163
172
|
self.slow_mo = slow_mo
|
|
@@ -178,6 +187,14 @@ class PlaywrightAdapter:
|
|
|
178
187
|
# links), each with the last action before it (ADR-009).
|
|
179
188
|
self._app_errors: list[app_errors.AppError] = []
|
|
180
189
|
self._last_action = "page load"
|
|
190
|
+
# Run evidence (fusiontest.core.evidence): console and network problems
|
|
191
|
+
# since the goal began, the trace chunk in progress, the video's clock.
|
|
192
|
+
self.evidence_dir = Path(evidence_dir) if evidence_dir else None
|
|
193
|
+
self.record_traces = record_traces
|
|
194
|
+
self._evidence = evidence.GoalEvidence()
|
|
195
|
+
self._tracing = None # the context's Tracing while a chunk records
|
|
196
|
+
self._video_started: float | None = None
|
|
197
|
+
self._video_path: Path | None = None
|
|
181
198
|
|
|
182
199
|
# ── Lifecycle ──────────────────────────────────────────────────────────────
|
|
183
200
|
|
|
@@ -262,9 +279,10 @@ class PlaywrightAdapter:
|
|
|
262
279
|
args=_docker_args,
|
|
263
280
|
**launch_options,
|
|
264
281
|
)
|
|
265
|
-
context = await self._browser.new_context(viewport=self.viewport)
|
|
282
|
+
context = await self._browser.new_context(viewport=self.viewport, **self._recording_options())
|
|
266
283
|
self._watch_app_errors(context)
|
|
267
284
|
self._page = await context.new_page()
|
|
285
|
+
await self._start_recording(context)
|
|
268
286
|
if url:
|
|
269
287
|
await self._page.goto(url, wait_until="domcontentloaded", timeout=60_000)
|
|
270
288
|
await self._settle(_SETTLE_MAX_MS_NAVIGATE)
|
|
@@ -275,13 +293,24 @@ class PlaywrightAdapter:
|
|
|
275
293
|
"""Launch an Electron app via Playwright's Electron API."""
|
|
276
294
|
self._electron_app = await self._playwright.electron.launch(
|
|
277
295
|
executable_path=self.electron_app_path,
|
|
296
|
+
**self._recording_options(),
|
|
278
297
|
)
|
|
279
298
|
self._page = await self._electron_app.first_window()
|
|
280
299
|
self._watch_app_errors(self._page.context)
|
|
300
|
+
await self._start_recording(self._page.context)
|
|
281
301
|
await self._page.wait_for_load_state("domcontentloaded")
|
|
282
302
|
|
|
283
303
|
async def async_stop(self) -> None:
|
|
284
304
|
"""Close the browser and Playwright. Safe to call more than once."""
|
|
305
|
+
await self._stop_tracing()
|
|
306
|
+
if self._page is not None and self._video_path is None:
|
|
307
|
+
self._video_path = await self._page_video_path(self._page)
|
|
308
|
+
if self._video_path is not None:
|
|
309
|
+
# Closing the context (not just the browser) waits for the video to be written.
|
|
310
|
+
try:
|
|
311
|
+
await self._page.context.close()
|
|
312
|
+
except Exception as exc: # noqa: BLE001 — already closed / crashed
|
|
313
|
+
logger.debug("Ignoring error while closing the context: %s", exc)
|
|
285
314
|
browser, self._browser = self._browser, None
|
|
286
315
|
playwright, self._playwright = self._playwright, None
|
|
287
316
|
for closer in (browser.close if browser else None, playwright.stop if playwright else None):
|
|
@@ -302,6 +331,9 @@ class PlaywrightAdapter:
|
|
|
302
331
|
"""Collect failures from every page in the context, including new tabs."""
|
|
303
332
|
context.on("weberror", self._on_web_error)
|
|
304
333
|
context.on("response", self._on_response)
|
|
334
|
+
if self.evidence_dir is not None:
|
|
335
|
+
context.on("console", self._on_console)
|
|
336
|
+
context.on("requestfailed", self._on_request_failed)
|
|
305
337
|
|
|
306
338
|
def _page_url(self) -> str:
|
|
307
339
|
try:
|
|
@@ -326,6 +358,14 @@ class PlaywrightAdapter:
|
|
|
326
358
|
return
|
|
327
359
|
if found is not None:
|
|
328
360
|
self._app_errors.append(found)
|
|
361
|
+
if self.evidence_dir is not None and response.status >= 400:
|
|
362
|
+
try:
|
|
363
|
+
request = response.request
|
|
364
|
+
self._note_network(evidence.NetworkEntry(
|
|
365
|
+
method=request.method, url=evidence.clean_url(response.url),
|
|
366
|
+
status=response.status, failure="", resource=request.resource_type))
|
|
367
|
+
except Exception as exc: # noqa: BLE001 — never let observation break a run
|
|
368
|
+
logger.debug("Ignoring response evidence error: %s", exc)
|
|
329
369
|
|
|
330
370
|
def drain_app_errors(self) -> list[app_errors.AppError]:
|
|
331
371
|
"""App errors seen since the last call.
|
|
@@ -352,6 +392,129 @@ class PlaywrightAdapter:
|
|
|
352
392
|
except Exception as exc: # noqa: BLE001 — never let observation break a run
|
|
353
393
|
logger.debug("Could not settle app-error events: %s", exc)
|
|
354
394
|
|
|
395
|
+
# ── Run evidence (fusiontest.core.evidence) ────────────────────────────────
|
|
396
|
+
|
|
397
|
+
def _recording_options(self) -> dict:
|
|
398
|
+
if self.evidence_dir is None:
|
|
399
|
+
return {}
|
|
400
|
+
video_dir = self.evidence_dir / "video"
|
|
401
|
+
video_dir.mkdir(parents=True, exist_ok=True)
|
|
402
|
+
return {"record_video_dir": str(video_dir), "record_video_size": dict(self.viewport)}
|
|
403
|
+
|
|
404
|
+
async def _start_recording(self, context) -> None:
|
|
405
|
+
if self.evidence_dir is None:
|
|
406
|
+
return
|
|
407
|
+
self._video_started = time.monotonic()
|
|
408
|
+
if not self.record_traces:
|
|
409
|
+
return
|
|
410
|
+
try:
|
|
411
|
+
await context.tracing.start(screenshots=True, snapshots=True)
|
|
412
|
+
self._tracing = context.tracing
|
|
413
|
+
except Exception as exc: # noqa: BLE001 — evidence is a nice-to-have
|
|
414
|
+
logger.warning("Could not start a trace: %s", exc)
|
|
415
|
+
|
|
416
|
+
async def _stop_tracing(self) -> None:
|
|
417
|
+
tracing, self._tracing = self._tracing, None
|
|
418
|
+
if tracing is None:
|
|
419
|
+
return
|
|
420
|
+
try:
|
|
421
|
+
await tracing.stop()
|
|
422
|
+
except Exception as exc: # noqa: BLE001 — browser already gone
|
|
423
|
+
logger.debug("Ignoring error while stopping the trace: %s", exc)
|
|
424
|
+
|
|
425
|
+
@staticmethod
|
|
426
|
+
async def _page_video_path(page) -> Path | None:
|
|
427
|
+
try:
|
|
428
|
+
video = page.video
|
|
429
|
+
return Path(await video.path()) if video else None
|
|
430
|
+
except Exception: # noqa: BLE001 — no video for this page
|
|
431
|
+
return None
|
|
432
|
+
|
|
433
|
+
def _on_console(self, message) -> None:
|
|
434
|
+
try:
|
|
435
|
+
level = message.type
|
|
436
|
+
if level not in ("error", "warning"):
|
|
437
|
+
return
|
|
438
|
+
if message.text.startswith("Failed to load resource:"):
|
|
439
|
+
return # Chrome's echo of a failed request: in the network log, with its URL
|
|
440
|
+
page = getattr(message, "page", None)
|
|
441
|
+
where = app_errors.page_of(page.url) if page is not None else ""
|
|
442
|
+
self._note(self._evidence.console, evidence.ConsoleEntry(
|
|
443
|
+
level=level, text=evidence.clip(message.text), page=where))
|
|
444
|
+
except Exception as exc: # noqa: BLE001 — never let observation break a run
|
|
445
|
+
logger.debug("Ignoring console evidence error: %s", exc)
|
|
446
|
+
|
|
447
|
+
def _on_request_failed(self, request) -> None:
|
|
448
|
+
try:
|
|
449
|
+
failure = request.failure or ""
|
|
450
|
+
if "ERR_ABORTED" in failure: # navigations away, cancelled fetches
|
|
451
|
+
return
|
|
452
|
+
self._note_network(evidence.NetworkEntry(
|
|
453
|
+
method=request.method, url=evidence.clean_url(request.url), status=0,
|
|
454
|
+
failure=evidence.clip(failure), resource=request.resource_type))
|
|
455
|
+
except Exception as exc: # noqa: BLE001 — never let observation break a run
|
|
456
|
+
logger.debug("Ignoring request evidence error: %s", exc)
|
|
457
|
+
|
|
458
|
+
def _note_network(self, entry: evidence.NetworkEntry) -> None:
|
|
459
|
+
self._note(self._evidence.network, entry)
|
|
460
|
+
|
|
461
|
+
def _note(self, entries: list, entry) -> None:
|
|
462
|
+
if len(entries) < evidence.MAX_ENTRIES:
|
|
463
|
+
entries.append(entry)
|
|
464
|
+
else:
|
|
465
|
+
self._evidence.dropped += 1
|
|
466
|
+
|
|
467
|
+
def begin_goal_evidence(self) -> None:
|
|
468
|
+
"""Start collecting evidence for the next goal."""
|
|
469
|
+
if self.evidence_dir is None:
|
|
470
|
+
return
|
|
471
|
+
self._settle_app_error_events() # late events belong to the last goal
|
|
472
|
+
self._evidence = evidence.GoalEvidence(
|
|
473
|
+
video_start=(time.monotonic() - self._video_started) if self._video_started else None)
|
|
474
|
+
if self._tracing is not None:
|
|
475
|
+
try:
|
|
476
|
+
self._run(self._tracing.start_chunk())
|
|
477
|
+
except Exception as exc: # noqa: BLE001 — chunk already open, or browser gone
|
|
478
|
+
logger.debug("Could not start a trace chunk: %s", exc)
|
|
479
|
+
|
|
480
|
+
def end_goal_evidence(self, index: int, keep_trace: bool, redact=None,
|
|
481
|
+
secrets: list[str] | None = None) -> evidence.GoalEvidence | None:
|
|
482
|
+
"""The evidence collected since begin_goal_evidence(). Saves the goal's
|
|
483
|
+
trace as <evidence_dir>/traces/<NN>.zip when keep_trace, scrubbed of
|
|
484
|
+
secrets. redact: applied to console text."""
|
|
485
|
+
if self.evidence_dir is None:
|
|
486
|
+
return None
|
|
487
|
+
self._settle_app_error_events()
|
|
488
|
+
found, self._evidence = self._evidence, evidence.GoalEvidence()
|
|
489
|
+
if redact is not None:
|
|
490
|
+
found.console = [evidence.ConsoleEntry(e.level, redact(e.text), e.page) for e in found.console]
|
|
491
|
+
found.network = [evidence.NetworkEntry(e.method, redact(e.url), e.status, e.failure, e.resource)
|
|
492
|
+
for e in found.network]
|
|
493
|
+
if self._tracing is not None:
|
|
494
|
+
path = self.evidence_dir / "traces" / f"{index + 1:02d}.zip"
|
|
495
|
+
try:
|
|
496
|
+
if keep_trace:
|
|
497
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
498
|
+
self._run(self._tracing.stop_chunk(path=str(path)))
|
|
499
|
+
evidence.scrub_trace(path, secrets or [])
|
|
500
|
+
if path.exists():
|
|
501
|
+
found.trace = str(path)
|
|
502
|
+
else:
|
|
503
|
+
self._run(self._tracing.stop_chunk())
|
|
504
|
+
except Exception as exc: # noqa: BLE001 — browser gone (timeout) or chunk not open
|
|
505
|
+
logger.debug("Could not save the trace chunk: %s", exc)
|
|
506
|
+
return found
|
|
507
|
+
|
|
508
|
+
def finish_evidence(self) -> Path | None:
|
|
509
|
+
"""Close the browser (which finishes writing the video) and return the
|
|
510
|
+
video's path, if one was recorded."""
|
|
511
|
+
if self.evidence_dir is None:
|
|
512
|
+
return None
|
|
513
|
+
if self._loop is not None and not self._loop.is_closed():
|
|
514
|
+
self.stop()
|
|
515
|
+
path = self._video_path
|
|
516
|
+
return path if path is not None and path.exists() and path.stat().st_size > 0 else None
|
|
517
|
+
|
|
355
518
|
# ── Screen reading ─────────────────────────────────────────────────────────
|
|
356
519
|
|
|
357
520
|
def site_links(self, limit: int = 10) -> list[str]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fusiontest
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.49
|
|
4
4
|
Summary: AI-powered UI testing for mobile and desktop — by FusionLeap.io
|
|
5
5
|
Author-email: FusionLeap <hello@fusionleap.io>
|
|
6
6
|
License: MIT
|
|
@@ -108,6 +108,7 @@ what passes as regression goals. See [docs/coding-agents.md](docs/coding-agents.
|
|
|
108
108
|
| Multi-provider LLMs | Groq, Claude, Gemini, OpenAI or local Ollama, with automatic fallback |
|
|
109
109
|
| Safe secrets | `{{PASSWORD}}` placeholders — the AI never sees values, which are only typed on allowed sites |
|
|
110
110
|
| Guardrails | Invalid-action checks, loop detection, backtracking, no-progress detection |
|
|
111
|
+
| Run evidence | Web & Electron: a video of the run, a Playwright trace per failed goal, and console and network errors, in the report and the dashboard |
|
|
111
112
|
| Reporting | JSON reports, dashboard uploads, failure screenshots, Slack, GitHub Actions annotations, webhooks |
|
|
112
113
|
| Platforms | Web (Playwright), Electron, Android & iOS (Appium), Windows, macOS |
|
|
113
114
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|