Skip to content

Testing

Test Organization

Tests are organized by component:

  • tests/api/ — API server tests
  • tests/cli/ — CLI command tests
  • tests/client/ — Python client tests
  • tests/core/ — Core module tests
  • tests/fixtures/ — shared fixtures
  • tests/janitor/ — Kubernetes janitor tests
  • tests/runner/ — Runner tests
  • tests/util/ — shared test helpers
  • tests/test_e2e.py — End-to-end tests (requires Minikube)
  • tests/test_runtime.py — runtime unit tests
  • tests/test_smoke_diagnostics.py, tests/test_smoke_tool_calls.py, tests/test_smoke_network_connectivity.py, tests/test_smoke_isolation.py — smoke-diagnostic unit tests
  • tests/smoke/ — Smoke tests against live environments
  • services/modules/*/tests/ — Lambda and Batch service tests

Running Tests

Run the pytest commands from hawk/. Run scripts/dev/smoke from the repository root.

# Run all unit tests, without the ones marked slow
pytest

# Run specific package tests (matches CI)
pytest tests/api -n logical -vv
pytest tests/cli -n logical -vv
pytest tests/core -n logical -vv
pytest tests/janitor -n logical -vv
pytest tests/runner tests/memory_high_agent -n logical -vv

# Run the slow tests, which start real processes, scans and evals (CI runs them in their own leg).
# pytest skips them unless given --slow; `--slow` without `-m slow` runs everything.
pytest tests/runner tests/memory_high_agent --slow -m slow -n auto -vv

# Run the smoke-diagnostic unit tests (the runner CI leg also runs these)
pytest tests/test_smoke_diagnostics.py -n auto -vv

# Run the runner tests that build and run Docker images (the runner CI leg also runs these)
pytest tests/runner --e2e -m e2e -n auto -vv

# Run E2E tests (requires running Minikube)
pytest --e2e -m e2e tests/test_e2e.py -vv --timeout=600

Smoke Tests

Smoke tests validate a deployed environment by running real evals against real models.

Run them from the repository root after logging Pulumi into the deployment's S3 backend. The smoke wrapper resolves the selected stack's API URL, but login is interactive and must target that same API first:

export AWS_PROFILE="<profile-for-the-target-account>"
export PULUMI_FALLBACK_TO_STATE_SECRETS_MANAGER=true
pulumi login "s3://<state-bucket>?region=<region>&awssdk=v2"
STACK="<stack>"
API_URL="$(pulumi stack output api_url -s "$STACK")"
HAWK_API_URL="$API_URL" hawk login
scripts/dev/smoke --stack "$STACK"                   # warehouse included
scripts/dev/smoke --stack "$STACK" --skip-warehouse  # exclude warehouse checks
scripts/dev/smoke --stack "$STACK" -k test_real_llm  # filter tests by name
scripts/dev/smoke --stack "$STACK" --sharded  # every eval set sharded, restricted credentials

The selected AWS credentials must reach the stack's account. Use hawk login --no-browser in a devcontainer, SSH session, or other headless environment.

--sharded needs a stack with restricted credentials enabled, and is not a CI job.

A run holds a lock in the stack's warehouse, so a second run against the same stack waits up to 25 minutes in all: for the first, and then until no job it can list whose ID starts with smoke- is pending, running, waiting for capacity or stuck. If such jobs outlast the wait the run fails and names them; hawk delete ends one. The lock needs the warehouse database even with --skip-warehouse; --no-lock runs without it. To see or end a holder that is stuck, use the queries in hawk/tests/smoke/framework/stack_lock.py.

For validating a dependency bump with them, see Validating a dependency update.

Running the smoke suite from CI

.github/workflows/smoke.yml runs the suite from GitHub Actions against a deployed stack, with config from_environ (no Pulumi access from the runner):

  • Manual (workflow_dispatch): choose the stack (stg, the default, or tst), a pytest -k filter (default test_permitted_models; post-deploy selects the post-deploy and daily runs' subset below, all runs every test) and whether to skip warehouse checks (default yes; untick it to match an automatic run).
  • Post-deploy and daily, tst only: after every successful Pulumi deploy of main (workflow_run) and once a day (schedule). These run every test, with warehouse checks on, but the cases tst or CI's token can't run (GPU nodes, task images, human evals, WIF, providers tst doesn't serve, restricted usage) and test_sharded_eval_set, which takes about 13 minutes. A skipped test fails these runs, so a new test tst can't run needs a term in the -k expression smoke.yml sets for them. Mark a test that takes five minutes or more @pytest.mark.starts_first: the standalone runner starts those first (plain pytest ignores the mark). A failed run posts to the deploy Slack channel, naming the tests that failed, when the environment has a SLACK_BOT_TOKEN; otherwise the red workflow run is the signal.
  • Nightly, tst only: every test, with warehouse checks on; a skip does not fail the run. Most cases the post-deploy runs leave out skip here too, for what tst or CI's settings lack (test_gpu[t4] always), each with its reason on the run's page.
  • Kueue: test_scan submits its scan at high priority and requires high-priority Kueue admission when SMOKE_KUEUE_ADMISSION_ENABLED is true, or when the scan's job status shows any admission state other than an unknown with no queue. To diagnose a failure, see Kueue status and diagnosis.
  • A strict default needs saying too: on a stack whose hawk:defaultIsolationLevel is strict, set SMOKE_DEFAULT_ISOLATION_LEVEL to strict, or test_unset_isolation_runs_at_the_deployments_default_level expects standard and fails.
  • A failure in a CI log shows only the test's outcome, the first line of its reason with common credential shapes masked, the line of the test file it failed at, and its eval-set or scan IDs, because the repo's Actions logs are public: look the IDs up in Datadog or with kubectl.
  • Not provisioned yet: if the <stack>-smoke environment does not exist, or lacks any of the URL and Tailscale variables or the Okta client ID and secret listed below, the run skips the smoke job (green, no Slack post) instead of failing. The existence check deliberately runs in a job that names no environment, because referencing a missing environment would create it, unprotected and empty. A failed pre-check or smoke job on a post-deploy, daily or nightly run posts to Slack; a cancelled smoke job means someone cancelled it, or over 100 runs were waiting for the stack, and is not alerted.

Each stack needs a <stack>-smoke GitHub environment (managed in METR/infra-shared, github/repo_environments.py) carrying the same names: vars HAWK_API_URL, HAWK_MIDDLEMAN_URL, SMOKE_TEST_LOG_VIEWER_SERVER_BASE_URL, SMOKE_TEST_WAREHOUSE_DATABASE_URL, AWS_WAREHOUSE_ROLE_ARN, TAILSCALE_OAUTH_CLIENT_ID, TAILSCALE_AUDIENCE, SMOKE_LIVE_INGEST_ENABLED (true on stacks whose live_ingest_enabled output is true, else test_live_ingest skips), SMOKE_NITRO_REFUSE_32BIT (false on stacks whose hawk:nitroRefuse32Bit is false, else test_nitro_sandbox fails), SMOKE_NITRO_WITHOUT_NETWORK_CARD (false on stacks whose hawk:nitroWithoutNetworkCard is false, else test_nitro_sandbox fails: it asserts its strict guest has no network card), SMOKE_KUEUE_ADMISSION_ENABLED (true on stacks with hawk:kueueAdmissionEnabled on: see Kueue above), SMOKE_VSOCK_EGRESS_ENABLED (true on stacks whose egress_over_vsock output is true: the isolation scenarios then fail a sandbox that keeps its network card, and the one that opens the whole internet with no card skips without it) and HAWK_RELAY_URL (the stack's relay_url output; unset, test_relay_contract asserts the stack has no relay), plus the optional SMOKE_DEFAULT_ISOLATION_LEVEL described above and HAWK_SMOKE_TOKEN_ENDPOINT (the OIDC token endpoint of the stack's auth server: set it, or the workflow sends the client secret to whichever endpoint the stack's /auth/config names); secrets HAWK_SMOKE_OKTA_CLIENT_ID and HAWK_SMOKE_OKTA_CLIENT_SECRET (an Okta M2M service app on that stack's auth server; a HAWK_SMOKE_OKTA_CLIENT_ID var is still accepted as a fallback); optional secret SLACK_BOT_TOKEN. It also needs a Tailscale tag hawk-<stack>-smoke-runner allowed to reach the stack's ALB, and, for the warehouse scenarios and the stack lock, hawk:smokeWarehouseAccess enabled on the stack (stg and tst only; it creates the OIDC role the workflow assumes). SMOKE_TEST_WAREHOUSE_DATABASE_URL must name the cluster's writer endpoint; without it or the role, CI runs unlocked and post-deploy runs fail on the skipped warehouse test.

Restricted scan usage attribution

The opt-in scan scenario submits two transcripts with two Scout processes and a real model in both the primary and critic roles. The target must already have restricted credentials enabled, model invocation access for the logged-in user, and Middleman traffic logs, CloudWatch EMF metrics, and the usage API configured. Recent usage also requires Valkey connected to both the API and Middleman; on a dev stack, enable hawk:valkeyEnabled before running the scenario. The scenario does not change flags or deploy infrastructure. It verifies that the submitted job uses an ex- runner; declaring transcript sources alone does not select restricted mode.

After the normal smoke login and stack setup above, choose a full Inspect OpenAI model descriptor that the target Middleman serves. The scenario installs the OpenAI SDK in the scan runner:

HAWK_SMOKE_RESTRICTED_USAGE_MODEL=openai/gpt-4o-mini \
  scripts/dev/smoke --stack "$STACK" -k test_scan_restricted_usage_attribution

The scenario skips when that variable is absent. It waits up to ten minutes for recent usage and history grouped by job, task (scan), user, and canonical team, plus team-member history with its applied team filter and the scan job's own history under its user and under its team. User and team totals also include other traffic. Normal smoke cleanup removes both submitted jobs.

Local tests cover the component boundaries separately:

  • tests/core/db/test_restricted_credentials.py persists attribution and signs renewed claims, including empty teams and later ownership changes.
  • tests/api/test_restricted_submission.py checks that resume creates a new grant for the current submitter while preserving the logical job's owner.
  • tests/runner/test_restricted_scan_credentials.py runs real Scout child processes and repeated HTTPS exchanges with a local test issuer. It does not run the production Hawk/KMS issuer.
  • Middleman's restricted passthrough tests check signed accounting, forged correlation headers, traffic envelopes, EMF output and priority identity. Hawk's usage-query tests cover consuming the accounting fields.

These local checks do not establish live IAM/S3 access or deployed telemetry ingestion. Use the opt-in smoke scenario for the deployed accounting path. Broader live credential validation should also exercise:

  • Supported runner images and scoped S3 reads, writes and denied access.
  • Job histories using user credentials and restricted credentials, stopping, eval/scan/resume final writes, SIGTERM/SIGINT and forced termination.
  • Retained completion reporting after credential expiry, API restart and deletion retries.

Restricted credential protocol

Hawk's async OAuth route supports only client credentials with HTTP Basic; there are no refresh tokens or browser grants. test_token_service_oauth.py owns protocol parsing, request bounds and sanitized errors. test_token_service_server.py checks interoperability with an independent Authlib client, transaction/signing order and cancellation cleanup; test_token_service_signer.py covers the KMS bridge. Run these suites when upgrading their dependencies. Adding another grant or client authentication method should reopen the OAuth library decision.

E2E Tests

By default, E2E tests run entirely locally with Minikube and require no METR account, AWS credentials, registry login, or LLM API key. Run these commands inside the devcontainer, starting from the repository root:

cd hawk
uv sync --all-extras --all-groups --locked
source .venv/bin/activate
../scripts/dev/start-minikube.sh
set -a
source .env
set +a
pytest --e2e -m e2e tests/test_e2e.py -vv --timeout=600

The startup script creates hawk/.env from .env.example if needed, builds the API and runner with the public python:3.13-slim-trixie base image, and logs in through the bundled local Dex provider. Local Compose and Minikube builds use this public base by default; production builds retain the Docker Hardened Images base, whose registry requires a Docker login. Internet access is still needed to download public images and Python packages.

The E2E evaluations explicitly request 2Gi of runner memory, so they fit a small local cluster even when hawk/.env retains the general 16Gi default. CI also uses 2Gi for its test environment.

CI uses the same trust decision for Batch/E2E images and the E2E model:

Run Python base E2E model
main pushes and PR branches in METR/hawk, except Dependabot dhi.io/python:3.13-dev openai/gpt-4o-mini
Fork and Dependabot PRs python:3.13-slim-trixie mockllm/model
Local default python:3.13-slim-trixie mockllm/model

The Python image defaults are pinned to multi-architecture digests in CI, Compose, and the Minikube setup script. Update the matching pins together when upgrading the images; the tags above are shown without digests for readability.

Trusted CI keeps Docker Hub and DHI authentication, the private GHCR devcontainer cache, and the existing OpenAI API key. Fork and Dependabot runs need none of those secrets and build the devcontainer from public sources. Forks run the same tests after any required GitHub workflow approval.

To test DHI locally, run this from hawk/ with the virtual environment active:

docker login dhi.io
export PYTHON_BASE_IMAGE=dhi.io/python:3.13-dev@sha256:cacda18986eefebc42b0c6c03565ec2d65a4507b6adff559e4daf0f1e2bfe338
../scripts/dev/start-minikube.sh

The image override is independent of HAWK_E2E_MODEL; local tests still use the mock unless you select the live model below.

The tests submit evals through the real CLI and API, run Kubernetes jobs, and verify the evaluation logs in MinIO. They install the pinned public inspect_evals task and, by default, use Inspect's deterministic mockllm/model provider. Both model modes execute the task's solver and scorer. The secret test passes dummy values and verifies they reach the job's Kubernetes Secret; this test always uses mockllm/model. The eval task does not require a separate task sandbox. Use the smoke suite for broader coverage of real model providers against a deployed environment.

To run the real OpenAI eval locally, add your own key and the direct OpenAI endpoint to hawk/.env:

HAWK_API_RUNNER_SECRET_OPENAI_API_KEY=sk-...
HAWK_API_OPENAI_BASE_URL=https://api.openai.com/v1

Then, from hawk/ with the virtual environment active, recreate the API so the runner receives the key and select the live model explicitly:

docker compose up -d --force-recreate api
set -a
source .env
set +a
HAWK_E2E_MODEL=openai/gpt-4o-mini pytest --e2e -m e2e tests/test_e2e.py -vv --timeout=600

HAWK_E2E_MODEL supports mockllm/model (the default) and openai/gpt-4o-mini. The latter makes real, billable model requests.

The scan E2E test remains skipped because it hangs in CI; it is not part of the credential-free eval coverage.

Frontend Tests

hawk/www has two suites:

# From hawk/www:
pnpm test           # fast, the bulk of the coverage: .tsx files under jsdom, .ts under node
pnpm test:browser   # real Chromium, src/browser only

A .ts test that needs the DOM opts into jsdom with a // @vitest-environment jsdom comment at its top.

pnpm test:browser runs the 13 files in src/browser/. The ag-grid tests mount our own list components (EvalSetList, ScanList, JobsList, SampleList) with their data hooks mocked, and assert the contracts between the grid and our configuration: custom cellRenderers, valueFormatters, getRowId, the object-form rowSelection, defaultColDef.sortable, and the IDatasource that drives SampleList's infinite row model.

A real browser is required because ag-grid only renders rows into a measured viewport; jsdom reports every element as 0×0, so the grid comes out empty and none of the above is exercised.

The goal is drift detection — catching the case where a library changed and our usage did not. That is why the tests render real components rather than synthetic grids: a synthetic grid only re-tests ag-grid's own behaviour, which is upstream's job and tells us nothing about whether EvalSetList still works.

Make new tests earn their place

A test here is only worth its runtime if it fails when our code drifts. Verify a new one by mutating the component it covers — change getRowId, drop a valueFormatter, flip sortable — and confirm it goes red. If it still passes, it is testing the library, not us.

Keep the suite small and the assertions shallow. Notes for adding to it:

  • Render inside a desktop-sized wrapper (width: 1400). The default test page is ~414px, narrow enough that ag-grid column-virtualises and trailing columns never reach the DOM.
  • Scope lookups to the grid (.ag-header-cell-text, .ag-row) rather than page-wide getByText, which goes ambiguous against surrounding chrome.

Install the browser once:

pnpm exec playwright install chromium --only-shell

Managed macOS fleets

Playwright's bundled Chromium is ad-hoc signed with no Team ID, and some managed Macs kill it on launch — Playwright then reports Target page, context or browser has been closed. Point it at a locally installed, notarised Chrome instead:

PLAYWRIGHT_CHROMIUM_CHANNEL=chrome pnpm test:browser

Validating a dependency update

Which suite actually exercises a bump depends on the ecosystem, so "run the smoke tests" is not always the right answer.

Ecosystem What validates it
uv (Python) Unit tests, then the smoke suite against a real deployment — this is the most thorough option available
npm (hawk/www) pnpm test, pnpm typecheck, pnpm build, and pnpm test:browser. Smoke tests never load the browser bundle and add nothing
docker Varies per image — see below. Do not assume E2E or smoke covers it
github-actions Only CI running on the PR itself

Docker bumps are not uniformly covered

Dependabot tracks the Docker directories below, and CI builds only some of them. Check which image actually changed before assuming a green PR means anything:

Dockerfile Built in CI by
.devcontainer/ devcontainer.yml, and E2E runs inside the built image
hawk/services/modules/<batch>/, .../docker_lambda/ python-test-batch / python-test-lambda, which build with target: test and run the tests inside
hawk/ The e2e job, via start-minikube.sh: the api image (docker compose up --build) and the runner image (build-and-push-runner-image.sh). sandbox-tools-image builds the sandbox-tools target
middleman/ The e2e job, via start-minikube.sh (docker compose up --build)
relay/ Lint only (infra-lint.yml). Not built
infra/hawk/execd/ python-test-package (runner), whose Docker tests build it
infra/hawk/egress-over-vsock/ python-test-package (runner), whose Docker tests build it
jumphost/, hawk/services/modules/viewer/ Nothing. First built at deploy time
hawk/services/modules/viewer-plugin-base/, hawk/viewer-plugins/template/ viewer-plugin-base.yml builds and smoke-tests both on a pull request from this repository, except Dependabot. Fork and Dependabot pull requests skip that job.
infra/hawk/egress-proxy/ Not built: hawk-ci.yml's runner tests run the image it pins, with the config Hawk renders
infra/hawk/coredns/, infra/hawk/sandbox-default/, infra/core/datadog-agent/, infra/core/datadog-synthetics/ Nothing. CI does not run these images

Smoke tests run whatever images are already deployed, and SMOKE_IMAGE_TAG overrides only the runner. For a directory CI does not build, build the image locally and deploy it to a dev stack, or the bump ships unbuilt.

For runner-only iteration without AWS, use the local Minikube workflow. For the more thorough validation of a Python bump against deployed services, build a runner image from the branch and point a dev stack's smoke run at it. This does not require deploying the whole branch. Complete the Smoke Tests setup above in the same shell, then authenticate Docker to the stack's ECR and run:

IMAGE_TAG=my-tag
ENVIRONMENT="$(pulumi stack output env -s "$STACK")"
AWS_REGION="$(pulumi stack output region -s "$STACK")"
(
  cd hawk
  PULUMI_STACK="$STACK" \
    ENVIRONMENT="$ENVIRONMENT" AWS_REGION="$AWS_REGION" \
    ../scripts/dev/build-and-push-runner-image.sh "$IMAGE_TAG"
)
SMOKE_IMAGE_TAG="$IMAGE_TAG" scripts/dev/smoke --stack "$STACK"  # all tests, no -k filter

Four limits worth knowing:

  • SMOKE_IMAGE_TAG only replaces the runner image. A bump to an api-group dependency is not exercised until the branch is deployed to a dev stack with pulumi up.
  • test_nitro_sandbox skips, since the API refuses an eval set that names nitro on a pinned runner image. Test an inspect-k8s-sandbox change on Nitro with the branch deployed.
  • On a stack with hawk:egressThroughProxy on, test_strict_isolation_hardens_the_sandbox skips, since the API refuses an eval set that names hosts at strict on a pinned runner image. Test the egress proxy with the branch deployed.
  • The <stack>-smoke CI environments only permit main, so smoke.yml cannot be dispatched against a PR branch (see Running the smoke suite from CI). Run locally against a dev stack instead.

For full smoke coverage, install skopeo (otherwise the requires_task_images tests skip silently) and leave the warehouse enabled (for requires_warehouse).

Also check for over-broad mocks after any upgrade. Patching a library constructor (aioboto3.Session.client) rather than our own factory (my_module.aws_clients.get_s3_client) breaks whenever a dependency changes how it reaches external services — a previously-passing test failing with MagicMock can't be used in 'await' expression is the signature. See the mock scoping guidance in hawk/tests/AGENTS.md.

Testing Tools

Tool Purpose
pytest-xdist Parallel test execution (-n auto)
pytest-asyncio Async test support (auto mode)
pytest-mock General mocking
pyfakefs Filesystem mocking
moto, pytest-aioboto3 AWS mocking
testcontainers[postgres] PostgreSQL containers
time-machine Time mocking

Code Quality Checks

Must pass before completion. Run the repo's pre-commit hooks — the same checks CI's Lint job runs (see Code Quality for setup):

pre-commit run --all-files