56 lines
3.4 KiB
Markdown
56 lines
3.4 KiB
Markdown
# External Draft Update API Implementation Plan
|
||
|
||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||
|
||
**Goal:** Add a documented, authenticated PATCH endpoint that changes only editorial fields on existing unpublished drafts.
|
||
|
||
**Architecture:** Extend the existing FastAPI `/api/v1/drafts` router with one Pydantic input model and one guarded handler. Reuse current sanitizers, slug normalization, API authentication, persistence, and response serialization so update behavior cannot diverge from creation behavior.
|
||
|
||
**Tech Stack:** Python, FastAPI, Pydantic, SQLAlchemy, unittest/TestClient, Forgejo Actions, Docker Compose.
|
||
|
||
---
|
||
|
||
### Task 1: Specify update behavior with tests
|
||
|
||
**Files:**
|
||
- Modify: `tests/test_draft_api.py`
|
||
|
||
- [ ] Add a helper that creates a video-linked draft and returns its identifiers.
|
||
- [ ] Add a test that PATCHes editorial fields and verifies the returned payload, sanitized HTML, updated cover, preserved `video.id`, preserved `status=draft`, and `publishedAt=null`.
|
||
- [ ] Add tests for empty payload (`422`), wrong key (`401`), missing article (`404`), published/non-draft article (`409`), duplicate slug (`409`), invalid cover URL (`422`), and forbidden unknown fields (`422`).
|
||
- [ ] Run `python -m unittest tests.test_draft_api -v` and verify the new tests fail because PATCH is not implemented.
|
||
|
||
### Task 2: Implement the guarded PATCH endpoint
|
||
|
||
**Files:**
|
||
- Modify: `app/routes.py`
|
||
|
||
- [ ] Add `DraftUpdateIn` with optional editorial fields and `model_config = ConfigDict(extra="forbid")`.
|
||
- [ ] Add `PATCH /api/v1/drafts/{article_id}` after the existing GET detail route.
|
||
- [ ] Authenticate with `require_draft_api_key` and reject missing/rejected, non-draft, or published records before mutation.
|
||
- [ ] Reject an empty update and apply the create endpoint's validation, slug normalization, HTML sanitation, and duplicate-title stripping only to supplied fields.
|
||
- [ ] Commit once, roll back on `IntegrityError`, refresh, and return `draft_api_payload`.
|
||
- [ ] Run `python -m unittest tests.test_draft_api -v` and verify every draft API test passes.
|
||
|
||
### Task 3: Document and validate the contract
|
||
|
||
**Files:**
|
||
- Modify: `docs/draft-api.md`
|
||
- Modify: `/Users/dima/.codex/skills/dzen-assistant-api/SKILL.md`
|
||
- Modify: `/Users/dima/.codex/skills/dzen-assistant-api/references/api-contract.md`
|
||
|
||
- [ ] Document allowed fields, draft-only guards, status codes, and explicit non-capabilities.
|
||
- [ ] Run `python -m unittest discover -s tests -v`.
|
||
- [ ] Run `git diff --check` and inspect the scoped diff.
|
||
|
||
### Task 4: Deploy and prove the production boundary
|
||
|
||
**Files:**
|
||
- Commit only the scoped application, tests, docs, and skill updates.
|
||
|
||
- [ ] Push `main` so the existing Forgejo workflow deploys API, worker, and beat.
|
||
- [ ] Poll `https://dzen.nstarikov.ru/health` and `/openapi.json` until PATCH appears on `/api/v1/drafts/{article_id}`.
|
||
- [ ] Read drafts 508–510 before mutation and record title, slug, video ID, status, and published date.
|
||
- [ ] PATCH only `lead`, `bodyHtml`, `ctaHtml`, and `featureImageUrl` using the prepared editorial payload and uploaded covers.
|
||
- [ ] Read drafts 508–510 back and verify unchanged title, slug, video ID, `status=draft`, `publishedAt=null`, one `[[VK_VIDEO]]` marker, one rendered iframe, exact cover URL, internal Dzen links, opinion block, and signature link.
|
||
|