Files
VirtualBuddy/VirtualWormholeTests/GuestSystemInformationTests.swift
Guilherme Rambo 9af56efdf1 Guest metadata service & UI (#802)
* Add new guest system information service to collect up-to-date details about the guest that can be displayed offline in the host

* Tweak get info wording

* Update agents

* Add preview library item with guest system info

* Improve VM metadata overlays in library view

* Xcode update

* Improve VM get info UI
2026-11-03 12:51:13 -03:00

38 lines
2.0 KiB
Swift

import Foundation
import Testing
@testable import VirtualWormhole
struct GuestSystemInformationTests {
@Test func sipSummaryDoesNotConfuseCustomProtectionsWithOverallStatus() {
let descriptions: [(String?, GuestSystemInformation.SIPStatus)] = [
("System Integrity Protection status: enabled.", .enabled),
("System Integrity Protection status: disabled.", .disabled),
("System Integrity Protection status: unknown (Custom Configuration).\n\nFilesystem Protections: disabled", .custom),
("Unexpected output\nFilesystem Protections: enabled", .unknown),
(nil, .unknown)
]
for (description, status) in descriptions {
#expect(GuestSystemInformation(osVersion: "26.0", sipDescription: description).sipStatus == status)
}
}
@Test func oldHostDoesNotAdvertiseSystemInformation() throws {
let reply = try JSONDecoder().decode(InitializeGuestReply.self, from: Data(#"{"notifications":[]}"#.utf8))
#expect(reply.capabilities == nil)
// Existing guests ignore the additive field in new host replies.
struct LegacyReply: Decodable { let notifications: Set<String> }
let data = try JSONEncoder().encode(InitializeGuestReply(notifications: ["existing"], capabilities: [SystemInformationGuestService.capability]))
#expect(try JSONDecoder().decode(LegacyReply.self, from: data).notifications == ["existing"])
}
@Test func liveCollectorReturnsCurrentSystemWithoutRequiringPrivileges() async throws {
let information = try await SystemInformationCollector.collect()
#expect(!information.osVersion.isEmpty)
#expect(information.osBuild?.isEmpty == false)
#expect(information.processorCount == ProcessInfo.processInfo.processorCount)
#expect(information.memoryBytes == ProcessInfo.processInfo.physicalMemory)
#expect(information.bootDate != nil)
#expect(information.sipDescription?.isEmpty == false)
}
}