feat(api): sync réel — outbox POST /sync/ops idempotente + snapshot GET /sync/permissions (owner V1)

- operations.operation_id/ref_id BIGINT (= id client pending_operations), UNIQUE(device_id, operation_id) idempotente ; migration 000004 corrigée + test
- service/sync.go : ApplyBatch séquentiel (no-op si déjà traitée ; create déjà présent / update/move sur ressource absente / delete absent = no-op) ;
  arrêt à la première erreur non-idempotente (NAME_CONFLICT, NOT_FOUND, INVALID_REQUEST) + trace après succès ; ops share/share_link accusées sans état (V1)
- handlers/sync.go : POST /sync/ops → {applied, failed|null} ; GET /sync/permissions?after= → snapshot delta (effectiveAccess owner, cachedAt ms)
- snapshot : repo.ListOwned (delta updated_at en ms, trié) ; index partiel racine (owner_id, name) WHERE parent_id IS NULL
- GET /files sans folderId = racine uniquement (convention useFiles(undefined)) ; tests files_test corrigés (codes d'erreur imbriqués, tailles)
- fix dbtest : ping la connexion maintenance (création de la DB cible possible) — les tests handlers/repo tournent enfin contre PG réel
- tests handlers end-to-end : batch appliqué + retry idempotent, arrêt sur NAME_CONFLICT, delete idempotent, snapshot + delta
This commit is contained in:
m
2026-09-10 19:50:23 +02:00
parent 37ad2d4275
commit 5d96814853
14 changed files with 759 additions and 41 deletions
+12 -1
View File
@@ -109,9 +109,20 @@ func TestMigrationsUpDown(t *testing.T) {
assertHexCheck(t, conn, "devices", "device_id")
assertHexCheck(t, conn, "resources", "resource_id")
assertHexCheck(t, conn, "operations", "operation_id")
assertHexCheck(t, conn, "ocr_jobs", "job_id")
// operation_id outbox = id client (INTEGER) — cf. docs/api-v1.md §6.1
var opType string
err = conn.QueryRow(`
SELECT data_type FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'operations' AND column_name = 'operation_id'`).Scan(&opType)
if err != nil {
t.Fatalf("operation_id type: %v", err)
}
if opType != "bigint" {
t.Errorf("operation_id attendu bigint, got %s", opType)
}
var resourceTypeCheck int
err = conn.QueryRow(`
SELECT COUNT(*) FROM pg_constraint c