__snapshots__fix(conversation-sync): thread connectionId into search-sync Map via KV context
The search Map iterated over query strings and (via createMapWithContext) passed
only the bare query as $.item, so conversationSyncSearch got an empty connectionId
on the Step Functions path and every provider lookup ran WHERE id = ''. Mirror the
meeting-sync workaround: conversation-sync.setup stashes a run:{id}:search-map-ctx
KV blob (connectionId, connectionData, maxResults, folder, queryContexts), the
search Map wraps each query into { query }, and conversationSyncSearch hydrates the
connection context from KV when connectionId is absent (local runtime path still
passes it directly). Adds a hydration regression test and updates the CDK snapshot.Jul 13, 2026, 9:01 PMworkflow-state-machines.snapshot.tsfeat: add initial sync test suite (81 tests, 4 layers)
Layer 1 — Step function unit tests (18 tests)
conversation-sync-steps.test.ts covers critical edge cases:
- Domain steps correctly destructure [domain, bool] tuple from SF Map
- domainSearchEnabled=false returns early without hitting Gmail
- CRM collect with 0 batch KV keys returns empty array
- OOM retry in finalize-conversation: eventsLimit 30→20→10
- crm-map-ctx written with correct fields including maxResults (10/20 by mode)
- phase2Only cleanup short-circuit returns provided IDs without KV reads
Layer 2 — Orchestration integration tests (26 tests)
conversation-sync-orchestration.test.ts mocks all step functions and
verifies runConversationSyncLocal calls them in the right order:
- Mode branching (full/two-phase/phase1Only/phase2Only)
- KV progress calls (startPhase1, completePhase1AndStartPhase2, etc.)
- Source enablement (enabled=false prevents step from being called)
- Fan-out counts (3 labels → 3 calls, 5 domains → 5 calls)
- Finalization waves (15 IDs → 2 waves of 10+5)
- Config pass-through (afterDate, daysBack, queryContext by string)
- Error handling (markFailed called in two-phase, not in full mode)
Layer 3 — CDK snapshot test (tsx script)
aws/__tests__/workflow-state-machines.snapshot.ts synthesizes CDK and
compares against a committed JSON snapshot. Run with --update to refresh.
Catches: step name changes, timeout changes, concurrency changes,
dropped steps from the chain.
Layer 4 — KV data flow contract tests (13 tests)
conversation-sync-kv-flow.test.ts verifies that conversationSyncCleanup
reads every batch key that source steps write:
batch:sent, batch:inbox, batch:label:*, batch:search:*, batch:meetings:*,
batch:meeting-domain:*, batch:crm:*, batch:crm-domain:*, batch:slack
Also:
- Export runConversationSyncLocal for testability
- Convert require() calls in runConversationSyncLocal to static ESM imports
so vi.mock() can intercept them in tests
- Update INITIAL_SYNC_TESTS.md: remove stale phase2Only throws assertions,
add tracingContext and crm-map-ctx field assertions
Made-with: CursorApr 12, 2026, 2:09 PM