From 88616124b6b9fa926e56b66704f48538257cfd1a Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Tue, 11 Aug 2026 15:42:01 +0700 Subject: [PATCH] more fixes for tests --- .github/workflows/ios.yml | 10 +++++- Sources/Shared/Models/AppModel.swift | 19 +++++++++-- .../Shared/Services/PhoneWatchBridge.swift | 6 +++- Tests/CryptoKitAESGCMEngineTests.swift | 34 ++++++++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 289ae99..09c574b 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -32,4 +32,12 @@ jobs: xcodebuild test \ -project Luma.xcodeproj \ -scheme Luma \ - -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max,OS=26.4.1' + -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max,OS=26.4.1' \ + -resultBundlePath TestResults.xcresult + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Luma-TestResults + path: TestResults.xcresult diff --git a/Sources/Shared/Models/AppModel.swift b/Sources/Shared/Models/AppModel.swift index a20bb0c..16f862b 100644 --- a/Sources/Shared/Models/AppModel.swift +++ b/Sources/Shared/Models/AppModel.swift @@ -4,6 +4,14 @@ import Foundation import UniformTypeIdentifiers import WebRTC +enum RuntimeEnvironment { + static var isRunningTests: Bool { + let environment = ProcessInfo.processInfo.environment + return environment["XCTestConfigurationFilePath"] != nil + || environment["XCTestBundlePath"] != nil + } +} + @MainActor final class AppModel: ObservableObject { @Published private(set) var account: AccountConfiguration? @@ -186,9 +194,11 @@ final class AppModel: ObservableObject { } } - bootstrapTask = Task { [weak self] in - guard let self else { return } - await self.bootstrap() + if !RuntimeEnvironment.isRunningTests { + bootstrapTask = Task { [weak self] in + guard let self else { return } + await self.bootstrap() + } } } @@ -242,6 +252,7 @@ final class AppModel: ObservableObject { } func bootstrap() async { + guard !RuntimeEnvironment.isRunningTests else { return } guard let saved = preferences.load() else { return } account = saved globalEncryptionEnabled = preferences.encryptionEnabled(for: saved.normalizedJID) @@ -376,6 +387,7 @@ final class AppModel: ObservableObject { } func reconnect() async { + guard !RuntimeEnvironment.isRunningTests else { return } guard let account else { return } do { guard let password = try credentials.password(for: account.normalizedJID) else { @@ -390,6 +402,7 @@ final class AppModel: ObservableObject { func setApplicationActive(_ active: Bool) { appIsActive = active + guard !RuntimeEnvironment.isRunningTests else { return } xmpp.setApplicationActive(active) if !active { resetTypingState() diff --git a/Sources/Shared/Services/PhoneWatchBridge.swift b/Sources/Shared/Services/PhoneWatchBridge.swift index 523e1b8..6066315 100644 --- a/Sources/Shared/Services/PhoneWatchBridge.swift +++ b/Sources/Shared/Services/PhoneWatchBridge.swift @@ -49,7 +49,10 @@ final class PhoneWatchBridge: NSObject, WCSessionDelegate { private var deliveredVoiceTransferIDs: Set = [] override init() { - session = WCSession.isSupported() ? .default : nil + session = + !RuntimeEnvironment.isRunningTests && WCSession.isSupported() + ? .default + : nil super.init() pendingVoiceMessages = Self.loadPersistedVoiceMessages() session?.delegate = self @@ -150,6 +153,7 @@ final class PhoneWatchBridge: NSObject, WCSessionDelegate { func sessionDidBecomeInactive(_ session: WCSession) {} func sessionDidDeactivate(_ session: WCSession) { + guard !RuntimeEnvironment.isRunningTests else { return } session.activate() } diff --git a/Tests/CryptoKitAESGCMEngineTests.swift b/Tests/CryptoKitAESGCMEngineTests.swift index 4724240..1d1460c 100644 --- a/Tests/CryptoKitAESGCMEngineTests.swift +++ b/Tests/CryptoKitAESGCMEngineTests.swift @@ -22,19 +22,45 @@ final class CryptoKitAESGCMEngineTests: XCTestCase { func testModifiedTagFails() { let engine = CryptoKitAESGCMEngine() + let key = Data(repeating: 0x31, count: 16) let iv = Data(repeating: 0x22, count: 12) + var ciphertext = Data() var tag = Data() - XCTAssertTrue( + + guard engine.encrypt( - iv: iv, key: key, message: Data("secret".utf8), output: &ciphertext, tag: &tag)) + iv: iv, + key: key, + message: Data("secret".utf8), + output: &ciphertext, + tag: &tag + ) + else { + XCTFail("AES-GCM encryption unexpectedly failed") + return + } + + XCTAssertEqual(tag.count, 16) + + guard tag.count == 16 else { + return + } + var modifiedTag = tag - modifiedTag[0] ^= 0x01 + modifiedTag[modifiedTag.startIndex] ^= 0x01 var decrypted = Data() + XCTAssertFalse( engine.decrypt( - iv: iv, key: key, encoded: ciphertext, auth: modifiedTag, output: &decrypted)) + iv: iv, + key: key, + encoded: ciphertext, + auth: modifiedTag, + output: &decrypted + ) + ) } }