Files
syops/project-governance/plans/2026-03-28-stability-hardening-plan.md
T
2026-04-27 17:03:56 +08:00

92 lines
4.2 KiB
Markdown

# Stability Hardening Implementation Plan
> **For agent:** REQUIRED SUB-SKILL: Use Section 4 or Section 5 to implement this plan.
**Goal:** Strengthen the existing document cleaning system without redesign by expanding backend coverage for critical workflows and removing known deprecations.
**Architecture:** Keep the current FastAPI + SQLAlchemy + RQ structure intact. Add focused backend tests around task execution and admin APIs, then make the smallest production changes needed to satisfy those tests and remove framework/runtime deprecation warnings.
**Tech Stack:** FastAPI, SQLAlchemy, pytest, Vue/Vite build verification, SQLite test database
## Constraints
- Continue from the current implementation. Do not rebuild flows or replace the current architecture.
- Save governance artifacts under `project-governance/`.
- Run targeted verification after each completed block, then run the full backend suite and frontend build at the end.
- Frontend code is out of scope unless backend changes force a UI adjustment.
### Task 1: Establish plan and baseline
**Files:**
- Create: `project-governance/plans/2026-03-28-stability-hardening-plan.md`
- Read: `backend/tests/conftest.py`
- Read: `backend/app/tasks.py`
- Read: `backend/app/main.py`
- Read: `backend/app/models.py`
**Step 1:** Record the implementation plan in this file.
**Step 2:** Confirm the current backend and frontend verification commands still pass:
- `cd backend && python -m pytest tests -q`
- `cd frontend && npm run build`
**Step 3:** Use the baseline output as the comparison point for later changes.
### Task 2: Add conversion and Dify task coverage
**Files:**
- Modify: `backend/tests/conftest.py`
- Create or modify: `backend/tests/test_tasks.py`
- Modify as needed: `backend/app/tasks.py`
**Step 1:** Write failing tests covering:
- conversion task success path
- conversion task failure path
- Dify sync success path
- Dify sync failure path
**Step 2:** Run only the new task-focused tests and confirm they fail for the expected reasons.
**Step 3:** Implement the smallest production changes needed to make those tests pass.
**Step 4:** Re-run the task-focused tests and confirm they pass cleanly.
### Task 3: Add delete flow coverage
**Files:**
- Modify: `backend/tests/test_uploads.py` or create `backend/tests/test_files_api.py`
- Modify as needed: `backend/app/api/files.py`
**Step 1:** Write failing tests for:
- delete local document only
- delete local document and remote Dify document
**Step 2:** Run the delete-focused tests and confirm they fail for the expected reasons.
**Step 3:** Apply the minimum production changes required.
**Step 4:** Re-run the delete-focused tests and confirm they pass.
### Task 4: Add admin API coverage
**Files:**
- Create: `backend/tests/test_admin_api.py`
- Modify as needed: `backend/app/api/admin.py`
- Modify as needed: `backend/app/api/jobs.py`
- Modify as needed: `backend/app/api/auth.py`
**Step 1:** Write failing tests for the core management endpoints:
- create user
- update user
- fetch settings
- update settings
- list jobs
- enforce admin protection on admin endpoints
**Step 2:** Run the admin-focused tests and confirm they fail for the expected reasons.
**Step 3:** Make the smallest production changes required.
**Step 4:** Re-run the admin-focused tests and confirm they pass.
### Task 5: Remove known deprecations
**Files:**
- Modify: `backend/app/main.py`
- Modify: `backend/app/models.py`
- Modify: `backend/app/tasks.py`
- Modify as needed: `backend/tests/conftest.py`
**Step 1:** Replace FastAPI startup `on_event` usage with a `lifespan` handler.
**Step 2:** Replace `datetime.utcnow()` defaults and timestamps with timezone-aware UTC helpers.
**Step 3:** Run the backend suite and check that the previously observed deprecation warnings are removed.
**Step 4:** If warnings remain, trace the exact source and make the smallest additional fix.
### Task 6: Final verification
**Files:**
- Read: `backend/tests/*.py`
- Read: `frontend/package.json`
**Step 1:** Run the full backend suite:
- `cd backend && python -m pytest tests -q`
**Step 2:** Run the frontend build:
- `cd frontend && npm run build`
**Step 3:** Summarize:
- changed behavior
- test evidence
- remaining risks or uncovered areas