fusiontest 0.2.28__tar.gz → 0.2.29__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.29}/PKG-INFO +3 -1
- {fusiontest-0.2.28 → fusiontest-0.2.29}/README.md +2 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/cli.py +100 -25
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/bugs.py +2 -1
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/runner.py +16 -5
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/desktop/playwright_adapter.py +28 -13
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/discovery/goal_generator.py +47 -9
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/PKG-INFO +3 -1
- {fusiontest-0.2.28 → fusiontest-0.2.29}/pyproject.toml +1 -1
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/sites/shop/bugs.js +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/sites/shop/help.html +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/sites/shop/index.html +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/action_model.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/app_errors.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/goal_verifier.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/promise_checker.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/replay.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/reproduce.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/secrets.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/shared_traces.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/SOURCES.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/requires.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.28 → fusiontest-0.2.29}/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.29
|
|
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
|
|
@@ -149,14 +149,7 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
149
149
|
# Values can also be inlined directly (not recommended for passwords):
|
|
150
150
|
# secrets:
|
|
151
151
|
# 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
|
|
152
|
+
cfg_secrets = _config_secrets(cfg)
|
|
160
153
|
|
|
161
154
|
# Record & replay (ADR-007): flags override the config file's `replay:` block.
|
|
162
155
|
replay_cfg = cfg.get("replay") or {}
|
|
@@ -263,6 +256,18 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
|
|
|
263
256
|
sys.exit(_exit_code(result))
|
|
264
257
|
|
|
265
258
|
|
|
259
|
+
def _config_secrets(cfg: dict) -> dict[str, str]:
|
|
260
|
+
"""The config file's `secrets:` block, each value read from the environment
|
|
261
|
+
variable it names when that's set (so the file holds names, not passwords)."""
|
|
262
|
+
import os
|
|
263
|
+
|
|
264
|
+
secrets: dict[str, str] = {}
|
|
265
|
+
for key, val in (cfg.get("secrets") or {}).items():
|
|
266
|
+
env_resolved = os.getenv(str(val))
|
|
267
|
+
secrets[str(key)] = env_resolved if env_resolved is not None else str(val)
|
|
268
|
+
return secrets
|
|
269
|
+
|
|
270
|
+
|
|
266
271
|
# ── scan (ADR-009) ────────────────────────────────────────────────────────────
|
|
267
272
|
|
|
268
273
|
DEFAULT_SCAN_GOALS = "fusiontest.goals.yaml"
|
|
@@ -278,6 +283,10 @@ def _is_local_host(host: str) -> bool:
|
|
|
278
283
|
@click.argument("url")
|
|
279
284
|
@click.option("--max-flows", type=click.IntRange(1, 30), default=10, show_default=True,
|
|
280
285
|
help="How many flows to discover and check")
|
|
286
|
+
@click.option("--login", default=None, metavar="GOAL",
|
|
287
|
+
help="Sign in first, as a goal with {{VAR}} secrets, e.g. \"Sign in with email "
|
|
288
|
+
"{{EMAIL}} and password {{PASSWORD}}\". Flows are then discovered from the "
|
|
289
|
+
"signed-in pages, and each flow signs in first.")
|
|
281
290
|
@click.option("--find-bugs", is_flag=True,
|
|
282
291
|
help="Beta: also look for bugs (crashes, server errors, dead links, broken promises), "
|
|
283
292
|
"each confirmed in fresh browser sessions before it's reported")
|
|
@@ -291,7 +300,7 @@ def _is_local_host(host: str) -> bool:
|
|
|
291
300
|
@click.option("--output", "-o", type=click.Path(), help="Write JSON report to this path")
|
|
292
301
|
@click.option("--config", "config_file", type=click.Path(), default=None,
|
|
293
302
|
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):
|
|
303
|
+
def scan(url, max_flows, login, find_bugs, backend, headless, save_path, yes, output, config_file):
|
|
295
304
|
"""Map what works on a site: discover its flows, run each one, report the result.
|
|
296
305
|
|
|
297
306
|
\b
|
|
@@ -304,10 +313,17 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
304
313
|
Examples:
|
|
305
314
|
fusiontest scan https://staging.example.com
|
|
306
315
|
fusiontest scan http://localhost:3000 --find-bugs --save fusiontest.goals.yaml
|
|
316
|
+
fusiontest scan https://staging.example.com \\
|
|
317
|
+
--login "Sign in with email {{EMAIL}} and password {{PASSWORD}}"
|
|
318
|
+
|
|
319
|
+
\b
|
|
320
|
+
Secrets ({{EMAIL}}) come from environment variables of that name, or the
|
|
321
|
+
config file's `secrets:` block; the AI never sees their values.
|
|
307
322
|
"""
|
|
308
323
|
from urllib.parse import urlsplit
|
|
309
324
|
|
|
310
325
|
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
326
|
+
from fusiontest.core.secrets import resolve_goals
|
|
311
327
|
from fusiontest.discovery.goal_generator import (
|
|
312
328
|
GoalGenerationError,
|
|
313
329
|
GoalGenerator,
|
|
@@ -321,6 +337,14 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
321
337
|
config_path = Path(config_file) if config_file else Path("fusiontest.config.yaml")
|
|
322
338
|
cfg = (yaml.safe_load(config_path.read_text()) or {}) if config_path.exists() else {}
|
|
323
339
|
backend = _resolve_backend(backend, cfg)
|
|
340
|
+
secrets = _config_secrets(cfg)
|
|
341
|
+
if login:
|
|
342
|
+
_, resolver = resolve_goals([login], secrets)
|
|
343
|
+
if resolver.unresolved_vars:
|
|
344
|
+
missing = ", ".join(sorted(resolver.unresolved_vars))
|
|
345
|
+
console.print(f"[red]No value for {escape(missing)}:[/red] set environment variable(s) "
|
|
346
|
+
f"of that name, or map them under `secrets:` in fusiontest.config.yaml.")
|
|
347
|
+
sys.exit(1)
|
|
324
348
|
|
|
325
349
|
# Exploration is real: it clicks, types and submits.
|
|
326
350
|
if not _is_local_host(host) and not yes:
|
|
@@ -336,17 +360,20 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
336
360
|
console.print(Panel.fit(
|
|
337
361
|
f"[bold]FusionTest scan[/bold] {escape(url)}\n"
|
|
338
362
|
f"Backend: [cyan]{backend}[/cyan] · Bug finding: "
|
|
339
|
-
+ ("[cyan]on (beta)[/cyan]" if find_bugs else "off")
|
|
363
|
+
+ ("[cyan]on (beta)[/cyan]" if find_bugs else "off")
|
|
364
|
+
+ (" · Signs in first" if login else ""),
|
|
340
365
|
border_style="blue",
|
|
341
366
|
))
|
|
342
367
|
|
|
343
368
|
# 1. Discover flows grounded in the site's content.
|
|
344
369
|
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"),
|
|
345
370
|
console=console) as progress:
|
|
346
|
-
progress.add_task("
|
|
371
|
+
progress.add_task("Signing in, then reading the site..." if login
|
|
372
|
+
else "Reading the site and finding flows to check...", total=None)
|
|
373
|
+
discovery = GoalGeneratorConfig(max_goals=max_flows)
|
|
347
374
|
try:
|
|
348
|
-
|
|
349
|
-
|
|
375
|
+
snapshot = _signed_in_snapshot(url, login, backend, secrets, discovery) if login else None
|
|
376
|
+
flows = GoalGenerator(discovery).generate(url, preferred_backend=backend, snapshot=snapshot)
|
|
350
377
|
except GoalGenerationError as exc:
|
|
351
378
|
console.print(f"[red]Couldn't discover flows:[/red] {escape(str(exc))}")
|
|
352
379
|
sys.exit(2)
|
|
@@ -361,6 +388,7 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
361
388
|
trace_dir = Path(replay_cfg.get("trace_dir") or DEFAULT_TRACE_DIR)
|
|
362
389
|
runner = FusionTestRunner(_build_adapter("playwright", None, url, headless), RunnerConfig(
|
|
363
390
|
backend=backend,
|
|
391
|
+
secrets=secrets,
|
|
364
392
|
screenshot_on_failure=True,
|
|
365
393
|
trace_store=_trace_store(trace_dir, bool(replay_cfg.get("shared", True))),
|
|
366
394
|
reverify_every=0,
|
|
@@ -371,9 +399,17 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
371
399
|
console=console) as progress:
|
|
372
400
|
progress.add_task("Checking each flow" + (" and looking for bugs" if find_bugs else "") + "...",
|
|
373
401
|
total=None)
|
|
402
|
+
if login:
|
|
403
|
+
# Each flow starts signed in: open the start page and sign in, then
|
|
404
|
+
# the flow continues from wherever sign-in lands.
|
|
405
|
+
goals = [g for f in flows for g in (login, f.text)]
|
|
406
|
+
goal_urls = [u for _ in flows for u in (url, None)]
|
|
407
|
+
run_url = ""
|
|
408
|
+
else:
|
|
409
|
+
goals, goal_urls, run_url = [f.text for f in flows], None, url
|
|
374
410
|
try:
|
|
375
|
-
result = runner.run(goals=
|
|
376
|
-
platform="playwright", url=
|
|
411
|
+
result = runner.run(goals=goals, goal_urls=goal_urls, name=f"Scan: {host}",
|
|
412
|
+
platform="playwright", url=run_url)
|
|
377
413
|
finally:
|
|
378
414
|
stop = getattr(runner.adapter, "stop", None)
|
|
379
415
|
if callable(stop):
|
|
@@ -385,7 +421,7 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
385
421
|
# 3. Coverage map, then bugs.
|
|
386
422
|
shot_dir = Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR))
|
|
387
423
|
bug_shots = _save_bug_screenshots(result, shot_dir)
|
|
388
|
-
working = _print_coverage(flows, result)
|
|
424
|
+
working = _print_coverage(flows, result, signed_in=bool(login))
|
|
389
425
|
if find_bugs:
|
|
390
426
|
_print_bugs(result, bug_shots)
|
|
391
427
|
else:
|
|
@@ -402,20 +438,49 @@ def scan(url, max_flows, find_bugs, backend, headless, save_path, yes, output, c
|
|
|
402
438
|
|
|
403
439
|
# 4. Offer to watch the flows that work.
|
|
404
440
|
if working:
|
|
405
|
-
_offer_to_watch(url, working, save_path)
|
|
441
|
+
_offer_to_watch(url, working, save_path, login)
|
|
406
442
|
|
|
407
443
|
|
|
408
|
-
def
|
|
409
|
-
"""
|
|
444
|
+
def _signed_in_snapshot(url, login, backend, secrets, discovery):
|
|
445
|
+
"""Sign in once in a headless browser, then capture the signed-in pages."""
|
|
446
|
+
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
447
|
+
from fusiontest.discovery.goal_generator import GoalGenerationError, snapshot_site
|
|
448
|
+
|
|
449
|
+
adapter = _build_adapter("playwright", None, url, True)
|
|
450
|
+
try:
|
|
451
|
+
signed_in = FusionTestRunner(adapter, RunnerConfig(
|
|
452
|
+
backend=backend, secrets=secrets, screenshot_on_failure=False, trace_store=None,
|
|
453
|
+
)).run(goals=[login], name="Sign in", platform="playwright", url=url)
|
|
454
|
+
step = signed_in.steps[0] if signed_in.steps else None
|
|
455
|
+
if step is None or not step.success:
|
|
456
|
+
why = (step.error if step else signed_in.error) or "the sign-in goal didn't complete"
|
|
457
|
+
raise GoalGenerationError(f"Couldn't sign in: {why}")
|
|
458
|
+
return snapshot_site(url, discovery, adapter=adapter)
|
|
459
|
+
finally:
|
|
460
|
+
try:
|
|
461
|
+
adapter.stop()
|
|
462
|
+
except Exception: # noqa: BLE001
|
|
463
|
+
pass
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def _print_coverage(flows, result, signed_in: bool = False) -> list:
|
|
467
|
+
"""The coverage map: each flow and whether it works. Returns the flows that do.
|
|
468
|
+
signed_in: the run's goals alternate sign-in, flow, sign-in, flow, ..."""
|
|
410
469
|
table = Table(title="Coverage", header_style="bold", box=None, pad_edge=False, title_justify="left")
|
|
411
470
|
table.add_column("#", style="dim", width=3)
|
|
412
471
|
table.add_column("Flow", min_width=24)
|
|
413
472
|
table.add_column("Result", width=16)
|
|
414
473
|
table.add_column("Steps", width=6)
|
|
415
474
|
working = []
|
|
475
|
+
stride, offset = (2, 1) if signed_in else (1, 0)
|
|
416
476
|
for i, flow in enumerate(flows):
|
|
417
|
-
|
|
418
|
-
|
|
477
|
+
login_step = result.steps[i * 2] if signed_in and i * 2 < len(result.steps) else None
|
|
478
|
+
index = i * stride + offset
|
|
479
|
+
step = result.steps[index] if index < len(result.steps) else None
|
|
480
|
+
if login_step is not None and not login_step.success:
|
|
481
|
+
step = login_step # the flow never started: say why
|
|
482
|
+
cell = "[yellow]couldn't sign in[/yellow]"
|
|
483
|
+
elif step is None:
|
|
419
484
|
cell = "[dim]not checked[/dim]"
|
|
420
485
|
elif step.success:
|
|
421
486
|
cell = "[green]works[/green]"
|
|
@@ -451,14 +516,15 @@ def _print_bugs(result, bug_shots: dict[int, Path]) -> None:
|
|
|
451
516
|
console.print(f" [dim]Expected:[/dim] {escape(bug.expected or '—')}")
|
|
452
517
|
console.print(f" [dim]Actual:[/dim] {escape(bug.actual or '—')}")
|
|
453
518
|
if bug.steps:
|
|
454
|
-
|
|
519
|
+
after = f", after {bug.earlier_steps} earlier step(s) in this run" if bug.earlier_steps else ""
|
|
520
|
+
console.print(f" [dim]Steps to reproduce ({len(bug.steps)}{after}):[/dim]")
|
|
455
521
|
for n, step in enumerate(bug.steps, 1):
|
|
456
522
|
console.print(f" {n}. {escape(step)}", soft_wrap=True)
|
|
457
523
|
if i in bug_shots:
|
|
458
524
|
console.print(f" [dim]Screenshot: {escape(str(bug_shots[i]))}[/dim]", soft_wrap=True)
|
|
459
525
|
|
|
460
526
|
|
|
461
|
-
def _offer_to_watch(url: str, working: list, save_path: str | None) -> None:
|
|
527
|
+
def _offer_to_watch(url: str, working: list, save_path: str | None, login: str | None = None) -> None:
|
|
462
528
|
"""Save the flows that work as a goals file, to run on every deploy."""
|
|
463
529
|
path = Path(save_path) if save_path else None
|
|
464
530
|
if path is None:
|
|
@@ -472,9 +538,18 @@ def _offer_to_watch(url: str, working: list, save_path: str | None) -> None:
|
|
|
472
538
|
path = Path(DEFAULT_SCAN_GOALS)
|
|
473
539
|
if path.exists() and not click.confirm(f"{path} exists. Replace it?", default=False):
|
|
474
540
|
return
|
|
475
|
-
|
|
541
|
+
if login:
|
|
542
|
+
# Each flow signs in from the start page first; flows have no url of
|
|
543
|
+
# their own, so they continue from where signing in lands.
|
|
544
|
+
goals = [g for f in working for g in ({"name": "Sign in", "url": url, "goal": login},
|
|
545
|
+
{"name": f.name, "goal": f.text})]
|
|
546
|
+
data = {"goals": goals}
|
|
547
|
+
note = "# Signing in needs the same secrets as the scan ({{VAR}} from env or config).\n"
|
|
548
|
+
else:
|
|
549
|
+
data = {"url": url, "goals": [{"name": f.name, "goal": f.text} for f in working]}
|
|
550
|
+
note = ""
|
|
476
551
|
path.write_text("# Flows that worked when FusionTest scanned this site.\n"
|
|
477
|
-
"# Run them on every deploy: fusiontest run -f " + str(path) + "\n"
|
|
552
|
+
"# Run them on every deploy: fusiontest run -f " + str(path) + "\n" + note
|
|
478
553
|
+ yaml.safe_dump(data, sort_keys=False, allow_unicode=True))
|
|
479
554
|
console.print(f"\n[green]✓[/green] Saved {len(working)} flow(s) to [cyan]{escape(str(path))}[/cyan]. "
|
|
480
555
|
"Run them on every deploy; they replay from their recordings, without AI calls, "
|
|
@@ -26,7 +26,8 @@ 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)
|
|
31
32
|
# PNG of the screen when it happened again in a fresh session (not in to_dict:
|
|
32
33
|
# uploaded separately).
|
|
@@ -759,21 +759,32 @@ class FusionTestRunner:
|
|
|
759
759
|
step.app_errors = list(drain())
|
|
760
760
|
except Exception as exc: # noqa: BLE001 — observation must never fail a run
|
|
761
761
|
logger.debug("Could not read app errors: %s", exc)
|
|
762
|
-
def steps_to(at: int) -> list[str]:
|
|
762
|
+
def steps_to(at: int) -> tuple[list[str], int]:
|
|
763
|
+
"""Steps to reproduce: from the last page opened before `at` (each goal
|
|
764
|
+
that opens its start page begins afresh), and how many came before."""
|
|
765
|
+
entries = self._log[:at]
|
|
766
|
+
last_open = max((i for i, e in enumerate(entries) if e.kind in ("start", "navigate")), default=0)
|
|
767
|
+
earlier = sum(1 for e in entries[:last_open] if e.kind == "action")
|
|
763
768
|
steps: list[str] = []
|
|
764
|
-
for e in
|
|
769
|
+
for e in entries[last_open:]:
|
|
765
770
|
# Opening the page you're already on adds nothing (repeated taps do).
|
|
766
771
|
if e.text and not (e.kind != "action" and steps and steps[-1] == e.text):
|
|
767
772
|
steps.append(e.text)
|
|
768
|
-
return steps
|
|
773
|
+
return steps, earlier
|
|
769
774
|
|
|
770
|
-
|
|
775
|
+
def bug_at(make, source, at: int):
|
|
776
|
+
steps, earlier = steps_to(at)
|
|
777
|
+
bug = make(source, steps, resolver.redact)
|
|
778
|
+
bug.earlier_steps = earlier
|
|
779
|
+
return bug
|
|
780
|
+
|
|
781
|
+
found = [BugCandidate(bug=bug_at(bugs.from_app_error, e, len(self._log)),
|
|
771
782
|
signature=e.signature, at=len(self._log), app_error=e.signature)
|
|
772
783
|
for e in step.app_errors]
|
|
773
784
|
# A finding about an action that already raised an app error (a dead
|
|
774
785
|
# link that "didn't open the Help page") is the same bug said twice.
|
|
775
786
|
errored_actions = {e.after for e in step.app_errors}
|
|
776
|
-
found += [BugCandidate(bug=bugs.from_finding
|
|
787
|
+
found += [BugCandidate(bug=bug_at(bugs.from_finding, f, f.at),
|
|
777
788
|
signature=(f.kind, f.summary.lower()), at=f.at, evidence=list(f.evidence))
|
|
778
789
|
for f in step.findings if f.action not in errored_actions]
|
|
779
790
|
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.29
|
|
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
|
|
File without changes
|