Skip to main content

pytest-session-trace

Discussions

Pytest plugin that turns a recorded agent session (Claude Code JSONL, henhouse tools.v1 JSON, or legacy call list) into deterministic tool-call assertions. No LLM in CI. No network. No MCP SDK.

Install

Python 3.10+. Requires henhouse:

pip install henhouse pytest-session-trace

Or install tagged releases from GitHub:

pip install git+https://github.com/gmhoward9289-ops/henhouse@v0.1.2
pip install git+https://github.com/gmhoward9289-ops/pytest-session-trace@v0.1.7

Develop from sibling clones under dev/:

pip install -e ../henhouse
pip install -e .
pytest tests -v --session-trace tests/fixtures/one_write.jsonl

Example

from session_trace.assert_tools import assert_tool_called, assert_tool_order

def test_wrote(session_trace):
    assert_tool_called(session_trace, "Write")
    assert_tool_order(session_trace, ["Write"])

Point the fixture at a transcript or henhouse envelope:

pytest --session-trace path/to/session.jsonl
pytest --session-trace path/to/calls.json
# or
set SESSION_TRACE=path/to/session.jsonl

If neither --session-trace nor SESSION_TRACE is set, tests that request the session_trace fixture are skipped so this plugin can be installed globally without breaking unrelated suites.

Recorders

roost and leghorn record and display live Claude Code sessions. This plugin only asserts against a saved JSONL or python -m henhouse output.

Parsing is delegated to henhouse (load_tool_calls, ToolCall).

Pair with pytest-mcp-contract in the same repo: that plugin asserts the MCP server registers the right tools, read-only annotations, and input JSON schemas; this plugin asserts a saved session actually called them. Public starter: pytest-mcp-contract/examples/proof_stack/. swamp-ops docs/SESSION_TRACE.md documents the private dogfood pattern.

python -m session_trace codegen emits assert_tool_input_contains for MCP args (query, repo, limit, …) as well as editor tools.

Optional extra [anchor] uses trust_but_anchor.locate to fail closed when a quoted argument is not in a source file:

pip install -e ".[anchor]"

Starter test from a transcript

python -m session_trace path/to/session.jsonl > test_session.py
python -m session_trace --anchor path/to/session.jsonl > test_session.py
python -m session_trace path/to/session.jsonl --test-name test_agent_flow --tools Write,Read
python -m session_trace path/to/session.jsonl --no-order --tools swamp_estate_status

With --anchor, codegen emits assert_arg_anchored when Write/Edit/StrReplace text quotes a prior Read tool_result in the JSONL (requires [anchor] extra). Supported write shapes: Write contents; Edit new_string, contents, or old_string; StrReplace new_string (preferred) or old_string.

Flag Effect
--test-name NAME Generated test function name (default test_session)
--no-order Omit assert_tool_order
--tools NAME,... Only emit assertions for listed tools

That file is a copy-pasteable starting point, not a required CI step for this package.

Have a recorded session and a pytest file that pins it? Post the workflow in Show and tell.

License

Apache-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_session_trace-0.1.7.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_session_trace-0.1.7-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_session_trace-0.1.7.tar.gz.

File metadata

  • Download URL: pytest_session_trace-0.1.7.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytest_session_trace-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e491d8603c0d26a3dc3280bb1ba08f3a649d573986c2746a814f94581a88c2db
MD5 94cf2556468683f97f4f8a13bdd621a3
BLAKE2b-256 2bc2ab7fbce3bb6f9e742a69a95e74ae5189a6cb73b276bfe5af9f20a7d0be9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_session_trace-0.1.7.tar.gz:

Publisher: release.yml on gmhoward9289-ops/pytest-session-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_session_trace-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_session_trace-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 81370d6d5149262e588b0b51ebfd5cc32a9a093ae6ca178edc3a98178576df5f
MD5 f50b60284adf84bfbdf9ce6e4b2f5549
BLAKE2b-256 a7056b79d73d9aad57b30df56e40e65eb38bbabc264fcf7fe923f949b08497c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_session_trace-0.1.7-py3-none-any.whl:

Publisher: release.yml on gmhoward9289-ops/pytest-session-trace

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page