fusiontest 0.2.43__tar.gz → 0.2.45__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.43 → fusiontest-0.2.45}/PKG-INFO +16 -4
- {fusiontest-0.2.43 → fusiontest-0.2.45}/README.md +13 -3
- fusiontest-0.2.45/fusiontest/agent/__init__.py +2 -0
- fusiontest-0.2.45/fusiontest/agent/mcp_server.py +236 -0
- fusiontest-0.2.45/fusiontest/agent/verify.py +351 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/__init__.py +196 -22
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/sites/shop/index.html +30 -6
- fusiontest-0.2.45/fusiontest/bench/suites/diffs/order-retry.diff +31 -0
- fusiontest-0.2.45/fusiontest/bench/suites/diffs/sale-banner.diff +10 -0
- fusiontest-0.2.45/fusiontest/bench/suites/diffs/stock-check.diff +22 -0
- fusiontest-0.2.45/fusiontest/bench/suites/shop-hard.yaml +38 -0
- fusiontest-0.2.45/fusiontest/bench/suites/shop-intent.yaml +32 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/cli.py +236 -12
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/action_model.py +83 -21
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/goal_verifier.py +28 -7
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/runner.py +109 -8
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/desktop/playwright_adapter.py +20 -2
- fusiontest-0.2.45/fusiontest/discovery/intent.py +220 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/PKG-INFO +16 -4
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/SOURCES.txt +9 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/requires.txt +3 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/pyproject.toml +5 -2
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/sites/shop/bugs.js +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/sites/shop/help.html +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/suites/shop-bugs.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/app_errors.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/bugs.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/promise_checker.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/replay.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/reproduce.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/secrets.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/shared_traces.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/discovery/goal_generator.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.43 → fusiontest-0.2.45}/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.45
|
|
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
|
|
@@ -29,6 +29,8 @@ Requires-Dist: Appium-Python-Client>=3.1; extra == "mobile"
|
|
|
29
29
|
Requires-Dist: selenium>=4.18; extra == "mobile"
|
|
30
30
|
Provides-Extra: desktop
|
|
31
31
|
Requires-Dist: playwright>=1.43; extra == "desktop"
|
|
32
|
+
Provides-Extra: mcp
|
|
33
|
+
Requires-Dist: mcp<3,>=2.3; extra == "mcp"
|
|
32
34
|
Provides-Extra: windows
|
|
33
35
|
Requires-Dist: Appium-Python-Client>=3.1; extra == "windows"
|
|
34
36
|
Requires-Dist: selenium>=4.18; extra == "windows"
|
|
@@ -82,9 +84,13 @@ Requires-Dist: fusiontest[api,claude,desktop,gemini,groq,macos,mobile,mpnet,open
|
|
|
82
84
|
> AI-powered UI testing for web, desktop and mobile — built by [FusionLeap.io](https://fusionleap.io)
|
|
83
85
|
|
|
84
86
|
FusionTest runs UI tests written as plain-English goals. An LLM reads the
|
|
85
|
-
screen and decides what to do,
|
|
86
|
-
|
|
87
|
-
without calling the AI at all.
|
|
87
|
+
screen and decides what to do, an independent judge model confirms each goal
|
|
88
|
+
from the screen, a screenshot and the app's own errors, and goals that pass are
|
|
89
|
+
recorded so later runs replay them without calling the AI at all.
|
|
90
|
+
|
|
91
|
+
Coding agents use it to verify their changes: `fusiontest verify` (or the MCP
|
|
92
|
+
server) reads the diff, checks what it promises in the running app, and keeps
|
|
93
|
+
what passes as regression goals. See [docs/coding-agents.md](docs/coding-agents.md).
|
|
88
94
|
|
|
89
95
|
---
|
|
90
96
|
|
|
@@ -93,6 +99,9 @@ without calling the AI at all.
|
|
|
93
99
|
| Feature | Notes |
|
|
94
100
|
|---|---|
|
|
95
101
|
| Natural-language goals | `"Open the Pricing page and verify all three plans are shown"` |
|
|
102
|
+
| Verify a change | `fusiontest verify` plans checks from a diff and judges them; JSON verdict for agents and CI |
|
|
103
|
+
| MCP server | `fusiontest mcp`: `verify_change`, `run_goals`, `scan_site` for Claude Code and other agents |
|
|
104
|
+
| Independent judge | A stronger model judges pass/fail (Claude or OpenAI when set) while a cheap one clicks |
|
|
96
105
|
| Goal discovery | Crawls a site and proposes goals grounded in its real content |
|
|
97
106
|
| Record & replay | Passing goals replay with no LLM calls; the AI repairs them when the page changes |
|
|
98
107
|
| Honest results | Capacity or infrastructure problems are reported as **errors**, not test failures |
|
|
@@ -144,6 +153,9 @@ export GROQ_API_KEY=gsk_... # or ANTHROPIC_API_KEY / GEMINI_API_KEY / O
|
|
|
144
153
|
fusiontest run --url https://example.com \
|
|
145
154
|
--goal "Verify the page heading says Example Domain" --headless
|
|
146
155
|
|
|
156
|
+
# Changed the UI? Check that the change does what it says (uncommitted changes by default)
|
|
157
|
+
fusiontest verify --url http://localhost:5173
|
|
158
|
+
|
|
147
159
|
# No goals yet? Map what works on a test/staging site, and save the flows that do
|
|
148
160
|
fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
|
|
149
161
|
# Behind a login: EMAIL and PASSWORD come from the environment, never the AI
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
> AI-powered UI testing for web, desktop and mobile — built by [FusionLeap.io](https://fusionleap.io)
|
|
4
4
|
|
|
5
5
|
FusionTest runs UI tests written as plain-English goals. An LLM reads the
|
|
6
|
-
screen and decides what to do,
|
|
7
|
-
|
|
8
|
-
without calling the AI at all.
|
|
6
|
+
screen and decides what to do, an independent judge model confirms each goal
|
|
7
|
+
from the screen, a screenshot and the app's own errors, and goals that pass are
|
|
8
|
+
recorded so later runs replay them without calling the AI at all.
|
|
9
|
+
|
|
10
|
+
Coding agents use it to verify their changes: `fusiontest verify` (or the MCP
|
|
11
|
+
server) reads the diff, checks what it promises in the running app, and keeps
|
|
12
|
+
what passes as regression goals. See [docs/coding-agents.md](docs/coding-agents.md).
|
|
9
13
|
|
|
10
14
|
---
|
|
11
15
|
|
|
@@ -14,6 +18,9 @@ without calling the AI at all.
|
|
|
14
18
|
| Feature | Notes |
|
|
15
19
|
|---|---|
|
|
16
20
|
| Natural-language goals | `"Open the Pricing page and verify all three plans are shown"` |
|
|
21
|
+
| Verify a change | `fusiontest verify` plans checks from a diff and judges them; JSON verdict for agents and CI |
|
|
22
|
+
| MCP server | `fusiontest mcp`: `verify_change`, `run_goals`, `scan_site` for Claude Code and other agents |
|
|
23
|
+
| Independent judge | A stronger model judges pass/fail (Claude or OpenAI when set) while a cheap one clicks |
|
|
17
24
|
| Goal discovery | Crawls a site and proposes goals grounded in its real content |
|
|
18
25
|
| Record & replay | Passing goals replay with no LLM calls; the AI repairs them when the page changes |
|
|
19
26
|
| Honest results | Capacity or infrastructure problems are reported as **errors**, not test failures |
|
|
@@ -65,6 +72,9 @@ export GROQ_API_KEY=gsk_... # or ANTHROPIC_API_KEY / GEMINI_API_KEY / O
|
|
|
65
72
|
fusiontest run --url https://example.com \
|
|
66
73
|
--goal "Verify the page heading says Example Domain" --headless
|
|
67
74
|
|
|
75
|
+
# Changed the UI? Check that the change does what it says (uncommitted changes by default)
|
|
76
|
+
fusiontest verify --url http://localhost:5173
|
|
77
|
+
|
|
68
78
|
# No goals yet? Map what works on a test/staging site, and save the flows that do
|
|
69
79
|
fusiontest scan https://staging.example.com --save fusiontest.goals.yaml
|
|
70
80
|
# Behind a login: EMAIL and PASSWORD come from the environment, never the AI
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""
|
|
2
|
+
fusiontest/agent/mcp_server.py
|
|
3
|
+
|
|
4
|
+
FusionTest as MCP tools for coding agents (ADR-010): `fusiontest mcp` serves
|
|
5
|
+
them over stdio. A coding agent that changed a web app calls verify_change to
|
|
6
|
+
learn, from an independent judge, whether the running app does what the
|
|
7
|
+
change promised; checks that pass can be kept as regression goals.
|
|
8
|
+
|
|
9
|
+
The tools are thin wrappers over fusiontest.agent.verify, so an agent gets
|
|
10
|
+
exactly what `fusiontest verify --json` prints (schema fusiontest.verify/1).
|
|
11
|
+
|
|
12
|
+
Safety is the CLI's: checks click and type like a user, so a host that isn't
|
|
13
|
+
local needs allow_remote=true; secrets stay {{VAR}} placeholders the models
|
|
14
|
+
never see, filled from the environment or fusiontest.config.yaml.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
import os
|
|
21
|
+
from collections.abc import Callable
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
from urllib.parse import urlsplit
|
|
25
|
+
|
|
26
|
+
from fusiontest.agent.verify import (
|
|
27
|
+
SCHEMA,
|
|
28
|
+
AdapterFactory,
|
|
29
|
+
VerifyRequest,
|
|
30
|
+
read_change,
|
|
31
|
+
save_passing,
|
|
32
|
+
with_scheme,
|
|
33
|
+
)
|
|
34
|
+
from fusiontest.agent.verify import verify as default_verify
|
|
35
|
+
|
|
36
|
+
logger = logging.getLogger(__name__)
|
|
37
|
+
|
|
38
|
+
INSTRUCTIONS = """\
|
|
39
|
+
FusionTest checks a running web app in a real browser, the way a user would,
|
|
40
|
+
and an independent model judges each check from the screen, a screenshot and
|
|
41
|
+
the app's own errors.
|
|
42
|
+
|
|
43
|
+
Use verify_change after changing a web app's UI, with the app running (e.g. a
|
|
44
|
+
local dev server): it reads the change (your uncommitted git changes by
|
|
45
|
+
default), plans a few checks of what the change promises, runs them, and
|
|
46
|
+
returns a verdict per check with the reason and, for failures, a screenshot
|
|
47
|
+
path. Fix what fails and call it again. Use run_goals for checks you write
|
|
48
|
+
yourself, scan_site to map what works on a site, and pass save_to to keep
|
|
49
|
+
passing checks as regression goals (run on every deploy with
|
|
50
|
+
`fusiontest run -f <file>`).
|
|
51
|
+
|
|
52
|
+
Status: passed | failed (a check failed: likely a bug in the change) | error
|
|
53
|
+
(couldn't evaluate: LLM capacity, browser, sign-in) | nothing_to_verify (the
|
|
54
|
+
change has nothing visible). Checks click and submit forms: use local or
|
|
55
|
+
staging sites; other hosts need allow_remote=true.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def build_server(verify_fn: Callable[..., dict] | None = None,
|
|
60
|
+
adapter_factory: AdapterFactory | None = None,
|
|
61
|
+
cwd: str | None = None):
|
|
62
|
+
"""The MCP server with FusionTest's tools. verify_fn and adapter_factory
|
|
63
|
+
are for tests; cwd is the repository whose changes are verified."""
|
|
64
|
+
from mcp.server.mcpserver import MCPServer
|
|
65
|
+
from mcp.types import ToolAnnotations
|
|
66
|
+
|
|
67
|
+
from fusiontest import __version__
|
|
68
|
+
|
|
69
|
+
verify = verify_fn or default_verify
|
|
70
|
+
repo = cwd or os.getcwd()
|
|
71
|
+
secrets = _config_secrets(repo)
|
|
72
|
+
reports: list[dict] = []
|
|
73
|
+
server = MCPServer("fusiontest", instructions=INSTRUCTIONS, version=__version__)
|
|
74
|
+
acts = ToolAnnotations(read_only_hint=False, destructive_hint=False, idempotent_hint=False,
|
|
75
|
+
open_world_hint=True)
|
|
76
|
+
|
|
77
|
+
def finish(request: VerifyRequest, save_to: str | None) -> dict[str, Any]:
|
|
78
|
+
verdict = verify(request, adapter_factory=adapter_factory)
|
|
79
|
+
if save_to and verdict["checks"]:
|
|
80
|
+
path = Path(save_to) if Path(save_to).is_absolute() else Path(repo) / save_to
|
|
81
|
+
verdict["saved"] = {"path": str(path),
|
|
82
|
+
"added": save_passing(verdict, path, request.login)}
|
|
83
|
+
reports.append(verdict)
|
|
84
|
+
del reports[:-20]
|
|
85
|
+
return verdict
|
|
86
|
+
|
|
87
|
+
def refused(url: str, why: str) -> dict[str, Any]:
|
|
88
|
+
return {"schema": SCHEMA, "status": "error", "exit_code": 2, "summary": why, "url": url,
|
|
89
|
+
"backend": "", "judge": "", "checks": [], "bugs": []}
|
|
90
|
+
|
|
91
|
+
def request_for(url: str, allow_remote: bool, **fields) -> VerifyRequest | str:
|
|
92
|
+
url = with_scheme(url)
|
|
93
|
+
host = urlsplit(url).hostname or url
|
|
94
|
+
if not allow_remote and not _is_local_host(host):
|
|
95
|
+
return (f"Not checking {host}: checks click buttons and submit forms like a user. "
|
|
96
|
+
"Use a local or staging site, and pass allow_remote=true to confirm.")
|
|
97
|
+
return VerifyRequest(url=url, secrets=secrets,
|
|
98
|
+
screenshot_dir=Path(repo) / ".fusiontest" / "screenshots", **fields)
|
|
99
|
+
|
|
100
|
+
@server.tool(annotations=acts)
|
|
101
|
+
def verify_change(url: str, diff: str | None = None, git_range: str | None = None,
|
|
102
|
+
intent: str = "", login: str | None = None, max_checks: int = 6,
|
|
103
|
+
find_bugs: bool = False, save_to: str | None = None,
|
|
104
|
+
allow_remote: bool = False) -> dict[str, Any]:
|
|
105
|
+
"""Check that a code change does what it promises, in the running app.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
url: The running app, e.g. http://localhost:5173 (your dev server).
|
|
109
|
+
diff: The change as a unified diff. Default: `git diff HEAD` in the
|
|
110
|
+
repository (your uncommitted changes), or `git diff <git_range>`.
|
|
111
|
+
git_range: Verify committed changes instead, e.g. "main...HEAD".
|
|
112
|
+
intent: What the change is for (task, PR description). Improves the checks.
|
|
113
|
+
login: A sign-in goal run before each check, with {{VAR}} placeholders
|
|
114
|
+
for secrets, e.g. "Sign in with {{EMAIL}} and {{PASSWORD}}".
|
|
115
|
+
max_checks: At most this many checks (1-12).
|
|
116
|
+
find_bugs: Also report confirmed bugs (crashes, server errors) seen while checking.
|
|
117
|
+
save_to: A goals file to add passing checks to, for regression runs.
|
|
118
|
+
allow_remote: Required to check a host that isn't local.
|
|
119
|
+
"""
|
|
120
|
+
if not diff:
|
|
121
|
+
try:
|
|
122
|
+
diff = read_change(git_range=git_range, cwd=repo)
|
|
123
|
+
except RuntimeError as exc:
|
|
124
|
+
if not intent:
|
|
125
|
+
return refused(url, str(exc))
|
|
126
|
+
diff = ""
|
|
127
|
+
req = request_for(url, allow_remote, diff=diff, intent=intent, login=login,
|
|
128
|
+
max_goals=max(1, min(max_checks, 12)), find_bugs=find_bugs)
|
|
129
|
+
return refused(url, req) if isinstance(req, str) else finish(req, save_to)
|
|
130
|
+
|
|
131
|
+
@server.tool(annotations=acts)
|
|
132
|
+
def run_goals(url: str, goals: list[str], login: str | None = None,
|
|
133
|
+
find_bugs: bool = False, save_to: str | None = None,
|
|
134
|
+
allow_remote: bool = False) -> dict[str, Any]:
|
|
135
|
+
"""Run checks you wrote, each a plain-English goal ending in what to
|
|
136
|
+
verify, e.g. "Add Blue Mug to the cart and verify the cart shows 1 item".
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
url: The running app; each goal starts from this page.
|
|
140
|
+
goals: The goals to check, in order.
|
|
141
|
+
login: A sign-in goal run before each check ({{VAR}} placeholders for secrets).
|
|
142
|
+
find_bugs: Also report confirmed bugs seen while checking.
|
|
143
|
+
save_to: A goals file to add passing checks to, for regression runs.
|
|
144
|
+
allow_remote: Required to check a host that isn't local.
|
|
145
|
+
"""
|
|
146
|
+
if not goals:
|
|
147
|
+
return refused(url, "No goals given.")
|
|
148
|
+
req = request_for(url, allow_remote, goals=list(goals), login=login, find_bugs=find_bugs)
|
|
149
|
+
return refused(url, req) if isinstance(req, str) else finish(req, save_to)
|
|
150
|
+
|
|
151
|
+
@server.tool(annotations=acts)
|
|
152
|
+
def scan_site(url: str, max_flows: int = 8, login: str | None = None,
|
|
153
|
+
save_to: str | None = None, allow_remote: bool = False) -> dict[str, Any]:
|
|
154
|
+
"""Map what works on a site: find its main flows from its pages and
|
|
155
|
+
check each one. Useful before changing an app you don't know yet.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
url: The site's start page.
|
|
159
|
+
max_flows: How many flows to find and check (1-20).
|
|
160
|
+
login: A sign-in goal run first ({{VAR}} placeholders for secrets).
|
|
161
|
+
save_to: A goals file to add the flows that work to.
|
|
162
|
+
allow_remote: Required to check a host that isn't local.
|
|
163
|
+
"""
|
|
164
|
+
req = request_for(url, allow_remote, login=login)
|
|
165
|
+
if isinstance(req, str):
|
|
166
|
+
return refused(url, req)
|
|
167
|
+
try:
|
|
168
|
+
flows = _discover(req, max(1, min(max_flows, 20)), adapter_factory)
|
|
169
|
+
except Exception as exc: # noqa: BLE001 — reported, not raised
|
|
170
|
+
return refused(req.url, f"Couldn't find flows: {exc}")
|
|
171
|
+
req.goals = [f.text for f in flows]
|
|
172
|
+
return finish(req, save_to)
|
|
173
|
+
|
|
174
|
+
@server.tool(annotations=ToolAnnotations(read_only_hint=True, open_world_hint=False))
|
|
175
|
+
def last_report(index: int = -1) -> dict[str, Any]:
|
|
176
|
+
"""A verdict this server returned earlier (index -1: the latest), e.g.
|
|
177
|
+
to re-read reasons or screenshot paths."""
|
|
178
|
+
if not reports:
|
|
179
|
+
return {"schema": SCHEMA, "status": "error", "summary": "No checks have run yet."}
|
|
180
|
+
try:
|
|
181
|
+
return reports[index]
|
|
182
|
+
except IndexError:
|
|
183
|
+
return {"schema": SCHEMA, "status": "error",
|
|
184
|
+
"summary": f"No report {index}: {len(reports)} kept."}
|
|
185
|
+
|
|
186
|
+
return server
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _discover(request: VerifyRequest, max_flows: int, adapter_factory: AdapterFactory | None):
|
|
190
|
+
from fusiontest.agent.verify import _playwright, _signed_in_snapshot, _stop
|
|
191
|
+
from fusiontest.core.action_model import resolve_judge_backend
|
|
192
|
+
from fusiontest.discovery.goal_generator import (
|
|
193
|
+
GoalGenerator,
|
|
194
|
+
GoalGeneratorConfig,
|
|
195
|
+
_primary_backend,
|
|
196
|
+
snapshot_site,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
config = GoalGeneratorConfig(max_goals=max_flows)
|
|
200
|
+
factory = adapter_factory or _playwright
|
|
201
|
+
backend = _primary_backend(request.backend)
|
|
202
|
+
if request.login:
|
|
203
|
+
snapshot = _signed_in_snapshot(request, backend, resolve_judge_backend(backend), factory,
|
|
204
|
+
config)
|
|
205
|
+
else:
|
|
206
|
+
adapter = factory(request.url)
|
|
207
|
+
try:
|
|
208
|
+
snapshot = snapshot_site(request.url, config, adapter=adapter)
|
|
209
|
+
snapshot.signed_in = False
|
|
210
|
+
finally:
|
|
211
|
+
_stop(adapter)
|
|
212
|
+
return GoalGenerator(config).generate(request.url, preferred_backend=backend, snapshot=snapshot)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _config_secrets(repo: str) -> dict[str, str]:
|
|
216
|
+
"""`secrets:` from the repository's fusiontest.config.yaml, as for the CLI."""
|
|
217
|
+
import yaml
|
|
218
|
+
|
|
219
|
+
path = Path(repo) / "fusiontest.config.yaml"
|
|
220
|
+
if not path.exists():
|
|
221
|
+
return {}
|
|
222
|
+
cfg = yaml.safe_load(path.read_text()) or {}
|
|
223
|
+
return {str(k): os.getenv(str(v), str(v)) for k, v in (cfg.get("secrets") or {}).items()}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _is_local_host(host: str) -> bool:
|
|
227
|
+
host = (host or "").lower().strip("[]")
|
|
228
|
+
return host in ("localhost", "127.0.0.1", "::1") or host.endswith(
|
|
229
|
+
(".localhost", ".test", ".local", ".internal"))
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def serve(cwd: str | None = None) -> None:
|
|
233
|
+
"""Run the server over stdio (what `fusiontest mcp` does)."""
|
|
234
|
+
# stdout is the protocol channel: logs go to stderr.
|
|
235
|
+
logging.basicConfig(level=logging.WARNING, format="%(levelname)s %(name)s: %(message)s")
|
|
236
|
+
build_server(cwd=cwd).run("stdio")
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"""
|
|
2
|
+
fusiontest/agent/verify.py
|
|
3
|
+
|
|
4
|
+
Verify a change in the running app (ADR-010): turn a diff (or given goals)
|
|
5
|
+
into goals, run them with the judge, and return one machine-readable verdict.
|
|
6
|
+
Shared by `fusiontest verify` and the MCP server, so both answer the same way.
|
|
7
|
+
|
|
8
|
+
The verdict is a plain dict with a versioned schema ("fusiontest.verify/1"),
|
|
9
|
+
so agents and scripts can rely on its keys:
|
|
10
|
+
|
|
11
|
+
status passed | failed | error | nothing_to_verify
|
|
12
|
+
exit_code 0 passed or nothing to verify · 1 a check failed · 2 couldn't
|
|
13
|
+
evaluate (LLM capacity, infrastructure) — as for `fusiontest run`
|
|
14
|
+
summary one sentence
|
|
15
|
+
checks one per goal: goal, why, source (diff | site | given), outcome
|
|
16
|
+
(pass | fail | error), reason, steps, screenshot (path | null)
|
|
17
|
+
bugs confirmed bugs (with find_bugs), as on the dashboard
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
import re
|
|
24
|
+
from collections.abc import Callable
|
|
25
|
+
from dataclasses import dataclass, field
|
|
26
|
+
from datetime import datetime, timezone
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
from urllib.parse import urlsplit
|
|
29
|
+
|
|
30
|
+
import yaml
|
|
31
|
+
|
|
32
|
+
SCHEMA = "fusiontest.verify/1"
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
AdapterFactory = Callable[[str], object] # url -> a started adapter on that page
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class VerifyRequest:
|
|
41
|
+
url: str
|
|
42
|
+
diff: str = ""
|
|
43
|
+
intent: str = "" # what the change is for (e.g. the PR description)
|
|
44
|
+
goals: list[str] = field(default_factory=list) # given goals: no generation
|
|
45
|
+
login: str | None = None # a sign-in goal run before each check
|
|
46
|
+
backend: str | None = None # action model; None: the first with a key
|
|
47
|
+
judge: str | None = None # None: resolve_judge_backend's default
|
|
48
|
+
max_goals: int = 6
|
|
49
|
+
find_bugs: bool = False
|
|
50
|
+
secrets: dict[str, str] = field(default_factory=dict)
|
|
51
|
+
screenshot_dir: Path | None = None
|
|
52
|
+
trace_store: object | None = None # recordings for checks that pass (to watch them)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class _Check:
|
|
57
|
+
goal: str
|
|
58
|
+
why: str
|
|
59
|
+
source: str
|
|
60
|
+
name: str = ""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def verify(request: VerifyRequest, adapter_factory: AdapterFactory | None = None,
|
|
64
|
+
on_progress: Callable[[str], None] | None = None) -> dict:
|
|
65
|
+
"""Plan the checks, run them, and return the verdict dict. Never raises for
|
|
66
|
+
an app or LLM problem: those come back as status "error" with the reason."""
|
|
67
|
+
from fusiontest.core.action_model import resolve_judge_backend
|
|
68
|
+
from fusiontest.discovery.goal_generator import GoalGenerationError, _primary_backend
|
|
69
|
+
|
|
70
|
+
say = on_progress or (lambda _msg: None)
|
|
71
|
+
factory = adapter_factory or _playwright
|
|
72
|
+
try:
|
|
73
|
+
backend = _primary_backend(request.backend)
|
|
74
|
+
judge = resolve_judge_backend(backend, request.judge)
|
|
75
|
+
except (GoalGenerationError, ValueError) as exc:
|
|
76
|
+
return _verdict(request, "error", 2, str(exc))
|
|
77
|
+
|
|
78
|
+
if request.goals:
|
|
79
|
+
checks = [_Check(goal=g, why="given", source="given") for g in request.goals]
|
|
80
|
+
else:
|
|
81
|
+
say("Reading the change and the running site...")
|
|
82
|
+
try:
|
|
83
|
+
plan = _plan(request, backend, judge, factory)
|
|
84
|
+
except GoalGenerationError as exc:
|
|
85
|
+
return _verdict(request, "error", 2, f"Couldn't plan checks: {exc}",
|
|
86
|
+
backend=backend, judge=judge)
|
|
87
|
+
if not plan.goals:
|
|
88
|
+
return _verdict(request, "nothing_to_verify", 0,
|
|
89
|
+
f"Nothing to verify in the UI: {plan.no_ui_change}",
|
|
90
|
+
backend=backend, judge=judge)
|
|
91
|
+
checks = [_Check(goal=g.text, why=g.why, source=g.source, name=g.name) for g in plan.goals]
|
|
92
|
+
|
|
93
|
+
say(f"Running {len(checks)} check(s)...")
|
|
94
|
+
try:
|
|
95
|
+
result = _run(request, checks, backend, judge, factory)
|
|
96
|
+
except Exception as exc: # noqa: BLE001 — the browser or app couldn't be driven
|
|
97
|
+
logger.exception("verify: run failed")
|
|
98
|
+
return _verdict(request, "error", 2, f"Couldn't run the checks: {exc}",
|
|
99
|
+
backend=backend, judge=judge,
|
|
100
|
+
checks=[_check_dict(c, None, None) for c in checks])
|
|
101
|
+
return _report(request, checks, result, backend, judge)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# ── Planning ─────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
def _plan(request: VerifyRequest, backend: str, judge: str, factory: AdapterFactory):
|
|
107
|
+
from fusiontest.discovery.goal_generator import GoalGeneratorConfig, snapshot_site
|
|
108
|
+
from fusiontest.discovery.intent import goals_from_change
|
|
109
|
+
|
|
110
|
+
config = GoalGeneratorConfig()
|
|
111
|
+
if request.login:
|
|
112
|
+
snapshot = _signed_in_snapshot(request, backend, judge, factory, config)
|
|
113
|
+
else:
|
|
114
|
+
adapter = factory(request.url)
|
|
115
|
+
try:
|
|
116
|
+
snapshot = snapshot_site(request.url, config, adapter=adapter)
|
|
117
|
+
snapshot.signed_in = False
|
|
118
|
+
finally:
|
|
119
|
+
_stop(adapter)
|
|
120
|
+
return goals_from_change(request.diff, snapshot, intent=request.intent, backend=backend,
|
|
121
|
+
judge=judge, max_goals=request.max_goals)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _signed_in_snapshot(request, backend, judge, factory, config):
|
|
125
|
+
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
126
|
+
from fusiontest.discovery.goal_generator import GoalGenerationError, snapshot_site
|
|
127
|
+
|
|
128
|
+
adapter = factory(request.url)
|
|
129
|
+
try:
|
|
130
|
+
signed_in = FusionTestRunner(adapter, RunnerConfig(
|
|
131
|
+
backend=backend, judge_backend=judge, secrets=request.secrets,
|
|
132
|
+
screenshot_on_failure=False, trace_store=None,
|
|
133
|
+
)).run(goals=[request.login], name="Sign in", platform="playwright", url=request.url)
|
|
134
|
+
step = signed_in.steps[0] if signed_in.steps else None
|
|
135
|
+
if step is None or not step.success:
|
|
136
|
+
why = (step.error if step else signed_in.error) or "the sign-in goal didn't complete"
|
|
137
|
+
raise GoalGenerationError(f"Couldn't sign in: {why}")
|
|
138
|
+
return snapshot_site(request.url, config, adapter=adapter)
|
|
139
|
+
finally:
|
|
140
|
+
_stop(adapter)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# ── Running ──────────────────────────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
def _run(request: VerifyRequest, checks: list[_Check], backend: str, judge: str,
|
|
146
|
+
factory: AdapterFactory):
|
|
147
|
+
from fusiontest.core.runner import FusionTestRunner, RunnerConfig
|
|
148
|
+
|
|
149
|
+
runner = FusionTestRunner(factory(request.url), RunnerConfig(
|
|
150
|
+
backend=backend,
|
|
151
|
+
judge_backend=judge,
|
|
152
|
+
secrets=request.secrets,
|
|
153
|
+
screenshot_on_failure=True,
|
|
154
|
+
# Every check goes through the AI (it's a change being verified, not a
|
|
155
|
+
# replay); passing ones are recorded so they can be watched afterwards.
|
|
156
|
+
trace_store=request.trace_store, # type: ignore[arg-type]
|
|
157
|
+
reverify_every=0,
|
|
158
|
+
detect_bugs=request.find_bugs,
|
|
159
|
+
fresh_adapter=(lambda: factory(request.url)) if request.find_bugs else None,
|
|
160
|
+
))
|
|
161
|
+
if request.login:
|
|
162
|
+
goals = [g for c in checks for g in (request.login, c.goal)]
|
|
163
|
+
goal_urls = [u for _ in checks for u in (request.url, None)]
|
|
164
|
+
run_url = ""
|
|
165
|
+
else:
|
|
166
|
+
goals, goal_urls, run_url = [c.goal for c in checks], None, request.url
|
|
167
|
+
try:
|
|
168
|
+
return runner.run(goals=goals, goal_urls=goal_urls, name=f"Verify: {_host(request.url)}",
|
|
169
|
+
platform="playwright", url=run_url)
|
|
170
|
+
finally:
|
|
171
|
+
_stop(runner.adapter)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# ── The verdict ──────────────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
def _report(request: VerifyRequest, checks: list[_Check], result, backend: str, judge: str) -> dict:
|
|
177
|
+
stride, offset = (2, 1) if request.login else (1, 0)
|
|
178
|
+
shot_dir = _shot_dir(request)
|
|
179
|
+
out: list[dict] = []
|
|
180
|
+
for i, check in enumerate(checks):
|
|
181
|
+
login = result.steps[i * 2] if request.login and i * 2 < len(result.steps) else None
|
|
182
|
+
index = i * stride + offset
|
|
183
|
+
step = result.steps[index] if index < len(result.steps) else None
|
|
184
|
+
if login is not None and not login.success:
|
|
185
|
+
out.append(_check_dict(check, login, None, signed_in=False))
|
|
186
|
+
continue
|
|
187
|
+
shot = _save_shot(shot_dir, i, check.goal, step) if step is not None else None
|
|
188
|
+
out.append(_check_dict(check, step, shot))
|
|
189
|
+
if result.error and not any(c["outcome"] == "fail" for c in out):
|
|
190
|
+
logger.info("verify: run stopped early: %s", result.error)
|
|
191
|
+
|
|
192
|
+
failed = sum(c["outcome"] == "fail" for c in out)
|
|
193
|
+
errored = sum(c["outcome"] == "error" for c in out)
|
|
194
|
+
passed = sum(c["outcome"] == "pass" for c in out)
|
|
195
|
+
if failed:
|
|
196
|
+
status, code = "failed", 1
|
|
197
|
+
elif errored:
|
|
198
|
+
status, code = "error", 2
|
|
199
|
+
else:
|
|
200
|
+
status, code = "passed", 0
|
|
201
|
+
summary = f"{passed} of {len(out)} check(s) passed"
|
|
202
|
+
if failed:
|
|
203
|
+
summary += f", {failed} failed"
|
|
204
|
+
if errored:
|
|
205
|
+
summary += f", {errored} couldn't be evaluated"
|
|
206
|
+
if result.error and errored:
|
|
207
|
+
summary += f" ({result.error[:200]})"
|
|
208
|
+
verdict = _verdict(request, status, code, summary + ".", backend=backend, judge=judge,
|
|
209
|
+
checks=out)
|
|
210
|
+
verdict["bugs"] = [b.to_dict() for b in result.bugs_detected]
|
|
211
|
+
return verdict
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _check_dict(check: _Check, step, screenshot: Path | None, signed_in: bool = True) -> dict:
|
|
215
|
+
if step is None:
|
|
216
|
+
outcome, reason, steps = "error", "Not run.", 0
|
|
217
|
+
elif not signed_in:
|
|
218
|
+
outcome, reason, steps = ("error" if step.infra_error else "fail",
|
|
219
|
+
f"Couldn't sign in first: {step.error}", step.steps_taken)
|
|
220
|
+
else:
|
|
221
|
+
outcome = "error" if step.infra_error else ("pass" if step.success else "fail")
|
|
222
|
+
reason = (step.judge_reason if step.success else step.error) or step.judge_reason
|
|
223
|
+
steps = step.steps_taken
|
|
224
|
+
return {
|
|
225
|
+
"name": check.name or check.goal[:60],
|
|
226
|
+
"goal": check.goal,
|
|
227
|
+
"why": check.why,
|
|
228
|
+
"source": check.source,
|
|
229
|
+
"outcome": outcome,
|
|
230
|
+
"reason": reason,
|
|
231
|
+
"steps": steps,
|
|
232
|
+
"actions": list(step.actions) if step is not None else [],
|
|
233
|
+
"flaky": bool(getattr(step, "flaky", False)),
|
|
234
|
+
"screenshot": str(screenshot) if screenshot else None,
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _verdict(request: VerifyRequest, status: str, code: int, summary: str, *,
|
|
239
|
+
backend: str = "", judge: str = "", checks: list[dict] | None = None) -> dict:
|
|
240
|
+
return {
|
|
241
|
+
"schema": SCHEMA,
|
|
242
|
+
"status": status,
|
|
243
|
+
"exit_code": code,
|
|
244
|
+
"summary": summary,
|
|
245
|
+
"url": request.url,
|
|
246
|
+
"backend": backend,
|
|
247
|
+
"judge": judge,
|
|
248
|
+
"checks": checks or [],
|
|
249
|
+
"bugs": [],
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _shot_dir(request: VerifyRequest) -> Path | None:
|
|
254
|
+
if request.screenshot_dir is None:
|
|
255
|
+
return None
|
|
256
|
+
return request.screenshot_dir / datetime.now(timezone.utc).strftime("verify-%Y%m%dT%H%M%SZ")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _save_shot(root: Path | None, i: int, goal: str, step) -> Path | None:
|
|
260
|
+
if root is None or step.success or not step.screenshots:
|
|
261
|
+
return None
|
|
262
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
263
|
+
slug = re.sub(r"[^a-z0-9]+", "-", goal.lower()).strip("-")[:50] or "check"
|
|
264
|
+
path = root / f"{i + 1:02d}-{slug}.png"
|
|
265
|
+
path.write_bytes(step.screenshots[-1])
|
|
266
|
+
return path
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
# ── Watching: keep passing checks as regression goals ────────────────────────
|
|
270
|
+
|
|
271
|
+
def save_passing(verdict: dict, path: Path, login: str | None = None) -> int:
|
|
272
|
+
"""Add the checks that passed to a goals file (created if missing), so they
|
|
273
|
+
run on every deploy. Returns how many were added (duplicates are skipped)."""
|
|
274
|
+
url = verdict["url"]
|
|
275
|
+
data = (yaml.safe_load(path.read_text()) or {}) if path.exists() else {}
|
|
276
|
+
goals = data.setdefault("goals", [])
|
|
277
|
+
existing = {g.get("goal") if isinstance(g, dict) else g for g in goals}
|
|
278
|
+
file_url = data.get("url")
|
|
279
|
+
if not path.exists() and not login:
|
|
280
|
+
data["url"] = file_url = url
|
|
281
|
+
added = 0
|
|
282
|
+
for check in verdict["checks"]:
|
|
283
|
+
if check["outcome"] != "pass" or check["goal"] in existing:
|
|
284
|
+
continue
|
|
285
|
+
entry = {"name": check["name"], "goal": check["goal"]}
|
|
286
|
+
if login:
|
|
287
|
+
goals.append({"name": "Sign in", "url": url, "goal": login})
|
|
288
|
+
elif file_url != url:
|
|
289
|
+
entry["url"] = url
|
|
290
|
+
goals.append(entry)
|
|
291
|
+
existing.add(check["goal"])
|
|
292
|
+
added += 1
|
|
293
|
+
if added:
|
|
294
|
+
header = "" if path.exists() else (
|
|
295
|
+
"# Checks that passed when FusionTest verified a change.\n"
|
|
296
|
+
f"# Run them on every deploy: fusiontest run -f {path}\n")
|
|
297
|
+
ordered = {"url": data["url"], **data} if "url" in data else data
|
|
298
|
+
path.write_text(header + yaml.safe_dump(ordered, sort_keys=False, allow_unicode=True))
|
|
299
|
+
return added
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
# ── Reading the change ───────────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
def read_change(diff_path: str | None = None, git_range: str | None = None,
|
|
305
|
+
cwd: str | None = None) -> str:
|
|
306
|
+
"""The change to verify: a diff file, a git range, or (by default) the
|
|
307
|
+
uncommitted changes in the repository at `cwd`. Raises RuntimeError with
|
|
308
|
+
a message for the user when there's nothing to read."""
|
|
309
|
+
import subprocess
|
|
310
|
+
|
|
311
|
+
if diff_path:
|
|
312
|
+
return Path(diff_path).read_text()
|
|
313
|
+
args = ["git", "diff", git_range] if git_range else ["git", "diff", "HEAD"]
|
|
314
|
+
try:
|
|
315
|
+
done = subprocess.run(args, capture_output=True, text=True, check=False, cwd=cwd) # noqa: S603
|
|
316
|
+
except FileNotFoundError as exc:
|
|
317
|
+
raise RuntimeError("git isn't installed: pass the change as a diff") from exc
|
|
318
|
+
if done.returncode != 0:
|
|
319
|
+
raise RuntimeError(f"`{' '.join(args)}` failed: {done.stderr.strip()[:300]}")
|
|
320
|
+
if not done.stdout.strip():
|
|
321
|
+
raise RuntimeError(f"`{' '.join(args)}` is empty: nothing changed to verify "
|
|
322
|
+
"(give a git range for committed changes, or goals to check)")
|
|
323
|
+
return done.stdout
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
# ── Helpers ──────────────────────────────────────────────────────────────────
|
|
327
|
+
|
|
328
|
+
def _playwright(url: str):
|
|
329
|
+
from fusiontest.desktop.playwright_adapter import PlaywrightAdapter
|
|
330
|
+
adapter = PlaywrightAdapter(browser_type="chromium", headless=True)
|
|
331
|
+
adapter.start(url=url)
|
|
332
|
+
return adapter
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _stop(adapter) -> None:
|
|
336
|
+
stop = getattr(adapter, "stop", None)
|
|
337
|
+
if callable(stop):
|
|
338
|
+
try:
|
|
339
|
+
stop()
|
|
340
|
+
except Exception: # noqa: BLE001 — the browser may already be gone
|
|
341
|
+
pass
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def with_scheme(url: str) -> str:
|
|
345
|
+
"""http:// for a bare host or host:port ("localhost:5173" parses as a
|
|
346
|
+
scheme, so urlsplit alone can't tell)."""
|
|
347
|
+
return url if "://" in url else f"http://{url}"
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _host(url: str) -> str:
|
|
351
|
+
return urlsplit(url).hostname or url
|