Files
VirtualBuddy/Packages/MacDebugTarget/Tests/MacDebugTargetTests/DebugDeploymentTests.swift
Guilherme Rambo baa001af93 Refactor Xcode debugging support (#822)
* Refactor Xcode debugging support into independent Swift packages

* Fix remote process name in Xcode debug navigator, display progress for shared cache symbol extraction, bring app to the foreground when a run requires extracting symbols
2026-11-24 10:08:45 -03:00

46 lines
2.9 KiB
Swift

import MacDebugProtocol
import Foundation
import Testing
@testable import MacDebugTarget
struct DebugDeploymentTests {
@Test func signedBundlesReplaceTheSameInstallationAndInvalidUpdatesLeaveItIntact() async throws {
let fm = FileManager.default
let root = fm.temporaryDirectory.appendingPathComponent(UUID().uuidString)
defer { try? fm.removeItem(at: root) }
let product = root.appendingPathComponent("Build/Example.app")
let contents = product.appendingPathComponent("Contents")
let executable = contents.appendingPathComponent("MacOS/Example")
let resources = contents.appendingPathComponent("Resources")
try DebugTools.directory(executable.deletingLastPathComponent())
try DebugTools.directory(resources)
try fm.copyItem(at: URL(fileURLWithPath: "/usr/bin/true"), to: executable)
let plist = ["CFBundleIdentifier": "test.virtualbuddy.deployment", "CFBundleExecutable": "Example", "CFBundlePackageType": "APPL"]
try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0).write(to: contents.appendingPathComponent("Info.plist"))
let entitlement = root.appendingPathComponent("debug.plist")
try PropertyListSerialization.data(fromPropertyList: ["com.apple.security.get-task-allow": true], format: .xml, options: 0).write(to: entitlement)
let payload = resources.appendingPathComponent("revision")
let link = resources.appendingPathComponent("link")
try fm.createSymbolicLink(atPath: link.path, withDestinationPath: "revision")
func deploy(_ revision: String, debuggable: Bool) async throws -> URL {
try Data(revision.utf8).write(to: payload)
var sign = ["--force", "--sign", "-", "--timestamp=none"]
if debuggable { sign += ["--entitlements", entitlement.path] }
try await DebugTools.run(URL(fileURLWithPath: "/usr/bin/codesign"), sign + [product.path])
let staging = root.appendingPathComponent(UUID().uuidString)
try DebugTools.directory(staging)
let zip = staging.appendingPathComponent("App.zip")
try await DebugTools.run(URL(fileURLWithPath: "/usr/bin/ditto"), ["-c", "-k", "--keepParent", product.path, zip.path])
return try await TargetDebugTools.install(zip, into: staging).0
}
let first = try await deploy("one", debuggable: true)
let second = try await deploy("two", debuggable: true)
#expect(first == second)
let installed = first.appendingPathComponent("Contents/Resources/link")
#expect(try fm.destinationOfSymbolicLink(atPath: installed.path) == "revision")
#expect(try Data(contentsOf: installed) == Data("two".utf8))
await #expect(throws: MacDebugError.self) { try await deploy("three", debuggable: false) }
#expect(try Data(contentsOf: installed) == Data("two".utf8))
}
}