Simple models and tasks for integration testing
Project description
inspect-test-utils
A small collection of tasks, scorers, and a simple model for use with the Inspect AI framework. It is designed to support integration/acceptance tests, demos, and reproductions by providing:
- Ready-made Tasks that exercise common evaluation patterns (simple generation, numeric closeness, failure injection, and sandbox configuration).
- Scorers for deterministic or parameterized scoring (including hardcoded outputs and a logarithmic closeness score).
- A hardcoded ModelAPI implementation that can deterministically emit tool calls and/or final answers, useful for testing tool-calling flows without hitting external APIs.
Passing arguments Most tasks and the hardcoded model accept parameters. With the Inspect CLI you can pass them via --task-arg and --model-arg repeatedly:
- Example: make the task generate 3 samples and set a numeric target for guessing:
inspect eval inspect_test_utils/guess_number
--task-arg sample_count=3
--task-arg target=42.7
--model hardcoded --model-arg answer=42.6
What’s included
-
Tasks (inspect_test_utils.tasks)
- say_hello(sample_count=1): Simple task; expects a response that includes "hello".
- guess_number(sample_count=1, target="42.7"): Uses a logarithmic closeness scorer for numeric answers.
- hardcoded_score(sample_count=10, hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Scores are injected from parameters; useful for testing aggregations and edge cases (including NaN).
- sometimes_fails_setup(sample_count=10, fail_setup_on_epochs=None, failure_rate=0.2): Randomly raises during setup via a failing solver; useful to test retry/resume behavior.
- sometimes_fails_scoring(sample_count=10, fail_score_on_epochs=None, failure_rate=0.2): Randomly raises during scoring; useful to test scorer error handling.
- configurable_sandbox(sample_count=1, cpu=0.5, memory="2G", storage="2G", gpu=None, gpu_model=None, allow_internet=False): A task with runtime configurable sandbox.
-
Scorers (inspect_test_utils.scorers)
- failing_scorer(fail_on_epochs=None, failure_rate=0.2): Raises errors at a controlled rate for selected epochs.
- closeness_log(): Scores 1.0 for exact equality, otherwise 1/(1+log1p(relative_error)) for numeric strings.
- hardcoded_scorer(hardcoded_score=None, hardcoded_score_by_sample_id_and_epoch=None): Returns pre-specified Score objects or looks them up by sample id and epoch.
-
Model (inspect_test_utils.hardcoded)
- hardcoded: A ModelAPI that can emit a sequence of tool calls (e.g., bash) for a number of repetitions and then submit a final answer.
Parameters include:
- answer: final answer string (default: "done").
- repetitions: how many tool-call "turns" before submitting.
- tool_calls: list of tool calls or shell strings (e.g., ["echo hi", "ls -la"]) to simulate; defaults to none.
- delay: optional delay (seconds) before returning each model output.
- hardcoded: A ModelAPI that can emit a sequence of tool calls (e.g., bash) for a number of repetitions and then submit a final answer.
Parameters include:
Testing checkpoint/resume of an (agent, task) pair
inspect_test_utils includes a crash/resume harness that verifies an (agent, task) pair correctly checkpoints and resumes after a mid-run or scoring crash. Use it with any task that calls react() (or another checkpointer-aware solver) and has a checkpoint trigger configured.
from inspect_ai import Task
from inspect_ai.agent import react
from inspect_ai.dataset import Sample
from inspect_ai.scorer import includes
from inspect_ai.util import CheckpointSampleConfig
from inspect_test_utils import (
run_resume_test,
after_turns,
at_scoring,
assert_resumed,
assert_agent_not_restarted,
assert_score_recovered,
)
task = Task(
dataset=[
Sample(
id="s1",
input="go",
target="done",
checkpoint=CheckpointSampleConfig(sandbox_paths={"default": ["/root"]}),
)
],
solver=react(...),
scorer=includes(),
sandbox="docker",
)
# Crash mid-run (after the 2nd sandbox exec) and assert the agent resumed:
r = run_resume_test(task, crash=after_turns(2), compute_baseline=False)
assert_resumed(r)
# Crash at the first scoring call and assert the agent was NOT re-run (scoring-only resume):
task_no_sandbox = Task(
dataset=[Sample(id="s1", input="hi", target="hi")],
solver=react(...),
scorer=includes(),
)
r = run_resume_test(task_no_sandbox, crash=at_scoring())
assert_resumed(r)
assert_agent_not_restarted(r) # agent loop skipped on scoring resume
assert_score_recovered(r) # score matches baseline
Both after_turns(n) (crash after the n-th sandbox exec) and at_scoring() (crash at the first scorer call) are supported. after_turns requires compute_baseline=False because the exec patch is incompatible with a second in-process checkpointed eval.
run_resume_test uses an in-process soft crash (CrashInjected exception + eval_set retry). For a true os._exit crash as in a real k8s/hawk deployment, compose crash_after_exec(n, hard=True) into your task's solver chain — this is the resume_probe pattern generalised to any agent via the shared exec seam. Because hard=True calls os._exit, it cannot run inside pytest (it would kill the harness); it is intended for real eval-set jobs where the platform handles restart and resume.
Installation
pip install inspect-test-utils
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inspect_test_utils-1.4.0.tar.gz.
File metadata
- Download URL: inspect_test_utils-1.4.0.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e28e41b8dcc03434290ee08bb602a453351438d79b48b6c42dde99b5993866b6
|
|
| MD5 |
5a0aead6d14c1453e10edb5805807c13
|
|
| BLAKE2b-256 |
274459109a6487bb0887fd8422c92dc506de130c38cd5b48f11c5a35b0fb31c9
|
Provenance
The following attestation bundles were made for inspect_test_utils-1.4.0.tar.gz:
Publisher:
release.yml on METR/inspect-test-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inspect_test_utils-1.4.0.tar.gz -
Subject digest:
e28e41b8dcc03434290ee08bb602a453351438d79b48b6c42dde99b5993866b6 - Sigstore transparency entry: 1995529993
- Sigstore integration time:
-
Permalink:
METR/inspect-test-utils@19e37494f0411321b4a8348b0fadbde7259161e3 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/METR
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@19e37494f0411321b4a8348b0fadbde7259161e3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file inspect_test_utils-1.4.0-py3-none-any.whl.
File metadata
- Download URL: inspect_test_utils-1.4.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e847d59a48179d7d08a2303ae4c09173e741c55781317aafd8d487e73c70289
|
|
| MD5 |
9bff052895fdb8929f5149587c493c38
|
|
| BLAKE2b-256 |
366a5f78ece76688b2c597f70830c65d3eeeeb31597a663a025c7e5c8522cce6
|
Provenance
The following attestation bundles were made for inspect_test_utils-1.4.0-py3-none-any.whl:
Publisher:
release.yml on METR/inspect-test-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inspect_test_utils-1.4.0-py3-none-any.whl -
Subject digest:
7e847d59a48179d7d08a2303ae4c09173e741c55781317aafd8d487e73c70289 - Sigstore transparency entry: 1995530041
- Sigstore integration time:
-
Permalink:
METR/inspect-test-utils@19e37494f0411321b4a8348b0fadbde7259161e3 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/METR
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@19e37494f0411321b4a8348b0fadbde7259161e3 -
Trigger Event:
release
-
Statement type: