fusiontest 0.2.24__tar.gz → 0.2.26__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.24 → fusiontest-0.2.26}/PKG-INFO +1 -1
  2. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/__init__.py +7 -1
  3. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/cli.py +9 -5
  4. fusiontest-0.2.26/fusiontest/core/bugs.py +63 -0
  5. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/promise_checker.py +11 -3
  6. fusiontest-0.2.26/fusiontest/core/reproduce.py +50 -0
  7. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/runner.py +158 -18
  8. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/reporting/reporter.py +1 -1
  9. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/PKG-INFO +1 -1
  10. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/SOURCES.txt +2 -0
  11. {fusiontest-0.2.24 → fusiontest-0.2.26}/pyproject.toml +1 -1
  12. {fusiontest-0.2.24 → fusiontest-0.2.26}/README.md +0 -0
  13. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/__init__.py +0 -0
  14. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/sites/shop/bugs.js +0 -0
  15. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/sites/shop/help.html +0 -0
  16. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/sites/shop/index.html +0 -0
  17. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
  18. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/suites/shop.yaml +0 -0
  19. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/bench/suites/todomvc.yaml +0 -0
  20. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/__init__.py +0 -0
  21. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/action_model.py +0 -0
  22. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/app_errors.py +0 -0
  23. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/goal_verifier.py +0 -0
  24. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/netguard.py +0 -0
  25. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/replay.py +0 -0
  26. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/screen_parser.py +0 -0
  27. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/secrets.py +0 -0
  28. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/shared_traces.py +0 -0
  29. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/core/tokens.py +0 -0
  30. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/__init__.py +0 -0
  31. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
  32. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/github.yaml +0 -0
  33. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/hacker_news.yaml +0 -0
  34. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/httpbin.yaml +0 -0
  35. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/todomvc.yaml +0 -0
  36. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/demos/wikipedia.yaml +0 -0
  37. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/desktop/__init__.py +0 -0
  38. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/desktop/macos_adapter.py +0 -0
  39. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/desktop/playwright_adapter.py +0 -0
  40. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/desktop/windows_adapter.py +0 -0
  41. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/discovery/__init__.py +0 -0
  42. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/discovery/goal_generator.py +0 -0
  43. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/guardrails/__init__.py +0 -0
  44. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/guardrails/engine.py +0 -0
  45. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/mobile/__init__.py +0 -0
  46. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/mobile/android_adapter.py +0 -0
  47. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/mobile/ios_adapter.py +0 -0
  48. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/reporting/__init__.py +0 -0
  49. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/training/__init__.py +0 -0
  50. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/training/data_collector.py +0 -0
  51. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/training/dataset_builder.py +0 -0
  52. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest/training/trainer.py +0 -0
  53. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/dependency_links.txt +0 -0
  54. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/entry_points.txt +0 -0
  55. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/not-zip-safe +0 -0
  56. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/requires.txt +0 -0
  57. {fusiontest-0.2.24 → fusiontest-0.2.26}/fusiontest.egg-info/top_level.txt +0 -0
  58. {fusiontest-0.2.24 → fusiontest-0.2.26}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.24
3
+ Version: 0.2.26
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
@@ -417,6 +417,7 @@ class VariantResult:
417
417
  reports: list[str] = field(default_factory=list) # bugs FusionTest reported
418
418
  matches: list[str | None] = field(default_factory=list) # planted id per report, or None
419
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
420
421
  tasks_passed: int = 0
421
422
  tasks: int = 0
422
423
  failed_tasks: list[str] = field(default_factory=list) # "task — why", for diagnosis
@@ -435,7 +436,7 @@ class VariantResult:
435
436
 
436
437
  def score_variant(suite: BugSuite, variant: Variant, run: RunResult) -> VariantResult:
437
438
  planted = [suite.bugs[b] for b in variant.bugs]
438
- reports = [str(r) for r in run.bugs_detected]
439
+ reports = [str(b) for b in run.bugs_detected] # each bug's one-line title
439
440
  evaluated = run.steps and not run.errored
440
441
  classified = [classify_report(r, planted, suite.decoys) for r in reports]
441
442
  return VariantResult(
@@ -443,6 +444,7 @@ def score_variant(suite: BugSuite, variant: Variant, run: RunResult) -> VariantR
443
444
  outcome="run" if evaluated else "error",
444
445
  reports=reports, matches=[bug for bug, _ in classified],
445
446
  decoy_trips=[decoy for _, decoy in classified if decoy],
447
+ unconfirmed=[str(b) for b in getattr(run, "unconfirmed_bugs", [])],
446
448
  tasks_passed=sum(s.success for s in run.steps), tasks=len(suite.tasks),
447
449
  failed_tasks=[f"{s.goal} — {s.error}" for s in run.steps if not s.success],
448
450
  seconds=round(sum(s.duration_seconds for s in run.steps), 2),
@@ -487,6 +489,7 @@ class BugSummary:
487
489
  false_reports: int
488
490
  false_on_clean: int # reports on variants with nothing planted
489
491
  decoy_trips: int = 0 # false reports about decoys
492
+ unconfirmed: int = 0 # suspected bugs dropped because they didn't reproduce
490
493
 
491
494
  @property
492
495
  def precision(self) -> float | None:
@@ -514,6 +517,7 @@ def summarize_bugs(runs: list[BugSuiteRun]) -> BugSummary:
514
517
  reports=reports, true_reports=reports - false_reports, false_reports=false_reports,
515
518
  false_on_clean=sum(len(v.reports) for v in evaluated if not v.planted),
516
519
  decoy_trips=sum(len(v.decoy_trips) for v in evaluated),
520
+ unconfirmed=sum(len(v.unconfirmed) for v in evaluated),
517
521
  )
518
522
 
519
523
 
@@ -678,6 +682,8 @@ def _session(site: str, url: str, platform: str, goals: list[str], name: str, ba
678
682
  runner = runner_factory(adapter, RunnerConfig(
679
683
  backend=backend, trace_store=None, screenshot_on_failure=False,
680
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,
681
687
  ))
682
688
  start = time.time()
683
689
  # No url= here: the runner would reload it before every goal, and
@@ -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, ""])
@@ -1142,6 +1145,7 @@ def _upload_report(result) -> str | None:
1142
1145
  "stability_score": result.stability_score,
1143
1146
  "total_duration_seconds": result.total_duration_seconds,
1144
1147
  "steps": [s.to_dict() for s in result.steps],
1148
+ "bugs_detected": [b.to_dict() for b in result.bugs_detected],
1145
1149
  }
1146
1150
 
1147
1151
  try:
@@ -0,0 +1,63 @@
1
+ """
2
+ fusiontest.core.bugs — a bug report a developer can act on (ADR-009 §2).
3
+
4
+ Every reported bug says what kind of bug it is, where, what was expected and
5
+ what happened instead, the screen text that proves it, the steps that lead to
6
+ it, and how many fresh sessions it was reproduced in.
7
+
8
+ kind js_exception | http_error | broken_promise | inconsistency
9
+ title one line, e.g. "Broken promise: … (after tap 'Apply coupon', on /cart)"
10
+ steps from the run's start, in plain words; typed secrets stay {{VAR}}
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from dataclasses import asdict, dataclass, field
16
+
17
+ KINDS = ("js_exception", "http_error", "broken_promise", "inconsistency")
18
+
19
+
20
+ @dataclass
21
+ class Bug:
22
+ kind: str
23
+ title: str
24
+ page: str = ""
25
+ action: str = "" # the action right before the bug showed up
26
+ expected: str = ""
27
+ actual: str = ""
28
+ evidence: list[str] = field(default_factory=list) # screen text, quoted
29
+ steps: list[str] = field(default_factory=list) # to reproduce, from the start
30
+ reproduced: int = 0 # fresh sessions it happened again in (0: not checked)
31
+
32
+ def to_dict(self) -> dict:
33
+ return asdict(self)
34
+
35
+ def __str__(self) -> str:
36
+ return self.title
37
+
38
+
39
+ def from_app_error(error, steps: list[str], redact=lambda s: s) -> Bug:
40
+ """A Bug for an AppError (fusiontest.core.app_errors)."""
41
+ if error.kind == "js_exception":
42
+ kind, expected = "js_exception", "No uncaught JavaScript errors"
43
+ elif error.message.startswith("HTTP 5"):
44
+ kind, expected = "http_error", "The request succeeds"
45
+ else:
46
+ kind, expected = "http_error", "The page opens"
47
+ return Bug(kind=kind, title=redact(error.report()), page=error.page, action=redact(error.after),
48
+ expected=expected, actual=redact(error.message), steps=list(steps))
49
+
50
+
51
+ def from_finding(finding, steps: list[str], redact=lambda s: s) -> Bug:
52
+ """A Bug for a confirmed broken promise or inconsistency (fusiontest.core.promise_checker)."""
53
+ return Bug(kind=finding.kind, title=redact(finding.report()), page=finding.page,
54
+ action=redact(finding.action), expected=redact(finding.expected or ""),
55
+ actual=redact(finding.actual or finding.summary),
56
+ evidence=[redact(e) for e in finding.evidence], steps=list(steps))
57
+
58
+
59
+ def step_text(kind: str, url: str = "", action: str = "") -> str:
60
+ """One step to reproduce, in plain words."""
61
+ if kind in ("start", "navigate"):
62
+ return f"Open {url}"
63
+ return action[:1].upper() + action[1:] if action else ""
@@ -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,9 @@ 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
64
+ expected: str = ""
65
+ actual: str = ""
62
66
 
63
67
  def report(self) -> str:
64
68
  label = "Broken promise" if self.kind == "broken_promise" else "Inconsistent screen"
@@ -83,8 +87,9 @@ _REVIEW_SYSTEM = (
83
87
  "- design choices, wording, layout, or anything you are unsure about\n\n"
84
88
  "Respond with ONLY a JSON object: {\"findings\": [{\"kind\": \"broken_promise\" or "
85
89
  "\"inconsistency\", \"step\": <step number>, \"summary\": \"one sentence: which "
86
- "control or text, what was expected, what the screen shows instead\", \"evidence\": "
87
- "[\"short phrases copied EXACTLY from the screen text\"]}]}. "
90
+ "control or text, what was expected, what the screen shows instead\", \"expected\": "
91
+ "\"what should have happened\", \"actual\": \"what the screen shows instead\", "
92
+ "\"evidence\": [\"short phrases copied EXACTLY from the screen text\"]}]}. "
88
93
  "Use {\"findings\": []} when there are none — that is the usual answer."
89
94
  )
90
95
  _REVIEW = LLMRequest(
@@ -193,7 +198,10 @@ class PromiseChecker:
193
198
  logger.info("Promise check: dropped finding, evidence not on screen: %s", summary)
194
199
  continue
195
200
  findings.append(Finding(kind=kind, summary=summary, step=step, action=transition.action,
196
- page=_page(transition.before), evidence=evidence))
201
+ page=_page(transition.before), evidence=evidence,
202
+ at=transition.at,
203
+ expected=str(item.get("expected", "")).strip(),
204
+ actual=str(item.get("actual", "")).strip()))
197
205
  return findings
198
206
 
199
207
  # ── Confirmation ──────────────────────────────────────────────────────────
@@ -0,0 +1,50 @@
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.bugs import Bug
22
+ from fusiontest.core.replay import RecordedAction
23
+
24
+
25
+ @dataclass
26
+ class LogEntry:
27
+ kind: str # start (not replayed) | navigate | action
28
+ url: str = ""
29
+ action: RecordedAction | None = None
30
+ text: str = "" # in plain words, secrets masked: a step to reproduce
31
+
32
+
33
+ @dataclass
34
+ class BugCandidate:
35
+ bug: Bug
36
+ signature: tuple[str, str]
37
+ at: int # log entries replayed before checking
38
+ app_error: tuple[str, str] | None = None # signature to see again
39
+ evidence: list[str] = field(default_factory=list) # quotes to see again
40
+
41
+ @property
42
+ def report(self) -> str:
43
+ return self.bug.title
44
+
45
+
46
+ @dataclass
47
+ class Reproduction:
48
+ confirmed: list[BugCandidate]
49
+ unconfirmed: list[BugCandidate]
50
+ sessions: int = 0
@@ -19,8 +19,10 @@ from collections.abc import Callable
19
19
  from dataclasses import dataclass, field, replace
20
20
  from typing import Protocol, runtime_checkable
21
21
 
22
+ from fusiontest.core import bugs
22
23
  from fusiontest.core.action_model import Action, ActionBackend, ActionModel, LLMUnavailableError
23
24
  from fusiontest.core.app_errors import AppError
25
+ from fusiontest.core.bugs import Bug, step_text
24
26
  from fusiontest.core.goal_verifier import GoalVerifier, VerifierResult
25
27
  from fusiontest.core.promise_checker import Finding, PromiseChecker, Transition
26
28
  from fusiontest.core.replay import (
@@ -34,6 +36,7 @@ from fusiontest.core.replay import (
34
36
  trace_key,
35
37
  url_path,
36
38
  )
39
+ from fusiontest.core.reproduce import BugCandidate, LogEntry, Reproduction
37
40
  from fusiontest.core.screen_parser import UIElement
38
41
  from fusiontest.core.secrets import SecretResolver, host_matches, resolve_goals
39
42
  from fusiontest.core.tokens import TokenUsage
@@ -112,7 +115,9 @@ class RunResult:
112
115
  url: str = ""
113
116
  steps: list[StepResult] = field(default_factory=list)
114
117
  total_duration_seconds: float = 0.0
115
- bugs_detected: list[str] = field(default_factory=list)
118
+ bugs_detected: list[Bug] = field(default_factory=list)
119
+ # Suspected bugs that didn't happen again in fresh sessions (not reported).
120
+ unconfirmed_bugs: list[Bug] = field(default_factory=list)
116
121
  cancelled: bool = False
117
122
  # Set when the run stopped early because it could not be evaluated
118
123
  # (e.g. no LLM backend available). Remaining goals were not run.
@@ -200,6 +205,12 @@ class RunnerConfig:
200
205
  # RunResult.bugs_detected (ADR-009). Off until bug reports meet the
201
206
  # benchmark's precision gate; `fusiontest bench` turns it on.
202
207
  detect_bugs: bool = False
208
+ # Reproduce suspected bugs before reporting them (ADR-009 §2): a callable
209
+ # returning a new, started adapter on the app's start page. The run's
210
+ # actions are replayed in that many fresh sessions (no LLM calls); only
211
+ # bugs seen again every time are reported. None: report without reproducing.
212
+ fresh_adapter: Callable[[], object] | None = None
213
+ reproduce_times: int = 2
203
214
 
204
215
 
205
216
  # ── Runner ─────────────────────────────────────────────────────────────────────
@@ -233,6 +244,8 @@ class FusionTestRunner:
233
244
  # Trace fields of the last goal the LLM verified (see _make_recording).
234
245
  self._last_recording: dict | None = None
235
246
  self._promise_checker: PromiseChecker | None = None
247
+ # Every navigation and executed action of the run, for reproduction.
248
+ self._log: list[LogEntry] = []
236
249
  self._step_log = None
237
250
  if self.config.step_log_path:
238
251
  import pathlib # noqa: PLC0415
@@ -288,7 +301,12 @@ class FusionTestRunner:
288
301
  )
289
302
 
290
303
  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
304
+ reported: set[tuple[str, str]] = set() # bug signatures already suspected
305
+ candidates: list[BugCandidate] = []
306
+ self._log = []
307
+ start_url = url or _current_url(self.adapter)
308
+ if start_url: # where a fresh session starts too, so it's not replayed
309
+ self._log.append(LogEntry(kind="start", url=start_url, text=step_text("start", start_url)))
292
310
 
293
311
  for i, (goal, safe_goal) in enumerate(zip(model_goals, goals, strict=True), 1):
294
312
  # Cooperative cancellation check — run before starting the next goal
@@ -357,7 +375,7 @@ class FusionTestRunner:
357
375
  if watchdog is not None:
358
376
  watchdog.cancel()
359
377
 
360
- self._collect_bugs(step_result, result, reported, resolver)
378
+ self._collect_bugs(step_result, candidates, reported, resolver)
361
379
 
362
380
  # A timed-out goal couldn't be evaluated: record it as an error
363
381
  # (not a test failure), and stop the run — the browser is closed.
@@ -409,6 +427,13 @@ class FusionTestRunner:
409
427
  )
410
428
  break
411
429
 
430
+ if self.config.detect_bugs and candidates:
431
+ outcome = self._reproduce(candidates, resolver)
432
+ for c in outcome.confirmed:
433
+ c.bug.reproduced = outcome.sessions if self.config.fresh_adapter else 0
434
+ result.bugs_detected = [c.bug for c in outcome.confirmed]
435
+ result.unconfirmed_bugs = [c.bug for c in outcome.unconfirmed]
436
+
412
437
  result.total_duration_seconds = time.time() - run_start
413
438
  result.llm_calls = self._llm_calls()
414
439
  logger.info(
@@ -459,7 +484,7 @@ class FusionTestRunner:
459
484
  # Each executed action with the screens before and after it, for the
460
485
  # broken-promise check (ADR-009). pending: an action awaiting its "after".
461
486
  transitions: list[Transition] = []
462
- pending: tuple[str, str] | None = None
487
+ pending: tuple[str, str, int] | None = None
463
488
 
464
489
  for step_num in range(1, self.config.max_steps_per_goal + 1):
465
490
  step.steps_taken = step_num
@@ -480,7 +505,8 @@ class FusionTestRunner:
480
505
  screen_text = _redact(screen_text)
481
506
  _drop_if_no_effect(screen_text)
482
507
  if pending is not None:
483
- transitions.append(Transition(action=pending[0], before=pending[1], after=screen_text))
508
+ transitions.append(Transition(action=pending[0], before=pending[1], after=screen_text,
509
+ at=pending[2]))
484
510
  pending = None
485
511
 
486
512
  # No progress: tell the model its last action did nothing, and stop
@@ -607,6 +633,7 @@ class FusionTestRunner:
607
633
  logger.info(f" Backtracking (step {step_num})")
608
634
  self._backtrack(history)
609
635
  recorded.append(RecordedAction(action_type="back"))
636
+ self._log.append(LogEntry(kind="action", action=recorded[-1], text="Go back"))
610
637
  break
611
638
 
612
639
  if gr.should_skip:
@@ -631,7 +658,10 @@ class FusionTestRunner:
631
658
  history.append(action_str) # LLM context — real value ok
632
659
  safe_action_str = _redact(action_str)
633
660
  step.actions.append(safe_action_str) # stored — secrets masked
634
- pending = (_redact(_action_text(gr.action, elements)), screen_text)
661
+ action_text = _redact(_action_text(gr.action, elements))
662
+ self._log.append(LogEntry(kind="action", action=recorded[-1],
663
+ text=step_text("action", action=action_text)))
664
+ pending = (action_text, screen_text, len(self._log))
635
665
  self.guardrails.record_action(gr.action)
636
666
  # Only record screen hash for actions that change the page.
637
667
  # Scroll doesn't change DOM extraction (all elements captured
@@ -666,7 +696,7 @@ class FusionTestRunner:
666
696
  final_screen_text = screen_text # fall back to last known screen
667
697
  if pending is not None:
668
698
  transitions.append(Transition(action=pending[0], before=pending[1],
669
- after=final_screen_text))
699
+ after=final_screen_text, at=pending[2]))
670
700
 
671
701
  self._last_chance_verify(
672
702
  step, goal, final_screen_text, history, recorded,
@@ -719,28 +749,135 @@ class FusionTestRunner:
719
749
  store.save(GoalTrace(key=key, goal=safe_goal, start_url=goal_url, **self._last_recording))
720
750
  return step
721
751
 
722
- def _collect_bugs(self, step: StepResult, result: RunResult,
752
+ def _collect_bugs(self, step: StepResult, candidates: list[BugCandidate],
723
753
  reported: set[tuple[str, str]], resolver: SecretResolver) -> None:
724
754
  """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."""
755
+ app error or confirmed finding as a bug candidate, once."""
726
756
  drain = getattr(self.adapter, "drain_app_errors", None)
727
757
  if callable(drain):
728
758
  try:
729
759
  step.app_errors = list(drain())
730
760
  except Exception as exc: # noqa: BLE001 — observation must never fail a run
731
761
  logger.debug("Could not read app errors: %s", exc)
732
- candidates = [(e.signature, e.report()) for e in step.app_errors]
762
+ def steps_to(at: int) -> list[str]:
763
+ steps: list[str] = []
764
+ for e in self._log[:at]:
765
+ # Opening the page you're already on adds nothing (repeated taps do).
766
+ if e.text and not (e.kind != "action" and steps and steps[-1] == e.text):
767
+ steps.append(e.text)
768
+ return steps
769
+
770
+ found = [BugCandidate(bug=bugs.from_app_error(e, steps_to(len(self._log)), resolver.redact),
771
+ signature=e.signature, at=len(self._log), app_error=e.signature)
772
+ for e in step.app_errors]
733
773
  # A finding about an action that already raised an app error (a dead
734
774
  # link that "didn't open the Help page") is the same bug said twice.
735
775
  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)
776
+ found += [BugCandidate(bug=bugs.from_finding(f, steps_to(f.at), resolver.redact),
777
+ signature=(f.kind, f.summary.lower()), at=f.at, evidence=list(f.evidence))
778
+ for f in step.findings if f.action not in errored_actions]
779
+ for candidate in found:
780
+ logger.info(" Suspected bug: %s", candidate.report)
781
+ if self.config.detect_bugs and candidate.signature not in reported:
782
+ reported.add(candidate.signature)
783
+ candidates.append(candidate)
784
+
785
+ def _reproduce(self, candidates: list[BugCandidate], resolver: SecretResolver) -> Reproduction:
786
+ """Replay the run in fresh sessions; keep the candidates seen every time."""
787
+ factory = self.config.fresh_adapter
788
+ if factory is None or self.config.reproduce_times < 1:
789
+ return Reproduction(confirmed=list(candidates), unconfirmed=[])
790
+ still = list(range(len(candidates)))
791
+ sessions = 0
792
+ for attempt in range(1, self.config.reproduce_times + 1):
793
+ if not still:
794
+ break
795
+ logger.info("Reproducing %d suspected bug(s), fresh session %d/%d",
796
+ len(still), attempt, self.config.reproduce_times)
797
+ try:
798
+ adapter = factory()
799
+ except Exception as exc: # noqa: BLE001 — can't reproduce: nothing is confirmed
800
+ logger.warning("Could not open a fresh session to reproduce bugs: %s", exc)
801
+ still = []
802
+ break
803
+ sessions += 1
804
+ try:
805
+ seen = self._replay_log(adapter, [candidates[i] for i in still], resolver)
806
+ finally:
807
+ stop = getattr(adapter, "stop", None)
808
+ if callable(stop):
809
+ try:
810
+ stop()
811
+ except Exception: # noqa: BLE001
812
+ pass
813
+ still = [i for i in still if id(candidates[i]) in seen]
814
+ confirmed = [candidates[i] for i in still]
815
+ unconfirmed = [c for c in candidates if c not in confirmed]
816
+ for c in unconfirmed:
817
+ logger.info(" Not reproduced, not reported: %s", c.report)
818
+ return Reproduction(confirmed=confirmed, unconfirmed=unconfirmed, sessions=sessions)
819
+
820
+ 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."""
823
+ seen: set[int] = set()
824
+ errors: set[tuple[str, str]] = set()
825
+ last = max(c.at for c in candidates)
826
+ original, self.adapter = self.adapter, adapter # _bind_secrets reads the current host
827
+
828
+ def drain() -> None:
829
+ take = getattr(adapter, "drain_app_errors", None)
830
+ if callable(take):
831
+ try:
832
+ errors.update(e.signature for e in take())
833
+ except Exception: # noqa: BLE001
834
+ pass
835
+
836
+ def check(at: int, before: str) -> None:
837
+ due = [c for c in candidates if c.at == at]
838
+ if not due:
839
+ return
840
+ drain()
841
+ after = ""
842
+ if any(c.evidence for c in due):
843
+ time.sleep(0.8)
844
+ try:
845
+ after = resolver.redact(adapter.get_screen()[1])
846
+ except Exception: # noqa: BLE001
847
+ after = ""
848
+ for c in due:
849
+ if c.app_error is not None and c.app_error in errors:
850
+ seen.add(id(c))
851
+ elif c.evidence and evidence_present(c.evidence, before + "\n" + after):
852
+ seen.add(id(c))
853
+
854
+ try:
855
+ check(0, "")
856
+ for at, entry in enumerate(self._log[:last], 1):
857
+ before = ""
858
+ if entry.kind == "navigate":
859
+ if hasattr(adapter, "navigate"):
860
+ adapter.navigate(entry.url)
861
+ elif entry.action is not None:
862
+ time.sleep(0.8) # let the page settle, as the LLM loop does
863
+ elements, before = adapter.get_screen()
864
+ before = resolver.redact(before)
865
+ action = resolve_action(entry.action, elements)
866
+ if action is None:
867
+ logger.info(" Reproduction stopped: %s %r is gone",
868
+ entry.action.element_type, entry.action.element_label)
869
+ break
870
+ exec_action, blocked = self._bind_secrets(action, resolver)
871
+ if blocked or not adapter.execute(exec_action, elements):
872
+ logger.info(" Reproduction stopped: %s failed", entry.action.action_type)
873
+ break
874
+ drain()
875
+ check(at, before)
876
+ except Exception as exc: # noqa: BLE001 — whatever reproduced so far still counts
877
+ logger.info(" Reproduction stopped: %s", exc)
878
+ finally:
879
+ self.adapter = original
880
+ return seen
744
881
 
745
882
  def _checker(self) -> PromiseChecker | None:
746
883
  """The broken-promise checker, created on first use (no chat model: none)."""
@@ -782,6 +919,8 @@ class FusionTestRunner:
782
919
  if blocked or not self.adapter.execute(exec_action, elements):
783
920
  logger.info(f" Replay: action failed — {action}")
784
921
  return None
922
+ self._log.append(LogEntry(kind="action", action=recorded, text=step_text(
923
+ "action", action=resolver.redact(_action_text(action, elements)))))
785
924
  actions.append(resolver.redact(str(action)))
786
925
  if trace.actions:
787
926
  time.sleep(0.8)
@@ -823,6 +962,7 @@ class FusionTestRunner:
823
962
  def _navigate(self, url: str) -> None:
824
963
  """Open the goal's starting URL (if given and the adapter supports it)."""
825
964
  if url and hasattr(self.adapter, "navigate"):
965
+ self._log.append(LogEntry(kind="navigate", url=url, text=step_text("navigate", url)))
826
966
  try:
827
967
  self.adapter.navigate(url)
828
968
  logger.info(f" Navigated to: {url}")
@@ -88,7 +88,7 @@ class Reporter:
88
88
  "status": result.status,
89
89
  "stability_score": round(result.stability_score, 4),
90
90
  "total_duration_seconds": round(result.total_duration_seconds, 2),
91
- "bugs_detected": result.bugs_detected,
91
+ "bugs_detected": [b.to_dict() for b in result.bugs_detected],
92
92
  "steps": [s.to_dict() for s in result.steps],
93
93
  }
94
94
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fusiontest
3
- Version: 0.2.24
3
+ Version: 0.2.26
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
@@ -19,10 +19,12 @@ fusiontest/bench/suites/todomvc.yaml
19
19
  fusiontest/core/__init__.py
20
20
  fusiontest/core/action_model.py
21
21
  fusiontest/core/app_errors.py
22
+ fusiontest/core/bugs.py
22
23
  fusiontest/core/goal_verifier.py
23
24
  fusiontest/core/netguard.py
24
25
  fusiontest/core/promise_checker.py
25
26
  fusiontest/core/replay.py
27
+ fusiontest/core/reproduce.py
26
28
  fusiontest/core/runner.py
27
29
  fusiontest/core/screen_parser.py
28
30
  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.24"
7
+ version = "0.2.26"
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