Repository navigation
Add proofline.testing, a fake Proofline server for testing code that uses the SDK - #129
Open
amareshhebbar wants to merge 3 commits into
Open
amareshhebbar wants to merge 3 commits into
amareshhebbar wants to merge 3 commits into
Conversation
This branch has not been deployed
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.
Closes #128
What proofline.testing is
The problem. A Proofline customer writes code on top of the SDK. For example, a CI script that requests a review, waits for it, and fails the build on serious findings. To test that script today, they have three bad options:
unittest.mock. That is fragile. The mock returns whatever they guessed, not what Proofline really returns, so the test passes while production fails.The fix. The SDK already allows one door:
base_urlcan behttp://127.0.0.1. So this PR ships a small fake Proofline server inside the SDK. A test starts it, tells it what to say ("this review is queued, then running, then done with 2 findings"), and points the real client at it. The customer's code runs unchanged, with real HTTP, real retries and real parsing, but against a fake that answers in milliseconds.Think of a flight simulator. The pilot uses the real controls, and only the world outside is fake.
What makes it trustworthy. The fake builds every answer through the SDK's own generated models, which come from Proofline's API contract. So whatever the fake serves, the real client can read, and a broken test setup fails right away instead of later. It also records every request, so a test can check things like "my script asked for a review of PR 7 exactly once".
The same idea is behind Stripe's
stripe-mock, botocore'sStubberand moto for AWS.Example
What it supports
request_review,get_review,list_reviews,iter_reviews,list_pull_request_reviews,get_pull_request_review,stop_reviewandrerun_review.add_review(states=["RUNNING", "COMPLETED"])returns the next state on each read, sowait_for_reviewcan be tested through toCOMPLETED,INCOMPLETE,FAILEDorSTOPPED.fail_next(429, retry_after="1")and similar return real problem responses. The client's own retry and error handling deal with them.route(method, path, handler)serves an endpoint the fake does not cover.fake.requestsholds every request, with its method, path, query, headers and body.What it does not change
proofline/_generated/, the transport or the client methods.ProoflineClientandAsyncProoflineClient.Tests
tests/test_testing.pyhas 46 tests that run the real sync and async clients against the fake, with no mocks apart from the clock, the same waytests/test_http.pydoes. They cover staged states, outcomes, paging, stop and rerun, retries, wrong tokens, unknown ids, custom routes and bad setups. They cover 98% ofproofline/testing.py.scripts/check.pypasses in full, with 264 tests. The README has a new section, "Testing code that uses the SDK", whose example runs as written.AI assistance
I used an AI assistant to study the codebase, design the fake, and draft the code, tests and this description. I checked the design against the SDK's polling, retry and outcome code myself, ran a demo of a real CI gate against the fake, ran every check above, and I can answer questions about any line.