test(backend): cover the infrastructure layer (db/ + core + main) - #65
Merged
Conversation
Closes the backend coverage gaps the Track B service/router rounds skipped. Test-only; no source changes. - db/base.py 63% -> 100%: TimestampMixin.__init__ (defaults + explicit values). The real models all declare (Base, TimestampMixin) so Base.__init__ wins the MRO; an isolated probe model puts the mixin first to exercise it. - db/seed.py 0% -> 100% (bar the __main__ guard): seed_categories against a real session; seed_all empty/already-seeded/error-rollback via a stubbed AsyncSessionLocal. - core/cache.py 32% -> 100%: get_redis singleton, close_redis, and every CacheService method incl. error branches and delete_pattern scan. - db/session.py 47% -> 97%: get_db commit + rollback paths, init_db, drop_db (mocked sessionmaker/engine). The lone remaining line is the non-test pool-size branch, unreachable when ENVIRONMENT=test. - core/deps.py 69% -> 100%: all auth-dependency branches (user id/role, current user, api-client auth, require_client_scope). - main.py 74% -> 100%: proxy-headers middleware (CF + X-Forwarded paths), validation + Pantrie exception handlers, lifespan custom-domain and db-error branches, health/root. Backend suite: 399 passed; overall coverage 99%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wr2keVNHj51gFeShnKqa7Q
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.
Why
Part 2 of closing the remaining coverage gaps (after #64 took
App.tsx0%→100%). This covers the backend infrastructure layer — thedb/,core/, andmain.pymodules that the earlier Track B service/router rounds skipped. Test-only; no source changes.Coverage
db/base.pydb/seed.pycore/cache.pycore/deps.pymain.pydb/session.py¹ bar the
if __name__ == "__main__"entrypoint guard² the lone remaining line is the non-test
pool_sizebranch, which only runs whenENVIRONMENT != "test"Notable details
db/base.py—TimestampMixin.__init__is never reached through the real models (they all declare(Base, TimestampMixin), soBase.__init__wins the MRO). An isolated probe model on its own declarative base puts the mixin first to exercise both the default and explicit-value branches — without touching the app's metadata.core/cache.py— everyCacheServicemethod incl. error branches and thedelete_patternscan_iterpath, plus theget_redissingleton andclose_redis.core/deps.py— all auth-dependency branches: user id/role token parsing, current-user lookup, API-client auth, andrequire_client_scope. (create_access_tokenforcestype="access", so client-token cases stubdecode_token.)main.py— proxy-headers middleware (CF-Connecting-IP + X-Forwarded-* paths), the validation + Pantrie exception handlers, and the lifespan custom-domain and db-error branches (via a stubbedget_db, so it doesn't depend onDATABASE_URLvsTEST_DATABASE_URL).Result
pantrie-backendcontainer)🤖 Generated with Claude Code