Repository navigation
test(github): the GitHub session's fake lives under tests/support/fakes, held to GitHub's recorded answers by a contract suite - #1716
Merged
Conversation
…es, held to GitHub's recorded answers by a contract suite The GitHub session's fake moves from tests/github_session_fakes.py to tests/support/fakes/github.py, and every importer reads it from there. Its github_api fixture moves beside it out of tests/conftest.py, defined with pytest.fixture, so the support registration gives it to every test and the test selector sees it; install_async_client_fake, which keeps github_api and stub_web from sharing a test, moves to tests/web_fakes.py, since a support module imports no conftest. serve_github_api installs any double of GitHub's API as the fixture installs the fake. tests/test_github_contract.py runs ten cases through the real session twice: over GitHubApiFake, routed as a test over the fake routes it, and over RecordedGitHubApi, which replays GitHub's own answers to the same requests in order through httpx2.MockTransport, offline, matching each request on its method, URL, If-None-Match and body. The answers were recorded on 2026-10-19 through the session's own transport (tests/fixtures/github_api/recorded_answers.json): reads of GitHub's octocat/Hello-World example repository, a search with no query, a Markdown render and a /user read with the pinned fake token, kept without any token, OAuth scopes, OAuth client or request id. The cases cover a REST read, a read answered from its ETag after a read GitHub answers 404, a 404, a listing over the pages GitHub links, a reader that stops early, a listing read again from its first page's ETag, a refused token, a 422, a write answered with text and a write refused with a 400. Each compares answers, errors, requests and the ledger with values written in the case, and each fails under a mutant of the fake or the session. The suite found the fake's quota wrong where it makes an answer itself. GitHub reports the quota as it stands with every REST answer; a 304 spends none of it and a 404 spends one. The fake's 304 reported the quota of the answer it stood in for, and its 404 reported none. The fake now holds the quota it last reported for each resource, which a test may set: its own 304 reports it, and its own 404 spends one from it. github_text takes headers, so a text answer carries the quota GitHub sends with it. Rate limits, 5xx answers, refused connects, redirects and a missing scope's 403 are not recorded: GitHub cannot be made to send the first three without spending a quota or waiting for an outage, a redirect wants a moved repository that names no person, and the session reads a missing scope from the token's x-oauth-scopes, which the recordings remove. The page cap is the session's own rule and stays tested in tests/test_github_session.py, and the session sends no GraphQL. The github_api fixture now refuses any gh command the rate limiter would run, run_gh and the quota refresh, so a reader that falls back to run_gh fails offline with "A test over the fake GitHub API ran gh: <argv>" instead of starting gh with the pinned fake token. The gh-output table drops the rows gh writes for no GitHub failure: scope 'project', scope "project", project scope, requires additional permissions, requires the 'project' scope, need the 'project' scope and authentication required. gh's source at v2.102.0 and go-gh's at v2.16.1 hold none of them in any failure message: project scope is only in the help of gh's skill installer, and authentication required only in the exit-codes section of gh's man page and in an authenticating proxy's 407 reason phrase, Proxy Authentication Required, which the table now pins as no class. The session's signing-key 422 is already confirmed against the key listing since PR 5. docs/TESTING.md and ADR 0006 name the fake's place and its contract suite, the task file records PR 7 and reads the item as delivered, its follow-up for the remaining gh-text matchers being the 2026-10-19 amendment on #891, and changelog.d/983.md describes the whole item. Closes #983
Closed
24 tasks
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.
The last of #983's pull requests. The GitHub session's fake moves under
tests/support/fakes/, and a contract suite holds it to GitHub's recorded answers. This closes #983.The move.
tests/github_session_fakes.pybecomestests/support/fakes/github.py, and every importer reads it from there. Git shows a delete plus an add, since the files are 44% similar after the fixes below.github_apifixture moves beside the fake out oftests/conftest.py, defined with@pytest.fixture. test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312's support registration gives it to every test, and the test selector sees it.install_async_client_fakemoves totests/web_fakes.py, since a support module imports no conftest.The contract suite:
tests/test_github_contract.py. Ten cases run through the real session twice:GitHubApiFake, routed as a test over the fake routes it;RecordedGitHubApi, which replays GitHub's own answers to the same requests in order throughhttpx2.MockTransport, offline. It fails on an unrecorded request or an unused recording.The cases:
Each compares answers, errors, requests and the ledger against values written in the case. Every case fails under at least one mutant of the fake or the session.
The recordings, in
tests/fixtures/github_api/recorded_answers.json, were made on 2026-10-19 through the session's own transport.octocat/Hello-Worldexample, a search with no query, and two Markdown renders, which change nothing. A/userread used the pinned fake token.Fake bugs the suite found, and fixed. GitHub reports the quota with every REST answer: a 304 spends none and a 404 spends one.
github_texttakes headers.Folded from #983's amendments.
github_apifixture refuses any gh command the rate limiter would run,run_ghand the quota refresh. A reader that falls back torun_ghfails offline with "A test over the fake GitHub API ran gh: " instead of starting gh with the fake token.Records.
docs/TESTING.mdand ADR 0006 name the fake's place and its contract suite.changelog.d/983.mddescribes the whole item.Verification
github_textwith no headers.uv run devops cipassed (pre-push hook).Closes #983
Fail-to-pass: not applicable: moves a test double and adds its contract suite; the src change removes table rows gh never writes, which the new table test pins