Files
VirtualBuddy/VirtualCoreTests/DeveloperFeaturesSettingsTests.swift
Guilherme Rambo aabca5342d Xcode app provisioning (#823)
* Automatic provisioning of Mac apps launched via Xcode

* Improve Xcode integration sheet UI

* Security: harden local debugging socket and Xcode tool usage

* Soften rule around Xcode MCP use and xcodebuild prohibition

* Security: harden App Store Connect API key storage and access

* Fix debugged app incorrectly detected as not provisioned due to wildcard matching in provisioning profile

* Add previews for provisioning and debugging UI elements

* Disambiguate virtual machine vs. host Mac in provisioning and signing team management UIs

* Make Xcode debugging setup accessible from the Guest menu

* Completely disable debugging socket when developer features disabled, fix socket dying on accept failure

* Add versioning to scheme bindings, refer to VirtualBuddy components by a stable symlinked location, store scheme URLs so that app can potentially migrate schemes in the future

* Delay showing provisioning sheet so that an app that's already provisioned for the VM doesn't trigger it
2026-11-24 17:46:23 -03:00

68 lines
2.7 KiB
Swift

import Combine
import Foundation
import Testing
@testable import VirtualCore
struct DeveloperFeaturesSettingsTests {
@Test(arguments: [true, false])
func followsXcodeUntilTheUserChooses(xcodeInstalled: Bool) throws {
let suiteName = "DeveloperFeaturesSettingsTests.\(UUID().uuidString)"
let defaults = try #require(UserDefaults(suiteName: suiteName))
defer { defaults.removePersistentDomain(forName: suiteName) }
defaults.set("saveState", forKey: "closeBehavior")
var checks = 0
func readSettings(xcodeInstalled: Bool) throws -> VBSettings {
try VBSettings(with: defaults) {
checks += 1
return xcodeInstalled
}
}
var firstLaunch = try readSettings(xcodeInstalled: xcodeInstalled)
#expect(firstLaunch.developerFeaturesEnabled == xcodeInstalled)
#expect(firstLaunch.closeBehavior == .saveState)
// Saving another setting must not turn the detected default into a choice.
firstLaunch.enableTSSCheck.toggle()
try firstLaunch.write(to: defaults)
#expect(defaults.object(forKey: "developerFeaturesEnabled") == nil)
var nextLaunch = try readSettings(xcodeInstalled: !xcodeInstalled)
#expect(nextLaunch.developerFeaturesEnabled == !xcodeInstalled)
#expect(checks == 2)
nextLaunch.developerFeaturesEnabled = xcodeInstalled
try nextLaunch.write(to: defaults)
let afterChoice = try readSettings(xcodeInstalled: !xcodeInstalled)
#expect(afterChoice.developerFeaturesEnabled == xcodeInstalled)
#expect(checks == 2)
}
@Test func availabilityFollowsTheSettingAndTheRestriction() throws {
let suiteName = "DeveloperFeaturesSettingsTests.\(UUID().uuidString)"
let defaults = try #require(UserDefaults(suiteName: suiteName))
defer { defaults.removePersistentDomain(forName: suiteName) }
defaults.set(false, forKey: "developerFeaturesEnabled")
let container = VBSettingsContainer(with: defaults)
var values = [Bool]()
let subscription = container.developerFeaturesAvailability.sink { values.append($0) }
defer { subscription.cancel() }
#expect(values == [false])
container.settings.developerFeaturesEnabled = true
container.settings.enableTSSCheck.toggle()
#expect(values == [false, true])
defaults.set(true, forKey: "DisableDeveloperFeatures")
#expect(values == [false, true, false])
defaults.removeObject(forKey: "DisableDeveloperFeatures")
#expect(values == [false, true, false, true])
container.settings.developerFeaturesEnabled = false
#expect(values == [false, true, false, true, false])
}
}