Commit graph

21 commits

Author SHA1 Message Date
Johannes Millan
4f2dbcdaa7 feat(sync): handle auth errors for account deletion scenarios
When a SuperSync account is deleted, clients now properly detect
authentication failures and prompt for reconfiguration:

- Add _checkHttpStatus() helper to SuperSyncProvider that throws
  AuthFailSPError on 401/403 responses
- Clear cached credentials on auth failure to allow reconfiguration
- Add DELETE /api/test/user/:userId endpoint for E2E testing
- Add deleteTestUser() helper in supersync-helpers.ts
- Add E2E tests for account deletion and reconfiguration scenarios

The existing SyncWrapperService already handles AuthFailSPError by
showing a snackbar with "Configure" action, so no UI changes needed.
2026-01-02 15:48:17 +01:00
Johannes Millan
4e0f5e8999 fix(e2e): improve app loading detection and fix server TypeScript errors
- e2e/utils/waits.ts: Add proper retry logic and error handling when
  waiting for magic-side-nav to appear. Now throws a clear error if
  app doesn't load within 30s instead of silently continuing.

- packages/super-sync-server/src/auth.ts: Use nullish coalescing for
  passwordHash to handle passkey-only users (who have no password).

- packages/super-sync-server/src/passkey.ts: Add WebAuthn passkey
  authentication support. Fix TypeScript errors by importing types
  from @simplewebauthn/types and converting credential IDs to
  base64url strings.

Fixes flaky "Multiple fresh clients join and sync correctly after
snapshot" test that was failing when app didn't fully load.
2026-01-02 15:11:16 +01:00
Johannes Millan
6c098b6eaa Merge branch 'master' into feat/operation-logs
Resolve conflict in webdav-sync-expansion.spec.ts:
- Use simplified sync verification without reload (sync updates NgRx directly)
- Test: B marks task done -> sync -> verify A sees task as done
2025-12-29 21:54:15 +01:00
Johannes Millan
c4f536471a test(webdav): add e2e tests 2025-12-29 12:48:36 +01:00
Johannes Millan
1da70487f9 fix: address code review findings from Dec 27-29 changes
ESLint rule improvements:
- Fix require-hydration-guard to detect guards on combineLatest/forkJoin/zip
  results (eliminates 20+ false positive warnings)

Server improvements:
- Add OperationDownloadService unit tests (21 tests covering vector clock
  aggregation, gap detection, excludeClient parameter, snapshot optimization)
- Split ZIP bomb size limits: 10MB for /ops, 30MB for /snapshot
- Document storage quota update as intentionally non-atomic

E2E test improvements:
- Add waitForUISettle() helper using Angular stability instead of fixed timeouts
- Update supersync-cross-entity tests to use dynamic waits

Unit test improvements:
- Add HydrationStateService edge case tests (concurrent calls, cooldown cycles,
  timer cleanup, interleaved operations)
2025-12-29 10:37:12 +01:00
Johannes Millan
6276f89c75 test(e2e): prevent browser closed errors and fix context menu selectors
- Add page.isClosed() checks before waitForTimeout calls to prevent
  "Target page, context or browser has been closed" errors when tests
  timeout (supersync-helpers.ts, waits.ts, supersync.page.ts)
- Fix context menu selector in LWW tests: use .mat-mdc-menu-item instead
  of button[mat-menu-item] which doesn't match Angular Material menu items
- Add retry logic for opening context menus with proper wait/escape handling
- Skip "Subtask edit survives when parent is deleted" test - documents
  expected future behavior that is not yet implemented
2025-12-28 11:30:45 +01:00
Johannes Millan
0d6b65cdc1 fix(e2e): handle already-closed browser contexts in closeClient
The closeClient helper was throwing errors when trying to close browser
contexts that were already closed (due to test timeouts or failures).
This caused cascading errors in E2E tests and made debugging harder.

Fix by checking if page is closed before attempting to close the context,
and gracefully catching "already closed" errors.
2025-12-27 22:14:20 +01:00
Johannes Millan
6a26d914b5 test: skip tmp 2025-12-24 16:27:12 +01:00
Johannes Millan
72608a4aaa feat(migration): implement pre-migration dialog and backup functionality 2025-12-24 13:49:37 +01:00
Johannes Millan
c757ff500d test(sync): re-enable sync after import in tests and adjust baseURL fallback 2025-12-22 12:08:04 +01:00
Johannes Millan
5992fad51b fix(sync): perform archive flush synchronously to prevent DB lock error
Previously, flushYoungToOld was dispatched as an action and handled by
an NgRx effect. This caused a race condition during finish day:
1. Action dispatched, effect queued
2. Method returned, sync started, DB locked
3. Effect ran, tried to write, blocked by DB lock

Fix follows the same pattern as moveToArchive:
- Perform the flush synchronously in ArchiveService before dispatching
- Dispatch action for op-log capture only (syncs to other clients)
- Handler skips local operations (only runs for remote)

Also adds comprehensive unit tests and e2e test for this scenario.
2025-12-17 16:42:59 +01:00
Johannes Millan
d5a0258c85 fix(sync): use vector clocks for SYNC_IMPORT filtering instead of UUIDv7
Replace UUIDv7 timestamp-based filtering with vector clock comparison
in _filterOpsInvalidatedBySyncImport(). This fixes a bug where client
clock drift could cause pre-import operations to bypass filtering.

Vector clocks track causality ("did this client know about the import?")
rather than wall-clock time, making the filtering immune to clock drift.

Operations are now filtered based on comparison result:
- GREATER_THAN or EQUAL: keep (client had knowledge of import)
- LESS_THAN or CONCURRENT: filter (created without knowledge)

Also fix E2E tests to properly skip when SuperSync server isn't
running in TEST_MODE by checking test endpoint availability.
2025-12-17 14:50:50 +01:00
Johannes Millan
ef40c7ba6a fix(sync): ensure pending writes complete before conflict detection
Fix race condition where sync could start before local operation writes
completed to IndexedDB, causing conflict detection to miss pending ops.

- Add OperationWriteFlushService that uses sp_op_log lock to ensure all
  pending writes complete before reading from IndexedDB
- Call flushPendingWrites() before conflict detection in sync service
- Add retry with exponential backoff to createTestUser for rate limiting
- Add unit tests for flush service and sync ordering

The flush mechanism works by acquiring the same lock used by writeOperation().
Since effects use concatMap and Web Locks API guarantees FIFO ordering,
acquiring the lock means all prior writes have completed.
2025-12-13 11:50:36 +01:00
Johannes Millan
84e1bae3f7 fix(e2e): reduce console log noise with optional E2E_VERBOSE flag
By default, only errors are logged. Set E2E_VERBOSE=1 to see all browser
console messages for debugging.
2025-12-12 20:48:13 +01:00
Johannes Millan
31f6232760 fix(e2e): fix failing supersync models test due to wrong locator 2025-12-12 20:48:13 +01:00
Johannes Millan
c7c3ad9092 fix(e2e): Stabilize SuperSync and general E2E tests
Increased timeouts and added stability improvements for SuperSync E2E tests to address flakiness and resolve 'Sync already in progress' errors.

- Increased default 'waitForTask' timeout from 45s to 60s in 'supersync-helpers.ts'.
- Increased auto-sync detection timeout in 'SuperSyncPage' from 3s to 5s.
- Added a 1s delay in 'SuperSyncPage.triggerSync' to mitigate race conditions.

Also includes other related E2E and SuperSync server fixes:
- Updated 'test-backup.json' with new config properties.
- Improved error handling in 'import.page.ts' for file dispatch events.
- Added reload and app readiness waits in 'supersync.spec.ts' for time tracking tests.
- Enabled WAL journal mode in 'super-sync-server/src/db.ts' for better database performance.
- Implemented data cleanup for existing test users in 'super-sync-server/src/test-routes.ts' to ensure clean test states.

These changes collectively resolve intermittent failures across the E2E test suite.
2025-12-12 20:48:13 +01:00
Johannes Millan
8fa148aab6 fix(e2e): reduce flakiness in SuperSync E2E tests
Improvements to make sync tests more reliable:

- Increase waitForTask default timeout from 15s to 25s
- Add retry loop in waitForTask for DOM update delays
- Add UI settling delay (300ms) after syncAndWait
- Add waitForLoadState('domcontentloaded') after sync operations
- Improve conflict dialog handling with retry for G.APPLY button
- Wait for conflict dialog to close before continuing
- Add explicit timeouts to visibility assertions

These changes address timing issues where the UI hasn't fully
updated after sync operations complete.
2025-12-12 20:47:42 +01:00
Johannes Millan
e62f2f86fa feat(e2e): add SuperSync E2E test infrastructure for multi-client sync
- Add test mode to super-sync-server (TEST_MODE=true env var)
- Add /api/test/create-user endpoint for auto-verified test users
- Add /api/test/cleanup endpoint for wiping test data
- Create SuperSyncPage page object for sync configuration
- Create supersync-helpers.ts with test utilities
- Add 6 E2E sync scenarios:
  - 2.1: Client A creates task, Client B downloads
  - 2.2: Both clients create different tasks
  - 1.3: Update propagates between clients
  - 1.4: Delete propagates between clients
  - 3.1: Concurrent edits handled gracefully
  - 2.3: Parent/subtask relationships sync correctly
2025-12-12 20:47:41 +01:00
Johannes Millan
ca387ca2bf refactor(e2e): improve test reliability with deterministic waits
- Add waitForStatePersistence utility for sync tests to replace hardcoded delays
- Fix nav-list vs nav-list-tree selector inconsistencies across test files
- Replace waitForTimeout calls with proper element waits and Angular stability checks
- Update selectors.ts constants to use correct nav-list-tree component selector
2025-12-11 18:47:56 +01:00
Johannes Millan
e268076332 test(e2e): try to fix e2e tests 2025-12-10 21:26:48 +01:00
Johannes Millan
366545d374 test(e2e): improve e2e stability 2 2025-11-06 19:54:50 +01:00