super-productivity/packages/super-sync-server/tests
Johannes Millan 43c10ed73b refactor(sync): polish storage delta tracking and update tests
Picked up the remaining items from the multi-agent review:

- Hoist Operation / ServerOperation imports in sync.routes.ts so the
  upload path no longer needs `as unknown as import('./sync.types').*`
  double casts. The Set + filter pattern for accepted ops becomes an
  index-zip loop, dropping two iterations + the Set allocation.

- Pull APPROX_BYTES_PER_OP out of two inline locals in sync.service.ts
  into sync.const.ts so the constant is a single source of truth and
  the trade-off (over-estimate vs observed median op size) is documented
  in one place.

- Log when computeOpsStorageBytes silently skips an op whose payload
  fails JSON.stringify (BigInt, circular refs). Counter still
  under-counts but the cause is visible in logs.

- Update storage-quota docstrings to reflect that calculateStorageUsage /
  updateStorageUsage are now legitimately called from the
  freeStorageForUpload reconcile path (rare cleanup events), not only
  offline.

Tests:

- cleanup.spec.ts: assert updateStorageUsage is NOT called after
  deleteOldSyncedOpsForAllUsers (the per-user SUM loop was the DoS).
- storage-quota-cleanup.spec.ts: drop the assertion that
  deleteOldestRestorePointAndOps issues a pg_column_size query (it does
  not anymore); add a $executeRaw mock that mutates testUsers so the
  iterative-cleanup test exercises the real decrement path; tune
  starting storage to within a few KB of quota so cleanup's
  approximate decrement can detect progress within a few iterations.
- storage-quota.service.spec.ts: add the $executeRaw prisma mock and
  unit tests for incrementStorageUsage / decrementStorageUsage
  (positive path, Math.floor of non-integer deltas, no-op on
  NaN/Infinity/zero/negative, clamped UPDATE for decrement).
2026-05-12 16:46:38 +02:00
..
integration fix(sync): preserve own vector clock counter across full-state op resets 2026-04-01 15:41:13 +02:00
api.routes.spec.ts Pr 6741 (#6743) 2026-03-05 21:17:59 +01:00
auth-flows.spec.ts Pr 6741 (#6743) 2026-03-05 21:17:59 +01:00
cleanup.spec.ts refactor(sync): polish storage delta tracking and update tests 2026-05-12 16:46:38 +02:00
config.spec.ts feat(cors): normalize domain to lowercase and validate non-empty origins 2026-01-24 21:14:57 +01:00
conflict-detection.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
decompress-body.spec.ts refactor low-risk sync cleanup 2026-05-09 18:11:40 +02:00
device.service.spec.ts refactor(sync): extract DeviceService and OperationDownloadService 2025-12-27 20:43:25 +01:00
duplicate-operation-precheck.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
email.spec.ts Fix super-sync server auth and snapshot safety 2025-12-12 20:48:13 +01:00
gap-detection.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
magic-link-registration.spec.ts fix(sync): preserve own vector clock counter across full-state op resets 2026-04-01 15:41:13 +02:00
middleware.spec.ts Pr 6741 (#6743) 2026-03-05 21:17:59 +01:00
migration-sql.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
operation-download.service.spec.ts refactor(sync): improve vector clock implementation quality 2026-03-17 13:59:40 +01:00
passkey.spec.ts test(sync): fix failing unit tests for recent server changes 2026-01-24 21:14:58 +01:00
password-reset-api.spec.ts Revert "feat(sync): add rolling JWT token refresh on sync requests" 2026-02-02 17:15:13 +01:00
password-reset.spec.ts fix(security): address critical and high severity vulnerabilities 2025-12-31 12:15:56 +01:00
rate-limit.service.spec.ts refactor(sync): extract services from SyncService and migrate tests to Prisma 2025-12-27 20:38:26 +01:00
registration-api.spec.ts chore(sync-server): update npm scripts and expand legal docs 2025-12-15 13:47:42 +01:00
replace-token-expiry.spec.ts fix(sync): fix supersync server unit test failures 2026-03-22 10:10:19 +01:00
request-deduplication.service.spec.ts refactor(sync): extract services from SyncService and migrate tests to Prisma 2025-12-27 20:38:26 +01:00
retention-config.spec.ts fix(security): address critical and high severity vulnerabilities 2025-12-31 12:15:56 +01:00
security-fixes.spec.ts test(sync): fix failing unit tests for recent server changes 2026-01-24 21:14:58 +01:00
server-security.spec.ts fix(sync): prevent magic link prefetch failures and improve auth resilience (#7175) 2026-04-10 14:46:57 +02:00
setup.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
snapshot-skip-optimization.spec.ts test(sync-server): add comprehensive edge case tests for snapshot skip 2025-12-17 11:42:32 +01:00
snapshot.service.spec.ts fix(sync): preserve own vector clock counter across full-state op resets 2026-04-01 15:41:13 +02:00
storage-quota-cleanup.spec.ts refactor(sync): polish storage delta tracking and update tests 2026-05-12 16:46:38 +02:00
storage-quota.service.spec.ts refactor(sync): polish storage delta tracking and update tests 2026-05-12 16:46:38 +02:00
sync-compressed-body.routes.spec.ts refactor low-risk sync cleanup 2026-05-09 18:11:40 +02:00
sync-fixes.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
sync-operations.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
sync-types.spec.ts test(sync): add vector clock pruning edge case tests (#6506) 2026-02-13 12:42:36 +01:00
sync.routes.spec.ts refactor(sync): unify JWT expiry to 365 days for all auth methods 2026-02-16 18:44:27 +01:00
sync.service.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
sync.service.test-state.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
time-tracking-operations.spec.ts perf(sync): speed up SuperSync uploads 2026-05-12 00:37:00 +02:00
validation.service.spec.ts test(sync): add SECTION to ALLOWED_ENTITY_TYPES expectations 2026-04-29 18:06:15 +02:00
websocket-connection.service.spec.ts feat(sync): add Helm chart and WebSocket push for SuperSync (#6971) 2026-03-30 21:34:30 +02:00
websocket.routes.spec.ts feat(sync): add Helm chart and WebSocket push for SuperSync (#6971) 2026-03-30 21:34:30 +02:00