Skip to content

test(backend): cover the infrastructure layer (db/ + core + main) - #65

Merged
untraceablez merged 2 commits into
mainfrom
test/backend-infra-coverage
Jun 25, 2026
Merged

test(backend): cover the infrastructure layer (db/ + core + main)#65
untraceablez merged 2 commits into
mainfrom
test/backend-infra-coverage

Conversation

@untraceablez

Copy link
Copy Markdown
Owner

Why

Part 2 of closing the remaining coverage gaps (after #64 took App.tsx 0%→100%). This covers the backend infrastructure layer — the db/, core/, and main.py modules that the earlier Track B service/router rounds skipped. Test-only; no source changes.

Coverage

File Before After
db/base.py 63% 100%
db/seed.py 0% **100%**¹
core/cache.py 32% 100%
core/deps.py 69% 100%
main.py 74% 100%
db/session.py 47% 97%²

¹ bar the if __name__ == "__main__" entrypoint guard
² the lone remaining line is the non-test pool_size branch, which only runs when ENVIRONMENT != "test"

Notable details

  • db/base.pyTimestampMixin.__init__ is never reached through the real models (they all declare (Base, TimestampMixin), so Base.__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 — every CacheService method incl. error branches and the delete_pattern scan_iter path, plus the get_redis singleton and close_redis.
  • core/deps.py — all auth-dependency branches: user id/role token parsing, current-user lookup, API-client auth, and require_client_scope. (create_access_token forces type="access", so client-token cases stub decode_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 stubbed get_db, so it doesn't depend on DATABASE_URL vs TEST_DATABASE_URL).

Result

  • Backend suite: 399 passed (pantrie-backend container)
  • Overall project coverage: 97.8% → 99%

🤖 Generated with Claude Code

untraceablez and others added 2 commits June 25, 2026 14:46
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
@untraceablez
untraceablez merged commit e05a8f9 into main Jun 25, 2026
1 check passed
@untraceablez
untraceablez deleted the test/backend-infra-coverage branch June 25, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant