# M2: Setup Backend - Score Report **Repository scored:** `../newz` (`/home/daniel/Gitea/daniel/newz`), `backend/` working tree **Rubric:** `milestone/m2-setup-backend-scoring.md` **Model:** qwen3.5-9b ## Total Score: 17 / 25 base (+3 bonus, 20 with bonus) **As delivered, the score is 0.** `backend/config.py` defines both `model_config` and `class Config`, which Pydantic v2 rejects with `PydanticUserError: "Config" and "model_config" cannot be used together`. The application cannot be imported, so every test errors at collection. The rubric states that a score of 0 applies when "application won't run". The scores below assume that one line is fixed. ## Scoring by Criterion | Criterion | Score | Max | Notes | |---|---|---|---| | Application Structure | 2 | 2 | All expected folders and files present: `api/v1`, `core`, `db`, `models`, `schemas`, `tests`, `main.py`, `config.py`, `requirements.txt`, `Dockerfile`, `.gitignore`, `pytest.ini`, `README.md`. | | Database Setup | 2 | 2 | SQLAlchemy engine and session configured for SQLite via `DATABASE_URL`. Volume mapping in `docker-compose.yml`. | | Models Implementation | 2 | 2 | Article, Author and Category have the specified fields, foreign keys and relationships. No cascade deletes or extra indexes, so not 3. | | Endpoints | 2 | 2 | `GET /health` and `GET /api/v1/version` return correct JSON. `/api/v1/health` is not implemented, though a test expects it. | | Documentation | 2 | 2 | `backend/README.md` (200 lines) covers endpoints with examples, startup, configuration table and schema. It overstates some things: CORS is configured but no middleware is added, and it says foreign keys are enforced, which SQLite does not do by default. | | Test Infrastructure | 3 | 3 | `pytest.ini`, `conftest.py`, and all three test files present. `pytest` and `pytest-asyncio` are in `requirements.txt`. | | Test Coverage | 1 | 3 | 8 of 16 tests fail (see below). Coverage is 68%, which is above 50% but below the 70% target. | | Docker Support | 1 | 2 | `Dockerfile` present and reasonable, but not built here. Once the config bug is fixed, the container should start. Also `backend/.gitignore` lists `Dockerfile`, so git ignores it and it would not be committed. | | Code Quality | 2 | 3 | Type hints, docstrings, and separated models, schemas and session. Exception handlers exist for `ValidationError` and generic `Exception`. But `RequestValidationError` is not handled, so 422 responses use FastAPI's default format rather than the "standardized" format the README describes. | | **Base total** | **17** | **25** | | ### Bonus | Bonus | Awarded | Reason | |---|---|---| | +1 Schema-level input validation | Yes | Pydantic `Field` constraints on all schemas. | | +2 README with startup instructions and config examples | Yes | Local and Docker startup, environment variable table. | | +3 Docker Compose setup | Not counted | `docker-compose.yml` exists, but the rubric's +3 also lists performance optimizations, which are absent. | Bonus total: +3. ## Test Results Run in a temporary copy with the `config.py` fix and `httpx` added. Results: **8 failed, 8 passed**, 68% coverage. Failures: - `test_health.py::test_api_v1_health_exists`: `/api/v1/health` is not implemented. - `test_models.py::test_author_unique_constraints` and `test_category_unique_constraints`: the duplicate-insert checks are fragile, and the assertion logic is wrong. - `test_models.py::test_article_creation` and `test_article_default_published`: SQLAlchemy errors when committing against the test database. - `test_models.py::test_tables_exist`: the test database has no tables, so the fixture does not create them. - `test_models.py::test_foreign_keys_exist`: `NameError`, `db_engine` is not in scope. - `test_version.py::test_version_format`: asserts the version starts with `v`, but the endpoint returns `0.1.0`. The test and the README disagree. ## Other Issues Found 1. **`config.py` import failure.** Remove the `class Config` block, which duplicates `model_config`. This blocks the whole application. 2. **`requirements.txt` is missing `httpx`.** Starlette's `TestClient` requires it, so the test suite cannot collect without it. 3. **`backend/.gitignore` ignores `Dockerfile`.** Remove that line so the Dockerfile is committed. 4. **Git state.** `backend/` and `docker-compose.yml` are untracked. The `m2` commit on `main` contains only the prompt file. 5. **Version format.** `APP_VERSION` is `0.1.0`, but the test and the prompt's example expect `v0.1.0`. Pick one and align the test and the README. 6. **`Dockerfile` copies the whole `backend/` folder**, including `tests/` and any local `.env`. Consider a `.dockerignore`. ## Path to a Higher Score 1. Fix `config.py`, add `httpx` to `requirements.txt`, and remove `Dockerfile` from `backend/.gitignore`. 2. Make the `test_models.py` tests create tables and use proper `IntegrityError` assertions, and fix the `db_engine` reference. 3. Align the version format between code, tests and README. 4. Add `/api/v1/health`, or remove its test and README reference. 5. Add a `RequestValidationError` handler that returns the standardized error format. 6. Build and run the Docker image to confirm it works.