Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(lume): show provisioning status immediately in CLI lume ls (#839)

Francesco Bonacci77fa48752dd2
diff --git a/libs/lume/src/Errors/Errors.swift b/libs/lume/src/Errors/Errors.swift
index 6a625c1c1a..cb82ede131 100644
--- a/libs/lume/src/Errors/Errors.swift
+++ b/libs/lume/src/Errors/Errors.swift
@@ -171,6 +171,7 @@ enum VMError: Error, LocalizedError {
case internalError(String)
case unsupportedOS(String)
case invalidDisplayResolution(String)
+ case stillProvisioning(String)
var errorDescription: String? {
switch self {
case .alreadyExists(let name):
@@ -202,6 +203,8 @@ enum VMError: Error, LocalizedError {
return "Unsupported operating system: \(os)"
case .invalidDisplayResolution(let resolution):
return "Invalid display resolution: \(resolution)"
+ case .stillProvisioning(let name):
+ return "Virtual machine is still being provisioned: \(name)"
}
}
}
diff --git a/libs/lume/src/FileSystem/VMDirectory.swift b/libs/lume/src/FileSystem/VMDirectory.swift
index a207575fdf..d805efa4d6 100644
--- a/libs/lume/src/FileSystem/VMDirectory.swift
+++ b/libs/lume/src/FileSystem/VMDirectory.swift
@@ -49,27 +49,27 @@ struct VMDirectory: Sendable {
// MARK: - VM State Management
extension VMDirectory {
- /// Checks if the VM directory is fully initialized with all required files
+ /// Checks if the VM directory is initialized (either fully ready or provisioning)
+ /// A VM is considered initialized if it has:
+ /// - All required files (config + disk + nvram), OR
+ /// - Config + provisioning marker (VM is being created)
func initialized() -> Bool {
- // Add detailed logging for debugging
let configExists = configPath.exists()
let diskExists = diskPath.exists()
let nvramExists = nvramPath.exists()
-
- // Logger.info(
- // "VM directory initialization check",
- // metadata: [
- // "directory": dir.path,
- // "config_path": configPath.path,
- // "config_exists": "\(configExists)",
- // "disk_path": diskPath.path,
- // "disk_exists": "\(diskExists)",
- // "nvram_path": nvramPath.path,
- // "nvram_exists": "\(nvramExists)"
- // ]
- // )
-
- return configExists && diskExists && nvramExists
+ let provisioningExists = provisioningPath.exists()
+
+ // Fully initialized VM
+ if configExists && diskExists && nvramExists {
+ return true
+ }
+
+ // VM being provisioned (has config and provisioning marker)
+ if configExists && provisioningExists {
+ return true
+ }
+
+ return false
}
/// Checks if the VM directory exists
diff --git a/libs/lume/src/LumeController.swift b/libs/lume/src/LumeController.swift
index b4a50057a0..9567d8a3a6 100644
--- a/libs/lume/src/LumeController.swift
+++ b/libs/lume/src/LumeController.swift
@@ -179,6 +179,18 @@ final class LumeController {
)
}
+
+ /// Validates that a VM is not currently being provisioned
+ /// - Parameters:
+ /// - vmDir: The VM directory to check
+ /// - name: The VM name (for error message)
+ /// - Throws: VMError.stillProvisioning if the VM has a provisioning marker
+ private func validateNotProvisioning(_ vmDir: VMDirectory, name: String) throws {
+ if vmDir.loadProvisioningMarker() != nil {
+ throw VMError.stillProvisioning(name)
+ }
+ }
+
@MainActor
public func clone(
name: String, newName: String, sourceLocation: String? = nil, destLocation: String? = nil
@@ -196,7 +208,11 @@ final class LumeController {
do {
// Validate source VM exists
- _ = try self.validateVMExists(normalizedName, storage: sourceLocation)
+ let actualSourceLocation = try self.validateVMExists(normalizedName, storage: sourceLocation)
+
+ // Check if source VM is still being provisioned
+ let sourceVmDir = try home.getVMDirectory(normalizedName, storage: actualSourceLocation)
+ try validateNotProvisioning(sourceVmDir, name: normalizedName)
// Get the source VM and check if it's running
let sourceVM = try get(name: normalizedName, storage: sourceLocation)
@@ -614,6 +630,7 @@ final class LumeController {
}
}
+
/// Run unattended Setup Assistant automation on an existing macOS VM
@MainActor
public func setup(
@@ -764,6 +781,10 @@ final class LumeController {
let actualLocation = try self.validateVMExists(
normalizedName, storage: storage)
+ // Check if VM is still being provisioned
+ let vmDir = try home.getVMDirectory(normalizedName, storage: actualLocation)
+ try validateNotProvisioning(vmDir, name: normalizedName)
+
// Try to get VM from cache first
let vm: VM
if let cachedVM = SharedVM.shared.getVM(name: normalizedName) {
@@ -870,6 +891,9 @@ final class LumeController {
])
}
+ // Check if VM is still being provisioned
+ try validateNotProvisioning(vmDir, name: normalizedName)
+
// Validate parameters using the located VMDirectory
try validateRunParameters(
vmDir: vmDir, // Pass vmDir