driftcatch 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- driftcatch-0.1.0/.gitattributes +6 -0
- driftcatch-0.1.0/.gitignore +45 -0
- driftcatch-0.1.0/CHANGELOG.md +150 -0
- driftcatch-0.1.0/CODE_OF_CONDUCT.md +51 -0
- driftcatch-0.1.0/CONTRIBUTING.md +85 -0
- driftcatch-0.1.0/CRITIQUE.md +230 -0
- driftcatch-0.1.0/DESIGN.md +721 -0
- driftcatch-0.1.0/IMPLEMENTATION_PLAN.md +510 -0
- driftcatch-0.1.0/LICENSE +21 -0
- driftcatch-0.1.0/PKG-INFO +456 -0
- driftcatch-0.1.0/README.md +415 -0
- driftcatch-0.1.0/RELEASE_READINESS.md +293 -0
- driftcatch-0.1.0/_testbed/.env.example +2 -0
- driftcatch-0.1.0/docs/MCP.md +160 -0
- driftcatch-0.1.0/docs/assertions.md +235 -0
- driftcatch-0.1.0/docs/ci.md +209 -0
- driftcatch-0.1.0/docs/cli.md +173 -0
- driftcatch-0.1.0/docs/concepts.md +204 -0
- driftcatch-0.1.0/docs/configuration.md +183 -0
- driftcatch-0.1.0/docs/contracts.md +229 -0
- driftcatch-0.1.0/docs/faq.md +138 -0
- driftcatch-0.1.0/docs/getting-started.md +160 -0
- driftcatch-0.1.0/docs/index.md +87 -0
- driftcatch-0.1.0/docs/invariants.md +160 -0
- driftcatch-0.1.0/docs/matching.md +205 -0
- driftcatch-0.1.0/docs/recording-and-replay.md +176 -0
- driftcatch-0.1.0/docs/security.md +153 -0
- driftcatch-0.1.0/docs/suites.md +166 -0
- driftcatch-0.1.0/docs/troubleshooting.md +239 -0
- driftcatch-0.1.0/driftcatch/__init__.py +146 -0
- driftcatch-0.1.0/driftcatch/_name.py +12 -0
- driftcatch-0.1.0/driftcatch/agentio.py +246 -0
- driftcatch-0.1.0/driftcatch/bisect.py +160 -0
- driftcatch-0.1.0/driftcatch/cli.py +1035 -0
- driftcatch-0.1.0/driftcatch/config.py +166 -0
- driftcatch-0.1.0/driftcatch/contracts.py +508 -0
- driftcatch-0.1.0/driftcatch/coverage.py +165 -0
- driftcatch-0.1.0/driftcatch/determinism.py +282 -0
- driftcatch-0.1.0/driftcatch/errors.py +149 -0
- driftcatch-0.1.0/driftcatch/intercept/__init__.py +8 -0
- driftcatch-0.1.0/driftcatch/intercept/http.py +400 -0
- driftcatch-0.1.0/driftcatch/intercept/tools.py +187 -0
- driftcatch-0.1.0/driftcatch/invariants.py +646 -0
- driftcatch-0.1.0/driftcatch/match/__init__.py +60 -0
- driftcatch-0.1.0/driftcatch/match/base.py +161 -0
- driftcatch-0.1.0/driftcatch/match/keys.py +61 -0
- driftcatch-0.1.0/driftcatch/match/normalizers.py +130 -0
- driftcatch-0.1.0/driftcatch/match/registry.py +82 -0
- driftcatch-0.1.0/driftcatch/match/resolve.py +195 -0
- driftcatch-0.1.0/driftcatch/match/strategies.py +146 -0
- driftcatch-0.1.0/driftcatch/mcp_server.py +417 -0
- driftcatch-0.1.0/driftcatch/providers.py +227 -0
- driftcatch-0.1.0/driftcatch/py.typed +0 -0
- driftcatch-0.1.0/driftcatch/pytest_plugin.py +170 -0
- driftcatch-0.1.0/driftcatch/record.py +162 -0
- driftcatch-0.1.0/driftcatch/recording/__init__.py +57 -0
- driftcatch-0.1.0/driftcatch/recording/fingerprint.py +75 -0
- driftcatch-0.1.0/driftcatch/recording/io.py +257 -0
- driftcatch-0.1.0/driftcatch/recording/schema.py +261 -0
- driftcatch-0.1.0/driftcatch/redact.py +127 -0
- driftcatch-0.1.0/driftcatch/replay.py +152 -0
- driftcatch-0.1.0/driftcatch/review.py +102 -0
- driftcatch-0.1.0/driftcatch/session.py +126 -0
- driftcatch-0.1.0/driftcatch/suite.py +135 -0
- driftcatch-0.1.0/driftcatch/take.py +632 -0
- driftcatch-0.1.0/driftcatch/trajectory.py +208 -0
- driftcatch-0.1.0/driftcatch/ui/__init__.py +15 -0
- driftcatch-0.1.0/driftcatch/ui/server.py +245 -0
- driftcatch-0.1.0/driftcatch/ui/templates/app.html +346 -0
- driftcatch-0.1.0/driftcatch/whatif.py +65 -0
- driftcatch-0.1.0/examples/__init__.py +0 -0
- driftcatch-0.1.0/examples/refund_agent/__init__.py +0 -0
- driftcatch-0.1.0/examples/refund_agent/agent.py +147 -0
- driftcatch-0.1.0/examples/refund_agent/recordings/refund_1182.json +80 -0
- driftcatch-0.1.0/examples/refund_agent/test_refund.py +74 -0
- driftcatch-0.1.0/pyproject.toml +106 -0
- driftcatch-0.1.0/scripts/demo_invariants.py +147 -0
- driftcatch-0.1.0/scripts/smoke_roundtrip.py +116 -0
- driftcatch-0.1.0/tests/__init__.py +0 -0
- driftcatch-0.1.0/tests/conftest.py +84 -0
- driftcatch-0.1.0/tests/integration/__init__.py +0 -0
- driftcatch-0.1.0/tests/integration/fake_provider.py +148 -0
- driftcatch-0.1.0/tests/integration/test_agent_surface.py +224 -0
- driftcatch-0.1.0/tests/integration/test_cli.py +155 -0
- driftcatch-0.1.0/tests/integration/test_docs_match_cli.py +187 -0
- driftcatch-0.1.0/tests/integration/test_durability.py +191 -0
- driftcatch-0.1.0/tests/integration/test_end_to_end.py +402 -0
- driftcatch-0.1.0/tests/integration/test_exit_codes.py +239 -0
- driftcatch-0.1.0/tests/integration/test_hardening.py +289 -0
- driftcatch-0.1.0/tests/integration/test_live_mode.py +249 -0
- driftcatch-0.1.0/tests/integration/test_mcp.py +270 -0
- driftcatch-0.1.0/tests/integration/test_output_and_latency.py +262 -0
- driftcatch-0.1.0/tests/integration/test_real_sdks.py +458 -0
- driftcatch-0.1.0/tests/integration/test_suite.py +281 -0
- driftcatch-0.1.0/tests/integration/test_ui.py +132 -0
- driftcatch-0.1.0/tests/unit/__init__.py +0 -0
- driftcatch-0.1.0/tests/unit/test_analysis.py +290 -0
- driftcatch-0.1.0/tests/unit/test_contracts.py +536 -0
- driftcatch-0.1.0/tests/unit/test_fingerprint.py +73 -0
- driftcatch-0.1.0/tests/unit/test_invariants.py +306 -0
- driftcatch-0.1.0/tests/unit/test_io.py +113 -0
- driftcatch-0.1.0/tests/unit/test_match.py +382 -0
- driftcatch-0.1.0/tests/unit/test_name_safety.py +94 -0
- driftcatch-0.1.0/tests/unit/test_reasoning_models.py +152 -0
- driftcatch-0.1.0/tests/unit/test_schema.py +99 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
|
|
10
|
+
# Tooling
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
htmlcov/
|
|
16
|
+
|
|
17
|
+
# DriftCatch
|
|
18
|
+
*.json.tmp
|
|
19
|
+
|
|
20
|
+
# Frontend (UI, later phase)
|
|
21
|
+
node_modules/
|
|
22
|
+
driftcatch/ui/static/
|
|
23
|
+
|
|
24
|
+
# Editors / OS
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
.DS_Store
|
|
28
|
+
Thumbs.db
|
|
29
|
+
|
|
30
|
+
# Temporary testing environment - never committed, may contain credentials
|
|
31
|
+
_testbed/
|
|
32
|
+
|
|
33
|
+
# Credentials - belt and braces alongside _testbed/
|
|
34
|
+
.env
|
|
35
|
+
.env.*
|
|
36
|
+
!.env.example
|
|
37
|
+
*.pem
|
|
38
|
+
*.key
|
|
39
|
+
|
|
40
|
+
# Demo render output and the Remotion toolchain
|
|
41
|
+
# assets/ holds the committed copies that the README links to
|
|
42
|
+
demo/out/
|
|
43
|
+
demo/video/out/
|
|
44
|
+
demo/video/node_modules/
|
|
45
|
+
demo/sandbox/
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to DriftCatch are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
While the version is `0.x`, the recording format and the Python API may change
|
|
9
|
+
between minor versions. Breaking changes are listed under **Changed** with a
|
|
10
|
+
migration note. The on-disk recording format carries its own integer version and
|
|
11
|
+
refuses to load a format it does not understand, so an upgrade never silently
|
|
12
|
+
misreads an old golden.
|
|
13
|
+
|
|
14
|
+
## [Unreleased]
|
|
15
|
+
|
|
16
|
+
## [0.1.0] - unreleased
|
|
17
|
+
|
|
18
|
+
First public release.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
**Recording and replay**
|
|
23
|
+
- `drift.take(name)` context manager: records LLM calls and tool calls on first
|
|
24
|
+
run, replays them deterministically afterwards.
|
|
25
|
+
- Interception at the HTTP client layer (`httpx` and `httpx2`), so any provider
|
|
26
|
+
SDK or gateway that speaks HTTP is supported without a per-provider adapter.
|
|
27
|
+
- Streaming support, including assembly of streamed tool calls and of reasoning
|
|
28
|
+
deltas from o1-style, DeepSeek-R1, QwQ, Nemotron and Anthropic thinking models.
|
|
29
|
+
- `@drift.tool` decorator for recording and replaying tool side effects, with a
|
|
30
|
+
`passthrough` list for tools that must stay live during replay.
|
|
31
|
+
- Atomic, gzip-compressed recordings with plaintext status, fingerprint and
|
|
32
|
+
trajectory so a behaviour change is legible in a pull request diff.
|
|
33
|
+
|
|
34
|
+
**The approval gate**
|
|
35
|
+
- Recording a run does not approve it. `drift approve` / `drift reject` make the
|
|
36
|
+
distinction explicit, because a recorded-but-wrong golden would otherwise
|
|
37
|
+
become a permanently enforced bug.
|
|
38
|
+
- `drift review` for walking pending recordings.
|
|
39
|
+
- Replaying an unapproved recording warns.
|
|
40
|
+
|
|
41
|
+
**Drift detection**
|
|
42
|
+
- Two-tier model. Tier 1 (`drift check`) replays offline and for free, catching
|
|
43
|
+
changes in your own code, prompts, model id and tool schemas. Tier 2
|
|
44
|
+
(`drift check --live`) spends real money against the provider and catches
|
|
45
|
+
model-behaviour change, thresholded with `pass_k`.
|
|
46
|
+
- Four behaviour-determining inputs fingerprinted separately (system prompt,
|
|
47
|
+
model id, tool schemas, matcher config) so a drift report names its cause.
|
|
48
|
+
- `drift bisect` for attributing a drift to one of those inputs.
|
|
49
|
+
- `drift diff`, `drift explain`, `drift show` for inspecting a divergence,
|
|
50
|
+
reported at the first point of divergence rather than at the end.
|
|
51
|
+
|
|
52
|
+
**Invariant mining**
|
|
53
|
+
- `drift learn` mines behavioural rules from the approved corpus using seven
|
|
54
|
+
templates: `always_precedes`, `always_called`, `never_called`,
|
|
55
|
+
`always_terminal`, `never_consecutive`, `max_tool_calls`, `data_equality`.
|
|
56
|
+
- Four anti-spurious filters: minimum support, a confidence gate, a requirement
|
|
57
|
+
that the value actually varies across runs, and Daikon-style redundancy
|
|
58
|
+
removal.
|
|
59
|
+
- `drift invariants` enforces mined rules as a test gate.
|
|
60
|
+
|
|
61
|
+
**Assertions**
|
|
62
|
+
- `assert_output()` for what the model said: `contains`, `excludes`, `matches`,
|
|
63
|
+
`equals`, `is_json`, `json_has`, `not_empty` and `satisfies` for an arbitrary
|
|
64
|
+
deterministic predicate. Mechanical checks only - there is no scoring and no
|
|
65
|
+
LLM judge, because that is evaluation and a different discipline.
|
|
66
|
+
- `assert_latency()` with `under(total_ms=, per_call_ms=)` and
|
|
67
|
+
`within_factor_of_golden()`.
|
|
68
|
+
- Per-event latency is captured on every real call, including calls that
|
|
69
|
+
failed, and survives the round trip to disk.
|
|
70
|
+
|
|
71
|
+
**Scenario suites**
|
|
72
|
+
- `drift.Suite(name, cases, check=...)` runs one test body across a table of
|
|
73
|
+
cases, each with its own recording, and applies one shared policy to every
|
|
74
|
+
case. Empty tables and unusable case names are refused at construction rather
|
|
75
|
+
than on the twelfth case of a live run.
|
|
76
|
+
|
|
77
|
+
**Tool contracts**
|
|
78
|
+
- `drift contracts` compares each tool's declared JSON schema with how it is
|
|
79
|
+
actually used across the approved corpus: dead schema surface costing tokens
|
|
80
|
+
on every request, arguments the model invented, unstable result shapes, and
|
|
81
|
+
per-tool error rates and median latency. An analysis command that never fails
|
|
82
|
+
a build.
|
|
83
|
+
- Findings that recommend *removing* something are withheld below a corpus of
|
|
84
|
+
5, since "never used" on a thin corpus means "not yet seen". The report says
|
|
85
|
+
findings were withheld rather than claiming there were none.
|
|
86
|
+
|
|
87
|
+
**Tooling**
|
|
88
|
+
- 24 CLI commands, with `--json` on the machine-readable ones, documented exit
|
|
89
|
+
codes and errors that carry a `hint` field.
|
|
90
|
+
- `drift approve` and `drift reject` for non-interactive approval, alongside the
|
|
91
|
+
interactive `drift review`.
|
|
92
|
+
- `drift status --require-approved` exits 7 when any recording is still
|
|
93
|
+
pending, as a CI gate.
|
|
94
|
+
- A pytest plugin.
|
|
95
|
+
- A local web UI (`drift ui`) for reviewing recordings and diffs.
|
|
96
|
+
- An MCP server (`drift mcp`) exposing ten read-only tools to coding agents.
|
|
97
|
+
Mutating commands are deliberately not exposed: an agent's reflex on a red
|
|
98
|
+
test is to make it green.
|
|
99
|
+
- `drift scan` for secrets in recordings, and redaction on the write path.
|
|
100
|
+
- `drift init` writes an `AGENTS.md` section so coding agents discover the
|
|
101
|
+
framework's conventions.
|
|
102
|
+
|
|
103
|
+
### Fixed
|
|
104
|
+
|
|
105
|
+
Found while bringing the documentation in line with the code, and each one now
|
|
106
|
+
has a regression test.
|
|
107
|
+
|
|
108
|
+
- **Advertised exit codes were never emitted.** `drift init` writes an
|
|
109
|
+
`AGENTS.md` section promising that `3` means a behaviour regression and `7`
|
|
110
|
+
means not approved. The CLI emitted neither: `drift check` returned pytest's
|
|
111
|
+
raw exit code, so an agent branching on `3` could never match. pytest's codes
|
|
112
|
+
are now translated onto the documented contract.
|
|
113
|
+
- **`drift check` reported success when it collected no tests.** pytest exits
|
|
114
|
+
`5` for "no tests collected"; passing that through both collided with
|
|
115
|
+
`SECRETS_FOUND` and, worse, made "verified nothing" look like "verified
|
|
116
|
+
everything". It is now an error that says so.
|
|
117
|
+
- **`drift show <missing>` exited `1` instead of the documented `6`.** Library
|
|
118
|
+
errors are now mapped to exit codes by type at one chokepoint, so every
|
|
119
|
+
command that reports a missing recording agrees.
|
|
120
|
+
- **The `AGENTS.md` template told agents to run `drift record --update`**,
|
|
121
|
+
which pytest rejects; the flag is `--drift-update`. A template that instructs
|
|
122
|
+
an agent to run a failing command is worse than none.
|
|
123
|
+
- **Tool contracts read no declared parameters from real recordings.**
|
|
124
|
+
``parse_request`` normalises every tool to ``{"name", "schema"}`` so the
|
|
125
|
+
matcher sees one shape, and the extractor never unwrapped that layer. Tools
|
|
126
|
+
were listed, every parameter was reported as undeclared, and the unit tests
|
|
127
|
+
missed it because they built the request object directly instead of going
|
|
128
|
+
through the normalisation. Found by a live run against a real SDK; the unit
|
|
129
|
+
tests now go through ``parse_request`` so the fixture cannot drift from
|
|
130
|
+
reality again.
|
|
131
|
+
- **Replayed events reported the recorded duration as this run's latency.** The
|
|
132
|
+
replayer hands back the golden's own event object, so a latency assertion
|
|
133
|
+
during replay compared a number against itself and passed unconditionally.
|
|
134
|
+
Replayed steps are now marked at the session boundary and excluded.
|
|
135
|
+
|
|
136
|
+
### Documentation
|
|
137
|
+
|
|
138
|
+
- Fifteen pages under `docs/`, indexed from `docs/index.md`.
|
|
139
|
+
- Automated consistency checks: every command invoked in any documentation file
|
|
140
|
+
must exist, every real command must appear in the CLI reference, every exit
|
|
141
|
+
code must be documented, and every page must be reachable from the index.
|
|
142
|
+
This project had already shipped a README naming two commands that did not
|
|
143
|
+
exist, so the check is automated rather than remembered.
|
|
144
|
+
- `LICENSE` (MIT), `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md` and this changelog.
|
|
145
|
+
|
|
146
|
+
### Security
|
|
147
|
+
- Recording names are validated at the path chokepoint and refused — never
|
|
148
|
+
silently sanitised — so a name arriving from a CLI argument, a UI route or an
|
|
149
|
+
MCP tool call cannot escape the recordings directory.
|
|
150
|
+
- Pruned recordings refuse to replay rather than serving an empty body.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors and maintainers pledge to make participation in this
|
|
6
|
+
project a harassment-free experience for everyone, regardless of age, body size,
|
|
7
|
+
visible or invisible disability, ethnicity, sex characteristics, gender identity
|
|
8
|
+
and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our standards
|
|
16
|
+
|
|
17
|
+
Examples of behaviour that contributes to a positive environment:
|
|
18
|
+
|
|
19
|
+
- Demonstrating empathy and kindness toward other people
|
|
20
|
+
- Being respectful of differing opinions, viewpoints and experiences
|
|
21
|
+
- Giving and gracefully accepting constructive feedback
|
|
22
|
+
- Accepting responsibility, apologising to those affected by our mistakes, and
|
|
23
|
+
learning from the experience
|
|
24
|
+
- Focusing on what is best for the community, not just for ourselves
|
|
25
|
+
|
|
26
|
+
Examples of unacceptable behaviour:
|
|
27
|
+
|
|
28
|
+
- The use of sexualised language or imagery, and sexual attention or advances
|
|
29
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
|
30
|
+
- Public or private harassment
|
|
31
|
+
- Publishing others' private information, such as a physical or email address,
|
|
32
|
+
without their explicit permission
|
|
33
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
|
34
|
+
professional setting
|
|
35
|
+
|
|
36
|
+
## Enforcement
|
|
37
|
+
|
|
38
|
+
Instances of abusive, harassing or otherwise unacceptable behaviour may be
|
|
39
|
+
reported to the project maintainer. All complaints will be reviewed and
|
|
40
|
+
investigated promptly and fairly. The maintainer is obligated to respect the
|
|
41
|
+
privacy and security of the reporter of any incident.
|
|
42
|
+
|
|
43
|
+
Maintainers have the right and responsibility to remove, edit or reject
|
|
44
|
+
comments, commits, code, issues and other contributions that are not aligned
|
|
45
|
+
with this Code of Conduct, and will communicate reasons for moderation decisions
|
|
46
|
+
when appropriate.
|
|
47
|
+
|
|
48
|
+
## Attribution
|
|
49
|
+
|
|
50
|
+
This Code of Conduct is adapted from the [Contributor Covenant](
|
|
51
|
+
https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Contributing to DriftCatch
|
|
2
|
+
|
|
3
|
+
Thanks for considering a contribution. This document covers how to get set up,
|
|
4
|
+
what the quality bar is, and the few design positions that are deliberate rather
|
|
5
|
+
than accidental.
|
|
6
|
+
|
|
7
|
+
## Getting set up
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/neeldeshmane/driftcatch
|
|
11
|
+
cd driftcatch
|
|
12
|
+
python -m venv .venv && . .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Verify the checkout:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python -m pytest -n 4 -q # the suite runs in parallel on purpose
|
|
20
|
+
python -m mypy driftcatch
|
|
21
|
+
python -m ruff check driftcatch tests examples
|
|
22
|
+
python -m ruff format --check driftcatch tests examples
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The suite is offline. No test in `tests/` makes a network call, and CI asserts
|
|
26
|
+
that. If you need a real provider for exploratory work, keep it out of `tests/`.
|
|
27
|
+
|
|
28
|
+
## The quality bar
|
|
29
|
+
|
|
30
|
+
- **Every behaviour change needs a test.** Not a test that the code runs — a
|
|
31
|
+
test that the behaviour is right.
|
|
32
|
+
- `mypy --strict` is clean and stays clean.
|
|
33
|
+
- `ruff` with the project's rule set, line length 100.
|
|
34
|
+
- `from __future__ import annotations` at the top of every module.
|
|
35
|
+
- Public functions get docstrings that say *why*, not *what*. The what is in the
|
|
36
|
+
signature.
|
|
37
|
+
|
|
38
|
+
### Tests run in parallel
|
|
39
|
+
|
|
40
|
+
CI runs `pytest -n 4`. A tool that promises determinism must not leak state
|
|
41
|
+
between concurrent tests, so this is a correctness check, not a speed
|
|
42
|
+
optimisation. If your test only passes serially, it is telling you something.
|
|
43
|
+
|
|
44
|
+
## Design positions that are deliberate
|
|
45
|
+
|
|
46
|
+
Before proposing one of these, please open an issue — they are choices, not
|
|
47
|
+
oversights.
|
|
48
|
+
|
|
49
|
+
**Replay cannot detect model-behaviour change.** It is physically impossible: a
|
|
50
|
+
recording contains what the model said then, not what it would say now. That is
|
|
51
|
+
what Tier 2 (`--live`) is for. Please do not file "replay should catch model
|
|
52
|
+
updates".
|
|
53
|
+
|
|
54
|
+
**Recording is not approving.** The approval gate exists because a recorded run
|
|
55
|
+
can be wrong, and an unreviewed golden turns a bug into an enforced contract.
|
|
56
|
+
Anything that makes approval implicit defeats the feature.
|
|
57
|
+
|
|
58
|
+
**DriftCatch does not evaluate answer quality.** Scoring whether an answer is
|
|
59
|
+
*good* is a different discipline, well served by promptfoo and DeepEval.
|
|
60
|
+
DriftCatch gates whether behaviour *changed*. Keeping that line sharp is why the
|
|
61
|
+
tool is small enough to trust.
|
|
62
|
+
|
|
63
|
+
**DriftCatch does not own your agent.** There is no agent registry, no base
|
|
64
|
+
class and no runtime to adopt. It wraps calls you already make. Anything that
|
|
65
|
+
requires restructuring the user's agent is out of scope.
|
|
66
|
+
|
|
67
|
+
**The MCP server is read-only.** An agent facing a red test will try to make it
|
|
68
|
+
green, and `approve` is the fastest way to do that. Mutating commands stay in
|
|
69
|
+
human hands.
|
|
70
|
+
|
|
71
|
+
## Pull requests
|
|
72
|
+
|
|
73
|
+
- One concern per pull request.
|
|
74
|
+
- Say what behaviour changed and how you verified it. Paste the commands.
|
|
75
|
+
- Update `CHANGELOG.md` under `## [Unreleased]`.
|
|
76
|
+
- If you changed the recording format, bump `RECORDING_VERSION` and say so
|
|
77
|
+
loudly — old goldens must fail to load rather than be misread.
|
|
78
|
+
|
|
79
|
+
## Reporting a security issue
|
|
80
|
+
|
|
81
|
+
Please do not open a public issue for a vulnerability. Email the maintainer
|
|
82
|
+
instead, and allow time for a fix before disclosure.
|
|
83
|
+
|
|
84
|
+
Areas worth scrutiny: recording names reaching the filesystem, secret redaction
|
|
85
|
+
on the write path, and anything reachable from the MCP server.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Critique of the v1 Design
|
|
2
|
+
|
|
3
|
+
> A hard, honest review of `REHEARSAL_DESIGN.md`. Issues are ordered by severity.
|
|
4
|
+
> **One blocking issue is architectural**: a central claim in the v1 design is not physically possible as written.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Summary verdict
|
|
9
|
+
|
|
10
|
+
The core idea is sound and worth building. But v1 has **three blocking defects**, **ten major gaps**, and **under-states the competition badly enough that the differentiation story has to be re-based**.
|
|
11
|
+
|
|
12
|
+
The good news: fixing the blocking architectural flaw doesn't kill the project — it makes it a *better, more honest* product, and it surfaces the one feature that genuinely differentiates it from the incumbent (`vcrpy`). That feature is **staleness detection**, which v1 listed as a *risk* rather than the headline capability it should be.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## BLOCKING — must be fixed before any code is written
|
|
17
|
+
|
|
18
|
+
### B1. Replay cannot detect model-behaviour change. Stage 5 is impossible as written.
|
|
19
|
+
|
|
20
|
+
This is the big one.
|
|
21
|
+
|
|
22
|
+
The v1 doc's flagship demo (§6 Stage 5) claims: a teammate rewords the prompt, the model now calls `web_search` instead of `lookup_order`, and replay catches it.
|
|
23
|
+
|
|
24
|
+
**It cannot.** Under replay, the LLM's response is served *from the tape*. The model never runs. Therefore the agent's decisions are frozen to whatever was recorded — it is structurally incapable of "switching to web_search." Replay would either (a) serve the old response and the agent would dutifully call `lookup_order` again (false green), or (b) fail to match because the request changed, which tells you *something* changed but not *what the model would now do*.
|
|
25
|
+
|
|
26
|
+
This isn't a nitpick — it's the headline demo of the whole framework, and it would collapse the first time anyone tried it.
|
|
27
|
+
|
|
28
|
+
It's also the single most-cited criticism of VCR-style replay for LLMs:
|
|
29
|
+
|
|
30
|
+
> "If you change a prompt, the LLM might respond differently in real life, but VCR will keep aggressively replaying the old response. Your tests will pass, but they're testing outdated reality."
|
|
31
|
+
|
|
32
|
+
**Fix — split into two tiers with different guarantees:**
|
|
33
|
+
|
|
34
|
+
| Tier | What runs | Cost | Catches | Cadence |
|
|
35
|
+
|---|---|---|---|---|
|
|
36
|
+
| **Tier 1 — Replay** | your code, with model+tool responses pinned from tape | free, ms | regressions in *your* glue: parsing, control flow, state, retries, error handling | every commit |
|
|
37
|
+
| **Tier 2 — Live behaviour check** | the real model, N times | real API spend | *model-behaviour* change ("now picks a different tool") | on prompt/model change, nightly, pre-release |
|
|
38
|
+
|
|
39
|
+
Plus a third, cheap capability that v1 missed entirely:
|
|
40
|
+
|
|
41
|
+
- **Request diff (free, under replay).** When your prompt/context/tool-schema changes, the *request* you send diverges from the recorded request. You can diff requests without running the model. This catches "someone changed the prompt upstream" for zero cost — it just can't tell you what the model would now decide.
|
|
42
|
+
|
|
43
|
+
Being explicit about which tier buys which guarantee is strictly better product design than v1's single blurred flow.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### B2. The assertion API in the worked example does not work.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
def refund_agent(message):
|
|
51
|
+
...
|
|
52
|
+
return f"Refunded ${order.total} to order {order.id}" # <- a plain string
|
|
53
|
+
|
|
54
|
+
def test_refund():
|
|
55
|
+
with rh.tape("refund_1182"):
|
|
56
|
+
result = refund_agent("refund order 1182")
|
|
57
|
+
rh.assert_tools(result).called("lookup_order") # <- result is a string
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`result` is the agent's own return value — a string. It carries no trajectory, no events, no cost. `assert_tools(result)` has nothing to read. The example as printed would raise immediately.
|
|
61
|
+
|
|
62
|
+
**Fix — assert on the recording, not on the agent's return value:**
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
with us.take("refund_1182") as take:
|
|
66
|
+
result = refund_agent("refund order 1182")
|
|
67
|
+
|
|
68
|
+
take.assert_tools().called("lookup_order").never("web_search")
|
|
69
|
+
take.assert_cost().under(tokens=8_000)
|
|
70
|
+
assert "Refunded $40" in result # ordinary assertion on the agent's output
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The context manager yields the recording object. This is also how `vcrpy` and most recorders work, so it matches user expectation.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### B3. "Adapters per provider & framework" is the wrong interception layer.
|
|
78
|
+
|
|
79
|
+
v1 specifies an adapter per provider (OpenAI, Anthropic, LiteLLM…) *and* per framework (LangGraph, CrewAI, Pydantic AI…). That is an unbounded maintenance surface — every SDK version bump can break you, forever, and you can never claim broad coverage.
|
|
80
|
+
|
|
81
|
+
**Fix — intercept at the HTTP transport layer.** Nearly every Python LLM SDK (OpenAI, Anthropic, LiteLLM, Mistral, Cohere, Google GenAI) issues requests through **`httpx`**. One transport-level interceptor covers all of them at once, survives SDK refactors, and is how the mature prior art (cagent, llama-stack, vcrpy) does it.
|
|
82
|
+
|
|
83
|
+
Framework "adapters" then shrink to a much smaller job: **extracting the trajectory** and **intercepting tool calls** (see M5), not proxying model calls. This cuts v0 scope dramatically while *increasing* coverage.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## MAJOR — fix before launch
|
|
88
|
+
|
|
89
|
+
### M1. The name is taken.
|
|
90
|
+
|
|
91
|
+
- **`rehearsal`** is an existing PyPI package (a measurement/research library).
|
|
92
|
+
- **`rehearser`** is also taken — and is, ironically, almost the same concept ("replay interactions for python method, HTTP or etc.", keywords include *contract testing, testing tools, rehearsal, proxy*).
|
|
93
|
+
|
|
94
|
+
Shipping under either name means a confusing install story and no clean namespace.
|
|
95
|
+
|
|
96
|
+
**Fix:** pick a new name and verify it on **PyPI, TestPyPI, npm, and GitHub** before writing a line. Candidates (all still need verification): **Understudy**, **Tapedeck**, **Takes**, **Soundcheck**. This document and the new design use **Understudy** as the working name, isolated to a single constant so renaming is a one-line change.
|
|
97
|
+
|
|
98
|
+
### M2. The competition is substantially stronger than v1 admits.
|
|
99
|
+
|
|
100
|
+
v1's comparison table lists "VCR-style cassettes" as a vague also-ran. Reality:
|
|
101
|
+
|
|
102
|
+
- **`vcrpy` + `pytest-recording` is the incumbent**, and **LangChain's own documentation officially recommends it** for exactly this use case. That is a very strong default to displace.
|
|
103
|
+
- **`coding-agent-vcr`** already exists on PyPI — "VCR / time-travel replay for Claude Code and Codex — deterministic offline agent testing."
|
|
104
|
+
- **`cendor-cassette`** exists.
|
|
105
|
+
- There are already published write-ups titled "VCR-style record/replay for LLM tests — make your agent tests deterministic and free."
|
|
106
|
+
|
|
107
|
+
**Consequence:** "record and replay LLM calls" is **not** a differentiator. It is table stakes, available today in two lines of config. The differentiation must be re-based onto what `vcrpy` structurally cannot do:
|
|
108
|
+
|
|
109
|
+
1. **Staleness detection** (see M9) — vcrpy will serve stale responses forever and never tell you.
|
|
110
|
+
2. **Trajectory/behaviour as a first-class object** — vcrpy knows HTTP, not tool calls, ordering, or agent decisions.
|
|
111
|
+
3. **The approval gate** — vcrpy has no notion of a human-blessed golden.
|
|
112
|
+
4. **The two-tier model** (B1) — vcrpy has no concept of a live behaviour check.
|
|
113
|
+
|
|
114
|
+
The README must answer *"why not just use vcrpy?"* above the fold. If it can't, the project is dead on arrival on Hacker News.
|
|
115
|
+
|
|
116
|
+
### M3. Cascading mismatch makes output useless.
|
|
117
|
+
|
|
118
|
+
If the prompt changes, event #1 stops matching — and so do events #2…#N, because everything downstream shifts. v1 has no story for this. A user changing one word would see fifty failures.
|
|
119
|
+
|
|
120
|
+
**Fix:** matching is **sequential and fail-fast**. Report the **first divergence point only** — "diverged at event #3 (llm): request differs from tape" with a focused diff — then stop. One change → one clear error.
|
|
121
|
+
|
|
122
|
+
### M4. Secrets and PII in committed tapes — an adoption blocker, barely mentioned.
|
|
123
|
+
|
|
124
|
+
Tapes contain full prompts and responses and are *committed to git*. That means: API keys in `Authorization` headers, customer data in prompts, PII in responses. Confirmed as a real failure mode in practice — cassettes capture `Authorization` headers unless explicitly filtered.
|
|
125
|
+
|
|
126
|
+
v1 mentions "secret redaction" once, as a parenthetical in a diagram. For any company, this is a go/no-go question.
|
|
127
|
+
|
|
128
|
+
**Fix — make it a first-class, default-on subsystem:**
|
|
129
|
+
- Redaction happens **at record time, before anything touches disk** (never a post-process).
|
|
130
|
+
- Default deny-list: `authorization`, `api-key`, `x-api-key`, `cookie`, `set-cookie`, plus common key patterns (`sk-`, `AKIA`, bearer tokens).
|
|
131
|
+
- `understudy scan` command to audit existing tapes.
|
|
132
|
+
- Documented PII policy + custom redactor hooks.
|
|
133
|
+
- Refuse to write a tape if a known key pattern survives redaction.
|
|
134
|
+
|
|
135
|
+
### M5. Tool interception is undesigned — and it's the hard part.
|
|
136
|
+
|
|
137
|
+
Model calls are HTTP and therefore interceptable. **Tools are arbitrary Python functions.** There is no universal hook. v1 simply assumes tool calls get captured.
|
|
138
|
+
|
|
139
|
+
**Fix — be explicit and honest about the three mechanisms:**
|
|
140
|
+
1. **Explicit decorator** (`@us.tool`) — always works, requires a one-line change per tool. The documented default.
|
|
141
|
+
2. **MCP transport interception** — MCP tool calls go over a transport, so they're interceptable like HTTP. Free coverage for MCP users.
|
|
142
|
+
3. **Framework adapters** — for LangGraph/CrewAI, hook the framework's own tool-dispatch point. Best-effort, per-framework.
|
|
143
|
+
|
|
144
|
+
Do not claim automatic universal tool capture. It isn't achievable.
|
|
145
|
+
|
|
146
|
+
### M6. "Trajectory" is never defined — yet the whole diff depends on it.
|
|
147
|
+
|
|
148
|
+
v1 shows `"trajectory": ["lookup_order", "issue_refund"]` — just tool names. That is too thin to be useful and too thin to diff meaningfully. Unanswered: are arguments included? Nesting/sub-agents? Parallel branches? Retries? LLM steps, or only tools?
|
|
149
|
+
|
|
150
|
+
**Fix:** define a precise, versioned trajectory schema (see new design §5). Diff tolerance becomes a real, explicit knob: `tools` / `tools+order` / `tools+order+args`.
|
|
151
|
+
|
|
152
|
+
### M7. Errors and exceptions are never captured.
|
|
153
|
+
|
|
154
|
+
If a tool raises, or the API returns 429/500, **that is behaviour** — often the exact behaviour you most want to pin (retry logic!). v1 records only successful results.
|
|
155
|
+
|
|
156
|
+
**Fix:** events carry `result` **or** `error` (type, message, status). Replay must be able to *re-raise* a recorded exception so retry/error paths are testable. This is a significant capability vcrpy handles poorly.
|
|
157
|
+
|
|
158
|
+
### M8. Parallel test execution would corrupt tapes.
|
|
159
|
+
|
|
160
|
+
`pytest-xdist` is near-universal in real repos. v1 implies global interception (monkeypatching, a global config). Under parallel workers that's a race: interleaved writes, cross-test event bleed, nondeterministic failures — in a tool whose entire value proposition is determinism.
|
|
161
|
+
|
|
162
|
+
**Fix:** all interception state lives in a **per-test context** bound to a `contextvars.ContextVar` (async-safe and thread-safe), never module globals. Tape writes are **atomic** (write temp + `os.replace`). Add an xdist test to CI from day one.
|
|
163
|
+
|
|
164
|
+
### M9. Staleness is treated as a risk. It should be the headline feature.
|
|
165
|
+
|
|
166
|
+
v1 buries "tape rot" in the risk table. But staleness is *the* criticism of replay testing, and handling it well is the clearest thing that separates this from `vcrpy`.
|
|
167
|
+
|
|
168
|
+
**Fix — promote it to a core subsystem.** Every tape stores a **fingerprint** of the things that determine whether it still reflects reality:
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
fingerprint = hash(system_prompt + tool_schemas + model_id + matcher_config)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
On every run, recompute and compare. If it differs, the tape is marked **STALE** and the framework says so:
|
|
175
|
+
|
|
176
|
+
> `⚠ tape "refund_1182" is STALE — the system prompt changed since it was approved.
|
|
177
|
+
> Replay still passes, but it no longer reflects current model behaviour.
|
|
178
|
+
> Run: understudy check --live refund_1182`
|
|
179
|
+
|
|
180
|
+
That single feature answers "your tests pass while testing outdated reality" — and nothing in the incumbent toolchain does it. **This should be on the first screen of the README.**
|
|
181
|
+
|
|
182
|
+
### M10. Tape size and repo bloat.
|
|
183
|
+
|
|
184
|
+
Full prompts + responses, especially with long contexts or streaming chunks, produce large files. A few hundred tests could add tens of MB to a repo, slowing clones and making diffs unreadable.
|
|
185
|
+
|
|
186
|
+
**Fix:** gzip event bodies by default; keep metadata and trajectory in readable plaintext (so PR diffs stay reviewable); warn above a configurable per-tape size budget; offer `--prune` to drop raw bodies while keeping the trajectory for behaviour-only tests.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## MINOR / SCOPE DISCIPLINE
|
|
191
|
+
|
|
192
|
+
| # | Issue | Fix |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| S1 | **v0 scope creep** — OTel export, local web UI, TypeScript port, cut-point replay, seeded fault injection are all in v1's plan. | Cut all of them from v0. Ship Python + CLI + pytest only. Each is a post-traction feature. |
|
|
195
|
+
| S2 | **"Local web UI (premium version)"** signals paid tiers before the project has a single user, and conflicts with the "neutral open tool" positioning. | Remove all commercial signalling from the OSS docs. |
|
|
196
|
+
| S3 | **Cost assertions** assume comparable token accounting across providers. | Normalize usage into one schema per provider; document which providers report what. |
|
|
197
|
+
| S4 | **Tape format versioning** is listed as an "open question." | It is not optional — tapes are committed artifacts. Ship `version: 1` plus a loader that refuses unknown versions with a clear message, from the first commit. |
|
|
198
|
+
| S5 | Says "five components," lists seven. | Editorial. |
|
|
199
|
+
| S6 | No stated Python version floor, packaging tool, or typing policy. | Python 3.11+, `uv`, `ruff`, strict `mypy`, `pydantic` at boundaries. |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## What survives, and what the project actually is
|
|
204
|
+
|
|
205
|
+
After the above, the honest positioning is **narrower but much more defensible** than v1's:
|
|
206
|
+
|
|
207
|
+
> **Understudy is not "record/replay for LLMs" — that already exists and is free.**
|
|
208
|
+
> Understudy is **an agent-behaviour regression system**: it pins your agent's behaviour as a human-approved golden, gives you free deterministic tests of your own code, tells you the moment a tape stops reflecting reality, and gives you a deliberate live check to re-verify behaviour when it matters.
|
|
209
|
+
|
|
210
|
+
The four load-bearing differentiators:
|
|
211
|
+
|
|
212
|
+
1. **Staleness detection via fingerprinting** — the headline.
|
|
213
|
+
2. **Trajectory as a first-class, diffable object** — behaviour, not bytes.
|
|
214
|
+
3. **Human approval gate** — golden state, reviewed in the PR.
|
|
215
|
+
4. **Two-tier model** — a free gate on every commit, a deliberate live check when it counts.
|
|
216
|
+
|
|
217
|
+
Everything else (record, replay, matching, normalizers) is **necessary plumbing, not a selling point.** Build it well, but don't market it.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Honest risk assessment
|
|
222
|
+
|
|
223
|
+
- **Displacing a documented default is hard.** `vcrpy` + `pytest-recording` is free, mature, and recommended in LangChain's docs. You must be clearly better *on the axes above*, not merely different.
|
|
224
|
+
- **Tool interception will never be fully automatic.** Accept the one-line decorator and say so plainly.
|
|
225
|
+
- **Tier 2 costs real money**, so adoption of the behaviour-check half depends on teams accepting a paid nightly run. Keep Tier 1 valuable enough to stand alone.
|
|
226
|
+
- **The hard engineering is concentrated in one module** (request normalization + matching). If that isn't excellent, nothing else matters. Build it first, and build it with a brutal test suite.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
*Next: `DESIGN.md` (revised architecture) and `IMPLEMENTATION_PLAN.md` (mechanical build order).*
|