-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_swebench_properties.py
More file actions
60 lines (50 loc) · 1.8 KB
/
Copy pathtest_swebench_properties.py
File metadata and controls
60 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Provability-Fabric Contributors
#
# Deterministic invariant checks (no Hypothesis dependency).
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
from bench.swebench.cost_reporter import CostReporter
from bench.swebench.workspace import WorkspaceManifest
def test_aggregate_token_totals_idempotent_empty():
assert CostReporter.aggregate_token_totals([]) == {
"prompt_tokens_total": 0,
"completion_tokens_total": 0,
}
def test_workspace_manifest_sha256_stable():
m1 = WorkspaceManifest(
instance_id="i",
repo="o/r",
base_commit="abc",
workspace_root="/w",
repo_path="/w/r",
task_prompt_path="/w/t",
scratch_path="/w/s",
resolved_commit="def",
)
h1 = m1.sha256()
h2 = m1.sha256()
assert h1 == h2
assert len(h1) == 64
def test_cost_aggregate_token_totals_associative():
"""Splitting the report list should not change the summed tokens."""
reports = [
{"instance_id": "a", "prompt_tokens": 1, "completion_tokens": 2},
{"instance_id": "b", "prompt_tokens": 3, "completion_tokens": 4},
{"instance_id": "c", "prompt_tokens": 5, "completion_tokens": 6},
]
full = CostReporter.aggregate_token_totals(reports)
mid = CostReporter.aggregate_token_totals(reports[:2])
last = CostReporter.aggregate_token_totals(reports[2:])
assert (
full["prompt_tokens_total"]
== mid["prompt_tokens_total"] + last["prompt_tokens_total"]
)
assert (
full["completion_tokens_total"]
== mid["completion_tokens_total"] + last["completion_tokens_total"]
)