import Testing import Foundation import AVFoundation import MusicShared @testable import Music // End-to-end reproduction of the reported bug: // "After streaming a full track, AVPlayer fails with 'Operation Stopped' // and the player does NOT auto-advance to the next track." // // These tests drive the *real* StreamingPlaybackProvider against the *real* // StreamingServer, exactly as the app does, and assert that playing a track to // its natural end results in a clean finish (onTrackFinished fires, no error). @MainActor struct StreamingPlaybackEndToEndTests { static let testAPIKey = "e2e-test-key" // Spins the main run loop (where AVPlayer delivers its callbacks) until // `condition` is true or `timeout` seconds elapse. Returns true if the // condition was met. Polls in small slices so an async @MainActor test // lets AVPlayer's main-queue observers run. private func waitUntil(timeout: Double, _ condition: () -> Bool) async -> Bool { let slices = Int(timeout / 0.05) for _ in 0.. finishedCleanly=\(finishedCleanly), playbackError=\(String(describing: provider.playbackError)), providerDuration=\(provider.duration), currentTime=\(provider.currentTime)") // 7. A fully streamed track must end cleanly so the queue can advance. #expect(provider.playbackError == nil) #expect(finishedCleanly == true) } }