shiftedx-bench / tests /test_runner_summary_release.py
Shiftedx's picture
Fix immutable provenance flags for Shiftedx Bench v0.5.1
335e669 verified
Raw
History Blame Contribute Delete
6.8 kB
from __future__ import annotations
from pathlib import Path
from shiftedx_bench.models import BenchCase
from shiftedx_bench.cli import make_parser
from shiftedx_bench.release import sanitize_manifest, sanitize_result_row, scan_public_tree
from shiftedx_bench.runner import run_cases
from shiftedx_bench.summary import summarize_results
from shiftedx_bench.util import read_jsonl
class FakeClient:
def __init__(self, prompt_tokens=10): self.prompt_tokens = prompt_tokens
def complete(self, payload, stream=False):
return {
"content": '{"answer":7}', "reasoning_content": "", "tool_calls": [],
"finish_reason": "stop", "usage": {"prompt_tokens": self.prompt_tokens, "completion_tokens": 5},
"prompt_tokens": self.prompt_tokens, "completion_tokens": 5, "wall_s": 1.0,
"ttft_s": 0.2, "end_to_end_tokens_per_second": 5.0, "mtplx_stats": {},
}
def test_runner_resumes_and_enforces_server_token_count(tmp_path):
case = BenchCase(
case_id="c", suite_id="s", lane="long-context", messages=[{"role":"user","content":"x"}],
scorer="strict_json_exact", expected={"answer": 7},
metadata={"target_prompt_tokens": 10, "requested_position": .5, "family": "single"},
)
output = tmp_path / "results.jsonl"
run_cases([case], client=FakeClient(), model="m", output_path=output)
run_cases([case], client=FakeClient(), model="m", output_path=output)
rows = read_jsonl(output)
assert len(rows) == 1 and rows[0]["passed"]
mismatch = tmp_path / "mismatch.jsonl"
run_cases([case], client=FakeClient(prompt_tokens=9), model="m", output_path=mismatch)
assert not read_jsonl(mismatch)[0]["passed"]
def test_summary_separates_scorecards_and_context():
rows = []
for length, passed in [(4096, True), (8192, True), (16384, False)]:
rows.append({
"variant":"ar", "lane":"long-context", "case_id":str(length), "passed":passed,
"metadata":{"target_prompt_tokens":length,"requested_position":.5,"family":"single"},
"telemetry":{"wall_s":1.0,"ttft_s":.1,"end_to_end_tokens_per_second":10.0},
})
summary = summarize_results(rows, effective_threshold=.9)
assert summary["context"]["ar"]["effective_context_length"] == 8192
assert summary["interpretation"]["single_intelligence_score"] is None
def test_summary_uses_explicit_baseline_and_reports_regressions():
rows = [
{"variant": "parent", "lane": "quality", "case_id": "a", "passed": True, "metadata": {}, "telemetry": {}},
{"variant": "candidate", "lane": "quality", "case_id": "a", "passed": False, "metadata": {}, "telemetry": {}},
]
summary = summarize_results(rows, baseline_variant="parent")
comparison = summary["parity"]["candidate"]
assert comparison["baseline"] == "parent"
assert not comparison["zero_regression_gate"]
assert comparison["regressions"] == [{"case_id": "a", "lane": "quality"}]
def test_public_scan_detects_tokens_and_user_paths(tmp_path):
clean = tmp_path / "clean"
clean.mkdir()
(clean / "README.md").write_text("public documentation")
assert scan_public_tree(clean)["ok"]
fake_token = "h" + "f_" + "abcdefghijklmnopqrstuvwxyz1234"
fake_path = "/" + "Users/example/private"
(clean / "bad.txt").write_text(fake_token + "\n" + fake_path)
result = scan_public_tree(clean)
assert not result["ok"]
assert {item["issue"] for item in result["failures"]} >= {"Hugging Face access token", "macOS user path"}
def test_public_result_export_omits_responses_paths_and_identifiers():
row = {
"schema_version": "1.0",
"run_id": "private-run",
"suite_id": "shiftedx-agentic-v1",
"case_id": "repair",
"lane": "agentic",
"variant": "candidate",
"passed": False,
"score": 0,
"score_max": 1,
"error": "FileNotFoundError: /" + "Users/example/private.py",
"response": {"content": "private output", "request_id": "request-private"},
"telemetry": {
"wall_s": 2.0,
"prompt_tokens": 10,
"harness_receipts": [{"tool": "read_file"}],
"turns": [{"request_id": "private"}],
},
"metadata": {
"agentic_control_profile": "shiftedx-harness-v1",
"agentic_family": "repair_loop",
"forbidden_calls": ["delete_file"],
},
"request_hash": "a" * 64,
}
public = sanitize_result_row(row)
assert public["error_category"] == "evaluation_error"
assert public["telemetry"] == {"wall_s": 2.0, "prompt_tokens": 10}
assert public["metadata"] == {
"agentic_control_profile": "shiftedx-harness-v1",
"agentic_family": "repair_loop",
}
text = str(public)
assert "private" not in text and ("/" + "Users/") not in text and "response" not in public
def test_public_manifest_export_keeps_revisions_and_drops_host_state():
manifest = {
"run_id": "private",
"created_at": "private",
"suite_id": "shiftedx-agentic-v1",
"benchmark_version": "0.5.0",
"model": "local-model",
"config_sha256": "a" * 64,
"tokenizer_fingerprint": "b" * 64,
"planned_cases": 30,
"variants": [{
"label": "candidate",
"request_overrides": {
"reasoning_effort": "medium",
"thinking": {"enabled": True},
"private_path": "/" + "Users/example",
},
}],
"environment": {"platform": "private-host"},
"evaluated_artifact": {"repo_id": "Org/Model", "revision": "c" * 40},
"benchmark_source": {"repo_id": "Shiftedx/shiftedx-bench", "revision": "d" * 40},
"agentic_control_profile": "shiftedx-harness-v1",
}
public = sanitize_manifest(manifest)
assert public["evaluated_artifact"]["revision"] == "c" * 40
assert public["benchmark_source"]["revision"] == "d" * 40
assert public["variants"][0]["request_overrides"] == {
"reasoning_effort": "medium",
"thinking": {"enabled": True},
}
assert "run_id" not in public and "environment" not in public and "model" not in public
def test_run_suite_accepts_immutable_post_publish_provenance():
args = make_parser().parse_args([
"run-suite",
"--base-url", "http://example.invalid/v1",
"--model", "served-model",
"--output", "results.jsonl",
"--config", "configs/suites-smoke-v1.json",
"--suite", "agentic",
"--hf-repo", "Org/Model",
"--hf-revision", "a" * 40,
"--benchmark-revision", "b" * 40,
])
assert args.hf_repo == "Org/Model"
assert args.hf_revision == "a" * 40
assert args.benchmark_revision == "b" * 40