Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
c1bbffd
1
Parent(s): 6148e16
deploy: backend from 8439c8b
Browse files- gates-leaf-lane-c.md +1 -1
- routes/codemap.md +1 -1
- tests/README.md +21 -35
- tests/codemap.md +2 -1
gates-leaf-lane-c.md
CHANGED
|
@@ -8,4 +8,4 @@
|
|
| 8 |
EXPECT: Lane C changes are limited to this gate file and the seven new test modules; existing unrelated dirty files are preserved.
|
| 9 |
Evidence: status showed the seven new modules and gate file, plus pre-existing dirty `backend/main.py` and `backend/routes/at_risk_resolution.py`; neither production file nor `conftest.py` was edited in Lane C.
|
| 10 |
|
| 11 |
-
Gate-check script evidence: `gate-check.mjs`
|
|
|
|
| 8 |
EXPECT: Lane C changes are limited to this gate file and the seven new test modules; existing unrelated dirty files are preserved.
|
| 9 |
Evidence: status showed the seven new modules and gate file, plus pre-existing dirty `backend/main.py` and `backend/routes/at_risk_resolution.py`; neither production file nor `conftest.py` was edited in Lane C.
|
| 10 |
|
| 11 |
+
Gate-check script evidence: `gate-check.mjs` exists at `.agents/skills/unlazy/scripts/gate-check.mjs`; run it as `node .agents/skills/unlazy/scripts/gate-check.mjs GATES.md` (or per-leaf `gates/` file). The pytest evidence and the scoped status check above are recorded directly.
|
routes/codemap.md
CHANGED
|
@@ -5,7 +5,7 @@ FastAPI route modules expose tutoring, curriculum, assessment, teacher, admin, a
|
|
| 5 |
|
| 6 |
## Design
|
| 7 |
- Modules define `APIRouter` instances, Pydantic request/response models, endpoint handlers, and local request/auth validation.
|
| 8 |
-
- `main.py` imports and mounts the routers; `ROLE_POLICIES`
|
| 9 |
- Handlers use domain services for reusable work, while some routes retain endpoint-specific orchestration and Firestore access.
|
| 10 |
- Representative routers: `rag_routes`, `deepseek_rag_routes`, `practice`, `curriculum_routes`, `class_records_router`, `admin_routes`.
|
| 11 |
|
|
|
|
| 5 |
|
| 6 |
## Design
|
| 7 |
- Modules define `APIRouter` instances, Pydantic request/response models, endpoint handlers, and local request/auth validation.
|
| 8 |
+
- `main.py` imports and mounts the routers; `ROLE_POLICIES` in `backend/main.py` (referenced by symbol, never by line number) controls path/role authorization, with `resolve_required_roles` as the single enforcement point and `backend/tests/role_policy_expectations.py` as the executable contract.
|
| 9 |
- Handlers use domain services for reusable work, while some routes retain endpoint-specific orchestration and Firestore access.
|
| 10 |
- Representative routers: `rag_routes`, `deepseek_rag_routes`, `practice`, `curriculum_routes`, `class_records_router`, `admin_routes`.
|
| 11 |
|
tests/README.md
CHANGED
|
@@ -1,46 +1,32 @@
|
|
| 1 |
-
# Backend Tests
|
| 2 |
|
| 3 |
-
##
|
| 4 |
-
The test suite has pollution when run in default pytest order. Tests pass in isolation or in specific groupings.
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
### Option 1: Run core API tests only (137 tests, all green)
|
| 9 |
```bash
|
| 10 |
cd backend
|
| 11 |
-
python -m pytest tests/
|
| 12 |
```
|
| 13 |
|
| 14 |
-
|
| 15 |
-
```bash
|
| 16 |
-
python -m pytest tests/ -v --ignore=tests/test_video_routes.py --ignore=tests/test_admin_model_routes.py --ignore=tests/test_hf_monitoring_routes.py
|
| 17 |
-
```
|
| 18 |
|
| 19 |
-
### Option 3: Individual test files (all green individually)
|
| 20 |
```bash
|
| 21 |
-
#
|
| 22 |
-
python -m pytest tests/test_api.py -v # 90 passed
|
| 23 |
-
python -m pytest tests/test_rag_pipeline.py -v # 13 passed
|
| 24 |
-
python -m pytest tests/test_quiz_battle.py -v # 19 passed
|
| 25 |
-
python -m pytest tests/test_model_profiles.py -v # 15 passed
|
| 26 |
-
python -m pytest tests/test_video_routes.py -v # 11 passed
|
| 27 |
-
python -m pytest tests/test_admin_model_routes.py -v # 19 passed
|
| 28 |
-
python -m pytest tests/test_hf_monitoring_routes.py -v # 8 passed
|
| 29 |
```
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
-
|
| 36 |
-
-
|
| 37 |
-
|
| 38 |
-
##
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
##
|
| 44 |
-
|
| 45 |
-
-
|
| 46 |
-
- Tests pass individually or in safe groupings
|
|
|
|
| 1 |
+
# Backend Tests
|
| 2 |
|
| 3 |
+
## Running the suite
|
|
|
|
| 4 |
|
| 5 |
+
The full suite runs green in default order — no ignores, subsets, or ordering workarounds needed:
|
| 6 |
|
|
|
|
| 7 |
```bash
|
| 8 |
cd backend
|
| 9 |
+
python -m pytest tests/ -v --tb=short
|
| 10 |
```
|
| 11 |
|
| 12 |
+
Run with `PYTHONPATH=<repo>/backend` and UTF-8 mode enabled (this is what CI does). Targeted runs:
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
```bash
|
| 15 |
+
python -m pytest backend/tests/<module>.py -q # from repo root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
```
|
| 17 |
|
| 18 |
+
Latest verified state: 579 passed, 0 failed.
|
| 19 |
+
|
| 20 |
+
## Fixtures (`conftest.py`)
|
| 21 |
+
|
| 22 |
+
- Firebase auth / Firebase Admin test doubles, so no production credentials are needed.
|
| 23 |
+
- Isolated-auth fixture: binds student/teacher claims per test module. Always apply it to auth-sensitive modules — suite-wide auth mocks previously leaked teacher claims into student cases (wrong role = wrong status codes, not real failures).
|
| 24 |
+
|
| 25 |
+
## Auth/authorization regression coverage
|
| 26 |
+
|
| 27 |
+
- `test_role_policies_regression.py` — matrix over `ROLE_POLICIES`; expectations live in `role_policy_expectations.py`.
|
| 28 |
+
- `test_diagnostic_iar_states.py`, `test_intervention_pipeline.py`, `test_quiz_battle_api.py`, `test_quiz_generation_regression.py`, `test_rag_regression.py`, `test_risk_wri_regression.py` — all assert 403-first rejection for unauthorized roles.
|
| 29 |
+
|
| 30 |
+
## History (resolved)
|
| 31 |
+
|
| 32 |
+
An older revision of this file described test pollution under default ordering (module-level auth roles, MagicMock resets). That failure mode is gone: the isolated-auth fixture plus per-module claim binding fixed it. If ordering failures ever return, check fixture isolation before reintroducing subsets or ignores.
|
|
|
tests/codemap.md
CHANGED
|
@@ -5,9 +5,10 @@ Python regression and contract tests for backend routes, services, RAG retrieval
|
|
| 5 |
|
| 6 |
## Design
|
| 7 |
- Pytest test modules use focused test functions/classes and `unittest.mock` fixtures to isolate external boundaries.
|
| 8 |
-
- `conftest.py` provides Firebase auth/Firebase Admin test doubles so tests do not require production credentials.
|
| 9 |
- Route tests use FastAPI `TestClient` and `main.app`; unit tests import service/RAG symbols directly.
|
| 10 |
- Representative coverage: `test_rag_pipeline.py`, `test_160_rag_lesson_retrieval.py`, `test_video_routes.py`, `test_admin_model_routes.py`, `test_wri_service.py`, and `test_memory_health.py`.
|
|
|
|
| 11 |
|
| 12 |
## Flow
|
| 13 |
- Test setup → `conftest.py` patches Firebase boundaries → imports route/service modules or constructs `TestClient(app)`.
|
|
|
|
| 5 |
|
| 6 |
## Design
|
| 7 |
- Pytest test modules use focused test functions/classes and `unittest.mock` fixtures to isolate external boundaries.
|
| 8 |
+
- `conftest.py` provides Firebase auth/Firebase Admin test doubles so tests do not require production credentials, plus an isolated-auth fixture that binds student/teacher claims per test module (suite-wide auth mocks previously leaked teacher claims into student cases — always apply the isolated fixture to auth-sensitive modules).
|
| 9 |
- Route tests use FastAPI `TestClient` and `main.app`; unit tests import service/RAG symbols directly.
|
| 10 |
- Representative coverage: `test_rag_pipeline.py`, `test_160_rag_lesson_retrieval.py`, `test_video_routes.py`, `test_admin_model_routes.py`, `test_wri_service.py`, and `test_memory_health.py`.
|
| 11 |
+
- Auth/authorization regression coverage: `test_role_policies_regression.py` (matrix over `ROLE_POLICIES`, expectations in `role_policy_expectations.py`), `test_diagnostic_iar_states.py`, `test_intervention_pipeline.py`, `test_quiz_battle_api.py`, `test_quiz_generation_regression.py`, `test_rag_regression.py`, `test_risk_wri_regression.py` — all assert 403-first rejection for unauthorized roles.
|
| 12 |
|
| 13 |
## Flow
|
| 14 |
- Test setup → `conftest.py` patches Firebase boundaries → imports route/service modules or constructs `TestClient(app)`.
|