import XCTest @testable import MealMood /// Smoke cover for the dictation entry point. /// /// **This does not reproduce the crash it was written for.** The production /// crash (`dispatch_assert_queue` inside the `requestAuthorization` handler) /// needs TCC to deliver the callback asynchronously on a background queue, which /// is what happens on device when the permission prompt is answered. The /// simulator delivers it synchronously on the calling thread instead, so the /// isolation check passes and the pre-fix code runs clean here — verified by /// reverting the fix and watching these tests still pass. /// /// What it does cover: `start` settles instead of hanging, and does not report /// recording when permission is unavailable. Verifying the crash itself needs a /// real device with the speech and microphone permissions reset. @MainActor final class SpeechDictationServiceTests: XCTestCase { func testStartSettlesWithoutRecordingWhenPermissionIsUnavailable() async throws { let service = SpeechDictationService() XCTAssertEqual(service.state, .idle) service.start(localeIdentifier: "en-US") let deadline = Date().addingTimeInterval(10) while service.state == .idle && Date() < deadline { try await Task.sleep(nanoseconds: 100_000_000) } XCTAssertNotEqual(service.state, .recording, "No permission is granted in this environment, so it must not record") } func testStartTwiceDoesNotBlowUp() { let service = SpeechDictationService() service.start(localeIdentifier: "en-US") service.start(localeIdentifier: "en-US") XCTAssertNotEqual(service.state, .recording) } }