fusiontest 0.2.23__tar.gz → 0.2.25__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 (57) hide show
  1. {fusiontest-0.2.23 → fusiontest-0.2.25}/PKG-INFO +1 -1
  2. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/__init__.py +16 -0
  3. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/suites/shop-bugs.yaml +6 -4
  4. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/cli.py +8 -5
  5. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/promise_checker.py +4 -1
  6. fusiontest-0.2.25/fusiontest/core/reproduce.py +44 -0
  7. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/runner.py +138 -17
  8. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/PKG-INFO +1 -1
  9. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/SOURCES.txt +1 -0
  10. {fusiontest-0.2.23 → fusiontest-0.2.25}/pyproject.toml +1 -1
  11. {fusiontest-0.2.23 → fusiontest-0.2.25}/README.md +0 -0
  12. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/__init__.py +0 -0
  13. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/sites/shop/bugs.js +0 -0
  14. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/sites/shop/help.html +0 -0
  15. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/sites/shop/index.html +0 -0
  16. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/suites/shop.yaml +0 -0
  17. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/bench/suites/todomvc.yaml +0 -0
  18. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/__init__.py +0 -0
  19. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/action_model.py +0 -0
  20. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/app_errors.py +0 -0
  21. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/goal_verifier.py +0 -0
  22. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/netguard.py +0 -0
  23. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/replay.py +0 -0
  24. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/screen_parser.py +0 -0
  25. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/secrets.py +0 -0
  26. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/shared_traces.py +0 -0
  27. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/core/tokens.py +0 -0
  28. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/__init__.py +0 -0
  29. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
  30. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/github.yaml +0 -0
  31. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/hacker_news.yaml +0 -0
  32. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/httpbin.yaml +0 -0
  33. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/todomvc.yaml +0 -0
  34. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/demos/wikipedia.yaml +0 -0
  35. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/desktop/__init__.py +0 -0
  36. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/desktop/macos_adapter.py +0 -0
  37. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/desktop/playwright_adapter.py +0 -0
  38. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/desktop/windows_adapter.py +0 -0
  39. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/discovery/__init__.py +0 -0
  40. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/discovery/goal_generator.py +0 -0
  41. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/guardrails/__init__.py +0 -0
  42. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/guardrails/engine.py +0 -0
  43. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/mobile/__init__.py +0 -0
  44. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/mobile/android_adapter.py +0 -0
  45. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/mobile/ios_adapter.py +0 -0
  46. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/reporting/__init__.py +0 -0
  47. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/reporting/reporter.py +0 -0
  48. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/training/__init__.py +0 -0
  49. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/training/data_collector.py +0 -0
  50. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/training/dataset_builder.py +0 -0
  51. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest/training/trainer.py +0 -0
  52. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/dependency_links.txt +0 -0
  53. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/entry_points.txt +0 -0
  54. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/not-zip-safe +0 -0
  55. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/requires.txt +0 -0
  56. {fusiontest-0.2.23 → fusiontest-0.2.25}/fusiontest.egg-info/top_level.txt +0 -0
  57. {fusiontest-0.2.23 → fusiontest-0.2.25}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.23
3
+ Version: 0.2.25
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
@@ -154,6 +154,8 @@ def _load_bug_suite(data: dict, source: str) -> BugSuite:
154
154
  match = [str(k).lower() for k in (raw or {}).get("match") or []]
155
155
  if kind not in BUG_KINDS or not match:
156
156
  raise bad(f"bug {bug_id!r} needs a kind ({' | '.join(BUG_KINDS)}) and match keywords")
157
+ if _nested_keywords(match):
158
+ raise bad(f"bug {bug_id!r}: a keyword contains another {_nested_keywords(match)}")
157
159
  bugs[str(bug_id)] = PlantedBug(id=str(bug_id), kind=kind,
158
160
  description=str(raw.get("description", "")), match=match)
159
161
  variants = []
@@ -178,6 +180,8 @@ def _load_bug_suite(data: dict, source: str) -> BugSuite:
178
180
  match = [str(k).lower() for k in (raw or {}).get("match") or []]
179
181
  if not match:
180
182
  raise bad(f"decoy {decoy_id!r} needs match keywords")
183
+ if _nested_keywords(match):
184
+ raise bad(f"decoy {decoy_id!r}: a keyword contains another {_nested_keywords(match)}")
181
185
  shared = bug_keywords & set(match)
182
186
  if shared:
183
187
  raise bad(f"decoy {decoy_id!r} shares match keywords with a bug: {sorted(shared)}")
@@ -187,6 +191,12 @@ def _load_bug_suite(data: dict, source: str) -> BugSuite:
187
191
  platform=str(data.get("platform", "playwright")), site=str(data["site"]))
188
192
 
189
193
 
194
+ def _nested_keywords(match: list[str]) -> list[tuple[str, str]]:
195
+ """Pairs (inner, outer) where one keyword contains another: a single mention
196
+ of the outer one would count as two hits."""
197
+ return [(a, b) for a in match for b in match if a != b and a in b]
198
+
199
+
190
200
  def _shared_keywords(bugs: list[PlantedBug]) -> set[str]:
191
201
  seen: set[str] = set()
192
202
  shared: set[str] = set()
@@ -407,6 +417,7 @@ class VariantResult:
407
417
  reports: list[str] = field(default_factory=list) # bugs FusionTest reported
408
418
  matches: list[str | None] = field(default_factory=list) # planted id per report, or None
409
419
  decoy_trips: list[str] = field(default_factory=list) # decoys that false reports were about
420
+ unconfirmed: list[str] = field(default_factory=list) # suspected, not reproduced: not reported
410
421
  tasks_passed: int = 0
411
422
  tasks: int = 0
412
423
  failed_tasks: list[str] = field(default_factory=list) # "task — why", for diagnosis
@@ -433,6 +444,7 @@ def score_variant(suite: BugSuite, variant: Variant, run: RunResult) -> VariantR
433
444
  outcome="run" if evaluated else "error",
434
445
  reports=reports, matches=[bug for bug, _ in classified],
435
446
  decoy_trips=[decoy for _, decoy in classified if decoy],
447
+ unconfirmed=[str(r) for r in getattr(run, "unconfirmed_bugs", [])],
436
448
  tasks_passed=sum(s.success for s in run.steps), tasks=len(suite.tasks),
437
449
  failed_tasks=[f"{s.goal} — {s.error}" for s in run.steps if not s.success],
438
450
  seconds=round(sum(s.duration_seconds for s in run.steps), 2),
@@ -477,6 +489,7 @@ class BugSummary:
477
489
  false_reports: int
478
490
  false_on_clean: int # reports on variants with nothing planted
479
491
  decoy_trips: int = 0 # false reports about decoys
492
+ unconfirmed: int = 0 # suspected bugs dropped because they didn't reproduce
480
493
 
481
494
  @property
482
495
  def precision(self) -> float | None:
@@ -504,6 +517,7 @@ def summarize_bugs(runs: list[BugSuiteRun]) -> BugSummary:
504
517
  reports=reports, true_reports=reports - false_reports, false_reports=false_reports,
505
518
  false_on_clean=sum(len(v.reports) for v in evaluated if not v.planted),
506
519
  decoy_trips=sum(len(v.decoy_trips) for v in evaluated),
520
+ unconfirmed=sum(len(v.unconfirmed) for v in evaluated),
507
521
  )
508
522
 
509
523
 
@@ -668,6 +682,8 @@ def _session(site: str, url: str, platform: str, goals: list[str], name: str, ba
668
682
  runner = runner_factory(adapter, RunnerConfig(
669
683
  backend=backend, trace_store=None, screenshot_on_failure=False,
670
684
  detect_bugs=detect_bugs,
685
+ # Suspected bugs must happen again in fresh sessions (ADR-009 §2).
686
+ fresh_adapter=(lambda: adapter_factory(platform, start_url)) if detect_bugs else None,
671
687
  ))
672
688
  start = time.time()
673
689
  # No url= here: the runner would reload it before every goal, and
@@ -11,7 +11,9 @@
11
11
  #
12
12
  # A report matches the planted bug whose `match` keywords it mentions most
13
13
  # (case-insensitive); none mentioned means no match. Keep keywords specific to
14
- # the defect, and keep the bugs in one variant from sharing keywords.
14
+ # the defect, and keep the bugs in one variant from sharing keywords. No
15
+ # keyword may contain another in the same list ("fee" in "service fee"): one
16
+ # mention would count twice.
15
17
  #
16
18
  # Decoys are always on, in every variant: shop behaviour that looks like a bug
17
19
  # but is correct and explained on screen. A report that mentions a decoy's
@@ -19,7 +21,7 @@
19
21
  # as a decoy trip, so we can see which decoys fool the bug finder.
20
22
  name: shop-bugs
21
23
  kind: bugs
22
- version: 2 # v2: decoys and the tasks that reach them
24
+ version: 3 # v3: match keywords fixed (no keyword inside another); v2: decoys
23
25
  description: Bug finding on Acme Shop variants with planted defects (ADR-009)
24
26
  platform: playwright
25
27
  site: shop
@@ -45,7 +47,7 @@ bugs:
45
47
  total-wrong:
46
48
  kind: inconsistency
47
49
  description: "The cart total leaves out the last line item"
48
- match: [total, sum, subtotal]
50
+ match: [subtotal, "10% of", does not equal, doesn't equal, add up]
49
51
  remove-noop:
50
52
  kind: broken_promise
51
53
  description: "Remove in the cart does nothing"
@@ -75,7 +77,7 @@ decoys:
75
77
  match: [freeship, free shipping, free express]
76
78
  service-fee:
77
79
  description: "The order total is $1.50 more than the cart total: 'A $1.50 service fee is added at checkout'"
78
- match: [service fee, fee, "$1.50"]
80
+ match: [service fee, "$1.50"]
79
81
 
80
82
  # Bugs in one variant don't interfere with each other's tasks. `clean` has no
81
83
  # bugs: anything reported there is a false bug.
@@ -787,6 +787,8 @@ def _print_variants(run) -> None:
787
787
  detail += f" · missed {', '.join(missed)}"
788
788
  if v.decoy_trips:
789
789
  detail += f" · fooled by {', '.join(v.decoy_trips)}"
790
+ if v.unconfirmed:
791
+ detail += f" · {len(v.unconfirmed)} not reproduced"
790
792
  console.print(f" {mark} {v.variant:<10} {detail} "
791
793
  f"[dim](tasks passed {v.tasks_passed}/{v.tasks})[/dim]")
792
794
 
@@ -798,13 +800,13 @@ def _pct(x: float | None) -> str:
798
800
  def _bug_table(bug_summaries, bug_runs) -> Table:
799
801
  table = Table(title="Bug finding", header_style="bold", box=None, pad_edge=False)
800
802
  for col in ("Suite", "Backend", "Precision", "Recall", "False on clean", "Decoy trips", "Reports",
801
- "Errors", "Cost"):
803
+ "Not reproduced", "Errors", "Cost"):
802
804
  table.add_column(col, justify="left" if col in ("Suite", "Backend") else "right")
803
805
  for sm in bug_summaries:
804
806
  table.add_row(
805
807
  sm.suite, sm.backend, f"{_pct(sm.precision)} ({sm.true_reports}/{sm.reports})",
806
808
  f"{_pct(sm.recall)} ({sm.found}/{sm.planted})", str(sm.false_on_clean),
807
- str(sm.decoy_trips), str(sm.reports), str(sm.errors),
809
+ str(sm.decoy_trips), str(sm.reports), str(sm.unconfirmed), str(sm.errors),
808
810
  _cost_cell(bug_runs, sm.suite, sm.backend))
809
811
  return table
810
812
 
@@ -815,11 +817,12 @@ def _bench_markdown(summaries, runs, spend_line: str, bug_summaries=(), bug_runs
815
817
  lines += _goal_markdown(summaries, runs)
816
818
  if bug_summaries:
817
819
  lines += ["### Bug finding", "",
818
- "| Suite | Backend | Precision | Recall | False on clean | Decoy trips | Reports | Errors | Cost |",
819
- "|---|---|---|---|---|---|---|---|---|"]
820
+ "| Suite | Backend | Precision | Recall | False on clean | Decoy trips | Reports | Not reproduced "
821
+ "| Errors | Cost |",
822
+ "|---|---|---|---|---|---|---|---|---|---|"]
820
823
  lines += [f"| {sm.suite} | {sm.backend} | {_pct(sm.precision)} ({sm.true_reports}/{sm.reports}) | "
821
824
  f"{_pct(sm.recall)} ({sm.found}/{sm.planted}) | {sm.false_on_clean} | {sm.decoy_trips} | "
822
- f"{sm.reports} | "
825
+ f"{sm.reports} | {sm.unconfirmed} | "
823
826
  f"{sm.errors} | {_cost_cell(bug_runs, sm.suite, sm.backend)} |" for sm in bug_summaries]
824
827
  lines.append("")
825
828
  return "\n".join(lines + [spend_line, ""])
@@ -48,6 +48,7 @@ class Transition:
48
48
  action: str # as stored for the run: secrets masked
49
49
  before: str
50
50
  after: str
51
+ at: int = 0 # position of the action in the run's action log (1-based)
51
52
 
52
53
 
53
54
  @dataclass
@@ -59,6 +60,7 @@ class Finding:
59
60
  page: str
60
61
  evidence: list[str] = field(default_factory=list)
61
62
  confirmation: str = ""
63
+ at: int = 0 # the transition's position in the run's action log
62
64
 
63
65
  def report(self) -> str:
64
66
  label = "Broken promise" if self.kind == "broken_promise" else "Inconsistent screen"
@@ -193,7 +195,8 @@ class PromiseChecker:
193
195
  logger.info("Promise check: dropped finding, evidence not on screen: %s", summary)
194
196
  continue
195
197
  findings.append(Finding(kind=kind, summary=summary, step=step, action=transition.action,
196
- page=_page(transition.before), evidence=evidence))
198
+ page=_page(transition.before), evidence=evidence,
199
+ at=transition.at))
197
200
  return findings
198
201
 
199
202
  # ── Confirmation ──────────────────────────────────────────────────────────
@@ -0,0 +1,44 @@
1
+ """
2
+ fusiontest.core.reproduce — a bug is only real if it happens again (ADR-009 §2).
3
+
4
+ During a run the runner keeps an ActionLog: every navigation and executed
5
+ action, in order, across all goals (including actions with no visible effect,
6
+ which are exactly what "Remove does nothing" bugs are made of). Each suspected
7
+ bug becomes a BugCandidate that knows how far into the log it appeared and
8
+ what to look for:
9
+
10
+ app errors the same failure (signature) seen again by that point
11
+ findings the quoted evidence on screen again, around that action
12
+
13
+ After the run, the log is replayed in fresh app sessions — no LLM calls — and
14
+ only candidates that reproduce in every session are reported.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from dataclasses import dataclass, field
20
+
21
+ from fusiontest.core.replay import RecordedAction
22
+
23
+
24
+ @dataclass
25
+ class LogEntry:
26
+ kind: str # navigate | action
27
+ url: str = ""
28
+ action: RecordedAction | None = None
29
+
30
+
31
+ @dataclass
32
+ class BugCandidate:
33
+ report: str
34
+ signature: tuple[str, str]
35
+ at: int # log entries replayed before checking
36
+ app_error: tuple[str, str] | None = None # signature to see again
37
+ evidence: list[str] = field(default_factory=list) # quotes to see again
38
+
39
+
40
+ @dataclass
41
+ class Reproduction:
42
+ confirmed: list[BugCandidate]
43
+ unconfirmed: list[BugCandidate]
44
+ sessions: int = 0
@@ -34,6 +34,7 @@ from fusiontest.core.replay import (
34
34
  trace_key,
35
35
  url_path,
36
36
  )
37
+ from fusiontest.core.reproduce import BugCandidate, LogEntry, Reproduction
37
38
  from fusiontest.core.screen_parser import UIElement
38
39
  from fusiontest.core.secrets import SecretResolver, host_matches, resolve_goals
39
40
  from fusiontest.core.tokens import TokenUsage
@@ -113,6 +114,8 @@ class RunResult:
113
114
  steps: list[StepResult] = field(default_factory=list)
114
115
  total_duration_seconds: float = 0.0
115
116
  bugs_detected: list[str] = field(default_factory=list)
117
+ # Suspected bugs that didn't happen again in fresh sessions (not reported).
118
+ unconfirmed_bugs: list[str] = field(default_factory=list)
116
119
  cancelled: bool = False
117
120
  # Set when the run stopped early because it could not be evaluated
118
121
  # (e.g. no LLM backend available). Remaining goals were not run.
@@ -200,6 +203,12 @@ class RunnerConfig:
200
203
  # RunResult.bugs_detected (ADR-009). Off until bug reports meet the
201
204
  # benchmark's precision gate; `fusiontest bench` turns it on.
202
205
  detect_bugs: bool = False
206
+ # Reproduce suspected bugs before reporting them (ADR-009 §2): a callable
207
+ # returning a new, started adapter on the app's start page. The run's
208
+ # actions are replayed in that many fresh sessions (no LLM calls); only
209
+ # bugs seen again every time are reported. None: report without reproducing.
210
+ fresh_adapter: Callable[[], object] | None = None
211
+ reproduce_times: int = 2
203
212
 
204
213
 
205
214
  # ── Runner ─────────────────────────────────────────────────────────────────────
@@ -233,6 +242,8 @@ class FusionTestRunner:
233
242
  # Trace fields of the last goal the LLM verified (see _make_recording).
234
243
  self._last_recording: dict | None = None
235
244
  self._promise_checker: PromiseChecker | None = None
245
+ # Every navigation and executed action of the run, for reproduction.
246
+ self._log: list[LogEntry] = []
236
247
  self._step_log = None
237
248
  if self.config.step_log_path:
238
249
  import pathlib # noqa: PLC0415
@@ -288,7 +299,9 @@ class FusionTestRunner:
288
299
  )
289
300
 
290
301
  model_goals = [_with_placeholder_hint(g) if resolver.has_templates(g) else g for g in goals]
291
- reported: set[tuple[str, str]] = set() # app-error signatures already in bugs_detected
302
+ reported: set[tuple[str, str]] = set() # bug signatures already suspected
303
+ candidates: list[BugCandidate] = []
304
+ self._log = []
292
305
 
293
306
  for i, (goal, safe_goal) in enumerate(zip(model_goals, goals, strict=True), 1):
294
307
  # Cooperative cancellation check — run before starting the next goal
@@ -357,7 +370,7 @@ class FusionTestRunner:
357
370
  if watchdog is not None:
358
371
  watchdog.cancel()
359
372
 
360
- self._collect_bugs(step_result, result, reported, resolver)
373
+ self._collect_bugs(step_result, candidates, reported, resolver)
361
374
 
362
375
  # A timed-out goal couldn't be evaluated: record it as an error
363
376
  # (not a test failure), and stop the run — the browser is closed.
@@ -409,6 +422,11 @@ class FusionTestRunner:
409
422
  )
410
423
  break
411
424
 
425
+ if self.config.detect_bugs and candidates:
426
+ outcome = self._reproduce(candidates, resolver)
427
+ result.bugs_detected = [c.report for c in outcome.confirmed]
428
+ result.unconfirmed_bugs = [c.report for c in outcome.unconfirmed]
429
+
412
430
  result.total_duration_seconds = time.time() - run_start
413
431
  result.llm_calls = self._llm_calls()
414
432
  logger.info(
@@ -459,7 +477,7 @@ class FusionTestRunner:
459
477
  # Each executed action with the screens before and after it, for the
460
478
  # broken-promise check (ADR-009). pending: an action awaiting its "after".
461
479
  transitions: list[Transition] = []
462
- pending: tuple[str, str] | None = None
480
+ pending: tuple[str, str, int] | None = None
463
481
 
464
482
  for step_num in range(1, self.config.max_steps_per_goal + 1):
465
483
  step.steps_taken = step_num
@@ -480,7 +498,8 @@ class FusionTestRunner:
480
498
  screen_text = _redact(screen_text)
481
499
  _drop_if_no_effect(screen_text)
482
500
  if pending is not None:
483
- transitions.append(Transition(action=pending[0], before=pending[1], after=screen_text))
501
+ transitions.append(Transition(action=pending[0], before=pending[1], after=screen_text,
502
+ at=pending[2]))
484
503
  pending = None
485
504
 
486
505
  # No progress: tell the model its last action did nothing, and stop
@@ -607,6 +626,7 @@ class FusionTestRunner:
607
626
  logger.info(f" Backtracking (step {step_num})")
608
627
  self._backtrack(history)
609
628
  recorded.append(RecordedAction(action_type="back"))
629
+ self._log.append(LogEntry(kind="action", action=recorded[-1]))
610
630
  break
611
631
 
612
632
  if gr.should_skip:
@@ -631,7 +651,8 @@ class FusionTestRunner:
631
651
  history.append(action_str) # LLM context — real value ok
632
652
  safe_action_str = _redact(action_str)
633
653
  step.actions.append(safe_action_str) # stored — secrets masked
634
- pending = (_redact(_action_text(gr.action, elements)), screen_text)
654
+ self._log.append(LogEntry(kind="action", action=recorded[-1]))
655
+ pending = (_redact(_action_text(gr.action, elements)), screen_text, len(self._log))
635
656
  self.guardrails.record_action(gr.action)
636
657
  # Only record screen hash for actions that change the page.
637
658
  # Scroll doesn't change DOM extraction (all elements captured
@@ -666,7 +687,7 @@ class FusionTestRunner:
666
687
  final_screen_text = screen_text # fall back to last known screen
667
688
  if pending is not None:
668
689
  transitions.append(Transition(action=pending[0], before=pending[1],
669
- after=final_screen_text))
690
+ after=final_screen_text, at=pending[2]))
670
691
 
671
692
  self._last_chance_verify(
672
693
  step, goal, final_screen_text, history, recorded,
@@ -719,28 +740,126 @@ class FusionTestRunner:
719
740
  store.save(GoalTrace(key=key, goal=safe_goal, start_url=goal_url, **self._last_recording))
720
741
  return step
721
742
 
722
- def _collect_bugs(self, step: StepResult, result: RunResult,
743
+ def _collect_bugs(self, step: StepResult, candidates: list[BugCandidate],
723
744
  reported: set[tuple[str, str]], resolver: SecretResolver) -> None:
724
745
  """The goal's app errors onto the step, and (with detect_bugs) each new
725
- app error or confirmed finding into result.bugs_detected, once."""
746
+ app error or confirmed finding as a bug candidate, once."""
726
747
  drain = getattr(self.adapter, "drain_app_errors", None)
727
748
  if callable(drain):
728
749
  try:
729
750
  step.app_errors = list(drain())
730
751
  except Exception as exc: # noqa: BLE001 — observation must never fail a run
731
752
  logger.debug("Could not read app errors: %s", exc)
732
- candidates = [(e.signature, e.report()) for e in step.app_errors]
753
+ found = [BugCandidate(report=resolver.redact(e.report()), signature=e.signature,
754
+ at=len(self._log), app_error=e.signature) for e in step.app_errors]
733
755
  # A finding about an action that already raised an app error (a dead
734
756
  # link that "didn't open the Help page") is the same bug said twice.
735
757
  errored_actions = {e.after for e in step.app_errors}
736
- candidates += [((f.kind, f.summary.lower()), f.report()) for f in step.findings
737
- if f.action not in errored_actions]
738
- for signature, report in candidates:
739
- text = resolver.redact(report) # page text can echo a typed secret
740
- logger.info(" Bug: %s", text)
741
- if self.config.detect_bugs and signature not in reported:
742
- reported.add(signature)
743
- result.bugs_detected.append(text)
758
+ found += [BugCandidate(report=resolver.redact(f.report()), signature=(f.kind, f.summary.lower()),
759
+ at=f.at, evidence=list(f.evidence))
760
+ for f in step.findings if f.action not in errored_actions]
761
+ for candidate in found:
762
+ logger.info(" Suspected bug: %s", candidate.report)
763
+ if self.config.detect_bugs and candidate.signature not in reported:
764
+ reported.add(candidate.signature)
765
+ candidates.append(candidate)
766
+
767
+ def _reproduce(self, candidates: list[BugCandidate], resolver: SecretResolver) -> Reproduction:
768
+ """Replay the run in fresh sessions; keep the candidates seen every time."""
769
+ factory = self.config.fresh_adapter
770
+ if factory is None or self.config.reproduce_times < 1:
771
+ return Reproduction(confirmed=list(candidates), unconfirmed=[])
772
+ still = list(range(len(candidates)))
773
+ sessions = 0
774
+ for attempt in range(1, self.config.reproduce_times + 1):
775
+ if not still:
776
+ break
777
+ logger.info("Reproducing %d suspected bug(s), fresh session %d/%d",
778
+ len(still), attempt, self.config.reproduce_times)
779
+ try:
780
+ adapter = factory()
781
+ except Exception as exc: # noqa: BLE001 — can't reproduce: nothing is confirmed
782
+ logger.warning("Could not open a fresh session to reproduce bugs: %s", exc)
783
+ still = []
784
+ break
785
+ sessions += 1
786
+ try:
787
+ seen = self._replay_log(adapter, [candidates[i] for i in still], resolver)
788
+ finally:
789
+ stop = getattr(adapter, "stop", None)
790
+ if callable(stop):
791
+ try:
792
+ stop()
793
+ except Exception: # noqa: BLE001
794
+ pass
795
+ still = [i for i in still if id(candidates[i]) in seen]
796
+ confirmed = [candidates[i] for i in still]
797
+ unconfirmed = [c for c in candidates if c not in confirmed]
798
+ for c in unconfirmed:
799
+ logger.info(" Not reproduced, not reported: %s", c.report)
800
+ return Reproduction(confirmed=confirmed, unconfirmed=unconfirmed, sessions=sessions)
801
+
802
+ def _replay_log(self, adapter: object, candidates: list[BugCandidate],
803
+ resolver: SecretResolver) -> set[int]:
804
+ """Replay the action log on adapter; ids of the candidates that showed up again."""
805
+ seen: set[int] = set()
806
+ errors: set[tuple[str, str]] = set()
807
+ last = max(c.at for c in candidates)
808
+ original, self.adapter = self.adapter, adapter # _bind_secrets reads the current host
809
+
810
+ def drain() -> None:
811
+ take = getattr(adapter, "drain_app_errors", None)
812
+ if callable(take):
813
+ try:
814
+ errors.update(e.signature for e in take())
815
+ except Exception: # noqa: BLE001
816
+ pass
817
+
818
+ def check(at: int, before: str) -> None:
819
+ due = [c for c in candidates if c.at == at]
820
+ if not due:
821
+ return
822
+ drain()
823
+ after = ""
824
+ if any(c.evidence for c in due):
825
+ time.sleep(0.8)
826
+ try:
827
+ after = resolver.redact(adapter.get_screen()[1])
828
+ except Exception: # noqa: BLE001
829
+ after = ""
830
+ for c in due:
831
+ if c.app_error is not None and c.app_error in errors:
832
+ seen.add(id(c))
833
+ elif c.evidence and evidence_present(c.evidence, before + "\n" + after):
834
+ seen.add(id(c))
835
+
836
+ try:
837
+ check(0, "")
838
+ for at, entry in enumerate(self._log[:last], 1):
839
+ before = ""
840
+ if entry.kind == "navigate":
841
+ if hasattr(adapter, "navigate"):
842
+ adapter.navigate(entry.url)
843
+ elif entry.action is not None:
844
+ time.sleep(0.8) # let the page settle, as the LLM loop does
845
+ elements, before = adapter.get_screen()
846
+ before = resolver.redact(before)
847
+ action = resolve_action(entry.action, elements)
848
+ if action is None:
849
+ logger.info(" Reproduction stopped: %s %r is gone",
850
+ entry.action.element_type, entry.action.element_label)
851
+ break
852
+ exec_action, blocked = self._bind_secrets(action, resolver)
853
+ if blocked or not adapter.execute(exec_action, elements):
854
+ logger.info(" Reproduction stopped: %s failed", entry.action.action_type)
855
+ break
856
+ drain()
857
+ check(at, before)
858
+ except Exception as exc: # noqa: BLE001 — whatever reproduced so far still counts
859
+ logger.info(" Reproduction stopped: %s", exc)
860
+ finally:
861
+ self.adapter = original
862
+ return seen
744
863
 
745
864
  def _checker(self) -> PromiseChecker | None:
746
865
  """The broken-promise checker, created on first use (no chat model: none)."""
@@ -782,6 +901,7 @@ class FusionTestRunner:
782
901
  if blocked or not self.adapter.execute(exec_action, elements):
783
902
  logger.info(f" Replay: action failed — {action}")
784
903
  return None
904
+ self._log.append(LogEntry(kind="action", action=recorded))
785
905
  actions.append(resolver.redact(str(action)))
786
906
  if trace.actions:
787
907
  time.sleep(0.8)
@@ -823,6 +943,7 @@ class FusionTestRunner:
823
943
  def _navigate(self, url: str) -> None:
824
944
  """Open the goal's starting URL (if given and the adapter supports it)."""
825
945
  if url and hasattr(self.adapter, "navigate"):
946
+ self._log.append(LogEntry(kind="navigate", url=url))
826
947
  try:
827
948
  self.adapter.navigate(url)
828
949
  logger.info(f" Navigated to: {url}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.23
3
+ Version: 0.2.25
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
@@ -23,6 +23,7 @@ fusiontest/core/goal_verifier.py
23
23
  fusiontest/core/netguard.py
24
24
  fusiontest/core/promise_checker.py
25
25
  fusiontest/core/replay.py
26
+ fusiontest/core/reproduce.py
26
27
  fusiontest/core/runner.py
27
28
  fusiontest/core/screen_parser.py
28
29
  fusiontest/core/secrets.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fusiontest"
7
- version = "0.2.23"
7
+ version = "0.2.25"
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
File without changes