
    #[tokio::test]
    async fn test_sync_state_machine_initialization() {
        // Setup
        let sent_inits = Arc::new(Mutex::new(Vec::new()));
        let transport = Arc::new(MockTransport { 
            sent_adjustments: Arc::new(Mutex::new(Vec::new())),
            sent_pings: Arc::new(Mutex::new(Vec::new())),
            mock_stats: Arc::new(Mutex::new(HashMap::new())),
            sent_inits: sent_inits.clone(),
            sent_stables: Arc::new(Mutex::new(Vec::new())),
        });
        
        let config = Arc::new(RwLock::new(SyncConfig::default()));
        let time_server = Arc::new(TimeServer::new(vec![]).await.unwrap());
        let drift_compensator = Arc::new(DriftCompensator::new());
        
        let engine = SyncEngine::new(
            time_server.clone(),
            drift_compensator,
            config,
            Some(transport)
        );

        let stream_id = Uuid::new_v4();
        let listener_id = Uuid::new_v4();
        let mut listener = create_test_listener(listener_id, Some(0)); // Helper from existing tests
        listener.sync_state = SyncState::Desynchronized; // Start desync
        
        // Mock listeners map
        let listeners = Arc::new(DashMap::new());
        listeners.insert(listener_id, listener);
        
        // Run sync
        let track_id = Some("test_track".to_string());
        let result = engine.sync_listeners(stream_id, track_id, listeners.clone()).await;
        
        assert!(result.is_ok());
        
        // Verify SyncInit sent
        let inits = sent_inits.lock().unwrap();
        assert_eq!(inits.len(), 1);
        assert_eq!(inits[0], listener_id);
        
        // Verify state changed to Calibrating
        let updated_listener = listeners.get(&listener_id).unwrap();
        match updated_listener.sync_state {
            SyncState::Calibrating { .. } => (), // Success
            _ => panic!("State should be Calibrating, got {:?}", updated_listener.sync_state),
        }
    }
