fusiontest 0.2.26__tar.gz → 0.2.28__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.
Files changed (58) hide show
  1. {fusiontest-0.2.26 → fusiontest-0.2.28}/PKG-INFO +4 -1
  2. {fusiontest-0.2.26 → fusiontest-0.2.28}/README.md +3 -0
  3. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/cli.py +265 -11
  4. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/bugs.py +6 -1
  5. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/runner.py +16 -3
  6. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/PKG-INFO +4 -1
  7. {fusiontest-0.2.26 → fusiontest-0.2.28}/pyproject.toml +1 -1
  8. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/__init__.py +0 -0
  9. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/__init__.py +0 -0
  10. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/sites/shop/bugs.js +0 -0
  11. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/sites/shop/help.html +0 -0
  12. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/sites/shop/index.html +0 -0
  13. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
  14. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/suites/shop.yaml +0 -0
  15. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/bench/suites/todomvc.yaml +0 -0
  16. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/__init__.py +0 -0
  17. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/action_model.py +0 -0
  18. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/app_errors.py +0 -0
  19. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/goal_verifier.py +0 -0
  20. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/netguard.py +0 -0
  21. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/promise_checker.py +0 -0
  22. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/replay.py +0 -0
  23. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/reproduce.py +0 -0
  24. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/screen_parser.py +0 -0
  25. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/secrets.py +0 -0
  26. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/shared_traces.py +0 -0
  27. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/core/tokens.py +0 -0
  28. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/__init__.py +0 -0
  29. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
  30. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/github.yaml +0 -0
  31. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/hacker_news.yaml +0 -0
  32. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/httpbin.yaml +0 -0
  33. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/todomvc.yaml +0 -0
  34. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/demos/wikipedia.yaml +0 -0
  35. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/desktop/__init__.py +0 -0
  36. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/desktop/macos_adapter.py +0 -0
  37. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/desktop/playwright_adapter.py +0 -0
  38. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/desktop/windows_adapter.py +0 -0
  39. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/discovery/__init__.py +0 -0
  40. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/discovery/goal_generator.py +0 -0
  41. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/guardrails/__init__.py +0 -0
  42. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/guardrails/engine.py +0 -0
  43. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/mobile/__init__.py +0 -0
  44. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/mobile/android_adapter.py +0 -0
  45. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/mobile/ios_adapter.py +0 -0
  46. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/reporting/__init__.py +0 -0
  47. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/reporting/reporter.py +0 -0
  48. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/training/__init__.py +0 -0
  49. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/training/data_collector.py +0 -0
  50. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/training/dataset_builder.py +0 -0
  51. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest/training/trainer.py +0 -0
  52. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/SOURCES.txt +0 -0
  53. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/dependency_links.txt +0 -0
  54. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/entry_points.txt +0 -0
  55. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/not-zip-safe +0 -0
  56. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/requires.txt +0 -0
  57. {fusiontest-0.2.26 → fusiontest-0.2.28}/fusiontest.egg-info/top_level.txt +0 -0
  58. {fusiontest-0.2.26 → fusiontest-0.2.28}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.26
3
+ Version: 0.2.28
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
@@ -143,6 +143,9 @@ export GROQ_API_KEY=gsk_... # or ANTHROPIC_API_KEY / GEMINI_API_KEY / O
143
143
 
144
144
  fusiontest run --url https://example.com \
145
145
  --goal "Verify the page heading says Example Domain" --headless
146
+
147
+ # No goals yet? Map what works on a test/staging site, and save the flows that do
148
+ fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
146
149
  ```
147
150
 
148
151
  Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
@@ -64,6 +64,9 @@ export GROQ_API_KEY=gsk_... # or ANTHROPIC_API_KEY / GEMINI_API_KEY / O
64
64
 
65
65
  fusiontest run --url https://example.com \
66
66
  --goal "Verify the page heading says Example Domain" --headless
67
+
68
+ # No goals yet? Map what works on a test/staging site, and save the flows that do
69
+ fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
67
70
  ```
68
71
 
69
72
  Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
@@ -230,10 +230,12 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
230
230
  progress.stop()
231
231
 
232
232
  # Failure screenshots: saved next to the project, shown in the results.
233
- shots = _save_screenshots(result, Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR)))
233
+ shot_dir = Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR))
234
+ shots = _save_screenshots(result, shot_dir)
235
+ bug_shots = _save_bug_screenshots(result, shot_dir)
234
236
 
235
237
  # Print results table, then Slack / GitHub annotations if configured
236
- _print_results(result, shots)
238
+ _print_results(result, shots, bug_shots)
237
239
  _notify(result)
238
240
 
239
241
  # Save JSON report locally
@@ -243,8 +245,11 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
243
245
 
244
246
  # Upload report to FusionTest dashboard
245
247
  uploaded_run_id = _upload_report(result)
246
- if uploaded_run_id and shots and cfg.get("screenshots", {}).get("upload", True):
247
- _upload_screenshots(uploaded_run_id, shots)
248
+ if uploaded_run_id and cfg.get("screenshots", {}).get("upload", True):
249
+ if shots:
250
+ _upload_screenshots(uploaded_run_id, shots)
251
+ if bug_shots:
252
+ _upload_screenshots(uploaded_run_id, bug_shots, kind="bug")
248
253
 
249
254
  # Upload step telemetry (best-effort, non-blocking)
250
255
  if _api_key and _step_log_tmp:
@@ -258,6 +263,225 @@ def run(goal, goal_file, platform, app, url, locale, backend, headless, output,
258
263
  sys.exit(_exit_code(result))
259
264
 
260
265
 
266
+ # ── scan (ADR-009) ────────────────────────────────────────────────────────────
267
+
268
+ DEFAULT_SCAN_GOALS = "fusiontest.goals.yaml"
269
+ _LOCAL_SUFFIXES = (".localhost", ".test", ".local", ".internal")
270
+
271
+
272
+ def _is_local_host(host: str) -> bool:
273
+ host = (host or "").lower().strip("[]")
274
+ return host in ("localhost", "127.0.0.1", "::1") or host.endswith(_LOCAL_SUFFIXES)
275
+
276
+
277
+ @main.command()
278
+ @click.argument("url")
279
+ @click.option("--max-flows", type=click.IntRange(1, 30), default=10, show_default=True,
280
+ help="How many flows to discover and check")
281
+ @click.option("--find-bugs", is_flag=True,
282
+ help="Beta: also look for bugs (crashes, server errors, dead links, broken promises), "
283
+ "each confirmed in fresh browser sessions before it's reported")
284
+ @click.option("--backend", type=click.Choice(["gpt4o", "claude", "gemini", "groq", "ollama"]),
285
+ default="gpt4o", show_default=True, help="AI model backend")
286
+ @click.option("--headless/--no-headless", default=True, show_default=True)
287
+ @click.option("--save", "save_path", type=click.Path(dir_okay=False), default=None,
288
+ help=f"Save the flows that work to this goals file (default: ask; {DEFAULT_SCAN_GOALS})")
289
+ @click.option("--yes", "-y", is_flag=True,
290
+ help="Don't ask before scanning a site that isn't local")
291
+ @click.option("--output", "-o", type=click.Path(), help="Write JSON report to this path")
292
+ @click.option("--config", "config_file", type=click.Path(), default=None,
293
+ 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):
295
+ """Map what works on a site: discover its flows, run each one, report the result.
296
+
297
+ \b
298
+ Scan clicks buttons and submits forms, like a user would. Point it at a
299
+ test or staging site, not production. With --find-bugs (beta) it also
300
+ reports bugs it can confirm. Flows that work can be saved as a goals file
301
+ and run on every deploy with `fusiontest run -f`.
302
+
303
+ \b
304
+ Examples:
305
+ fusiontest scan https://staging.example.com
306
+ fusiontest scan http://localhost:3000 --find-bugs --save fusiontest.goals.yaml
307
+ """
308
+ from urllib.parse import urlsplit
309
+
310
+ from fusiontest.core.runner import FusionTestRunner, RunnerConfig
311
+ from fusiontest.discovery.goal_generator import (
312
+ GoalGenerationError,
313
+ GoalGenerator,
314
+ GoalGeneratorConfig,
315
+ )
316
+
317
+ _load_env()
318
+ if not urlsplit(url).scheme:
319
+ url = f"https://{url}"
320
+ host = urlsplit(url).hostname or url
321
+ config_path = Path(config_file) if config_file else Path("fusiontest.config.yaml")
322
+ cfg = (yaml.safe_load(config_path.read_text()) or {}) if config_path.exists() else {}
323
+ backend = _resolve_backend(backend, cfg)
324
+
325
+ # Exploration is real: it clicks, types and submits.
326
+ if not _is_local_host(host) and not yes:
327
+ if not sys.stdin.isatty():
328
+ console.print(f"[red]Not scanning {escape(host)}:[/red] scan clicks buttons and submits forms. "
329
+ "Use a test or staging site, and pass --yes to confirm.")
330
+ sys.exit(1)
331
+ if not click.confirm(f"Scan clicks buttons and submits forms on {host}, like a user would. "
332
+ "Is this a test or staging site?", default=False):
333
+ sys.exit(1)
334
+
335
+ console.print()
336
+ console.print(Panel.fit(
337
+ f"[bold]FusionTest scan[/bold] {escape(url)}\n"
338
+ f"Backend: [cyan]{backend}[/cyan] · Bug finding: "
339
+ + ("[cyan]on (beta)[/cyan]" if find_bugs else "off"),
340
+ border_style="blue",
341
+ ))
342
+
343
+ # 1. Discover flows grounded in the site's content.
344
+ with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"),
345
+ console=console) as progress:
346
+ progress.add_task("Reading the site and finding flows to check...", total=None)
347
+ try:
348
+ flows = GoalGenerator(GoalGeneratorConfig(max_goals=max_flows)).generate(
349
+ url, preferred_backend=backend)
350
+ except GoalGenerationError as exc:
351
+ console.print(f"[red]Couldn't discover flows:[/red] {escape(str(exc))}")
352
+ sys.exit(2)
353
+ console.print(f"\n[bold]Flows to check ({len(flows)}):[/bold]")
354
+ for i, flow in enumerate(flows, 1):
355
+ console.print(f" {i}. {escape(flow.name)} [dim]— {escape(flow.text)}[/dim]")
356
+ console.print()
357
+
358
+ # 2. Run each flow from the start page. Every flow goes through the AI and
359
+ # is recorded, so the ones that work can be replayed when watched.
360
+ replay_cfg = cfg.get("replay") or {}
361
+ trace_dir = Path(replay_cfg.get("trace_dir") or DEFAULT_TRACE_DIR)
362
+ runner = FusionTestRunner(_build_adapter("playwright", None, url, headless), RunnerConfig(
363
+ backend=backend,
364
+ screenshot_on_failure=True,
365
+ trace_store=_trace_store(trace_dir, bool(replay_cfg.get("shared", True))),
366
+ reverify_every=0,
367
+ detect_bugs=find_bugs,
368
+ fresh_adapter=(lambda: _build_adapter("playwright", None, url, True)) if find_bugs else None,
369
+ ))
370
+ with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"),
371
+ console=console) as progress:
372
+ progress.add_task("Checking each flow" + (" and looking for bugs" if find_bugs else "") + "...",
373
+ total=None)
374
+ try:
375
+ result = runner.run(goals=[f.text for f in flows], name=f"Scan: {host}",
376
+ platform="playwright", url=url)
377
+ finally:
378
+ stop = getattr(runner.adapter, "stop", None)
379
+ if callable(stop):
380
+ try:
381
+ stop()
382
+ except Exception: # noqa: BLE001
383
+ pass
384
+
385
+ # 3. Coverage map, then bugs.
386
+ shot_dir = Path(cfg.get("screenshots", {}).get("dir", DEFAULT_SCREENSHOT_DIR))
387
+ bug_shots = _save_bug_screenshots(result, shot_dir)
388
+ working = _print_coverage(flows, result)
389
+ if find_bugs:
390
+ _print_bugs(result, bug_shots)
391
+ else:
392
+ console.print("\n[dim]Tip: add --find-bugs (beta) to also look for bugs while scanning.[/dim]")
393
+ if result.error:
394
+ console.print(f"\n[yellow]Scan stopped early:[/yellow] {escape(result.error)}")
395
+
396
+ if output:
397
+ _save_report(result, output)
398
+ console.print(f"\n[dim]Report saved to: {output}[/dim]")
399
+ uploaded_run_id = _upload_report(result)
400
+ if uploaded_run_id and bug_shots and cfg.get("screenshots", {}).get("upload", True):
401
+ _upload_screenshots(uploaded_run_id, bug_shots, kind="bug")
402
+
403
+ # 4. Offer to watch the flows that work.
404
+ if working:
405
+ _offer_to_watch(url, working, save_path)
406
+
407
+
408
+ def _print_coverage(flows, result) -> list:
409
+ """The coverage map: each flow and whether it works. Returns the flows that do."""
410
+ table = Table(title="Coverage", header_style="bold", box=None, pad_edge=False, title_justify="left")
411
+ table.add_column("#", style="dim", width=3)
412
+ table.add_column("Flow", min_width=24)
413
+ table.add_column("Result", width=16)
414
+ table.add_column("Steps", width=6)
415
+ working = []
416
+ for i, flow in enumerate(flows):
417
+ step = result.steps[i] if i < len(result.steps) else None
418
+ if step is None:
419
+ cell = "[dim]not checked[/dim]"
420
+ elif step.success:
421
+ cell = "[green]works[/green]"
422
+ working.append(flow)
423
+ elif step.infra_error:
424
+ cell = "[yellow]couldn't check[/yellow]"
425
+ else:
426
+ cell = "[red]didn't complete[/red]"
427
+ failed_why = step is not None and not step.success and step.error
428
+ note = f"\n [dim]{escape(step.error[:160])}[/dim]" if failed_why else ""
429
+ table.add_row(str(i + 1), escape(flow.name) + note, cell, str(step.steps_taken) if step else "—")
430
+ console.print(table)
431
+ console.print(f"\n[bold]{len(working)} of {len(flows)} flows work.[/bold] "
432
+ "[dim]A flow that didn't complete may be a bug in the site or a step FusionTest "
433
+ "couldn't work out; the reason is shown under it.[/dim]")
434
+ return working
435
+
436
+
437
+ def _print_bugs(result, bug_shots: dict[int, Path]) -> None:
438
+ console.print()
439
+ if not result.bugs_detected:
440
+ console.print("[green]No bugs confirmed.[/green] [dim](Bug finding is in beta.)[/dim]")
441
+ if result.unconfirmed_bugs:
442
+ console.print(f"[dim]{len(result.unconfirmed_bugs)} suspected bug(s) didn't happen again in a "
443
+ "fresh session, so they're not reported.[/dim]")
444
+ return
445
+ console.print(f"[bold red]Bugs found ({len(result.bugs_detected)})[/bold red] "
446
+ "[dim]— beta: each was confirmed in fresh sessions; precision is still being "
447
+ "measured on our benchmark[/dim]")
448
+ for i, bug in enumerate(result.bugs_detected):
449
+ console.print(f"\n {i + 1}. {escape(bug.title)}", soft_wrap=True)
450
+ if bug.expected or bug.actual:
451
+ console.print(f" [dim]Expected:[/dim] {escape(bug.expected or '—')}")
452
+ console.print(f" [dim]Actual:[/dim] {escape(bug.actual or '—')}")
453
+ if bug.steps:
454
+ console.print(f" [dim]Steps to reproduce ({len(bug.steps)}):[/dim]")
455
+ for n, step in enumerate(bug.steps, 1):
456
+ console.print(f" {n}. {escape(step)}", soft_wrap=True)
457
+ if i in bug_shots:
458
+ console.print(f" [dim]Screenshot: {escape(str(bug_shots[i]))}[/dim]", soft_wrap=True)
459
+
460
+
461
+ def _offer_to_watch(url: str, working: list, save_path: str | None) -> None:
462
+ """Save the flows that work as a goals file, to run on every deploy."""
463
+ path = Path(save_path) if save_path else None
464
+ if path is None:
465
+ if not sys.stdin.isatty():
466
+ console.print(f"\n[dim]Save these {len(working)} working flows with --save {DEFAULT_SCAN_GOALS} "
467
+ "to run them on every deploy.[/dim]")
468
+ return
469
+ if not click.confirm(f"\nWatch these {len(working)} working flows? Save them to {DEFAULT_SCAN_GOALS}",
470
+ default=True):
471
+ return
472
+ path = Path(DEFAULT_SCAN_GOALS)
473
+ if path.exists() and not click.confirm(f"{path} exists. Replace it?", default=False):
474
+ return
475
+ data = {"url": url, "goals": [{"name": f.name, "goal": f.text} for f in working]}
476
+ path.write_text("# Flows that worked when FusionTest scanned this site.\n"
477
+ "# Run them on every deploy: fusiontest run -f " + str(path) + "\n"
478
+ + yaml.safe_dump(data, sort_keys=False, allow_unicode=True))
479
+ console.print(f"\n[green]✓[/green] Saved {len(working)} flow(s) to [cyan]{escape(str(path))}[/cyan]. "
480
+ "Run them on every deploy; they replay from their recordings, without AI calls, "
481
+ "until the site changes:")
482
+ console.print(f" [bold]fusiontest run -f {escape(str(path))}[/bold]", soft_wrap=True)
483
+
484
+
261
485
  def _save_screenshots(result, root: Path) -> dict[int, Path]:
262
486
  """Write each failed goal's screenshot to <root>/<time>/<NN>-<goal>.png.
263
487
  Returns {goal index: path}."""
@@ -278,9 +502,28 @@ def _save_screenshots(result, root: Path) -> dict[int, Path]:
278
502
  return saved
279
503
 
280
504
 
281
- def _upload_screenshots(run_id: str, shots: dict[int, Path]) -> None:
282
- """Attach failure screenshots to the uploaded run (best effort). The org can
283
- turn storage off in the dashboard; screenshots are kept 30 days."""
505
+ def _save_bug_screenshots(result, root: Path) -> dict[int, Path]:
506
+ """Write each reported bug's screenshot (taken when it reproduced) to
507
+ <root>/<time>/bug-<NN>-<kind>.png. Returns {bug index: path}."""
508
+ from datetime import datetime, timezone
509
+
510
+ with_shots = [(i, b) for i, b in enumerate(result.bugs_detected) if b.screenshot]
511
+ if not with_shots:
512
+ return {}
513
+ run_dir = root / datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
514
+ run_dir.mkdir(parents=True, exist_ok=True)
515
+ saved: dict[int, Path] = {}
516
+ for i, bug in with_shots:
517
+ path = run_dir / f"bug-{i + 1:02d}-{bug.kind.replace('_', '-')}.png"
518
+ path.write_bytes(bug.screenshot)
519
+ saved[i] = path
520
+ return saved
521
+
522
+
523
+ def _upload_screenshots(run_id: str, shots: dict[int, Path], kind: str = "goal") -> None:
524
+ """Attach failure (kind="goal") or bug (kind="bug") screenshots to the
525
+ uploaded run (best effort). The org can turn storage off in the dashboard;
526
+ screenshots are kept 30 days."""
284
527
  import os
285
528
 
286
529
  import httpx
@@ -289,15 +532,17 @@ def _upload_screenshots(run_id: str, shots: dict[int, Path]) -> None:
289
532
  headers = {"Authorization": f"Bearer {os.getenv('FUSIONTEST_API_KEY', '')}", "Content-Type": "image/png"}
290
533
  stored = 0
291
534
  for index, path in shots.items():
535
+ url = (f"{api_url}/api/runs/{run_id}/bugs/{index}/screenshot" if kind == "bug"
536
+ else f"{api_url}/api/runs/{run_id}/screenshots/{index}")
292
537
  try:
293
- resp = httpx.post(f"{api_url}/api/runs/{run_id}/screenshots/{index}",
294
- content=path.read_bytes(), headers=headers, timeout=30)
538
+ resp = httpx.post(url, content=path.read_bytes(), headers=headers, timeout=30)
295
539
  resp.raise_for_status()
296
540
  stored += bool(resp.json().get("stored"))
297
541
  except Exception as e: # noqa: BLE001 — never fail a run over a screenshot
298
542
  console.print(f"[yellow]Warning:[/yellow] Could not upload screenshot {path.name}: {e}")
299
543
  if stored:
300
- console.print(f"[dim]{stored} failure screenshot(s) attached to the run (kept 30 days).[/dim]")
544
+ what = "bug" if kind == "bug" else "failure"
545
+ console.print(f"[dim]{stored} {what} screenshot(s) attached to the run (kept 30 days).[/dim]")
301
546
 
302
547
 
303
548
  def _load_env() -> None:
@@ -1038,7 +1283,8 @@ def _providers(result, fallback: str) -> str:
1038
1283
  return first + (f" (and {', '.join(names[1:])})" if len(names) > 1 else "")
1039
1284
 
1040
1285
 
1041
- def _print_results(result, screenshots: dict[int, Path] | None = None) -> None:
1286
+ def _print_results(result, screenshots: dict[int, Path] | None = None,
1287
+ bug_screenshots: dict[int, Path] | None = None) -> None:
1042
1288
  if result.success:
1043
1289
  status = "[green]PASS ✓[/green]"
1044
1290
  elif _exit_code(result) == 2:
@@ -1085,6 +1331,13 @@ def _print_results(result, screenshots: dict[int, Path] | None = None) -> None:
1085
1331
  # One line per path, never wrapped, so it can be copied or clicked.
1086
1332
  console.print(f" {index + 1}. {escape(str(path))}", soft_wrap=True)
1087
1333
 
1334
+ if result.bugs_detected:
1335
+ console.print(f"\n[bold red]Bugs found ({len(result.bugs_detected)})[/bold red]")
1336
+ for index, bug in enumerate(result.bugs_detected):
1337
+ console.print(f" {index + 1}. {escape(bug.title)}", soft_wrap=True)
1338
+ if bug_screenshots and index in bug_screenshots:
1339
+ console.print(f" [dim]screenshot: {escape(str(bug_screenshots[index]))}[/dim]", soft_wrap=True)
1340
+
1088
1341
  if result.error:
1089
1342
  console.print(f"\n[yellow]Run stopped early:[/yellow] {escape(result.error)}")
1090
1343
 
@@ -1113,6 +1366,7 @@ def _save_report(result, path: str) -> None:
1113
1366
  "stability_score": result.stability_score,
1114
1367
  "total_duration_seconds": result.total_duration_seconds,
1115
1368
  "steps": [s.to_dict() for s in result.steps],
1369
+ "bugs_detected": [b.to_dict() for b in result.bugs_detected],
1116
1370
  }
1117
1371
  with open(path, "w") as f:
1118
1372
  json.dump(data, f, indent=2)
@@ -28,9 +28,14 @@ class Bug:
28
28
  evidence: list[str] = field(default_factory=list) # screen text, quoted
29
29
  steps: list[str] = field(default_factory=list) # to reproduce, from the start
30
30
  reproduced: int = 0 # fresh sessions it happened again in (0: not checked)
31
+ # PNG of the screen when it happened again in a fresh session (not in to_dict:
32
+ # uploaded separately).
33
+ screenshot: bytes | None = field(default=None, repr=False, compare=False)
31
34
 
32
35
  def to_dict(self) -> dict:
33
- return asdict(self)
36
+ data = asdict(self)
37
+ data.pop("screenshot")
38
+ return data
34
39
 
35
40
  def __str__(self) -> str:
36
41
  return self.title
@@ -789,6 +789,7 @@ class FusionTestRunner:
789
789
  return Reproduction(confirmed=list(candidates), unconfirmed=[])
790
790
  still = list(range(len(candidates)))
791
791
  sessions = 0
792
+ shots: dict[int, bytes] = {} # id(candidate) -> screen when it happened again
792
793
  for attempt in range(1, self.config.reproduce_times + 1):
793
794
  if not still:
794
795
  break
@@ -802,7 +803,7 @@ class FusionTestRunner:
802
803
  break
803
804
  sessions += 1
804
805
  try:
805
- seen = self._replay_log(adapter, [candidates[i] for i in still], resolver)
806
+ seen = self._replay_log(adapter, [candidates[i] for i in still], resolver, shots)
806
807
  finally:
807
808
  stop = getattr(adapter, "stop", None)
808
809
  if callable(stop):
@@ -812,14 +813,17 @@ class FusionTestRunner:
812
813
  pass
813
814
  still = [i for i in still if id(candidates[i]) in seen]
814
815
  confirmed = [candidates[i] for i in still]
816
+ for c in confirmed:
817
+ c.bug.screenshot = shots.get(id(c))
815
818
  unconfirmed = [c for c in candidates if c not in confirmed]
816
819
  for c in unconfirmed:
817
820
  logger.info(" Not reproduced, not reported: %s", c.report)
818
821
  return Reproduction(confirmed=confirmed, unconfirmed=unconfirmed, sessions=sessions)
819
822
 
820
823
  def _replay_log(self, adapter: object, candidates: list[BugCandidate],
821
- resolver: SecretResolver) -> set[int]:
822
- """Replay the action log on adapter; ids of the candidates that showed up again."""
824
+ resolver: SecretResolver, shots: dict[int, bytes] | None = None) -> set[int]:
825
+ """Replay the action log on adapter; ids of the candidates that showed up again.
826
+ shots: filled with a screenshot of each one at that moment."""
823
827
  seen: set[int] = set()
824
828
  errors: set[tuple[str, str]] = set()
825
829
  last = max(c.at for c in candidates)
@@ -850,6 +854,15 @@ class FusionTestRunner:
850
854
  seen.add(id(c))
851
855
  elif c.evidence and evidence_present(c.evidence, before + "\n" + after):
852
856
  seen.add(id(c))
857
+ if shots is not None and any(id(c) in seen for c in due):
858
+ try:
859
+ shot = adapter.get_screenshot()
860
+ except Exception: # noqa: BLE001 — a screenshot is a nice-to-have
861
+ shot = None
862
+ if shot:
863
+ for c in due:
864
+ if id(c) in seen:
865
+ shots[id(c)] = shot
853
866
 
854
867
  try:
855
868
  check(0, "")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.26
3
+ Version: 0.2.28
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
@@ -143,6 +143,9 @@ export GROQ_API_KEY=gsk_... # or ANTHROPIC_API_KEY / GEMINI_API_KEY / O
143
143
 
144
144
  fusiontest run --url https://example.com \
145
145
  --goal "Verify the page heading says Example Domain" --headless
146
+
147
+ # No goals yet? Map what works on a test/staging site, and save the flows that do
148
+ fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
146
149
  ```
147
150
 
148
151
  Groq, OpenAI and Ollama work out of the box; for Claude or Gemini add the
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fusiontest"
7
- version = "0.2.26"
7
+ version = "0.2.28"
8
8
  description = "AI-powered UI testing for mobile and desktop — by FusionLeap.io"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes