diff --git a/backend/Dockerfile.test b/backend/Dockerfile.test new file mode 100644 index 0000000..6bffc2f --- /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 0000000..d052618 --- /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 0000000..f07b152 --- /dev/null +++ b/backend/requirements-dev.txt @@ -0,0 +1,6 @@ +# Test + lint tooling — NEVER in the prod image (installed only in the Dockerfile's `dev` stage, +# which `siftlode publish` does not target). Pinned so the gate is reproducible: the same ruff the +# `siftlode check` backend lane runs, and pytest for the pure-logic suite. 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 0000000..ef8a94b --- /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