fusiontest 0.2.28__tar.gz → 0.2.30__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.28 → fusiontest-0.2.30}/PKG-INFO +3 -1
- {fusiontest-0.2.28 → fusiontest-0.2.30}/README.md +2 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/cli.py +133 -28
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/bugs.py +7 -3
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/replay.py +17 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/runner.py +140 -6
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/desktop/playwright_adapter.py +28 -13
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/discovery/goal_generator.py +47 -9
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/PKG-INFO +3 -1
- {fusiontest-0.2.28 → fusiontest-0.2.30}/pyproject.toml +1 -1
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/sites/shop/bugs.js +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/sites/shop/help.html +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/sites/shop/index.html +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/action_model.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/app_errors.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/goal_verifier.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/promise_checker.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/reproduce.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/secrets.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/shared_traces.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/SOURCES.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/requires.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.30}/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.30
|
|
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
|
|
@@ -146,6 +146,8 @@ fusiontest run --url https://example.com \
|
|
|
146
146
|
|
|
147
147
|
# No goals yet? Map what works on a test/staging site, and save the flows that do
|
|
148
148
|
fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
|
|
149
|
+
# Behind a login: EMAIL and PASSWORD come from the environment, never the AI
|
|
150
|
+
fusiontest scan https://staging.example.com --login "Sign in with email {{EMAIL}} and password {{PASSWORD}}"
|
|
149
151
|
```
|
|
150
152
|
|
|
151
153
|
Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
|
|
@@ -67,6 +67,8 @@ fusiontest run --url https://example.com \
|
|
|
67
67
|
|
|
68
68
|
# No goals yet? Map what works on a test/staging site, and save the flows that do
|
|
69
69
|
fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
|
|
70
|
+
# Behind a login: EMAIL and PASSWORD come from the environment, never the AI
|
|
71
|
+
fusiontest scan https://staging.example.com --login "Sign in with email {{EMAIL}} and password {{PASSWORD}}"
|
|
70
72
|
```
|
|
71
73
|
|
|
72
74
|
Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
|
|
@@ -66,8 +66,11 @@ def main():
|
|
|
66
66
|
help=f"Where replay recordings are stored (default: {DEFAULT_TRACE_DIR})")
|
|
67
67
|
@click.option("--reverify-every", type=click.IntRange(min=1), default=None,
|
|
68
68
|
help="Re-check a recorded goal with the LLM every N replays (default: 10)")
|
|
69
|
+
@click.option("--deploy", default=None,
|
|
70
|
+
help="Name of the deploy being tested (commit SHA, release…), shown in regression "
|
|
71
|
+
"reports. Default: FUSIONTEST_DEPLOY or the CI's commit SHA")
|
|
69
72
|
def run(goal, goal_file, platform, app, url, locale, backend, headless, output, config_file,
|
|
70
|
-
replay, trace_dir, reverify_every):
|
|
73
|
+
replay, trace_dir, reverify_every, deploy):
|
|
71
74
|
"""Run a FusionTest test — provide goals via --goal or --file."""
|
|
72
75
|
|
|
73
76
|
_load_env()
|
|
@@ -149,14 +152,7 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
149
152
|
# Values can also be inlined directly (not recommended for passwords):
|
|
150
153
|
# secrets:
|
|
151
154
|
# EMAIL: user@example.com
|
|
152
|
-
|
|
153
|
-
cfg_secrets: dict[str, str] = {}
|
|
154
|
-
for key, val in cfg_secrets_raw.items():
|
|
155
|
-
str_val = str(val)
|
|
156
|
-
# If the value looks like an env-var name (ALL_CAPS / underscores),
|
|
157
|
-
# try to resolve it from the environment first.
|
|
158
|
-
env_resolved = _os.getenv(str_val)
|
|
159
|
-
cfg_secrets[str(key)] = env_resolved if env_resolved is not None else str_val
|
|
155
|
+
cfg_secrets = _config_secrets(cfg)
|
|
160
156
|
|
|
161
157
|
# Record & replay (ADR-007): flags override the config file's `replay:` block.
|
|
162
158
|
replay_cfg = cfg.get("replay") or {}
|
|
@@ -178,6 +174,10 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
178
174
|
trace_store=_trace_store(Path(trace_dir), bool(replay_cfg.get("shared", True))),
|
|
179
175
|
# 0 = never replay: every goal goes through the LLM and re-records.
|
|
180
176
|
reverify_every=reverify_every if replay else 0,
|
|
177
|
+
# Regression watching: a goal that passed before and fails now is
|
|
178
|
+
# retried in a fresh browser before it's reported as a regression.
|
|
179
|
+
deploy=deploy or _deploy_from_env(),
|
|
180
|
+
fresh_adapter=(lambda: _build_adapter(platform, app, url, True)) if platform == "playwright" else None,
|
|
181
181
|
)
|
|
182
182
|
runner = FusionTestRunner(adapter, runner_cfg)
|
|
183
183
|
|
|
@@ -263,6 +263,35 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
263
263
|
sys.exit(_exit_code(result))
|
|
264
264
|
|
|
265
265
|
|
|
266
|
+
_DEPLOY_ENV = ("FUSIONTEST_DEPLOY", "GITHUB_SHA", "CI_COMMIT_SHA", "VERCEL_GIT_COMMIT_SHA",
|
|
267
|
+
"RENDER_GIT_COMMIT", "CIRCLE_SHA1", "BITBUCKET_COMMIT", "SOURCE_VERSION")
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _deploy_from_env() -> str:
|
|
271
|
+
"""The deploy being tested, from the environment: FUSIONTEST_DEPLOY, else the
|
|
272
|
+
CI or host's commit SHA (shortened to 7 characters)."""
|
|
273
|
+
import os
|
|
274
|
+
import re
|
|
275
|
+
|
|
276
|
+
for name in _DEPLOY_ENV:
|
|
277
|
+
value = os.getenv(name, "").strip()
|
|
278
|
+
if value:
|
|
279
|
+
return value[:7] if re.fullmatch(r"[0-9a-f]{40}", value) else value[:100]
|
|
280
|
+
return ""
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _config_secrets(cfg: dict) -> dict[str, str]:
|
|
284
|
+
"""The config file's `secrets:` block, each value read from the environment
|
|
285
|
+
variable it names when that's set (so the file holds names, not passwords)."""
|
|
286
|
+
import os
|
|
287
|
+
|
|
288
|
+
secrets: dict[str, str] = {}
|
|
289
|
+
for key, val in (cfg.get("secrets") or {}).items():
|
|
290
|
+
env_resolved = os.getenv(str(val))
|
|
291
|
+
secrets[str(key)] = env_resolved if env_resolved is not None else str(val)
|
|
292
|
+
return secrets
|
|
293
|
+
|
|
294
|
+
|
|
266
295
|
# ── scan (ADR-009) ────────────────────────────────────────────────────────────
|
|
267
296
|
|
|
268
297
|
DEFAULT_SCAN_GOALS = "fusiontest.goals.yaml"
|
|
@@ -278,6 +307,10 @@ def _is_local_host(host: str) -> bool:
|
|
|
278
307
|
@click.argument("url")
|
|
279
308
|
@click.option("--max-flows", type=click.IntRange(1, 30), default=10, show_default=True,
|
|
280
309
|
help="How many flows to discover and check")
|
|
310
|
+
@click.option("--login", default=None, metavar="GOAL",
|
|
311
|
+
help="Sign in first, as a goal with {{VAR}} secrets, e.g. \"Sign in with email "
|
|
312
|
+
"{{EMAIL}} and password {{PASSWORD}}\". Flows are then discovered from the "
|
|
313
|
+
"signed-in pages, and each flow signs in first.")
|
|
281
314
|
@click.option("--find-bugs", is_flag=True,
|
|
282
315
|
help="Beta: also look for bugs (crashes, server errors, dead links, broken promises), "
|
|
283
316
|
"each confirmed in fresh browser sessions before it's reported")
|
|
@@ -291,7 +324,7 @@ def _is_local_host(host: str) -> bool:
|
|
|
291
324
|
@click.option("--output", "-o", type=click.Path(), help="Write JSON report to this path")
|
|
292
325
|
@click.option("--config", "config_file", type=click.Path(), default=None,
|
|
293
326
|
help="Config file (default: fusiontest.config.yaml if present)")
|
|
294
|
-
def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, config_file):
|
|
327
|
+
def scan(url, max_flows, login, find_bugs, backend, headless, save_path, yes, output, config_file):
|
|
295
328
|
"""Map what works on a site: discover its flows, run each one, report the result.
|
|
296
329
|
|
|
297
330
|
\b
|
|
@@ -304,10 +337,17 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
304
337
|
Examples:
|
|
305
338
|
fusiontest scan https://staging.example.com
|
|
306
339
|
fusiontest scan http://localhost:3000 --find-bugs --save fusiontest.goals.yaml
|
|
340
|
+
fusiontest scan https://staging.example.com \\
|
|
341
|
+
--login "Sign in with email {{EMAIL}} and password {{PASSWORD}}"
|
|
342
|
+
|
|
343
|
+
\b
|
|
344
|
+
Secrets ({{EMAIL}}) come from environment variables of that name, or the
|
|
345
|
+
config file's `secrets:` block; the AI never sees their values.
|
|
307
346
|
"""
|
|
308
347
|
from urllib.parse import urlsplit
|
|
309
348
|
|
|
310
349
|
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
350
|
+
from fusiontest.core.secrets import resolve_goals
|
|
311
351
|
from fusiontest.discovery.goal_generator import (
|
|
312
352
|
GoalGenerationError,
|
|
313
353
|
GoalGenerator,
|
|
@@ -321,6 +361,14 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
321
361
|
config_path = Path(config_file) if config_file else Path("fusiontest.config.yaml")
|
|
322
362
|
cfg = (yaml.safe_load(config_path.read_text()) or {}) if config_path.exists() else {}
|
|
323
363
|
backend = _resolve_backend(backend, cfg)
|
|
364
|
+
secrets = _config_secrets(cfg)
|
|
365
|
+
if login:
|
|
366
|
+
_, resolver = resolve_goals([login], secrets)
|
|
367
|
+
if resolver.unresolved_vars:
|
|
368
|
+
missing = ", ".join(sorted(resolver.unresolved_vars))
|
|
369
|
+
console.print(f"[red]No value for {escape(missing)}:[/red] set environment variable(s) "
|
|
370
|
+
f"of that name, or map them under `secrets:` in fusiontest.config.yaml.")
|
|
371
|
+
sys.exit(1)
|
|
324
372
|
|
|
325
373
|
# Exploration is real: it clicks, types and submits.
|
|
326
374
|
if not _is_local_host(host) and not yes:
|
|
@@ -336,17 +384,20 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
336
384
|
console.print(Panel.fit(
|
|
337
385
|
f"[bold]FusionTest scan[/bold] {escape(url)}\n"
|
|
338
386
|
f"Backend: [cyan]{backend}[/cyan] · Bug finding: "
|
|
339
|
-
+ ("[cyan]on (beta)[/cyan]" if find_bugs else "off")
|
|
387
|
+
+ ("[cyan]on (beta)[/cyan]" if find_bugs else "off")
|
|
388
|
+
+ (" · Signs in first" if login else ""),
|
|
340
389
|
border_style="blue",
|
|
341
390
|
))
|
|
342
391
|
|
|
343
392
|
# 1. Discover flows grounded in the site's content.
|
|
344
393
|
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"),
|
|
345
394
|
console=console) as progress:
|
|
346
|
-
progress.add_task("
|
|
395
|
+
progress.add_task("Signing in, then reading the site..." if login
|
|
396
|
+
else "Reading the site and finding flows to check...", total=None)
|
|
397
|
+
discovery = GoalGeneratorConfig(max_goals=max_flows)
|
|
347
398
|
try:
|
|
348
|
-
|
|
349
|
-
|
|
399
|
+
snapshot = _signed_in_snapshot(url, login, backend, secrets, discovery) if login else None
|
|
400
|
+
flows = GoalGenerator(discovery).generate(url, preferred_backend=backend, snapshot=snapshot)
|
|
350
401
|
except GoalGenerationError as exc:
|
|
351
402
|
console.print(f"[red]Couldn't discover flows:[/red] {escape(str(exc))}")
|
|
352
403
|
sys.exit(2)
|
|
@@ -361,6 +412,7 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
361
412
|
trace_dir = Path(replay_cfg.get("trace_dir") or DEFAULT_TRACE_DIR)
|
|
362
413
|
runner = FusionTestRunner(_build_adapter("playwright", None, url, headless), RunnerConfig(
|
|
363
414
|
backend=backend,
|
|
415
|
+
secrets=secrets,
|
|
364
416
|
screenshot_on_failure=True,
|
|
365
417
|
trace_store=_trace_store(trace_dir, bool(replay_cfg.get("shared", True))),
|
|
366
418
|
reverify_every=0,
|
|
@@ -371,9 +423,17 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
371
423
|
console=console) as progress:
|
|
372
424
|
progress.add_task("Checking each flow" + (" and looking for bugs" if find_bugs else "") + "...",
|
|
373
425
|
total=None)
|
|
426
|
+
if login:
|
|
427
|
+
# Each flow starts signed in: open the start page and sign in, then
|
|
428
|
+
# the flow continues from wherever sign-in lands.
|
|
429
|
+
goals = [g for f in flows for g in (login, f.text)]
|
|
430
|
+
goal_urls = [u for _ in flows for u in (url, None)]
|
|
431
|
+
run_url = ""
|
|
432
|
+
else:
|
|
433
|
+
goals, goal_urls, run_url = [f.text for f in flows], None, url
|
|
374
434
|
try:
|
|
375
|
-
result = runner.run(goals=
|
|
376
|
-
platform="playwright", url=
|
|
435
|
+
result = runner.run(goals=goals, goal_urls=goal_urls, name=f"Scan: {host}",
|
|
436
|
+
platform="playwright", url=run_url)
|
|
377
437
|
finally:
|
|
378
438
|
stop = getattr(runner.adapter, "stop", None)
|
|
379
439
|
if callable(stop):
|
|
@@ -385,7 +445,7 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
385
445
|
# 3. Coverage map, then bugs.
|
|
386
446
|
shot_dir = Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR))
|
|
387
447
|
bug_shots = _save_bug_screenshots(result, shot_dir)
|
|
388
|
-
working = _print_coverage(flows, result)
|
|
448
|
+
working = _print_coverage(flows, result, signed_in=bool(login))
|
|
389
449
|
if find_bugs:
|
|
390
450
|
_print_bugs(result, bug_shots)
|
|
391
451
|
else:
|
|
@@ -402,20 +462,49 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
402
462
|
|
|
403
463
|
# 4. Offer to watch the flows that work.
|
|
404
464
|
if working:
|
|
405
|
-
_offer_to_watch(url, working, save_path)
|
|
465
|
+
_offer_to_watch(url, working, save_path, login)
|
|
406
466
|
|
|
407
467
|
|
|
408
|
-
def
|
|
409
|
-
"""
|
|
468
|
+
def _signed_in_snapshot(url, login, backend, secrets, discovery):
|
|
469
|
+
"""Sign in once in a headless browser, then capture the signed-in pages."""
|
|
470
|
+
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
471
|
+
from fusiontest.discovery.goal_generator import GoalGenerationError, snapshot_site
|
|
472
|
+
|
|
473
|
+
adapter = _build_adapter("playwright", None, url, True)
|
|
474
|
+
try:
|
|
475
|
+
signed_in = FusionTestRunner(adapter, RunnerConfig(
|
|
476
|
+
backend=backend, secrets=secrets, screenshot_on_failure=False, trace_store=None,
|
|
477
|
+
)).run(goals=[login], name="Sign in", platform="playwright", url=url)
|
|
478
|
+
step = signed_in.steps[0] if signed_in.steps else None
|
|
479
|
+
if step is None or not step.success:
|
|
480
|
+
why = (step.error if step else signed_in.error) or "the sign-in goal didn't complete"
|
|
481
|
+
raise GoalGenerationError(f"Couldn't sign in: {why}")
|
|
482
|
+
return snapshot_site(url, discovery, adapter=adapter)
|
|
483
|
+
finally:
|
|
484
|
+
try:
|
|
485
|
+
adapter.stop()
|
|
486
|
+
except Exception: # noqa: BLE001
|
|
487
|
+
pass
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _print_coverage(flows, result, signed_in: bool = False) -> list:
|
|
491
|
+
"""The coverage map: each flow and whether it works. Returns the flows that do.
|
|
492
|
+
signed_in: the run's goals alternate sign-in, flow, sign-in, flow, ..."""
|
|
410
493
|
table = Table(title="Coverage", header_style="bold", box=None, pad_edge=False, title_justify="left")
|
|
411
494
|
table.add_column("#", style="dim", width=3)
|
|
412
495
|
table.add_column("Flow", min_width=24)
|
|
413
496
|
table.add_column("Result", width=16)
|
|
414
497
|
table.add_column("Steps", width=6)
|
|
415
498
|
working = []
|
|
499
|
+
stride, offset = (2, 1) if signed_in else (1, 0)
|
|
416
500
|
for i, flow in enumerate(flows):
|
|
417
|
-
|
|
418
|
-
|
|
501
|
+
login_step = result.steps[i * 2] if signed_in and i * 2 < len(result.steps) else None
|
|
502
|
+
index = i * stride + offset
|
|
503
|
+
step = result.steps[index] if index < len(result.steps) else None
|
|
504
|
+
if login_step is not None and not login_step.success:
|
|
505
|
+
step = login_step # the flow never started: say why
|
|
506
|
+
cell = "[yellow]couldn't sign in[/yellow]"
|
|
507
|
+
elif step is None:
|
|
419
508
|
cell = "[dim]not checked[/dim]"
|
|
420
509
|
elif step.success:
|
|
421
510
|
cell = "[green]works[/green]"
|
|
@@ -451,14 +540,15 @@ def _print_bugs(result, bug_shots: dict[int, Path]) -> None:
|
|
|
451
540
|
console.print(f" [dim]Expected:[/dim] {escape(bug.expected or '—')}")
|
|
452
541
|
console.print(f" [dim]Actual:[/dim] {escape(bug.actual or '—')}")
|
|
453
542
|
if bug.steps:
|
|
454
|
-
|
|
543
|
+
after = f", after {bug.earlier_steps} earlier step(s) in this run" if bug.earlier_steps else ""
|
|
544
|
+
console.print(f" [dim]Steps to reproduce ({len(bug.steps)}{after}):[/dim]")
|
|
455
545
|
for n, step in enumerate(bug.steps, 1):
|
|
456
546
|
console.print(f" {n}. {escape(step)}", soft_wrap=True)
|
|
457
547
|
if i in bug_shots:
|
|
458
548
|
console.print(f" [dim]Screenshot: {escape(str(bug_shots[i]))}[/dim]", soft_wrap=True)
|
|
459
549
|
|
|
460
550
|
|
|
461
|
-
def _offer_to_watch(url: str, working: list, save_path: str | None) -> None:
|
|
551
|
+
def _offer_to_watch(url: str, working: list, save_path: str | None, login: str | None = None) -> None:
|
|
462
552
|
"""Save the flows that work as a goals file, to run on every deploy."""
|
|
463
553
|
path = Path(save_path) if save_path else None
|
|
464
554
|
if path is None:
|
|
@@ -472,9 +562,18 @@ def _offer_to_watch(url: str, working: list, save_path: str | None) -> None:
|
|
|
472
562
|
path = Path(DEFAULT_SCAN_GOALS)
|
|
473
563
|
if path.exists() and not click.confirm(f"{path} exists. Replace it?", default=False):
|
|
474
564
|
return
|
|
475
|
-
|
|
565
|
+
if login:
|
|
566
|
+
# Each flow signs in from the start page first; flows have no url of
|
|
567
|
+
# their own, so they continue from where signing in lands.
|
|
568
|
+
goals = [g for f in working for g in ({"name": "Sign in", "url": url, "goal": login},
|
|
569
|
+
{"name": f.name, "goal": f.text})]
|
|
570
|
+
data = {"goals": goals}
|
|
571
|
+
note = "# Signing in needs the same secrets as the scan ({{VAR}} from env or config).\n"
|
|
572
|
+
else:
|
|
573
|
+
data = {"url": url, "goals": [{"name": f.name, "goal": f.text} for f in working]}
|
|
574
|
+
note = ""
|
|
476
575
|
path.write_text("# Flows that worked when FusionTest scanned this site.\n"
|
|
477
|
-
"# Run them on every deploy: fusiontest run -f " + str(path) + "\n"
|
|
576
|
+
"# Run them on every deploy: fusiontest run -f " + str(path) + "\n" + note
|
|
478
577
|
+ yaml.safe_dump(data, sort_keys=False, allow_unicode=True))
|
|
479
578
|
console.print(f"\n[green]✓[/green] Saved {len(working)} flow(s) to [cyan]{escape(str(path))}[/cyan]. "
|
|
480
579
|
"Run them on every deploy; they replay from their recordings, without AI calls, "
|
|
@@ -1306,7 +1405,7 @@ def _print_results(result, screenshots: dict[int, Path] | None = None,
|
|
|
1306
1405
|
|
|
1307
1406
|
for i, step in enumerate(result.steps, 1):
|
|
1308
1407
|
if step.success:
|
|
1309
|
-
status_cell = "[green]PASS[/green]"
|
|
1408
|
+
status_cell = "[green]PASS[/green]" + (" [yellow](flaky)[/yellow]" if step.flaky else "")
|
|
1310
1409
|
elif step.infra_error:
|
|
1311
1410
|
status_cell = "[yellow]ERROR[/yellow]"
|
|
1312
1411
|
else:
|
|
@@ -1335,6 +1434,11 @@ def _print_results(result, screenshots: dict[int, Path] | None = None,
|
|
|
1335
1434
|
console.print(f"\n[bold red]Bugs found ({len(result.bugs_detected)})[/bold red]")
|
|
1336
1435
|
for index, bug in enumerate(result.bugs_detected):
|
|
1337
1436
|
console.print(f" {index + 1}. {escape(bug.title)}", soft_wrap=True)
|
|
1437
|
+
if bug.kind == "regression":
|
|
1438
|
+
checked = ("failed again in a fresh session" if bug.reproduced
|
|
1439
|
+
else "not re-checked in a fresh session")
|
|
1440
|
+
console.print(f" [dim]Last worked: {escape(bug.last_good)} · first failed: "
|
|
1441
|
+
f"{escape(bug.first_bad)} · {checked}[/dim]")
|
|
1338
1442
|
if bug_screenshots and index in bug_screenshots:
|
|
1339
1443
|
console.print(f" [dim]screenshot: {escape(str(bug_screenshots[index]))}[/dim]", soft_wrap=True)
|
|
1340
1444
|
|
|
@@ -1346,7 +1450,8 @@ def _print_results(result, screenshots: dict[int, Path] | None = None,
|
|
|
1346
1450
|
console.print(f"[dim]LLM calls: {escape(calls)}[/dim]")
|
|
1347
1451
|
|
|
1348
1452
|
replayed = sum(1 for s in result.steps if s.mode == "replayed")
|
|
1349
|
-
|
|
1453
|
+
# A repair that failed isn't a repair: the recording wasn't replaced.
|
|
1454
|
+
repaired = sum(1 for s in result.steps if s.mode == "repaired" and s.success)
|
|
1350
1455
|
if replayed or repaired:
|
|
1351
1456
|
tokens = result.total_token_usage
|
|
1352
1457
|
console.print(
|
|
@@ -5,7 +5,7 @@ Every reported bug says what kind of bug it is, where, what was expected and
|
|
|
5
5
|
what happened instead, the screen text that proves it, the steps that lead to
|
|
6
6
|
it, and how many fresh sessions it was reproduced in.
|
|
7
7
|
|
|
8
|
-
kind js_exception | http_error | broken_promise | inconsistency
|
|
8
|
+
kind js_exception | http_error | broken_promise | inconsistency | regression
|
|
9
9
|
title one line, e.g. "Broken promise: … (after tap 'Apply coupon', on /cart)"
|
|
10
10
|
steps from the run's start, in plain words; typed secrets stay {{VAR}}
|
|
11
11
|
"""
|
|
@@ -14,7 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
from dataclasses import asdict, dataclass, field
|
|
16
16
|
|
|
17
|
-
KINDS = ("js_exception", "http_error", "broken_promise", "inconsistency")
|
|
17
|
+
KINDS = ("js_exception", "http_error", "broken_promise", "inconsistency", "regression")
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
@dataclass
|
|
@@ -26,8 +26,12 @@ class Bug:
|
|
|
26
26
|
expected: str = ""
|
|
27
27
|
actual: str = ""
|
|
28
28
|
evidence: list[str] = field(default_factory=list) # screen text, quoted
|
|
29
|
-
steps: list[str] = field(default_factory=list) # to reproduce, from the
|
|
29
|
+
steps: list[str] = field(default_factory=list) # to reproduce, from the last page opened
|
|
30
|
+
earlier_steps: int = 0 # steps earlier in the run, before that page was opened (not shown)
|
|
30
31
|
reproduced: int = 0 # fresh sessions it happened again in (0: not checked)
|
|
32
|
+
# Regressions: the deploy (or date) the goal last passed on, and this one.
|
|
33
|
+
last_good: str = ""
|
|
34
|
+
first_bad: str = ""
|
|
31
35
|
# PNG of the screen when it happened again in a fresh session (not in to_dict:
|
|
32
36
|
# uploaded separately).
|
|
33
37
|
screenshot: bytes | None = field(default=None, repr=False, compare=False)
|
|
@@ -51,6 +51,9 @@ class GoalTrace:
|
|
|
51
51
|
evidence: list[str]
|
|
52
52
|
final_url_path: str = ""
|
|
53
53
|
replays_since_verify: int = 0
|
|
54
|
+
# When the goal last passed, and on which deploy (regression watching, ADR-009).
|
|
55
|
+
last_passed_at: str = ""
|
|
56
|
+
last_passed_deploy: str = ""
|
|
54
57
|
|
|
55
58
|
def to_dict(self) -> dict:
|
|
56
59
|
return asdict(self)
|
|
@@ -65,6 +68,8 @@ class GoalTrace:
|
|
|
65
68
|
evidence=list(data.get("evidence", [])),
|
|
66
69
|
final_url_path=data.get("final_url_path", ""),
|
|
67
70
|
replays_since_verify=int(data.get("replays_since_verify", 0)),
|
|
71
|
+
last_passed_at=str(data.get("last_passed_at") or "")[:40],
|
|
72
|
+
last_passed_deploy=str(data.get("last_passed_deploy") or "")[:100],
|
|
68
73
|
)
|
|
69
74
|
|
|
70
75
|
|
|
@@ -123,6 +128,18 @@ def url_path(url: str) -> str:
|
|
|
123
128
|
return urlsplit(url).path.rstrip("/") or "/"
|
|
124
129
|
|
|
125
130
|
|
|
131
|
+
def describe_recorded(action: RecordedAction) -> str:
|
|
132
|
+
"""A recorded action as a step in plain words ("Tap 'Add to cart'")."""
|
|
133
|
+
text = action.action_type[:1].upper() + action.action_type[1:]
|
|
134
|
+
if action.element_label:
|
|
135
|
+
text += f" '{action.element_label}'"
|
|
136
|
+
if action.occurrence:
|
|
137
|
+
text += f" (#{action.occurrence + 1})"
|
|
138
|
+
if action.value and action.action_type in ("type", "select", "press"):
|
|
139
|
+
text += f" with '{action.value}'"
|
|
140
|
+
return text
|
|
141
|
+
|
|
142
|
+
|
|
126
143
|
# ── Recording ────────────────────────────────────────────────────────────────
|
|
127
144
|
|
|
128
145
|
def record_action(action: Action, elements: list[UIElement]) -> RecordedAction:
|
|
@@ -29,6 +29,7 @@ from fusiontest.core.replay import (
|
|
|
29
29
|
GoalTrace,
|
|
30
30
|
RecordedAction,
|
|
31
31
|
TraceStore,
|
|
32
|
+
describe_recorded,
|
|
32
33
|
evidence_present,
|
|
33
34
|
record_action,
|
|
34
35
|
resolve_action,
|
|
@@ -86,6 +87,10 @@ class StepResult:
|
|
|
86
87
|
# Broken promises / inconsistencies confirmed by the PromiseChecker
|
|
87
88
|
# (only with RunnerConfig.detect_bugs).
|
|
88
89
|
findings: list[Finding] = field(default_factory=list)
|
|
90
|
+
# Passed before and failed now; set when the failure was confirmed (ADR-009 §4).
|
|
91
|
+
regression: Bug | None = None
|
|
92
|
+
# Failed, then passed when retried in a fresh session: not a regression.
|
|
93
|
+
flaky: bool = False
|
|
89
94
|
|
|
90
95
|
def to_dict(self) -> dict:
|
|
91
96
|
"""JSON-safe form for reports and the API (screenshots excluded)."""
|
|
@@ -211,6 +216,12 @@ class RunnerConfig:
|
|
|
211
216
|
# bugs seen again every time are reported. None: report without reproducing.
|
|
212
217
|
fresh_adapter: Callable[[], object] | None = None
|
|
213
218
|
reproduce_times: int = 2
|
|
219
|
+
# Regression watching (ADR-009 §4): the deploy being tested (a commit SHA,
|
|
220
|
+
# release name…), stored with each recording when its goal passes. A goal
|
|
221
|
+
# that passed before and now fails is retried in a fresh session
|
|
222
|
+
# (fresh_adapter) and reported as a regression only if it fails again.
|
|
223
|
+
deploy: str = ""
|
|
224
|
+
retry_regressions: bool = True
|
|
214
225
|
|
|
215
226
|
|
|
216
227
|
# ── Runner ─────────────────────────────────────────────────────────────────────
|
|
@@ -246,6 +257,9 @@ class FusionTestRunner:
|
|
|
246
257
|
self._promise_checker: PromiseChecker | None = None
|
|
247
258
|
# Every navigation and executed action of the run, for reproduction.
|
|
248
259
|
self._log: list[LogEntry] = []
|
|
260
|
+
# Set by _execute_goal when a goal with a recording fails: checked once
|
|
261
|
+
# the goal's watchdog is off (a retry can take a while).
|
|
262
|
+
self._suspect: tuple | None = None
|
|
249
263
|
self._step_log = None
|
|
250
264
|
if self.config.step_log_path:
|
|
251
265
|
import pathlib # noqa: PLC0415
|
|
@@ -303,6 +317,7 @@ class FusionTestRunner:
|
|
|
303
317
|
model_goals = [_with_placeholder_hint(g) if resolver.has_templates(g) else g for g in goals]
|
|
304
318
|
reported: set[tuple[str, str]] = set() # bug signatures already suspected
|
|
305
319
|
candidates: list[BugCandidate] = []
|
|
320
|
+
regressions: list[Bug] = []
|
|
306
321
|
self._log = []
|
|
307
322
|
start_url = url or _current_url(self.adapter)
|
|
308
323
|
if start_url: # where a fresh session starts too, so it's not replayed
|
|
@@ -375,6 +390,12 @@ class FusionTestRunner:
|
|
|
375
390
|
if watchdog is not None:
|
|
376
391
|
watchdog.cancel()
|
|
377
392
|
|
|
393
|
+
if self._suspect is not None and not watchdog_fired.is_set() and not app_closed:
|
|
394
|
+
step_result = self._check_regression(step_result, resolver)
|
|
395
|
+
if step_result.regression is not None:
|
|
396
|
+
regressions.append(step_result.regression)
|
|
397
|
+
self._suspect = None
|
|
398
|
+
|
|
378
399
|
self._collect_bugs(step_result, candidates, reported, resolver)
|
|
379
400
|
|
|
380
401
|
# A timed-out goal couldn't be evaluated: record it as an error
|
|
@@ -433,6 +454,9 @@ class FusionTestRunner:
|
|
|
433
454
|
c.bug.reproduced = outcome.sessions if self.config.fresh_adapter else 0
|
|
434
455
|
result.bugs_detected = [c.bug for c in outcome.confirmed]
|
|
435
456
|
result.unconfirmed_bugs = [c.bug for c in outcome.unconfirmed]
|
|
457
|
+
# Regressions are failures of goals that verifiably worked before:
|
|
458
|
+
# reported whether or not bug finding is on.
|
|
459
|
+
result.bugs_detected += regressions
|
|
436
460
|
|
|
437
461
|
result.total_duration_seconds = time.time() - run_start
|
|
438
462
|
result.llm_calls = self._llm_calls()
|
|
@@ -731,11 +755,13 @@ class FusionTestRunner:
|
|
|
731
755
|
key = trace_key(safe_goal, goal_url)
|
|
732
756
|
trace = store.get(key)
|
|
733
757
|
mode = "llm"
|
|
758
|
+
start_at = len(self._log)
|
|
734
759
|
if trace is not None:
|
|
735
760
|
if trace.replays_since_verify < self.config.reverify_every:
|
|
736
761
|
replayed = self._replay(trace, safe_goal, goal_url, resolver)
|
|
737
762
|
if replayed is not None:
|
|
738
763
|
trace.replays_since_verify += 1
|
|
764
|
+
self._stamp_pass(trace)
|
|
739
765
|
store.save(trace)
|
|
740
766
|
return replayed
|
|
741
767
|
logger.info(" Replay diverged — falling back to the LLM to repair the trace")
|
|
@@ -746,9 +772,106 @@ class FusionTestRunner:
|
|
|
746
772
|
step = self._run_goal(goal, safe_goal=safe_goal, navigate_url=goal_url, resolver=resolver)
|
|
747
773
|
step.mode = mode
|
|
748
774
|
if step.success and self._last_recording is not None:
|
|
749
|
-
store.save(
|
|
775
|
+
store.save(self._stamp_pass(
|
|
776
|
+
GoalTrace(key=key, goal=safe_goal, start_url=goal_url, **self._last_recording)))
|
|
777
|
+
elif trace is not None and not step.success and not step.infra_error:
|
|
778
|
+
# It passed before (that's how it got a recording): a regression, or flaky.
|
|
779
|
+
self._suspect = (trace, goal, safe_goal, goal_url, start_at, key)
|
|
780
|
+
return step
|
|
781
|
+
|
|
782
|
+
def _stamp_pass(self, trace: GoalTrace) -> GoalTrace:
|
|
783
|
+
from datetime import datetime, timezone # noqa: PLC0415
|
|
784
|
+
trace.last_passed_at = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
|
|
785
|
+
trace.last_passed_deploy = self.config.deploy
|
|
786
|
+
return trace
|
|
787
|
+
|
|
788
|
+
def _check_regression(self, step: StepResult, resolver: SecretResolver) -> StepResult:
|
|
789
|
+
"""A goal that passed before failed: retry it in a fresh session. Passes
|
|
790
|
+
→ flaky (the step passes, marked flaky). Fails again, or can't be
|
|
791
|
+
retried → a regression bug on the step."""
|
|
792
|
+
trace, goal, safe_goal, goal_url, start_at, key = self._suspect
|
|
793
|
+
retried = 0
|
|
794
|
+
if self.config.fresh_adapter is not None and self.config.retry_regressions:
|
|
795
|
+
retry = self._retry_in_fresh_session(goal, safe_goal, goal_url, resolver, start_at)
|
|
796
|
+
if retry is not None and retry.success:
|
|
797
|
+
logger.info(" Passed when retried in a fresh session: flaky, not a regression")
|
|
798
|
+
step.success, step.flaky = True, True
|
|
799
|
+
step.error = f"flaky: failed once ({step.error[:300]}), then passed in a fresh session"
|
|
800
|
+
step.token_usage += retry.token_usage
|
|
801
|
+
store = self.config.trace_store
|
|
802
|
+
if store is not None and self._last_recording is not None:
|
|
803
|
+
store.save(self._stamp_pass(
|
|
804
|
+
GoalTrace(key=key, goal=safe_goal, start_url=goal_url, **self._last_recording)))
|
|
805
|
+
return step
|
|
806
|
+
if retry is not None:
|
|
807
|
+
retried = 1
|
|
808
|
+
step.token_usage += retry.token_usage
|
|
809
|
+
last_good = trace.last_passed_deploy or trace.last_passed_at or "an earlier run"
|
|
810
|
+
first_bad = self.config.deploy or "this run"
|
|
811
|
+
proof = ", showing " + ", ".join(repr(e) for e in trace.evidence) if trace.evidence else ""
|
|
812
|
+
steps = ([step_text("navigate", trace.start_url)] if trace.start_url else []) + [
|
|
813
|
+
describe_recorded(a) for a in trace.actions]
|
|
814
|
+
step.regression = Bug(
|
|
815
|
+
kind="regression",
|
|
816
|
+
title=resolver.redact(f'Regression: "{safe_goal}" stopped working '
|
|
817
|
+
f"(last passed on {last_good})"),
|
|
818
|
+
page=url_path(trace.start_url),
|
|
819
|
+
expected=resolver.redact(f"It passes, as it did on {last_good}{proof}"),
|
|
820
|
+
actual=resolver.redact(step.error or "The goal no longer completes"),
|
|
821
|
+
steps=[resolver.redact(s) for s in steps],
|
|
822
|
+
reproduced=retried,
|
|
823
|
+
last_good=last_good,
|
|
824
|
+
first_bad=first_bad,
|
|
825
|
+
)
|
|
826
|
+
logger.warning(" %s", step.regression.title)
|
|
750
827
|
return step
|
|
751
828
|
|
|
829
|
+
def _retry_in_fresh_session(self, goal: str, safe_goal: str, goal_url: str,
|
|
830
|
+
resolver: SecretResolver, start_at: int) -> StepResult | None:
|
|
831
|
+
"""Re-create the run up to this goal in a fresh session (replaying the
|
|
832
|
+
action log, no LLM), then run the goal again. None if it can't be set up."""
|
|
833
|
+
try:
|
|
834
|
+
adapter = self.config.fresh_adapter()
|
|
835
|
+
except Exception as exc: # noqa: BLE001
|
|
836
|
+
logger.info(" Could not open a fresh session to retry: %s", exc)
|
|
837
|
+
return None
|
|
838
|
+
saved_log, original = list(self._log), self.adapter
|
|
839
|
+
self.adapter = adapter
|
|
840
|
+
try:
|
|
841
|
+
if not self._replay_entries(saved_log[:start_at], resolver):
|
|
842
|
+
logger.info(" Could not re-create the run's earlier steps in a fresh session")
|
|
843
|
+
return None
|
|
844
|
+
self.guardrails.reset_step()
|
|
845
|
+
return self._run_goal(goal, safe_goal=safe_goal, navigate_url=goal_url, resolver=resolver)
|
|
846
|
+
except Exception as exc: # noqa: BLE001 — a retry problem leaves the failure as it was
|
|
847
|
+
logger.info(" Retry in a fresh session failed to run: %s", exc)
|
|
848
|
+
return None
|
|
849
|
+
finally:
|
|
850
|
+
self.adapter, self._log = original, saved_log
|
|
851
|
+
stop = getattr(adapter, "stop", None)
|
|
852
|
+
if callable(stop):
|
|
853
|
+
try:
|
|
854
|
+
stop()
|
|
855
|
+
except Exception: # noqa: BLE001
|
|
856
|
+
pass
|
|
857
|
+
|
|
858
|
+
def _replay_entries(self, entries: list[LogEntry], resolver: SecretResolver) -> bool:
|
|
859
|
+
"""Replay logged navigations and actions on self.adapter (no LLM)."""
|
|
860
|
+
for entry in entries:
|
|
861
|
+
if entry.kind == "navigate":
|
|
862
|
+
if hasattr(self.adapter, "navigate"):
|
|
863
|
+
self.adapter.navigate(entry.url)
|
|
864
|
+
elif entry.action is not None:
|
|
865
|
+
time.sleep(0.8)
|
|
866
|
+
elements, _ = self.adapter.get_screen()
|
|
867
|
+
action = resolve_action(entry.action, elements)
|
|
868
|
+
if action is None:
|
|
869
|
+
return False
|
|
870
|
+
exec_action, blocked = self._bind_secrets(action, resolver)
|
|
871
|
+
if blocked or not self.adapter.execute(exec_action, elements):
|
|
872
|
+
return False
|
|
873
|
+
return True
|
|
874
|
+
|
|
752
875
|
def _collect_bugs(self, step: StepResult, candidates: list[BugCandidate],
|
|
753
876
|
reported: set[tuple[str, str]], resolver: SecretResolver) -> None:
|
|
754
877
|
"""The goal's app errors onto the step, and (with detect_bugs) each new
|
|
@@ -759,21 +882,32 @@ class FusionTestRunner:
|
|
|
759
882
|
step.app_errors = list(drain())
|
|
760
883
|
except Exception as exc: # noqa: BLE001 — observation must never fail a run
|
|
761
884
|
logger.debug("Could not read app errors: %s", exc)
|
|
762
|
-
def steps_to(at: int) -> list[str]:
|
|
885
|
+
def steps_to(at: int) -> tuple[list[str], int]:
|
|
886
|
+
"""Steps to reproduce: from the last page opened before `at` (each goal
|
|
887
|
+
that opens its start page begins afresh), and how many came before."""
|
|
888
|
+
entries = self._log[:at]
|
|
889
|
+
last_open = max((i for i, e in enumerate(entries) if e.kind in ("start", "navigate")), default=0)
|
|
890
|
+
earlier = sum(1 for e in entries[:last_open] if e.kind == "action")
|
|
763
891
|
steps: list[str] = []
|
|
764
|
-
for e in
|
|
892
|
+
for e in entries[last_open:]:
|
|
765
893
|
# Opening the page you're already on adds nothing (repeated taps do).
|
|
766
894
|
if e.text and not (e.kind != "action" and steps and steps[-1] == e.text):
|
|
767
895
|
steps.append(e.text)
|
|
768
|
-
return steps
|
|
896
|
+
return steps, earlier
|
|
897
|
+
|
|
898
|
+
def bug_at(make, source, at: int):
|
|
899
|
+
steps, earlier = steps_to(at)
|
|
900
|
+
bug = make(source, steps, resolver.redact)
|
|
901
|
+
bug.earlier_steps = earlier
|
|
902
|
+
return bug
|
|
769
903
|
|
|
770
|
-
found = [BugCandidate(bug=bugs.from_app_error
|
|
904
|
+
found = [BugCandidate(bug=bug_at(bugs.from_app_error, e, len(self._log)),
|
|
771
905
|
signature=e.signature, at=len(self._log), app_error=e.signature)
|
|
772
906
|
for e in step.app_errors]
|
|
773
907
|
# A finding about an action that already raised an app error (a dead
|
|
774
908
|
# link that "didn't open the Help page") is the same bug said twice.
|
|
775
909
|
errored_actions = {e.after for e in step.app_errors}
|
|
776
|
-
found += [BugCandidate(bug=bugs.from_finding
|
|
910
|
+
found += [BugCandidate(bug=bug_at(bugs.from_finding, f, f.at),
|
|
777
911
|
signature=(f.kind, f.summary.lower()), at=f.at, evidence=list(f.evidence))
|
|
778
912
|
for f in step.findings if f.action not in errored_actions]
|
|
779
913
|
for candidate in found:
|
|
@@ -47,6 +47,19 @@ _ARIA_PROP_RE = re.compile(r'^-?\s*/(\w+):\s*(.*\S)\s*$')
|
|
|
47
47
|
_ROW_CONTROL_ROLES = {"checkbox", "radio", "button", "switch", "link"}
|
|
48
48
|
_ROW_TEXT_ROLES = {"text", "heading"}
|
|
49
49
|
_ROW_ROLES = {"listitem", "row", "article", "group", "cell", "gridcell"}
|
|
50
|
+
# Links that end a session — never followed while exploring a site.
|
|
51
|
+
_SIGN_OUT_RE = re.compile(r"\b(log|sign)[\s_-]?(out|off)\b", re.IGNORECASE)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _page_key(url: str) -> str:
|
|
55
|
+
"""A URL as a page: no trailing slash, and its fragment only if it's a route."""
|
|
56
|
+
from urllib.parse import urldefrag # noqa: PLC0415
|
|
57
|
+
|
|
58
|
+
page, fragment = urldefrag(url)
|
|
59
|
+
page = page.rstrip("/")
|
|
60
|
+
return f"{page}#{fragment}" if fragment.startswith(("/", "!/")) else page
|
|
61
|
+
|
|
62
|
+
|
|
50
63
|
# How long drain_app_errors() lets in-flight responses and exceptions arrive.
|
|
51
64
|
_APP_ERROR_SETTLE_SECONDS = 0.3
|
|
52
65
|
|
|
@@ -324,23 +337,25 @@ class PlaywrightAdapter:
|
|
|
324
337
|
return self._run(self._async_site_links(limit))
|
|
325
338
|
|
|
326
339
|
async def _async_site_links(self, limit: int) -> list[str]:
|
|
327
|
-
from
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
)
|
|
336
|
-
base = self._page.url
|
|
340
|
+
"""Same-site links from the page's navigation (else the whole page). Hash
|
|
341
|
+
routes ("#/cart") count as pages; in-page anchors ("#pricing") don't.
|
|
342
|
+
Sign-out links are skipped: following one would end a signed-in session."""
|
|
343
|
+
from urllib.parse import urljoin, urlsplit # noqa: PLC0415
|
|
344
|
+
|
|
345
|
+
js = "els => els.map(e => [e.getAttribute('href'), (e.textContent || '').trim()])"
|
|
346
|
+
anchors: list[list[str]] = await self._page.locator("header a[href], nav a[href]").evaluate_all(js)
|
|
347
|
+
if not anchors:
|
|
348
|
+
anchors = await self._page.locator("a[href]").evaluate_all(js)
|
|
349
|
+
base = _page_key(self._page.url)
|
|
337
350
|
origin = urlsplit(base).netloc
|
|
338
351
|
links: list[str] = []
|
|
339
|
-
for href in
|
|
352
|
+
for href, text in anchors:
|
|
340
353
|
if not href or href.startswith(("mailto:", "tel:", "javascript:")):
|
|
341
354
|
continue
|
|
342
|
-
|
|
343
|
-
|
|
355
|
+
if _SIGN_OUT_RE.search(href) or _SIGN_OUT_RE.search(text or ""):
|
|
356
|
+
continue
|
|
357
|
+
url = _page_key(urljoin(self._page.url, href))
|
|
358
|
+
if urlsplit(url).netloc == origin and url != base and url not in links:
|
|
344
359
|
links.append(url)
|
|
345
360
|
return links[:limit]
|
|
346
361
|
|
|
@@ -69,6 +69,8 @@ class GoalGeneratorConfig:
|
|
|
69
69
|
class SiteSnapshot:
|
|
70
70
|
url: str
|
|
71
71
|
pages: list[tuple[str, str]] = field(default_factory=list) # (url, screen text)
|
|
72
|
+
signed_in: bool = False # captured after signing in (see snapshot_site)
|
|
73
|
+
broken: list[str] = field(default_factory=list) # linked pages that failed to load: left out
|
|
72
74
|
|
|
73
75
|
@property
|
|
74
76
|
def content(self) -> str:
|
|
@@ -79,35 +81,62 @@ class SiteSnapshot:
|
|
|
79
81
|
|
|
80
82
|
def snapshot_site(
|
|
81
83
|
url: str, config: GoalGeneratorConfig | None = None, block_private_networks: bool = False,
|
|
84
|
+
adapter=None,
|
|
82
85
|
) -> SiteSnapshot:
|
|
83
86
|
"""Capture the start page and pages linked from its navigation.
|
|
84
|
-
block_private_networks: server-side use — see PlaywrightAdapter.
|
|
87
|
+
block_private_networks: server-side use — see PlaywrightAdapter.
|
|
88
|
+
adapter: an already started session (e.g. signed in) to capture from,
|
|
89
|
+
starting at its current page; it's left open for the caller."""
|
|
85
90
|
from fusiontest.desktop.playwright_adapter import PlaywrightAdapter # noqa: PLC0415
|
|
86
91
|
|
|
87
92
|
cfg = config or GoalGeneratorConfig()
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
own = adapter is None
|
|
94
|
+
snapshot = SiteSnapshot(url=url, signed_in=not own)
|
|
95
|
+
if own:
|
|
96
|
+
adapter = PlaywrightAdapter(headless=True, block_private_networks=block_private_networks)
|
|
90
97
|
try:
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
if own:
|
|
99
|
+
adapter.start(url)
|
|
100
|
+
start = adapter.current_url() or url
|
|
101
|
+
snapshot.pages.append((start, _page_text(adapter, cfg)))
|
|
93
102
|
for link in adapter.site_links(limit=cfg.max_pages - 1):
|
|
94
103
|
try:
|
|
104
|
+
_page_errors(adapter) # not this page's
|
|
95
105
|
adapter.navigate(link)
|
|
106
|
+
failed = _page_errors(adapter)
|
|
107
|
+
if failed:
|
|
108
|
+
# A 404 or 500 page isn't the site's content: goals written
|
|
109
|
+
# from it would expect the failure.
|
|
110
|
+
logger.info("Discovery: leaving out %s (%s)", link, failed[0])
|
|
111
|
+
snapshot.broken.append(link)
|
|
112
|
+
continue
|
|
96
113
|
snapshot.pages.append((link, _page_text(adapter, cfg)))
|
|
97
114
|
except Exception as exc: # noqa: BLE001 — one bad page shouldn't sink discovery
|
|
98
115
|
logger.warning("Discovery: skipping %s (%s)", link, exc)
|
|
99
116
|
except Exception as exc: # noqa: BLE001
|
|
100
117
|
raise GoalGenerationError(f"Could not open {url}: {exc}") from exc
|
|
101
118
|
finally:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
if own:
|
|
120
|
+
try:
|
|
121
|
+
adapter.stop()
|
|
122
|
+
except Exception: # noqa: BLE001
|
|
123
|
+
pass
|
|
106
124
|
logger.info("Discovery snapshot of %s: %d page(s), %d chars",
|
|
107
125
|
url, len(snapshot.pages), len(snapshot.content))
|
|
108
126
|
return snapshot
|
|
109
127
|
|
|
110
128
|
|
|
129
|
+
def _page_errors(adapter) -> list[str]:
|
|
130
|
+
"""HTTP failures (404s, 5xx) the adapter saw since the last call, if it can tell."""
|
|
131
|
+
drain = getattr(adapter, "drain_app_errors", None)
|
|
132
|
+
if not callable(drain):
|
|
133
|
+
return []
|
|
134
|
+
try:
|
|
135
|
+
return [e.message for e in drain() if e.kind == "http_error"]
|
|
136
|
+
except Exception: # noqa: BLE001
|
|
137
|
+
return []
|
|
138
|
+
|
|
139
|
+
|
|
111
140
|
def _page_text(adapter, cfg: GoalGeneratorConfig) -> str:
|
|
112
141
|
_, screen = adapter.get_screen()
|
|
113
142
|
return screen[: cfg.max_chars_per_page]
|
|
@@ -132,6 +161,8 @@ Rules:
|
|
|
132
161
|
live production site. For forms, verify the fields and client-side validation
|
|
133
162
|
(e.g. required-field errors) instead of submitting successfully.
|
|
134
163
|
- Cover navigation, key content, forms and validation — as far as the site has them.
|
|
164
|
+
- Goals describe what should WORK. Never write a goal that expects an error page,
|
|
165
|
+
a "not found" page, a crash or any broken behaviour as the correct result.
|
|
135
166
|
- evidence: a short EXACT quote (3-80 characters) copied from the provided
|
|
136
167
|
content that the goal depends on — a heading, link, button or field label.
|
|
137
168
|
|
|
@@ -155,9 +186,16 @@ _REQUEST = LLMRequest(
|
|
|
155
186
|
|
|
156
187
|
|
|
157
188
|
def _build_user_message(snapshot: SiteSnapshot, max_goals: int) -> str:
|
|
189
|
+
signed_in = (
|
|
190
|
+
"These pages were captured while signed in. Each goal will be run right after "
|
|
191
|
+
"signing in, starting from the first page above: do not include signing in or "
|
|
192
|
+
"signing out in any goal.\n\n"
|
|
193
|
+
if snapshot.signed_in else ""
|
|
194
|
+
)
|
|
158
195
|
return (
|
|
159
196
|
f"Site: {snapshot.url}\n\n"
|
|
160
197
|
f"SITE CONTENT ({len(snapshot.pages)} page(s)):\n{snapshot.content}\n\n"
|
|
198
|
+
f"{signed_in}"
|
|
161
199
|
f"Write up to {max_goals} test goals for this site, grounded in the content above, "
|
|
162
200
|
f"across critical_path (the site's most important flows), happy_path (navigation "
|
|
163
201
|
f"and features) and edge_cases (validation and error states)."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fusiontest
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.30
|
|
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
|
|
@@ -146,6 +146,8 @@ fusiontest run --url https://example.com \
|
|
|
146
146
|
|
|
147
147
|
# No goals yet? Map what works on a test/staging site, and save the flows that do
|
|
148
148
|
fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
|
|
149
|
+
# Behind a login: EMAIL and PASSWORD come from the environment, never the AI
|
|
150
|
+
fusiontest scan https://staging.example.com --login "Sign in with email {{EMAIL}} and password {{PASSWORD}}"
|
|
149
151
|
```
|
|
150
152
|
|
|
151
153
|
Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
|
|
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
|