[Platform] HTTP-boundary record/replay cassettes for bridge tests#2128
Draft
wachterjohannes wants to merge 4 commits into
Draft
[Platform] HTTP-boundary record/replay cassettes for bridge tests#2128wachterjohannes wants to merge 4 commits into
wachterjohannes wants to merge 4 commits into
Conversation
c941e6e to
1cf8b18
Compare
Adds Mock\Http\CassetteHttpClient + HttpCassette: a cassette-backed HttpClientInterface passed to a real bridge Factory. By default the mode follows the cassette file - record (cassette missing + real key) stores raw HTTP responses; replay serves a MockResponse so the real Contract, ModelClient and ResultConverter run offline. Includes a Mistral example test driving the real Llm\ResultConverter from a committed cassette, plus secret redaction and SSE round-trip.
1cf8b18 to
4614bef
Compare
Contributor
Author
|
@OskarStark symfony/symfony#63781 RecorderHttpClient is the same idea at the same layer. As this PR would only be an improvement to the current test-setup we could postpone that OR merge this as something internal, use it in the bridges of this Repo and replace as soon as the RecorderHttpClient is landed (and we bump to this version). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a cassette-backed
HttpClientInterfacefor e2e-testing bridge internals offline. You passMock\Http\CassetteHttpClientto any real bridgeFactory(they all accept?HttpClientInterface):By default the mode follows the cassette file (override with the explicit
record:argument):Authorization/x-api-key/auth_bearer;MockResponse, so the real Contract +ModelClient+ResultConverterrun end-to-end with no network. Delete the cassette to re-record.Unlike
Test\InMemoryPlatformand theMockprovider (which bypass the converter), this exercises the bridge pipeline — so a bridge test can shrink to "load cassette → invoke → assert on the real converter output", and the cassette doubles as the request fixture.Mistral example (the payoff)
tests/Bridge/Mistral/ResultConverterCassetteTest.phpdrives the realBridge\Mistral\Llm\ResultConverterfrom committed cassettes:Covers both a
stop-finish text response and atool_calls-finish response (asToolCalls()).Details
MockHttpClientwith an array of responses); each interaction also stores a request signature + body for debugging/assertions.EventSourceHttpClient+SseStream.Symfony\AI\Platform\Mock\Http;symfony/http-clientstays a dev dependency (documented, likeInMemoryPlatform).