CI / lint-backend (push) Failing after 1m39s
CI / lint-mobile (push) Canceled after 11m8s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
138 lines
8.8 KiB
Markdown
138 lines
8.8 KiB
Markdown
# Découpage parallèle — Backend Kazier
|
|
|
|
Source : `FEEDBACK.md` (12 + A1-A16). But : 6 lots preneurs en parallèle, **zéro chevauchement de fichiers**.
|
|
Règle : chaque lot ne touche QUE ses fichiers. Si besoin transverse → note dans `Besoins inter-lots`, ne pas éditer hors lot.
|
|
|
|
Commande vérif par lot : `cd backend && go test ./...` (ou package ciblé). DB tests : `TEST_DATABASE_URL` si PG dispo, sinon skip OK.
|
|
|
|
---
|
|
|
|
## LOT 1 — AUTH critique (A1, #4, #12, A15-part)
|
|
**Fichiers exclusifs :**
|
|
- `backend/pkg/passwd/passwd.go`
|
|
- `backend/pkg/auth/auth.go`
|
|
- `backend/config/config.go`
|
|
- `backend/handlers/auth.go`
|
|
- `backend/handlers/middleware.go`
|
|
|
|
**Tâches :**
|
|
1. A1 : `dummyHash` aléatoire par boot (plus de `"kazier-constantime-dummy"` en dur). `AuthLogin` : early-return si `userErr != nil`, ne jamais toucher `user.ID` quand nil. Ajouter test : login user inconnu + password dummy → 401, pas 500.
|
|
2. #4 : `AUTH_SECRET` : refuser défaut `dev-secret-change-me` en prod (ex. `if ENV=prod && secret==défaut → Fatal`), exiger longueur ≥ 32, doc `.env.example`.
|
|
3. #12 : casser l'oracle : même code/délai que device existe ou non (vérifier device AVANT ou uniformiser 401). Ajouter rate-limit basique ou hook (même no-op + TODO).
|
|
4. A15-part : `Verify` : rejeter `userID/deviceID` non `^[0-9a-f]{32}$`. Middleware : option `EnforceDeviceExists` (défaut off, documenté) ou au moins log.
|
|
|
|
**Ne pas toucher :** `handlers/devices.go` (LOT 6), `repository/*` (LOT 4).
|
|
|
|
**Acceptance :** `go test ./pkg/passwd/... ./pkg/auth/... ./handlers/...` OK + test regression A1.
|
|
|
|
---
|
|
|
|
## LOT 2 — UPLOAD safe (A2, A3, A4, #5, #6, A16-part)
|
|
**Fichiers exclusifs :**
|
|
- `backend/service/resources.go`
|
|
- `backend/handlers/files.go`
|
|
|
|
**Tâches :**
|
|
1. #5 : sanit `extension` : `[a-z0-9]{1,10}` lowercase, sinon `""` ou `bin`. `destPath` sans `ext` si vide (pas de `id.`). Rejeter `/`, `..`, très long.
|
|
2. A2 : service : `io.LimitReader(src, MaxFileSize+1)` + vérifier octets écrits, retourner `ErrFileTooLarge` même si header ment.
|
|
3. A3 : écriture atomique : temp `destDir/.tmp-<id>` + `Fsync` + `Rename`. Pas d'overwrite direct.
|
|
4. #6 : au `UpdatePhysical` : lister `Glob(id.*)` ancien, `Remove` les autres ext. Sur `Insert` fail → `Remove(destPath)`. Sur `GetFile` fail après insert → tenter cleanup, au moins log.
|
|
5. A4 : `MkdirAll 0700`, fichier `0600` (`OpenFile` + `Chmod`). Vérifier umask.
|
|
6. A16-part : `file.Filename` → `name` : `TrimSpace`, cap 255, rejeter vide/`/`/`\n`. `Content-Type` : whitelist ou fallback `application/octet-stream`. `intParam/page/pageSize` : cap + 400 si négatif (pas fallback silencieux), `q` : `MaxLen 200`.
|
|
|
|
**Acceptance :** tests service upload : header menteur, ext vide/malicieuse, re-upload change ext → un seul fichier physique, perms 0600/0700.
|
|
|
|
---
|
|
|
|
## LOT 3 — SYNC core (#3, #7, A8, A9)
|
|
**Fichiers exclusifs :**
|
|
- `backend/service/sync.go`
|
|
- `backend/repository/operations.go`
|
|
- `backend/repository/shares.go`
|
|
|
|
**Tâches :**
|
|
1. #7 : rendre `ApplyBatch` atomique par op : `SELECT ... FOR UPDATE` ou transaction `Applied→apply→Record`. `Record` fail → retourner `applied:i` explicite, pas 500 nu.
|
|
2. #3 : `CreateLink` idempotent : `ON CONFLICT (id) DO NOTHING` + vérifier owner identique, sinon `NAME_CONFLICT`.
|
|
3. A9 : stocker `payload_hash (sha256)` dans `operations`, au replay même `(device,op)` comparer hash : différent → `INVALID_REQUEST` (pas skip silencieux). Migration `000011`.
|
|
4. A8 : uniformiser sémantiques : `update_metadata` absent → `NOT_FOUND` halt (pas no-op applied) ; `move/delete` non-owned → `NOT_FOUND` (pas applied silencieux) ; documenter choix. `create` : `ExistsOwner` + `Insert` en transaction ou `ON CONFLICT DO NOTHING` + check owner.
|
|
5. `classifySyncError` : ne plus fuir `err.Error()` brut (#8-part) : messages génériques + log interne.
|
|
|
|
**Ne pas toucher :** `repository/resources.go` (LOT 4) — si besoin, exposer interface, pas d'édit direct.
|
|
|
|
**Acceptance :** tests `service/sync_test.go` : replay même op, replay payload muté, create_link rejoué, move/delete grantee.
|
|
|
|
---
|
|
|
|
## LOT 4 — DATA ownership + migrations (#9, #10, A10, + parent-check)
|
|
**Fichiers exclusifs :**
|
|
- `backend/repository/users.go`
|
|
- `backend/repository/resources.go`
|
|
- `backend/repository/devices.go`
|
|
- `backend/service/bootstrap.go`
|
|
- `backend/db/migrations/*`
|
|
- `backend/db/db.go` (lecture seule sauf si besoin migration)
|
|
|
|
**Tâches :**
|
|
1. #9+A10 : `Count()` → `WHERE deleted_at IS NULL`. `UpdatePassword/MarkDeleted/GetByID` : ajouter `AND deleted_at IS NULL` + check `RowsAffected` → `ErrNotFound` si 0.
|
|
2. #10 : `000007` : supprimer `DELETE FROM resources` (backfill `owner_id` via user admin ou colonne nullable + migration douce). `000008 down` : down sans `::bigint` (ex. recréer colonne bigint + drop text, ou marquer irréversible avec message clair).
|
|
3. Parent-check atomique : `InsertFolder/InsertFile/MoveResource` : `INSERT ... SELECT` ou transaction `SELECT parent FOR SHARE → INSERT`, FK 500 → mapper `NOT_FOUND`.
|
|
4. `TouchResource/UpdateNameByID` : ajouter variantes scopées `TouchOwned(ownerID,...)`, `UpdateNameOwned(...)`, laisser anciennes en `deprecated` (LOT 3 migrera ensuite).
|
|
5. `NewID()` (A5) : retourner `(string,error)` OU `MustNewID` + `NewIDErr`. Choisir une signature, mettre à jour appelants **uniquement dans ces fichiers**.
|
|
|
|
**Acceptance :** `go test ./repository/... ./service/... ./db/...` + test soft-deleted login/bootstrap.
|
|
|
|
---
|
|
|
|
## LOT 5 — OCR + INFRA (A11, A12-part, A13, A14, #11)
|
|
**Fichiers exclusifs :**
|
|
- `backend/service/ocr.go`
|
|
- `backend/repository/ocr_jobs.go`
|
|
- `backend/ocr/*`
|
|
- `backend/cmd/server/main.go`
|
|
- `backend/service/services.go`, `move.go`, `upload.go`, `folders.go` (suppression)
|
|
|
|
**Tâches :**
|
|
1. #11 : supprimer les 4 stubs `UserCan*` toujours-true.
|
|
2. A11 : transitions gardées : `Complete/ Fail WHERE status='processing'`, `TouchProcessing WHERE status='queued'`, check `RowsAffected`. `ResetStaleProcessing` sur horloge DB (`now() - interval`), inclure `started_at IS NULL`. Ajouter index `(status,created_at)` (migration `000012` — coordonner nom avec LOT 4 pour éviter collision : LOT 5 prend `000012`, LOT 4 prend `000011`, LOT 3 payload_hash prend `000013`).
|
|
3. A13 : `Fail` avec `err`, `Complete` vérifie `UpdateOcrText RowsAffected`, sinon `Fail`. `tesseract.go` : `context.WithTimeout` par job (ex. 120s), `LimitReader` stdout/stderr (ex. 2MB), cap pages PDF (ex. 50) + erreur si tronqué, pas `continue` silencieux.
|
|
4. A12-part : `physicalPath` : `Lstat`, `IsRegular`, `EvalSymlinks` ∈ `UPLOAD_DIR`. `OCR_LANG` : whitelist `^[a-z+]{2,20}$`.
|
|
5. A14 : `main.go` : un seul pool (réutiliser `conn` pour migrate), `defer conn.Close()`, worker OCR avec `WaitGroup` + shutdown 5s documenté. Bootstrap : retry duplicate `username_normalized` ou `ON CONFLICT DO NOTHING`.
|
|
|
|
**Acceptance :** `go test ./ocr/... ./service/... ./repository/...` + test double-complete, stale requeue.
|
|
|
|
---
|
|
|
|
## LOT 6 — CONTRACT + DEVICE (A6, A7, §1 route, devices, secret-doc)
|
|
**Fichiers exclusifs :**
|
|
- `backend/handlers/router.go`
|
|
- `backend/handlers/share_links.go`
|
|
- `backend/handlers/sync.go`
|
|
- `backend/handlers/devices.go`
|
|
- `backend/handlers/health.go` (tests seulement si besoin)
|
|
- `backend/cmd/server/router_test.go`
|
|
- `backend/pkg/api/response.go` (messages génériques seulement)
|
|
|
|
**Tâches :**
|
|
1. §1 : réordonner `GET /files/folders` avant `GET /files/:id` + test `folders→200`, `:id=folders→404` (verrouille, même si Gin priorise statique).
|
|
2. A6 : `ShareLinkGet` : `errors.Is(err, ErrNotFound)`.
|
|
3. A7 : `ExpiresAt` : utiliser `exp` du token (retourner `Auth` ou parser), pas `Now()+TTL`. `TOKEN_ERROR` → `INTERNAL`. 32-hex malformé → `400 INVALID_REQUEST` partout (aligner `files.go` sur `devices.go`). `intParam/after` : 400 si garbage/négatif (pas fallback 0), `Atoi` 64-bit pour epoch-ms. `Bearer` : accepter `bearer` case-insensitive (option).
|
|
4. Devices : `POST /devices` : rate-limit/TODO + doc. `MarkUser` : check `RowsAffected` (device supprimé → 404).
|
|
5. `response.go` : messages génériques côté client, détail en log serveur (#8-part lot 6).
|
|
|
|
**Acceptance :** `router_test.go` étendu + tests handlers 400/404 cohérents.
|
|
|
|
---
|
|
|
|
## Ordre et dépendances
|
|
|
|
- Démarrage immédiat possible : LOT 1, LOT 2, LOT 5, LOT 6 (aucune dépendance mutuelle).
|
|
- LOT 3 et LOT 4 se touchent via `repository/resources.go` : LOT 4 seul l'édite. LOT 3 utilise l'interface existante, migrera vers `*Owned` au tour suivant.
|
|
- Migrations : LOT 4 = `000011`, LOT 5 = `000012`, LOT 3 = `000013`. Ne pas réutiliser un numéro.
|
|
- `NewID()` signature (LOT 4) : prévenir LOT 2/LOT 3 après merge, pas avant.
|
|
|
|
## Besoins inter-lots (ne pas éditer, juste signaler)
|
|
|
|
- LOT 3 → LOT 4 : besoin `TouchOwned/UpdateNameOwned`, `INSERT ... SELECT` parent.
|
|
- LOT 5 → LOT 2 : `physicalPath` safe partagé après merge LOT 2.
|
|
- Tous → LOT 6 : après uniformisation 400/404, aligner messages d'erreur.
|