Compare commits
2
Commits
e64b72454f
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a43a9f1cd | ||
|
|
0a51f7d60f |
No files matched your search
@@ -0,0 +1,72 @@
|
||||
# M4: Setup Developer Environment - Score Report
|
||||
|
||||
**Model:** qwen3.8-27b
|
||||
**Repository scored:** `../newz` (`/home/daniel/Gitea/daniel/newz`), committed `origin/develop` at `ed7b304` (M4 commit, after `9144411` sample-data fix)
|
||||
**Rubric:** `milestone/m4-setup-developer-environment-scoring.md`
|
||||
|
||||
## Total Score: 20 (17 / 29 base + 3 bonus) - Overall level 1 as delivered
|
||||
|
||||
**Overall level 1 as delivered.** On this machine, `make dev` (`docker compose up -d --build`) fails in the repo's own directory. The compose file hardcodes subnet `172.28.0.0/16` for `newzy-network`, and that range is already used by the running `newz_newzy-network` network from your working copy. Docker reports `Pool overlaps with other one on this address space`, so the stack does not start. The stack does work once the subnet line is removed (tested in a temp copy, see below). The rubric's level 2 also asks for a `.env` file with defaults, and the repo has only `.env.example`.
|
||||
|
||||
## Verification Performed
|
||||
|
||||
All checks ran on a clean `git archive` export of `origin/develop` in a temp directory. I did not touch the running `newz` stack.
|
||||
|
||||
| Check | Result |
|
||||
|---|---|
|
||||
| `docker compose config -q` | Passes. |
|
||||
| `make help` and `make -n` for dev, stop, restart, backend-start, frontend-start, clean | Targets expand as documented. |
|
||||
| `docker compose up -d --build` (as committed) | **Fails:** `Pool overlaps with other one on this address space` for `172.28.0.0/16`. |
|
||||
| Existing host state | A `newz` compose project is already running from `/home/daniel/Gitea/daniel/newz`, holding ports 3000 and 8000. I did not stop it. |
|
||||
| Same stack with the `ipam` block removed and host ports 13000/18000 (temp copy only) | **Starts.** Backend healthy. Via the frontend proxy: `/` and `/articles` return the SPA (200); `/api/v1/version` and `/api/v1/health` return 200 through nginx. |
|
||||
| Frontend container healthcheck | **Fails** with exit code 1 on every run. `wget http://localhost/` tries `[::1]:80`, but nginx listens on IPv4 only. The container reports `unhealthy`. (Confirmed on the running `newz-frontend-1` container as well.) |
|
||||
| Backend `pytest` (temp export) | 19 passed, 95% coverage. |
|
||||
| Frontend `npm run test` (temp export) | 23 passed in 5 files. |
|
||||
| Frontend `npm run e2e -- --project=chromium` (temp export) | 9 passed. |
|
||||
| Data directory after compose run | `./data/db` and `newzy.db` are created **owned by root**, so a non-root `rm -rf data/` (`make clean`) fails with `Permission denied`. |
|
||||
|
||||
## Scoring by Criterion
|
||||
|
||||
| Criterion | Score | Max | Notes |
|
||||
|---|---|---|---|
|
||||
| docker-compose Configuration | 3 | 4 | Both services with the right build contexts, ports 3000 and 8000, a bridge network, the `./data/db` volume, `depends_on` with `service_healthy`, and restart policies. Backend has a working healthcheck. Frontend healthcheck is broken (see above). The hardcoded subnet stops the stack from starting on hosts where that range is taken. |
|
||||
| Environment Configuration | 2 | 3 | `.env.example` documents each variable with comments and defaults. `.env` is not in the repo; the README asks users to copy the template. `.env*` is git-ignored, with `!.env.example`. |
|
||||
| Development Commands | 3 | 4 | `dev`, `stop`, `restart`, `backend-start`, `frontend-start`, `build`, `logs`, `status`, shells, and `help` are present. `make test` runs frontend unit and backend tests, but E2E is a separate `make e2e` target, so `test` does not cover both. `clean` runs `rm -rf data/`, which fails on the root-owned database directory. `docker image prune -f` removes only dangling images. |
|
||||
| Security & Best Practices | 2 | 3 | `.env`, `.env.*`, and `data/` are git-ignored. `data/.gitignore` keeps the directory structure while excluding the database. `.dockerignore` files exist for both services. Deduction: the backend image runs as root (no `USER`). |
|
||||
| Documentation | 3 | 3 | README section covers prerequisites, quick start, services, ports, networking and storage, environment variables, Makefile reference, troubleshooting (including the `data/` ownership fix), and running without Docker. Subnet conflicts are not documented. |
|
||||
| Service Communication | 1 | 2 | Bridge network with frontend → backend proxying verified through nginx. Deduction: the fixed subnet prevents startup on hosts with an overlapping network, and the frontend healthcheck fails, so services are reported as not healthy. |
|
||||
| Build Optimization | 3 | 3 | Backend uses `python:3.11-slim`, `pip --no-cache-dir`, `PYTHONDONTWRITEBYTECODE`, and `PYTHONUNBUFFERED`. Frontend is multi-stage (`node:20-alpine` build, `nginx:1.27-alpine` serve) with `npm ci`. Both services have `.dockerignore`. |
|
||||
| **Base total** | **17** | **29** | |
|
||||
|
||||
### Bonus
|
||||
|
||||
- **+1 Logs command and restart policies:** awarded. `make logs` and `restart: unless-stopped` on both services.
|
||||
- **+2 README Docker troubleshooting and `.dockerignore` files:** awarded. Troubleshooting section present, and both `.dockerignore` files exclude build artifacts.
|
||||
- **+3 Full test automation and clean that removes images:** not awarded. `make test` skips E2E, and `clean` does not remove all images.
|
||||
|
||||
Bonus total: +3.
|
||||
|
||||
### Critical Requirements Checklist (from rubric)
|
||||
|
||||
- [x] `docker-compose.yml` defines both backend and frontend services
|
||||
- [x] Ports 3000 and 8000 configured
|
||||
- [x] Docker network defined (but its fixed subnet clashes on this host)
|
||||
- [x] `.env.example` present (`.env` not committed)
|
||||
|
||||
## Other Issues Found
|
||||
|
||||
1. **Hardcoded subnet `172.28.0.0/16`.** Remove the `ipam` block (let Docker pick a range), or make the subnet configurable. Currently `make dev` fails on any host where that range is taken, including this one.
|
||||
2. **Frontend healthcheck fails.** Change the Dockerfile `HEALTHCHECK` to `wget -qO- http://127.0.0.1/` (or make nginx listen on `[::]:80` as well). The container otherwise serves correctly.
|
||||
3. **Root-owned `data/` after first run.** The backend container creates `./data/db` as root. Use a non-root `user:` in compose, or pre-create the directory in the Makefile. Otherwise `make clean` fails for ordinary users.
|
||||
4. **`make test` does not include E2E.** Either add `e2e` to the `test` target, or document that `make test` is unit-only.
|
||||
5. **No `.env` default file.** The M4 prompt asks for one. A committed `.env` with dev defaults, or a `make env` target that copies the template, would satisfy it.
|
||||
6. **Backend runs as root.** Add a non-root `USER` to `backend/Dockerfile`.
|
||||
7. **Running stack from your working copy** is still up on ports 3000 and 8000, and its frontend container is `unhealthy` (see item 2).
|
||||
|
||||
## Path to a Higher Score
|
||||
|
||||
1. Remove the fixed subnet from `docker-compose.yml`.
|
||||
2. Fix the frontend `HEALTHCHECK` target to `127.0.0.1`.
|
||||
3. Make the database directory writable by the host user, and confirm `make clean` works from a non-root shell.
|
||||
4. Add `e2e` to `make test` and add a `.env` default or a copy target.
|
||||
5. Run the backend container as a non-root user.
|
||||
@@ -0,0 +1,78 @@
|
||||
# M5: Setup Authentication - Score Report
|
||||
|
||||
**Model:** qwen3.8-27b
|
||||
**Repository scored:** `../newz` (`/home/daniel/Gitea/daniel/newz`), local `develop` at `b186d0f` (M5 commit, **not yet pushed**; `origin/develop` is at `ed7b304`)
|
||||
**Rubric:** `milestone/m5-setup-authentication-scoring.md`
|
||||
|
||||
## Total Score: 44 (40 base + 4 bonus) - Overall level 5
|
||||
|
||||
Overall level 5: all level 2 to 4 criteria are met, all three auth pages exist, and the forms validate input with loading states and status-coded errors. The backend, frontend build and tests all pass on the committed tree.
|
||||
|
||||
## Verification Performed
|
||||
|
||||
All checks ran on a clean `git archive b186d0f` export in a temp directory.
|
||||
|
||||
| Check | Result |
|
||||
|---|---|
|
||||
| Prompt parity | `milestones/m5-setup-authentication-prompt.md` in the commit is identical to the benchmark copy. |
|
||||
| Backend `pytest` | **51 passed**, 97% coverage (649 statements, 18 missed). |
|
||||
| Live backend (uvicorn) | `register` 201 with JWT; `me` 200 with a valid token; `me` 401 with no token and with a tampered token; `login` 200 on correct password and 401 on wrong password; duplicate register 400; invalid username 422; `logout` 204. The token's `exp - iat` is 604800 seconds (7 days). |
|
||||
| Password storage | No plaintext password appears in any database file. |
|
||||
| Frontend `npm ci` and `npm run build` | Pass (`tsc` and `vite build`, no errors). |
|
||||
| Frontend `npx vitest run` | **9 files, 53 tests, all pass.** |
|
||||
| Frontend `npm run e2e -- --project=chromium` | **19 passed**, including `auth.spec.ts`. |
|
||||
| `/api/auth/*` (path in the milestone prompt) | Returns 404. The routes live under `/api/v1/auth/*`, following the M2 prefix. The commit message records this as a deliberate choice. |
|
||||
| Docker | Not re-run in this pass. On this host, `make dev` still fails on the hardcoded subnet from M4. |
|
||||
|
||||
## Scoring by Criterion
|
||||
|
||||
| Criterion | Score | Max | Notes |
|
||||
|---|---|---|---|
|
||||
| Backend User Model | 3 | 3 | `User` has `id`, `username` (String(60), unique, indexed), `password_hash` (String(128)), and `created_at` (timezone-aware, defaulted). |
|
||||
| Password Hashing | 4 | 4 | PBKDF2-HMAC-SHA256 with 120,000 iterations. Salt from `secrets.token_hex(16)`, stored as `salt$digest`. `verify_password` uses `secrets.compare_digest`. Tests cover round-trip, unique salts, and malformed stored values. |
|
||||
| JWT Token System | 5 | 5 | `create_token` sets `sub`, `iat`, `exp` (7 days), signs with HS256 using `HN_SECRET_KEY` (dev default marked as change-me). Decoding validates the signature, expiry, and that the user still exists. Tests cover wrong key and expired tokens. |
|
||||
| Backend Auth Endpoints | 5 | 5 | `register` (201, `{token, username}`, username regex, duplicate check), `login` (hash check, 401 on failure), `logout` (204, requires a token), `me` (Bearer validation). The duplicate-username check returns 400, matching the QA notes. Deviation: `/api/v1/auth/*` instead of `/api/auth/*`. |
|
||||
| Frontend Authentication Context | 5 | 5 | `AuthProvider` exposes `username`, `ready`, `login`, `register`, and `logout`. On load it calls `GET /auth/me` with the stored token and drops the token on failure. `Login` and `Register` go through the context, so the token is stored on success. `RequireAuth` guards protected routes. |
|
||||
| Token Storage & Management | 3 | 3 | `AUTH_TOKEN` is used consistently. Login and register store the token, logout removes it, and an invalid stored token is cleared on restore. |
|
||||
| API Client Auth Methods | 4 | 4 | `login`, `register`, `logout`, and `me` are implemented. The `Authorization: Bearer` header is attached to every request when a token exists. Non-2xx responses throw `ApiError`. |
|
||||
| Frontend Auth Pages | 5 | 6 | `Login`, `Register` (with client-side username, password-length and password-match checks, a disabled submit while busy, and error messages), and `SignOut` (routed at `/sign-out`, clears the token, redirects to `/login`). Deduction: no explicit success message after login or register, only a redirect. |
|
||||
| Security Implementation | 4 | 4 | PBKDF2 at 120k iterations, HS256, secret from `HN_SECRET_KEY` with a dev-only default, no plaintext passwords, and CORS configured from M2. |
|
||||
| Git Configuration | 2 | 2 | `backend/.gitignore` excludes `*.db`, `*.sqlite`, and `data/`. Root `.gitignore` excludes `.env` and `.env.*`. `data/.gitignore` names `newzy.db` and `data.db`. |
|
||||
| **Base total** | **40** | **46** | |
|
||||
|
||||
### Bonus
|
||||
|
||||
- **+1 Input validation and password strength:** awarded. Username regex `^[a-zA-Z0-9_]{3,20}$` on the backend and frontend, and passwords need at least 8 characters.
|
||||
- **+2 Non-leaking errors and rate-limit placeholders:** not awarded. Login errors are generic ("Invalid username or password"), but there are no rate-limit placeholder comments or code.
|
||||
- **+3 Complete error handling and protected-route redirect:** awarded. Errors are shown to the user, and `RequireAuth` redirects unauthenticated users to `/login`.
|
||||
|
||||
Bonus total: +4.
|
||||
|
||||
### Critical Requirements Checklist (from rubric)
|
||||
|
||||
**Must have for score above 1:**
|
||||
- [x] Passwords never stored as plaintext
|
||||
- [x] PBKDF2 with at least 100,000 iterations (SHA256)
|
||||
- [x] JWT uses HS256
|
||||
- [x] `HN_SECRET_KEY` used for signing
|
||||
- [x] Token `exp` is 7 days after `iat`
|
||||
|
||||
**Must have for score above 3:**
|
||||
- [x] Context provides login, register, logout
|
||||
- [x] `AUTH_TOKEN` persistence in localStorage
|
||||
- [x] Session check on load calls `/auth/me`
|
||||
- [x] 401 responses for invalid tokens
|
||||
|
||||
## Other Observations
|
||||
|
||||
1. **M5 is not on `origin/develop`.** The commit `b186d0f` exists only on local `develop`. Push it, or open a pull request from it, before treating M5 as delivered.
|
||||
2. **Endpoint path differs from the prompt.** The prompt says `/api/auth/*`, but the implementation uses `/api/v1/auth/*`, consistent with the M2 prefix. Either update the prompt or add an alias route.
|
||||
3. **No rate limiting.** The prompt lists rate limiting as a known limitation, so this is expected, but the bonus placeholder is missing.
|
||||
4. **Docker not re-verified.** The M4 subnet conflict on this host still blocks `make dev`, so the auth changes were not run inside containers in this pass.
|
||||
|
||||
## Path to a Higher Score
|
||||
|
||||
1. Push `develop` (or open a pull request) so M5 is on the remote.
|
||||
2. Add a success notice after login and register, to reach level 6 on the auth pages.
|
||||
3. Add a rate-limit placeholder comment or middleware stub on the auth endpoints for the +2 bonus.
|
||||
4. Reconcile the endpoint path with the milestone prompt, either by updating the prompt or adding `/api/auth` aliases.
|
||||
Reference in new issue
Block a user