fusiontest 0.2.16__tar.gz → 0.2.18__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.16 → fusiontest-0.2.18}/PKG-INFO +1 -1
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/bench/__init__.py +72 -2
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/cli.py +121 -6
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/PKG-INFO +1 -1
- {fusiontest-0.2.16 → fusiontest-0.2.18}/pyproject.toml +1 -1
- {fusiontest-0.2.16 → fusiontest-0.2.18}/README.md +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/bench/sites/shop/index.html +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/bench/suites/shop.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/bench/suites/todomvc.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/action_model.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/goal_verifier.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/netguard.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/replay.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/runner.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/screen_parser.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/secrets.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/core/tokens.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/fusiontest_dashboard.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/github.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/hacker_news.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/httpbin.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/todomvc.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/demos/wikipedia.yaml +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/desktop/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/desktop/macos_adapter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/desktop/playwright_adapter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/desktop/windows_adapter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/discovery/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/discovery/goal_generator.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/guardrails/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/guardrails/engine.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/mobile/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/mobile/android_adapter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/mobile/ios_adapter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/reporting/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/reporting/reporter.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/training/__init__.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/training/data_collector.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/training/dataset_builder.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest/training/trainer.py +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/SOURCES.txt +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/dependency_links.txt +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/entry_points.txt +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/not-zip-safe +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/requires.txt +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/fusiontest.egg-info/top_level.txt +0 -0
- {fusiontest-0.2.16 → fusiontest-0.2.18}/setup.cfg +0 -0
|
@@ -19,6 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
|
|
20
20
|
import functools
|
|
21
21
|
import http.server
|
|
22
|
+
import json
|
|
22
23
|
import threading
|
|
23
24
|
from collections.abc import Callable, Iterator
|
|
24
25
|
from contextlib import contextmanager
|
|
@@ -119,6 +120,8 @@ class CaseResult:
|
|
|
119
120
|
steps: int = 0
|
|
120
121
|
seconds: float = 0.0
|
|
121
122
|
tokens: int = 0
|
|
123
|
+
input_tokens: int = 0
|
|
124
|
+
output_tokens: int = 0
|
|
122
125
|
error: str = ""
|
|
123
126
|
actions: list[str] = field(default_factory=list) # what the model did (secrets redacted)
|
|
124
127
|
|
|
@@ -139,6 +142,7 @@ def score_cases(suite: Suite, run: RunResult) -> list[CaseResult]:
|
|
|
139
142
|
results.append(CaseResult(
|
|
140
143
|
goal=case.goal, expect=case.expect, outcome=outcome, steps=step.steps_taken,
|
|
141
144
|
seconds=round(step.duration_seconds, 2), tokens=step.token_usage.total_tokens,
|
|
145
|
+
input_tokens=step.token_usage.input_tokens, output_tokens=step.token_usage.output_tokens,
|
|
142
146
|
error=step.error, actions=list(step.actions),
|
|
143
147
|
))
|
|
144
148
|
return results
|
|
@@ -153,6 +157,8 @@ class SuiteRun:
|
|
|
153
157
|
cases: list[CaseResult]
|
|
154
158
|
llm_calls: dict[str, int] = field(default_factory=dict)
|
|
155
159
|
seconds: float = 0.0
|
|
160
|
+
cost_usd: float | None = None # None when the model's price isn't known
|
|
161
|
+
stopped_for_budget: bool = False
|
|
156
162
|
|
|
157
163
|
def to_dict(self) -> dict:
|
|
158
164
|
return {**asdict(self), "cases": [{**asdict(c), "correct": c.correct} for c in self.cases]}
|
|
@@ -208,6 +214,51 @@ def summarize(runs: list[SuiteRun]) -> Summary:
|
|
|
208
214
|
)
|
|
209
215
|
|
|
210
216
|
|
|
217
|
+
# ── Cost ───────────────────────────────────────────────────────────────────────
|
|
218
|
+
|
|
219
|
+
# USD per million tokens (input, output) for the model each backend is pinned to.
|
|
220
|
+
# Anthropic list prices; keep in step with default_model_for_backend(). Backends
|
|
221
|
+
# without an entry (free-tier Groq, local Ollama, …) have no known cost and can't
|
|
222
|
+
# run under a cost limit.
|
|
223
|
+
PRICES_PER_MTOK: dict[str, tuple[float, float]] = {
|
|
224
|
+
"claude-sonnet-4-6": (3.00, 15.00),
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def model_price(backend: str) -> tuple[float, float] | None:
|
|
229
|
+
from fusiontest.core.action_model import default_model_for_backend
|
|
230
|
+
return PRICES_PER_MTOK.get(default_model_for_backend(backend))
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def cost_of(input_tokens: int, output_tokens: int, price: tuple[float, float]) -> float:
|
|
234
|
+
return (input_tokens * price[0] + output_tokens * price[1]) / 1_000_000
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class Ledger:
|
|
238
|
+
"""Month-to-date benchmark spend, persisted as JSON (CI keeps it in the cache).
|
|
239
|
+
|
|
240
|
+
A new calendar month (UTC) starts from zero.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
def __init__(self, path: Path, month: str):
|
|
244
|
+
self.path, self.month = path, month
|
|
245
|
+
self.spent_usd, self.runs = 0.0, 0
|
|
246
|
+
try:
|
|
247
|
+
data = json.loads(path.read_text())
|
|
248
|
+
except (OSError, ValueError):
|
|
249
|
+
data = {}
|
|
250
|
+
if data.get("month") == month:
|
|
251
|
+
self.spent_usd = float(data.get("spent_usd", 0.0))
|
|
252
|
+
self.runs = int(data.get("runs", 0))
|
|
253
|
+
|
|
254
|
+
def add(self, usd: float) -> None:
|
|
255
|
+
self.spent_usd = round(self.spent_usd + usd, 4)
|
|
256
|
+
self.runs += 1
|
|
257
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
258
|
+
self.path.write_text(json.dumps(
|
|
259
|
+
{"month": self.month, "spent_usd": self.spent_usd, "runs": self.runs}, indent=2))
|
|
260
|
+
|
|
261
|
+
|
|
211
262
|
# ── Running ────────────────────────────────────────────────────────────────────
|
|
212
263
|
|
|
213
264
|
AdapterFactory = Callable[[str, str], object] # (platform, url) -> started adapter
|
|
@@ -219,15 +270,32 @@ def run_suite(
|
|
|
219
270
|
adapter_factory: AdapterFactory,
|
|
220
271
|
repeat: int = 1,
|
|
221
272
|
runner_factory: Callable[..., FusionTestRunner] = FusionTestRunner,
|
|
273
|
+
max_cost_usd: float | None = None,
|
|
222
274
|
) -> SuiteRun:
|
|
223
275
|
"""One pass over the suite in a fresh app session.
|
|
224
276
|
|
|
225
277
|
Replay is off (no trace store) and the backend is pinned to its default
|
|
226
278
|
model with no fallback, so the model named is the model measured. When it
|
|
227
279
|
is rate-limited, cases become errors — reported, but not scored.
|
|
280
|
+
|
|
281
|
+
max_cost_usd: stop before the next case once this run's spend reaches it
|
|
282
|
+
(the remaining cases are reported as not run). Requires a priced model.
|
|
228
283
|
"""
|
|
229
284
|
import time
|
|
230
285
|
|
|
286
|
+
price = model_price(backend)
|
|
287
|
+
if max_cost_usd is not None and price is None:
|
|
288
|
+
raise ValueError(f"No price known for {backend}'s model; can't enforce a cost limit")
|
|
289
|
+
spent = 0.0
|
|
290
|
+
cancel = threading.Event()
|
|
291
|
+
|
|
292
|
+
def on_goal_done(_i: int, _n: int, step: StepResult) -> None:
|
|
293
|
+
nonlocal spent
|
|
294
|
+
if price is not None:
|
|
295
|
+
spent += cost_of(step.token_usage.input_tokens, step.token_usage.output_tokens, price)
|
|
296
|
+
if max_cost_usd is not None and spent >= max_cost_usd:
|
|
297
|
+
cancel.set()
|
|
298
|
+
|
|
231
299
|
with (serve_site(suite.site) if suite.site else _nullcontext(suite.url)) as url, \
|
|
232
300
|
_pinned_chain(backend):
|
|
233
301
|
adapter = adapter_factory(suite.platform, url)
|
|
@@ -239,7 +307,7 @@ def run_suite(
|
|
|
239
307
|
# No url= here: the runner would reload it before every goal, and
|
|
240
308
|
# cases share state (signed in, cart contents).
|
|
241
309
|
run = runner.run(goals=[c.goal for c in suite.cases], name=f"bench:{suite.name}",
|
|
242
|
-
platform=suite.platform)
|
|
310
|
+
platform=suite.platform, on_goal_done=on_goal_done, cancel_event=cancel)
|
|
243
311
|
elapsed = time.time() - start
|
|
244
312
|
finally:
|
|
245
313
|
stop = getattr(adapter, "stop", None)
|
|
@@ -250,7 +318,9 @@ def run_suite(
|
|
|
250
318
|
pass
|
|
251
319
|
return SuiteRun(suite=suite.name, suite_version=suite.version, backend=backend, repeat=repeat,
|
|
252
320
|
cases=score_cases(suite, run), llm_calls=dict(run.llm_calls),
|
|
253
|
-
seconds=round(elapsed, 1)
|
|
321
|
+
seconds=round(elapsed, 1),
|
|
322
|
+
cost_usd=round(spent, 4) if price is not None else None,
|
|
323
|
+
stopped_for_budget=cancel.is_set())
|
|
254
324
|
|
|
255
325
|
|
|
256
326
|
@contextmanager
|
|
@@ -480,8 +480,23 @@ _BACKENDS = ["gpt4o", "claude", "gemini", "groq", "ollama"]
|
|
|
480
480
|
show_default=True, help="Where to write the results JSON")
|
|
481
481
|
@click.option("--min-accuracy", type=click.FloatRange(0, 1), default=None,
|
|
482
482
|
help="Exit 1 if any suite × backend scores below this (e.g. 0.9) or has a false pass")
|
|
483
|
+
@click.option("--max-cost", type=click.FloatRange(min=0), default=None,
|
|
484
|
+
help="Stop once this invocation has spent this many USD (checked after every goal)")
|
|
485
|
+
@click.option("--monthly-limit", type=click.FloatRange(min=0), default=None,
|
|
486
|
+
help="USD per calendar month across invocations; needs --ledger")
|
|
487
|
+
@click.option("--ledger", "ledger_path", type=click.Path(dir_okay=False), default=None,
|
|
488
|
+
help="JSON file recording month-to-date spend (for --monthly-limit)")
|
|
489
|
+
@click.option("--summary-md", type=click.Path(dir_okay=False), default=None,
|
|
490
|
+
help="Also write the summary as Markdown (e.g. $GITHUB_STEP_SUMMARY)")
|
|
491
|
+
@click.option("--upload", is_flag=True,
|
|
492
|
+
help="Send results to your FusionTest dashboard (needs FUSIONTEST_API_KEY)")
|
|
493
|
+
@click.option("--source", default="cli", show_default=True,
|
|
494
|
+
help="Label stored with uploaded results, e.g. nightly")
|
|
495
|
+
@click.option("--from-results", "from_results", type=click.Path(exists=True, dir_okay=False),
|
|
496
|
+
default=None, help="Upload an existing results JSON instead of running (implies --upload)")
|
|
483
497
|
@click.option("--list", "list_suites", is_flag=True, help="List built-in suites")
|
|
484
|
-
def bench(suites, backends, repeat, headless, out_dir, min_accuracy,
|
|
498
|
+
def bench(suites, backends, repeat, headless, out_dir, min_accuracy, max_cost, monthly_limit,
|
|
499
|
+
ledger_path, summary_md, upload, source, from_results, list_suites):
|
|
485
500
|
"""Measure how well a backend runs known goals (ADR-008).
|
|
486
501
|
|
|
487
502
|
\b
|
|
@@ -505,6 +520,9 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, list_suites
|
|
|
505
520
|
return
|
|
506
521
|
|
|
507
522
|
_load_env()
|
|
523
|
+
if from_results:
|
|
524
|
+
ok = _upload_bench(json.loads(Path(from_results).read_text()), source)
|
|
525
|
+
sys.exit(0 if ok else 1)
|
|
508
526
|
try:
|
|
509
527
|
loaded = [fbench.load_suite(name) for name in (suites or fbench.builtin_suites())]
|
|
510
528
|
except ValueError as exc:
|
|
@@ -518,14 +536,49 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, list_suites
|
|
|
518
536
|
def adapter_factory(platform: str, url: str):
|
|
519
537
|
return _build_adapter(platform, None, url, headless)
|
|
520
538
|
|
|
539
|
+
# ── Budget ──
|
|
540
|
+
if monthly_limit is not None and not ledger_path:
|
|
541
|
+
console.print("[red]--monthly-limit needs --ledger[/red]")
|
|
542
|
+
sys.exit(1)
|
|
543
|
+
ledger = (fbench.Ledger(Path(ledger_path), datetime.now(timezone.utc).strftime("%Y-%m"))
|
|
544
|
+
if ledger_path else None)
|
|
545
|
+
budget = max_cost
|
|
546
|
+
if monthly_limit is not None:
|
|
547
|
+
left = round(monthly_limit - ledger.spent_usd, 4)
|
|
548
|
+
console.print(f"[dim]Month-to-date benchmark spend: ${ledger.spent_usd:.2f} of "
|
|
549
|
+
f"${monthly_limit:.2f} ({ledger.runs} runs)[/dim]")
|
|
550
|
+
if left <= 0:
|
|
551
|
+
console.print("[yellow]Monthly benchmark budget used up — skipping this run.[/yellow]")
|
|
552
|
+
return
|
|
553
|
+
budget = left if budget is None else min(budget, left)
|
|
554
|
+
if budget is not None:
|
|
555
|
+
unpriced = [b for b in backends if fbench.model_price(b) is None]
|
|
556
|
+
if unpriced:
|
|
557
|
+
console.print(f"[red]No price known for {', '.join(unpriced)}; can't run under a cost "
|
|
558
|
+
f"limit (priced models: {', '.join(fbench.PRICES_PER_MTOK)})[/red]")
|
|
559
|
+
sys.exit(1)
|
|
560
|
+
console.print(f"[dim]Budget for this run: ${budget:.2f}[/dim]")
|
|
561
|
+
|
|
521
562
|
runs: list = []
|
|
563
|
+
spent = 0.0
|
|
564
|
+
budget_hit = False
|
|
522
565
|
for suite in loaded:
|
|
523
566
|
for backend in backends:
|
|
524
567
|
for i in range(1, repeat + 1):
|
|
568
|
+
remaining = None if budget is None else round(budget - spent, 4)
|
|
569
|
+
if remaining is not None and remaining <= 0:
|
|
570
|
+
budget_hit = True
|
|
571
|
+
continue
|
|
525
572
|
console.print(f"[bold]{suite.name}[/bold] × [cyan]{backend}[/cyan] run {i}/{repeat} "
|
|
526
573
|
f"[dim]({len(suite.cases)} cases)[/dim]")
|
|
527
|
-
run = fbench.run_suite(suite, backend, adapter_factory, repeat=i
|
|
574
|
+
run = fbench.run_suite(suite, backend, adapter_factory, repeat=i,
|
|
575
|
+
max_cost_usd=remaining)
|
|
528
576
|
runs.append(run)
|
|
577
|
+
if run.cost_usd is not None:
|
|
578
|
+
spent += run.cost_usd
|
|
579
|
+
if ledger is not None:
|
|
580
|
+
ledger.add(run.cost_usd) # written per run, so a crash still counts
|
|
581
|
+
budget_hit = budget_hit or run.stopped_for_budget
|
|
529
582
|
for case in run.cases:
|
|
530
583
|
mark = "[green]✓[/green]" if case.correct else (
|
|
531
584
|
"[yellow]·[/yellow]" if case.outcome in ("error", "not_run") else "[red]✗[/red]")
|
|
@@ -536,11 +589,12 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, list_suites
|
|
|
536
589
|
for suite in loaded:
|
|
537
590
|
for backend in backends:
|
|
538
591
|
group = [r for r in runs if r.suite == suite.name and r.backend == backend]
|
|
539
|
-
|
|
592
|
+
if group:
|
|
593
|
+
summaries.append(fbench.summarize(group))
|
|
540
594
|
|
|
541
595
|
table = Table(title="Benchmark", header_style="bold", box=None, pad_edge=False)
|
|
542
596
|
for col in ("Suite", "Backend", "Accuracy", "False pass", "False fail", "Errors",
|
|
543
|
-
"Consistent", "Steps/case", "Calls/case", "Tokens/case", "Sec/case"):
|
|
597
|
+
"Consistent", "Steps/case", "Calls/case", "Tokens/case", "Sec/case", "Cost"):
|
|
544
598
|
table.add_column(col, justify="left" if col in ("Suite", "Backend") else "right")
|
|
545
599
|
for sm in summaries:
|
|
546
600
|
per_run = sm.cases // sm.runs if sm.runs else 0
|
|
@@ -550,21 +604,37 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, list_suites
|
|
|
550
604
|
f"{sm.consistent}/{per_run}" if sm.runs > 1 else "—",
|
|
551
605
|
f"{sm.steps_per_case:.1f}", f"{sm.calls_per_case:.1f}",
|
|
552
606
|
f"{sm.tokens_per_case:,.0f}", f"{sm.seconds_per_case:.1f}",
|
|
607
|
+
_cost_cell(runs, sm.suite, sm.backend),
|
|
553
608
|
)
|
|
554
609
|
console.print()
|
|
555
610
|
console.print(table)
|
|
611
|
+
spend_line = f"Spent ${spent:.2f}" + (f" of ${budget:.2f} budget" if budget is not None else "")
|
|
612
|
+
if ledger is not None:
|
|
613
|
+
spend_line += f" · month to date ${ledger.spent_usd:.2f}" + (
|
|
614
|
+
f" of ${monthly_limit:.2f}" if monthly_limit is not None else "")
|
|
615
|
+
if budget_hit:
|
|
616
|
+
spend_line += " · stopped early: budget reached"
|
|
617
|
+
console.print(f"[dim]{spend_line}[/dim]")
|
|
556
618
|
|
|
557
619
|
out = Path(out_dir)
|
|
558
620
|
out.mkdir(parents=True, exist_ok=True)
|
|
559
621
|
stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
560
622
|
path = out / f"bench-{stamp}.json"
|
|
561
|
-
|
|
623
|
+
results = {
|
|
562
624
|
"created_at": stamp,
|
|
563
625
|
"fusiontest_version": _package_version(),
|
|
626
|
+
"spent_usd": round(spent, 4),
|
|
627
|
+
"budget_usd": budget,
|
|
628
|
+
"stopped_for_budget": budget_hit,
|
|
564
629
|
"summaries": [sm.to_dict() for sm in summaries],
|
|
565
630
|
"runs": [r.to_dict() for r in runs],
|
|
566
|
-
}
|
|
631
|
+
}
|
|
632
|
+
path.write_text(json.dumps(results, indent=2))
|
|
567
633
|
console.print(f"\n[dim]Results: {path}[/dim]")
|
|
634
|
+
if upload and summaries:
|
|
635
|
+
_upload_bench(results, source)
|
|
636
|
+
if summary_md:
|
|
637
|
+
Path(summary_md).write_text(_bench_markdown(summaries, runs, spend_line), encoding="utf-8")
|
|
568
638
|
|
|
569
639
|
if min_accuracy is not None:
|
|
570
640
|
below = [sm for sm in summaries if sm.accuracy < min_accuracy or sm.false_pass]
|
|
@@ -575,6 +645,51 @@ def bench(suites, backends, repeat, headless, out_dir, min_accuracy, list_suites
|
|
|
575
645
|
sys.exit(1)
|
|
576
646
|
|
|
577
647
|
|
|
648
|
+
def _upload_bench(results: dict, source: str) -> bool:
|
|
649
|
+
"""POST a bench results dict to /api/bench. Returns True on success."""
|
|
650
|
+
import os
|
|
651
|
+
|
|
652
|
+
import httpx
|
|
653
|
+
|
|
654
|
+
api_key = os.getenv("FUSIONTEST_API_KEY")
|
|
655
|
+
api_url = os.getenv("FUSIONTEST_API_URL", "https://api.fusiontest.fusionleap.io")
|
|
656
|
+
if not api_key:
|
|
657
|
+
console.print("[yellow]Not uploaded:[/yellow] set FUSIONTEST_API_KEY (Dashboard → API Keys).")
|
|
658
|
+
return False
|
|
659
|
+
try:
|
|
660
|
+
resp = httpx.post(f"{api_url}/api/bench/", json={**results, "source": source},
|
|
661
|
+
headers={"Authorization": f"Bearer {api_key}"}, timeout=30)
|
|
662
|
+
resp.raise_for_status()
|
|
663
|
+
except Exception as e: # noqa: BLE001 — uploading must never lose the local results
|
|
664
|
+
console.print(f"[yellow]Warning:[/yellow] Could not upload benchmark results: {e}")
|
|
665
|
+
return False
|
|
666
|
+
console.print("[green]✓[/green] Benchmark results uploaded: "
|
|
667
|
+
"[cyan]https://app.fusiontest.fusionleap.io/benchmarks[/cyan]")
|
|
668
|
+
return True
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def _cost_cell(runs, suite: str, backend: str) -> str:
|
|
672
|
+
costs = [r.cost_usd for r in runs if r.suite == suite and r.backend == backend]
|
|
673
|
+
return "—" if any(c is None for c in costs) else f"${sum(costs):.2f}"
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
def _bench_markdown(summaries, runs, spend_line: str) -> str:
|
|
677
|
+
lines = ["## Benchmark", "",
|
|
678
|
+
"| Suite | Backend | Accuracy | False pass | False fail | Errors | Calls/case | Sec/case | Cost |",
|
|
679
|
+
"|---|---|---|---|---|---|---|---|---|"]
|
|
680
|
+
for sm in summaries:
|
|
681
|
+
lines.append(
|
|
682
|
+
f"| {sm.suite} | {sm.backend} | {sm.accuracy:.0%} ({sm.correct}/{sm.evaluated}) | "
|
|
683
|
+
f"{sm.false_pass} | {sm.false_fail} | {sm.errors} | {sm.calls_per_case:.1f} | "
|
|
684
|
+
f"{sm.seconds_per_case:.1f} | {_cost_cell(runs, sm.suite, sm.backend)} |")
|
|
685
|
+
misses = [(r, i, c) for r in runs for i, c in enumerate(r.cases, 1) if not c.correct]
|
|
686
|
+
if misses:
|
|
687
|
+
lines += ["", "**Misses**", ""]
|
|
688
|
+
lines += [f"- {r.suite} #{i} ({r.backend}): expected {c.expect}, got {c.outcome} — "
|
|
689
|
+
f"{c.goal} {('— ' + c.error[:160]) if c.error else ''}" for r, i, c in misses]
|
|
690
|
+
return "\n".join(lines + ["", spend_line, ""])
|
|
691
|
+
|
|
692
|
+
|
|
578
693
|
def _package_version() -> str:
|
|
579
694
|
from importlib.metadata import PackageNotFoundError, version
|
|
580
695
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|