TestRunsFactory
Run test suites and read results. Access via client.test_runs.
A run returns the cases to execute. Run your agent once per case on your
normal tracer with the run and case ids on the trace's root span, using
Tracer.test_case or by sending case["headers"] to a deployed agent.
Each case is scored as soon as its trace arrives.
run does all of this for you: it starts a run, plays every case
through a function you give it, and waits for the scores.
run = client.test_runs.start(
test_suite_id,
case_filter={"kind": "tags", "tags": ["billing"]},
candidate=os.environ["GIT_SHA"],
)
for case in run["cases"]:
with Tracer.test_case(run["run_id"], case["case_id"]):
support_agent(case["input"])
results = client.test_runs.results(run["run_id"])A case that names a test environment carries it as case["environment"],
a key of run["environments"]. run plays each case in its
environment, so tools marked @mockable answer from it. If you play the
cases yourself, wrap each one in use_environment.
start()
Start a run of the test suite's latest published version.
Returns run_id, test_suite_version and cases (each with
case_id, input and tagging headers). When test environments
are enabled, each case also has its environment and the run has
the environments its cases name.
With stored_traces=True each case's stored trace, named by its
metadata.trace_id, is scored instead of running the agent, so
there is nothing to run for the returned cases. Every published case
needs a trace in this project.
def start(test_suite_id, case_filter=None, candidate=None, candidate_meta=None, trigger=None, stored_traces=None) -> StartedRun:Parameters
Prop
Type
Returns
StartedRun
run()
Start a run, play every case through your agent, and wait for the scores.
run_case(case, environment) runs your agent on one case; it may be
async. It is called inside Tracer.test_case, so the trace it
produces is attached to the case. environment is the case's own
copy of the test environment definition it names, or None. Tools
marked @mockable answer from it without any code in run_case;
load its seed yourself.
Cases run max_concurrency at a time, each in its own thread, so
keep per-case state out of module globals or pass 1. Call this
outside any active span: each case must be its own trace.
Every case is played even if run_case raises on one; a
RuntimeError naming the first such case is raised afterwards.
Raises TimeoutError when cases are still unscored
timeout_seconds after the last one was played, which usually means
a case produced no trace.
A case with no checks has passed None: it neither passed nor
failed.
def run_case(case, environment):
support_agent(case["input"])
finished = client.test_runs.run(test_suite_id, run_case, candidate="sonnet")
failed = [r for r in finished["results"] if r["passed"] is False]def run(test_suite_id, run_case, *, case_filter=None, candidate=None, candidate_meta=None, trigger=None, max_concurrency=4, timeout_seconds=900) -> FinishedRun:Parameters
Prop
Type
Returns
FinishedRun
list()
List a test suite's runs, newest first (runs and next_offset).
def list(test_suite_id, offset=0, limit=50) -> Dict[str, Any]:Parameters
Prop
Type
Returns
Dict[str, Any]
get()
Get a run and how many of its cases have a trace, are scored and passed.
def get(run_id) -> RunSummary:Parameters
Prop
Type
Returns
RunSummary
results()
Get each case's trace, outcome and per-judge check results.
def results(run_id) -> RunResults:Parameters
Prop
Type
Returns
RunResults
score()
Trigger scoring of an existing run's traces with the latest published version.
Returns the new run's run_id right away; its cases are scored in the
background, so poll get for progress. The agent doesn't run again.
def score(run_id) -> Dict[str, Any]:Parameters
Prop
Type
Returns
Dict[str, Any]