diff --git a/backend/Dockerfile.test b/backend/Dockerfile.test new file mode 100644 index 00000000..6bffc2f8 --- /dev/null +++ b/backend/Dockerfile.test @@ -0,0 +1,12 @@ +# Test-only image — the app's Python deps + pytest/ruff, and NOTHING else. Code is bind-mounted at +# run time (not baked), so pytest always sees the working tree, and this file never touches the prod +# Dockerfile, so the published image can never carry test tooling. Same python + same pinned +# requirements.txt as the runtime stage, so tests run against the prod dependency set. Rebuilt only +# when a requirements file changes (the pip layer is cache-keyed on them); otherwise a no-op. +# +# docker build -f backend/Dockerfile.test -t siftlode-test:local backend +# docker run --rm -v "/backend:/app" -w /app siftlode-test:local python -m pytest +FROM python:3.12-slim +WORKDIR /app +COPY requirements.txt requirements-dev.txt ./ +RUN pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt diff --git a/backend/pytest.ini b/backend/pytest.ini new file mode 100644 index 00000000..d052618b --- /dev/null +++ b/backend/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +# Run from backend/ (the image's /app). `pythonpath = .` puts the app package on sys.path so tests +# import it as `app.*`, matching runtime. The suite is pure-logic only (no DB/network) — see tests/. +testpaths = tests +pythonpath = . +addopts = -q diff --git a/backend/requirements-dev.txt b/backend/requirements-dev.txt new file mode 100644 index 00000000..bc9c558d --- /dev/null +++ b/backend/requirements-dev.txt @@ -0,0 +1,7 @@ +# Test + lint tooling — NEVER in the prod image. Installed only by backend/Dockerfile.test (the +# throwaway test image), which the prod build (root Dockerfile) never references. Pinned so the +# suite is reproducible: pytest for the pure-logic tests, and ruff at the SAME version the gate's +# backend lint lane currently runs on the host (see the run_lint note in siftlode.sh). httpx is +# already an app dependency (requirements.txt), so its TestClient needs nothing extra here. +pytest==8.4.2 +ruff==0.15.21 diff --git a/backend/tests/test_links.py b/backend/tests/test_links.py new file mode 100644 index 00000000..ef8a94b0 --- /dev/null +++ b/backend/tests/test_links.py @@ -0,0 +1,53 @@ +"""Signed-grant HMAC for password-protected share links: a grant proves the viewer unlocked a +token, rides in the file URL (a