Compare commits

..

15 Commits

Author SHA1 Message Date
Barcode Betty 135064fc10 Merge pull request 'fix(ci): resolve dev lint + typecheck failures (CAR-1330)' (#48) from betty/car-1330-dev-ci-fix into dev
CI / lint (push) Successful in 7s
CI / typecheck (push) Successful in 18s
CI / test (push) Successful in 22s
CI / build-and-push (push) Successful in 1m6s
2026-06-11 04:17:51 +00:00
Savannah Savings b141377b02 Merge pull request 'fix(api): document dispose_engine lazy import + regression test (CAR-1135)' (#45) from barcode-betty/fix-car-1135-dispose-engine into dev
CI / lint (push) Successful in 4s
CI / typecheck (push) Successful in 19s
CI / test (push) Successful in 23s
CI / build-and-push (push) Successful in 1m30s
2026-06-10 05:13:18 +00:00
Barcode Betty a3a01eefe2 Merge pull request 'fix(ci): simplify Push step to match auth pattern (CAR-1362)' (#53) from betty/car-1362-push-unknown-fix into dev
CI / lint (push) Successful in 4s
CI / typecheck (push) Successful in 18s
CI / test (push) Successful in 24s
CI / build-and-push (push) Successful in 1m45s
2026-06-10 04:10:58 +00:00
Barcode Betty 354e26295c fix(ci): simplify Push step to match auth pattern (CAR-1362)
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Successful in 20s
CI / test (pull_request) Successful in 22s
CI / build-and-push (pull_request) Has been skipped
The Push Docker image step is failing post-merge of CAR-1362 with
buildx "unknown" error after layers push successfully. The pre-existing
failure was masked by the cache export error.

Simplify the Push step to match the proven-green cartsnitch/auth/ci.yml
pattern: drop `file: ./Dockerfile` (default) and `build-args:`
(APT_CACHE_BUST is only used to bust apt cache in stage 1 of multi-
stage build, not needed for the rebuilt image). Keep `if: github.event_name
== "push"` to skip on pull_request events.

Diff: 4 lines removed from .gitea/workflows/ci.yml Push step.

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-06-10 04:08:53 +00:00
Barcode Betty 30a447674d Merge pull request 'fix(ci): remove GHA cache-from/cache-to (CAR-1357)' (#52) from betty/car-1362-remove-gha-cache-dev into dev
CI / lint (push) Successful in 6s
CI / typecheck (push) Successful in 18s
CI / test (push) Successful in 21s
CI / build-and-push (push) Failing after 1m8s
2026-06-09 18:03:04 +00:00
Barcode Betty 7a7d8f451e fix(ci): remove GHA cache-from/cache-to (CAR-1357)
CI / lint (pull_request) Successful in 9s
CI / typecheck (pull_request) Successful in 18s
CI / test (pull_request) Successful in 23s
CI / build-and-push (pull_request) Has been skipped
The build-and-push job fails post-merge of CAR-1356 REGISTRY_TOKEN fix:
cache-from/cache-to: type=gha backend does not exist on Gitea. Build
succeeds but post-build cache export fails and cascades to skipping the
Push Docker image step. Confirmed in uat run 3444 + dev run 3445.

Per CAR-1362, drop cache-from and cache-to from both Build and Push
Docker image steps. Matches proven-green cartsnitch/auth/ci.yml pattern.

Refs: CAR-1362, CAR-1356, CAR-1330, CAR-1357.

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-06-09 18:01:21 +00:00
Barcode Betty 79e8baa609 fix(ci): use REGISTRY_TOKEN for build-and-push registry login (CAR-1330)
CI / lint (push) Successful in 4s
CI / typecheck (push) Successful in 17s
CI / test (push) Successful in 25s
CI / build-and-push (push) Failing after 54s
Squashed fix swaps github.token → secrets.REGISTRY_TOKEN at .gitea/workflows/ci.yml:121, matching the proven-green cartsnitch/auth pattern (CAR-1009). Parity fix with uat PR #49 to prevent reintroduction on next dev→uat promotion.

Note: includes 3 absorbed lint/typecheck commits from PR #48 (already merged to dev via #48) to unblock CI on this branch. No app code changes; one-line CI config swap only.

QA: PR #50 approved by @cs_charlie (review id 4616); CI run 3443 lint/typecheck/test all green.
Co-authored-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
Co-committed-by: Barcode Betty <32+cs_betty@noreply.git.farh.net>
2026-06-09 17:47:11 +00:00
Barcode Betty 8deaf6e599 fix(ci): resolve dev lint + typecheck failures (CAR-1330)
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Successful in 19s
CI / test (pull_request) Successful in 22s
CI / build-and-push (pull_request) Has been skipped
Three CI-blocking issues on dev branch (also present on uat, fixed in 2b20946):

1. tests/conftest.py — remove extra blank line (ruff format).
2. src/cartsnitch_api/middleware/rate_limit.py — delete duplicate
   _public_limiter/_auth_limiter/_auth_strict_limiter forward-decl block
   (the second occurrence; mypy no-redef).
3. src/cartsnitch_api/cache.py:38 — annotate
   value: str | bytes | None so mypy doesn't widen redis client return
   to Any (no-any-return).

Verified: ruff check . && ruff format --check . && mypy src/cartsnitch_api
all pass.

Sibling of CAR-1330 (which fixes uat directly). Heals dev so future
dev → uat promotions stay green.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-09 11:13:44 +00:00
Barcode Betty 7b595744e1 fix(api): mypy no-redef and no-any-return errors on dev (CAR-1335)
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Successful in 18s
CI / test (pull_request) Successful in 22s
CI / build-and-push (pull_request) Has been skipped
The api typecheck job is continue-on-error but still posts a failure
status that blocks merges. Three pre-existing mypy errors on dev were
inherited by every PR based on it:

1. middleware/rate_limit.py: duplicate 'name already defined' for
   _public_limiter, _auth_limiter, _auth_strict_limiter (declared at
   lines 111-113 and again at 124-126). The second set is redundant
   because actual assignment happens inside the if/else below.
2. cache.py:43 - 'Returning Any' from .get(); the redis client's get()
   return type isn't narrowed to bytes|str, so the final 'return value'
   branch is Any. Wrap with str() to satisfy the declared str|None.
3. middleware/rate_limit.py:150 - 'Returning Any' from _get_client_ip.
   request.headers.get() and request.client.host are typed Any; wrap
   the branches with str() to match the declared str return.

Refs CAR-1335.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-09 05:25:41 +00:00
Barcode Betty 4877513bbf style: ruff format conformance (CAR-1335)
- tests/test_openapi.py: collapse 2 blank lines to 1 (ruff format)
- tests/conftest.py: collapse 2 blank lines to 1 (ruff format)

These format nits block lint (a hard gate). The conftest.py one was
introduced in CAR-1132 (#42) and would have blocked every subsequent PR
on dev until fixed.

Refs CAR-1335, CAR-1135.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-09 05:23:36 +00:00
Barcode Betty 9e46bdc460 fix(api): document dispose_engine lazy import + regression test (CAR-1135)
CI / lint (pull_request) Failing after 4s
CI / typecheck (pull_request) Failing after 18s
CI / test (pull_request) Successful in 22s
CI / build-and-push (pull_request) Has been skipped
- main.py: add docstring inside the lifespan function explaining why
  dispose_engine is lazy-imported rather than top-level. The original
  import path (top-level) crashed the container at import time with
  'ImportError: cannot import name dispose_engine from cartsnitch_api.database'
  when database.py was stale or stripped during a CI build. Lazy import
  keeps the engine disposal behavior while preventing the module-load
  crash.
- tests/test_openapi.py: add test_dispose_engine_importable_from_database
  that asserts dispose_engine is importable and callable. This is the
  exact path the deployed UAT image was failing on, captured as a
  regression test so a future regression lands in CI before deploy.

Refs CAR-1135.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-09 05:13:08 +00:00
Savannah Savings 3860a5d061 Merge pull request 'Fix CAR-1132: SQLite UUID binding and User.id defaults in test fixtures' (#42) from betty/car-1132-comprehensive-fix into dev
CI / lint (push) Failing after 7s
CI / typecheck (push) Failing after 17s
CI / lint (pull_request) Failing after 3s
CI / test (push) Successful in 22s
CI / typecheck (pull_request) Failing after 18s
CI / build-and-push (push) Has been skipped
CI / test (pull_request) Successful in 22s
CI / build-and-push (pull_request) Has been skipped
2026-06-09 01:01:09 +00:00
Savannah Savings 7a7aaca064 Fix PostgreSQL connection pool issues (CAR-1077) (#39)
CI / lint (push) Successful in 5s
CI / typecheck (push) Successful in 28s
CI / lint (pull_request) Successful in 6s
CI / test (push) Failing after 1m0s
CI / build-and-push (push) Has been skipped
CI / typecheck (pull_request) Successful in 29s
CI / test (pull_request) Failing after 1m2s
CI / build-and-push (pull_request) Has been skipped
QA approved by Checkout Charlie; CTO Dev review approved by Savannah Savings. Adds pool_timeout=30 and DB-connectivity /health probe. Strict CI improvement (lint+typecheck green); remaining test failure pre-existing on dev, tracked under CAR-1132/PR#42.
2026-06-02 15:10:01 +00:00
Barcode Betty 76781ed238 style: fix ruff format in conftest.py
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Successful in 29s
CI / test (pull_request) Failing after 1m0s
CI / build-and-push (pull_request) Has been skipped
Add missing blank line between the _set_timestamp_defaults helper
and the next top-level constant so `ruff format --check .` passes.
Pre-existing on dev's HEAD; surfaced after rebasing PR #39 onto dev
in 2b20946.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-02 14:58:18 +00:00
Barcode Betty 2b20946ad7 fix: /health returns 503 on DB failure, pool_timeout=30, CI typecheck fixes
CI / lint (pull_request) Failing after 4s
CI / typecheck (pull_request) Failing after 25s
CI / test (pull_request) Failing after 1m5s
CI / build-and-push (pull_request) Has been skipped
QA review of PR #39 (CAR-1121) identified three blocking issues; this
commit addresses all three plus the typecheck errors flagged as CI RED.

CAR-1077 (PR #39) changes:
- database.py: add pool_timeout=30 so the engine fails fast when the
  connection pool is exhausted (defends against the "server closed
  connection unexpectedly" pod failures).
- routes/health.py: /health now calls SELECT 1 through Depends(get_db)
  and raises HTTPException(503) when the database is unreachable, so
  Kubernetes readiness probes can correctly mark the pod unhealthy and
  stop routing traffic to it.  Logs the failure at exception level for
  observability.
- Drop .mcp.json from this PR (root-level MCP server config, not
  related to the pool fix; tracked separately).

CI typecheck fixes (pre-existing on dev, were failing mypy on PR #39):
- auth/passwords.py: cast bcrypt return values so mypy doesn't widen
  to Any.
- config.py: silence the false-positive call-arg on Settings() — the
  three required fields are populated from the environment by
  pydantic-settings at runtime.
- cache.py: coerce the bytes/str union returned by the redis client
  to the documented str | None return type.
- middleware/rate_limit.py: annotate the three module-level limiters
  with the RateLimitBackend protocol, cast the redis zrange score to
  float before arithmetic, and add max_requests/window_seconds to the
  protocol so the response-header builder can read them.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-02 14:53:16 +00:00
9 changed files with 55 additions and 27 deletions
+1 -7
View File
@@ -118,7 +118,7 @@ jobs:
echo "CalVer tag: $VERSION"
- name: Log in to Gitea Container Registry
run: echo "${{ github.token }}" | docker login git.farh.net -u ${{ github.actor }} --password-stdin
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.farh.net -u ${{ github.actor }} --password-stdin
- name: Extract metadata
id: meta
@@ -140,8 +140,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APT_CACHE_BUST=${{ github.run_id }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Scan api image for vulnerabilities
uses: anchore/scan-action@v5
@@ -162,13 +160,9 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APT_CACHE_BUST=${{ github.run_id }}
cache-from: type=gha
- name: Create git tag
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
-11
View File
@@ -1,11 +0,0 @@
{
"mcpServers": {
"gitea": {
"type": "http",
"url": "https://git-mcp.farh.net/mcp",
"headers": {
"Authorization": "Bearer ${GITEA_TOKEN}"
}
}
}
}
+2 -2
View File
@@ -4,8 +4,8 @@ import bcrypt
def hash_password(password: str) -> str:
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
return str(bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode())
def verify_password(plain_password: str, hashed_password: str) -> bool:
return bcrypt.checkpw(plain_password.encode(), hashed_password.encode())
return bool(bcrypt.checkpw(plain_password.encode(), hashed_password.encode()))
+2 -2
View File
@@ -35,12 +35,12 @@ class CacheClient:
async def get(self, key: str) -> str | None:
if not self._client:
return None
value = await self._client.get(key)
value: str | bytes | None = await self._client.get(key)
if value is None:
return None
if isinstance(value, bytes):
return value.decode("utf-8", errors="replace")
return value
return str(value)
async def set(self, key: str, value: str, ttl_seconds: int = 300) -> None:
if not self._client:
+1
View File
@@ -14,6 +14,7 @@ def _build_engine_kwargs() -> dict:
kwargs.update(
pool_size=10,
max_overflow=20,
pool_timeout=30,
pool_pre_ping=True,
pool_recycle=3600,
)
+6
View File
@@ -25,6 +25,12 @@ from cartsnitch_api.routes.user import router as user_router
@asynccontextmanager
async def lifespan(app: FastAPI):
# Lazy import: keep `dispose_engine` out of the top-level imports so a
# stale or partially-built database.py never breaks module load on
# container start. The function is required for graceful pool cleanup
# on shutdown; if the import fails, the cache_client.close() that
# follows the yield would mask it. See CAR-1135 for the original
# ImportError that motivated this pattern.
from cartsnitch_api.database import dispose_engine
await cache_client.initialize()
+2 -2
View File
@@ -147,8 +147,8 @@ def _get_client_ip(request: Request) -> str:
"""Extract client IP, respecting X-Forwarded-For behind a reverse proxy."""
forwarded = request.headers.get("x-forwarded-for")
if forwarded:
return forwarded.split(",")[0].strip()
return request.client.host if request.client else "unknown"
return str(forwarded.split(",")[0].strip())
return str(request.client.host) if request.client else "unknown"
def _get_rate_limit_key(request: Request) -> tuple[str, RateLimitBackend]:
+27 -3
View File
@@ -1,16 +1,40 @@
"""Health check and error metrics endpoints."""
from fastapi import APIRouter, Depends
import logging
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession
from cartsnitch_api.auth.dependencies import verify_service_key
from cartsnitch_api.database import get_db
from cartsnitch_api.middleware.error_handler import get_error_monitor
logger = logging.getLogger(__name__)
router = APIRouter(tags=["health"])
@router.get("/health")
async def health():
return {"status": "ok"}
async def health(db: AsyncSession = Depends(get_db)):
"""Liveness + DB connectivity probe.
Returns HTTP 200 when the API process is responsive *and* the database
is reachable, so Kubernetes readiness probes can correctly route traffic
away from pods that have lost their database connection.
Returns HTTP 503 when the database is unreachable so K8s marks the pod
unhealthy and stops sending traffic to it.
"""
try:
await db.execute(text("SELECT 1"))
except Exception as exc:
logger.exception("Health check failed: database unreachable")
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail={"status": "unavailable", "database": "disconnected"},
) from exc
return {"status": "ok", "database": "connected"}
@router.get("/internal/error-stats", dependencies=[Depends(verify_service_key)])
+14
View File
@@ -3,8 +3,22 @@
import pytest
from httpx import ASGITransport, AsyncClient
from cartsnitch_api.database import dispose_engine
from cartsnitch_api.main import app
def test_dispose_engine_importable_from_database():
"""Regression for CAR-1135: api main.py used to import dispose_engine
at module level. A stale database.py (no dispose_engine) crashed the
container at import time with ImportError on line 9. The fix moved
the import inside the lifespan function, but `dispose_engine` must
still be importable from `cartsnitch_api.database` for the lifespan
teardown to actually close pooled connections.
"""
assert callable(dispose_engine)
assert dispose_engine.__name__ == "dispose_engine"
EXPECTED_ROUTES = [
# Auth (3 — register/login/refresh are handled by Better-Auth service)
("get", "/auth/me"),