mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-05 07:07:04 +00:00
Settings gains a Machines screen: health, CLI version, capability and binary skew, rename, and the supervised runner restart the web banner exposes. Skew derivation lives in HapiProtocol so it is testable without a hub. The icon badge counts unread sessions on the active hub, with a notification-settings toggle that clears it immediately. The Japanese app-language option is dropped (no shipped catalog). via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
87 lines
2.8 KiB
Swift
87 lines
2.8 KiB
Swift
import HapiProtocol
|
|
import XCTest
|
|
@testable import Hapi
|
|
|
|
final class MachineRowPresentationTests: XCTestCase {
|
|
private func machine(
|
|
displayName: String? = nil,
|
|
host: String = "mac-mini",
|
|
capabilities: [String]? = ["agent-availability", "cursor-chat-store-status"],
|
|
started: Double? = nil,
|
|
installed: Double? = nil,
|
|
supervised: Bool? = nil,
|
|
cpu: Double? = 12,
|
|
memory: Double? = 45
|
|
) -> Machine {
|
|
Machine(
|
|
id: "machine-123456789",
|
|
namespace: "default",
|
|
seq: 1,
|
|
createdAt: 0,
|
|
updatedAt: 0,
|
|
active: true,
|
|
activeAt: 0,
|
|
metadata: MachineMetadata(
|
|
host: host,
|
|
platform: "darwin",
|
|
happyCliVersion: "0.36.5",
|
|
displayName: displayName,
|
|
capabilities: capabilities,
|
|
startedCliMtimeMs: started,
|
|
installedCliMtimeMs: installed,
|
|
supervisedRestart: supervised
|
|
),
|
|
metadataVersion: 1,
|
|
runnerState: nil,
|
|
runnerStateVersion: 1,
|
|
health: MachineHealth(
|
|
collectedAt: 0,
|
|
cpuPercent: cpu,
|
|
memoryPercent: memory
|
|
)
|
|
)
|
|
}
|
|
|
|
func testDisplayNameFallsBackToHostThenIdPrefix() {
|
|
XCTAssertEqual(MachineRowUI(machine: machine(displayName: " Studio ")).title, "Studio")
|
|
XCTAssertEqual(MachineRowUI(machine: machine(displayName: " ")).title, "mac-mini")
|
|
}
|
|
|
|
func testSubtitleAndHealthAreCompact() {
|
|
let row = MachineRowUI(machine: machine())
|
|
XCTAssertEqual(row.subtitle, "darwin · CLI 0.36.5")
|
|
XCTAssertEqual(row.health, "CPU 12% · Mem 45%")
|
|
}
|
|
|
|
func testCapabilitySkewSurfacesEvenWhenTheRunnerIsOnline() {
|
|
let row = MachineRowUI(machine: machine(capabilities: ["agent-availability"]))
|
|
XCTAssertTrue(row.capabilitySkewed)
|
|
XCTAssertFalse(row.canRestart)
|
|
XCTAssertEqual(row.restartAvailability, .needsNewerBinary)
|
|
}
|
|
|
|
func testRestartNeedsANewerBinaryOnDiskAndASupervisor() {
|
|
let restartable = MachineRowUI(machine: machine(
|
|
started: 100,
|
|
installed: 200,
|
|
supervised: true
|
|
))
|
|
XCTAssertTrue(restartable.binaryUpdated)
|
|
XCTAssertTrue(restartable.canRestart)
|
|
|
|
let unsupervised = MachineRowUI(machine: machine(
|
|
started: 100,
|
|
installed: 200,
|
|
supervised: false
|
|
))
|
|
XCTAssertEqual(unsupervised.restartAvailability, .needsSupervisor)
|
|
|
|
let sameBinary = MachineRowUI(machine: machine(
|
|
started: 200,
|
|
installed: 200,
|
|
supervised: true
|
|
))
|
|
XCTAssertEqual(sameBinary.restartAvailability, .needsNewerBinary)
|
|
}
|
|
}
|