From 5a9006cf1a443636e7eecd95bb3e862c60ab6db3 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sat, 31 Oct 2026 13:31:11 -0400 Subject: [PATCH 1/4] Launch e2e app through Launch Services --- Sources/ParcelApp/AppStandardStreams.swift | 28 +++++ Sources/ParcelApp/ParcelApplication.swift | 4 + .../AppStandardStreamsTests.swift | 108 ++++++++++++++++++ .../ParcelE2ETests/E2EApplicationLaunch.swift | 53 +++++++++ .../E2EApplicationLaunchTests.swift | 44 +++++++ .../E2EHarnessRegressionTests.swift | 5 + .../FocusModesEndToEndTests.swift | 2 +- Tests/ParcelE2ETests/MouseEndToEndTests.swift | 2 +- Tests/ParcelE2ETests/ParcelE2ETests.swift | 41 +++---- 9 files changed, 258 insertions(+), 29 deletions(-) create mode 100644 Sources/ParcelApp/AppStandardStreams.swift create mode 100644 Tests/ParcelE2ETests/AppStandardStreamsTests.swift create mode 100644 Tests/ParcelE2ETests/E2EApplicationLaunch.swift create mode 100644 Tests/ParcelE2ETests/E2EApplicationLaunchTests.swift diff --git a/Sources/ParcelApp/AppStandardStreams.swift b/Sources/ParcelApp/AppStandardStreams.swift new file mode 100644 index 00000000..cbc9c2ec --- /dev/null +++ b/Sources/ParcelApp/AppStandardStreams.swift @@ -0,0 +1,28 @@ +import Darwin +import Foundation + +struct AppStandardStreams { + static func redirect( + environment: [String: String], outputDescriptor: Int32 = STDOUT_FILENO, errorDescriptor: Int32 = STDERR_FILENO + ) throws { + guard environment["PARCEL_E2E"] == "1", let path = environment["PARCEL_E2E_LOG_PATH"] else { return } + guard path.hasPrefix("/"), !path.contains("\0") else { + throw CocoaError(.fileWriteInvalidFileName, userInfo: [NSFilePathErrorKey: path]) + } + let descriptor = Darwin.open(path, O_WRONLY | O_CREAT | O_APPEND | O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK, 0o600) + guard descriptor >= 0 else { throw posixError() } + defer { Darwin.close(descriptor) } + var info = stat() + guard fstat(descriptor, &info) == 0 else { throw posixError() } + guard info.st_mode & S_IFMT == S_IFREG, info.st_uid == getuid(), info.st_nlink == 1 else { + throw CocoaError(.fileWriteNoPermission, userInfo: [NSFilePathErrorKey: path]) + } + guard dup2(descriptor, outputDescriptor) >= 0, dup2(descriptor, errorDescriptor) >= 0 else { + throw posixError() + } + } + + private static func posixError() -> NSError { + NSError(domain: NSPOSIXErrorDomain, code: Int(errno)) + } +} diff --git a/Sources/ParcelApp/ParcelApplication.swift b/Sources/ParcelApp/ParcelApplication.swift index 002091f1..a1664fdc 100644 --- a/Sources/ParcelApp/ParcelApplication.swift +++ b/Sources/ParcelApp/ParcelApplication.swift @@ -133,6 +133,10 @@ struct ParcelApplication { @MainActor static func main() { run(arguments: CommandLine.arguments) { + do { try AppStandardStreams.redirect(environment: ProcessInfo.processInfo.environment) } catch { + FileHandle.standardError.write(Data("\(error.localizedDescription)\n".utf8)) + exit(EXIT_FAILURE) + } let application = NSApplication.shared let delegate = AppDelegate() application.delegate = delegate diff --git a/Tests/ParcelE2ETests/AppStandardStreamsTests.swift b/Tests/ParcelE2ETests/AppStandardStreamsTests.swift new file mode 100644 index 00000000..4634fd60 --- /dev/null +++ b/Tests/ParcelE2ETests/AppStandardStreamsTests.swift @@ -0,0 +1,108 @@ +import Darwin +import Foundation +import Testing + +@testable import ParcelApp + +@Suite +struct AppStandardStreamsTests { + @Test func redirectsBothStreamsToOneAppendOnlyLog() throws { + try withDirectory { directory in + let log = directory.appendingPathComponent("app log") + try Data("existing\n".utf8).write(to: log) + let output = try FileHandle(forWritingTo: directory.appendingPathComponent("output")) + let errors = try FileHandle(forWritingTo: directory.appendingPathComponent("errors")) + defer { close(output, errors) } + try AppStandardStreams.redirect( + environment: ["PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": log.path], + outputDescriptor: output.fileDescriptor, errorDescriptor: errors.fileDescriptor) + try output.write(contentsOf: Data("stdout\n".utf8)) + try errors.write(contentsOf: Data("stderr\n".utf8)) + #expect(try String(contentsOf: log, encoding: .utf8) == "existing\nstdout\nstderr\n") + } + } + + @Test func createsAPrivateLogWhenThePathDoesNotExist() throws { + try withDirectory { directory in + let log = directory.appendingPathComponent("new log") + let output = try FileHandle(forWritingTo: directory.appendingPathComponent("output")) + let errors = try FileHandle(forWritingTo: directory.appendingPathComponent("errors")) + defer { close(output, errors) } + try AppStandardStreams.redirect( + environment: ["PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": log.path], + outputDescriptor: output.fileDescriptor, errorDescriptor: errors.fileDescriptor) + let attributes = try FileManager.default.attributesOfItem(atPath: log.path) + let permissions = try #require(attributes[.posixPermissions] as? NSNumber) + #expect(permissions.intValue & 0o777 == 0o600) + } + } + + @Test(arguments: [ + [:], ["PARCEL_E2E": "1"], ["PARCEL_E2E_LOG_PATH": "relative"], + ["PARCEL_E2E": "0", "PARCEL_E2E_LOG_PATH": "relative"], + ]) + func onlyExplicitE2ELoggingChangesDescriptors(environment: [String: String]) throws { + try AppStandardStreams.redirect(environment: environment, outputDescriptor: -1, errorDescriptor: -1) + } + + @Test(arguments: ["", "relative", "/tmp/null\0suffix"]) + func rejectsInvalidPaths(path: String) { + #expect(throws: CocoaError.self) { + try AppStandardStreams.redirect(environment: ["PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": path]) + } + } + + @Test func rejectsSymlinksHardLinksDirectoriesAndMissingParents() throws { + try withDirectory { directory in + let output = try FileHandle(forWritingTo: directory.appendingPathComponent("output")) + let errors = try FileHandle(forWritingTo: directory.appendingPathComponent("errors")) + defer { close(output, errors) } + let target = directory.appendingPathComponent("target") + let link = directory.appendingPathComponent("symlink") + let hardLink = directory.appendingPathComponent("hardlink") + try Data("unchanged".utf8).write(to: target) + try FileManager.default.createSymbolicLink(at: link, withDestinationURL: target) + try FileManager.default.linkItem(at: target, to: hardLink) + for path in [ + link.path, hardLink.path, directory.path, directory.appendingPathComponent("missing/log").path, + ] { + #expect(throws: (any Error).self) { + try AppStandardStreams.redirect( + environment: ["PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": path], + outputDescriptor: output.fileDescriptor, errorDescriptor: errors.fileDescriptor) + } + } + #expect(try String(contentsOf: target, encoding: .utf8) == "unchanged") + } + } + + @Test func descriptorFailureIsReported() throws { + try withDirectory { directory in + #expect(throws: NSError.self) { + try AppStandardStreams.redirect( + environment: [ + "PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": directory.appendingPathComponent("log").path, + ], + outputDescriptor: -1, errorDescriptor: -1) + } + } + } + + private func withDirectory(_ body: (URL) throws -> Void) throws { + let directory = FileManager.default.temporaryDirectory.appendingPathComponent("streams-\(UUID())") + try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) + defer { + do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } + } + try Data().write(to: directory.appendingPathComponent("output")) + try Data().write(to: directory.appendingPathComponent("errors")) + try body(directory) + } + + private func close(_ output: FileHandle, _ errors: FileHandle) { + do { + try output.close() + try errors.close() + } catch { Issue.record(error) } + } +} diff --git a/Tests/ParcelE2ETests/E2EApplicationLaunch.swift b/Tests/ParcelE2ETests/E2EApplicationLaunch.swift new file mode 100644 index 00000000..9703e017 --- /dev/null +++ b/Tests/ParcelE2ETests/E2EApplicationLaunch.swift @@ -0,0 +1,53 @@ +import AppKit +import Foundation +import Testing + +@MainActor +enum E2EApplicationLaunch { + static func open( + at url: URL, arguments: [String] = [], environment: [String: String], + launch: @MainActor (URL, NSWorkspace.OpenConfiguration) async throws -> NSRunningApplication = { + try await NSWorkspace.shared.openApplication(at: $0, configuration: $1) + } + ) async throws -> NSRunningApplication { + let configuration = NSWorkspace.OpenConfiguration() + configuration.arguments = arguments + configuration.environment = environment + // Launch Services gives the bundle its own TCC responsibility rather than inheriting the runner's. + configuration.createsNewApplicationInstance = true + configuration.activates = false + configuration.addsToRecentItems = false + return try await launch(url, configuration) + } + + static func stop(_ application: NSRunningApplication) async { + guard !application.isTerminated else { return } + let pid = application.processIdentifier + guard application.terminate() else { + Issue.record("Parcel application \(pid) refused termination") + await forceStop(application) + return + } + do { + try await waitUntil("application \(pid) termination", timeout: .seconds(15)) { + application.isTerminated + } + } catch { + Issue.record(error) + await forceStop(application) + } + } + + private static func forceStop(_ application: NSRunningApplication) async { + guard !application.isTerminated else { return } + guard application.forceTerminate() else { + Issue.record("Could not force termination of application \(application.processIdentifier)") + return + } + do { + try await waitUntil("forced application termination", timeout: .seconds(3)) { + application.isTerminated + } + } catch { Issue.record(error) } + } +} diff --git a/Tests/ParcelE2ETests/E2EApplicationLaunchTests.swift b/Tests/ParcelE2ETests/E2EApplicationLaunchTests.swift new file mode 100644 index 00000000..23b05450 --- /dev/null +++ b/Tests/ParcelE2ETests/E2EApplicationLaunchTests.swift @@ -0,0 +1,44 @@ +import AppKit +import Foundation +import Testing + +@Suite +@MainActor +struct E2EApplicationLaunchTests { + @Test func opensTheExactBundleWithIndependentResponsibilityAndSuppliedInputs() async throws { + let url = URL(fileURLWithPath: "/tmp/launch regression/Parcel.app") + let arguments = ["--test", "argument with spaces"] + let environment = ["PARCEL_E2E": "1", "PARCEL_E2E_LOG_PATH": "/tmp/app log", "CUSTOM": "value"] + let current = NSRunningApplication.current + var calls = 0 + let application = try await E2EApplicationLaunch.open( + at: url, arguments: arguments, environment: environment, + launch: { receivedURL, configuration in + calls += 1 + #expect(receivedURL == url) + #expect(configuration.arguments == arguments) + #expect(configuration.environment == environment) + #expect(configuration.createsNewApplicationInstance) + #expect(!configuration.activates) + #expect(!configuration.addsToRecentItems) + return current + }) + #expect(calls == 1) + #expect(application === current) + } + + @Test func launchErrorsPropagateWithoutRetryingOrReturningAnUnrelatedApp() async { + var calls = 0 + do { + _ = try await E2EApplicationLaunch.open( + at: URL(fileURLWithPath: "/tmp/missing.app"), environment: [:], + launch: { _, configuration in + calls += 1 + #expect(configuration.arguments.isEmpty) + throw E2EError(description: "Launch Services refused the bundle") + }) + Issue.record("A failed launch must not return an application") + } catch { #expect(String(describing: error) == "Launch Services refused the bundle") } + #expect(calls == 1) + } +} diff --git a/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift b/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift index 520bbefd..4e4b8ea3 100644 --- a/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift +++ b/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift @@ -49,6 +49,11 @@ struct E2EHarnessRegressionTests { } } + @Test func preflightMessageReportsTheActualGrant() { + #expect(E2ERunPolicy.preflightMessage(trusted: false).contains("lacks Accessibility permission")) + #expect(E2ERunPolicy.preflightMessage(trusted: true).contains("has Accessibility permission")) + } + @Test func trustedPreflightDoesNotRunLiveScenarios() throws { #expect(try E2ERunPolicy.validate(trusted: true, environment: ["PARCEL_E2E": "1"])) #expect( diff --git a/Tests/ParcelE2ETests/FocusModesEndToEndTests.swift b/Tests/ParcelE2ETests/FocusModesEndToEndTests.swift index d37d960a..309ae28b 100644 --- a/Tests/ParcelE2ETests/FocusModesEndToEndTests.swift +++ b/Tests/ParcelE2ETests/FocusModesEndToEndTests.swift @@ -356,7 +356,7 @@ extension RealAppEndToEndTests { _ = try await session.cli(["quit", "--json"]) try await waitUntil("quitting closes every privacy window") { let windows = try serverWindows() - return !process.isRunning && !windows.contains { $0.pid == pid } + return process.isTerminated && !windows.contains { $0.pid == pid } } #expect(try await fixture.snapshot().windows.count == 2) } diff --git a/Tests/ParcelE2ETests/MouseEndToEndTests.swift b/Tests/ParcelE2ETests/MouseEndToEndTests.swift index 87ee2b30..747905f1 100644 --- a/Tests/ParcelE2ETests/MouseEndToEndTests.swift +++ b/Tests/ParcelE2ETests/MouseEndToEndTests.swift @@ -544,7 +544,7 @@ private final class FixtureMouseEvents { } func restore() async throws { - guard session.app?.isRunning == true else { return } + guard let app = session.app, !app.isTerminated else { return } try await post(["restore"]) isDown = false } diff --git a/Tests/ParcelE2ETests/ParcelE2ETests.swift b/Tests/ParcelE2ETests/ParcelE2ETests.swift index 441ad041..6701a5a4 100644 --- a/Tests/ParcelE2ETests/ParcelE2ETests.swift +++ b/Tests/ParcelE2ETests/ParcelE2ETests.swift @@ -385,8 +385,7 @@ final class E2ESession { let appURL: URL let cliURL: URL let e2eToken: String - private(set) var app: Process? - private var appLog: FileHandle? + private(set) var app: NSRunningApplication? private var fixtures: [FixtureProcess] = [] private(set) var configuration: E2EConfiguration @@ -424,21 +423,14 @@ final class E2ESession { guard FileManager.default.createFile(atPath: logURL.path, contents: nil) else { throw E2EError(description: "Could not create Parcel app log") } - let log = try FileHandle(forWritingTo: logURL) - appLog = log - let process = Process() - process.executableURL = executable var environment = ProcessInfo.processInfo.environment environment["PARCEL_CONFIG_PATH"] = configURL.path environment["PARCEL_SOCKET_PATH"] = socketURL.path environment["PARCEL_E2E"] = "1" environment["PARCEL_E2E_TOKEN"] = e2eToken environment["PARCEL_E2E_DROP_ONE_DESTROYED"] = dropOneDestroyedWindow ? "1" : nil - process.environment = environment - process.standardOutput = log - process.standardError = log - try process.run() - app = process + environment["PARCEL_E2E_LOG_PATH"] = logURL.path + app = try await E2EApplicationLaunch.open(at: appURL, environment: environment) try await waitUntil("Parcel bundle IPC startup") { try self.requireAppRunning() return FileManager.default.fileExists(atPath: self.socketURL.path) @@ -557,31 +549,25 @@ final class E2ESession { func quit() async throws { _ = try await cli(["run", "--json", "quit"]) - let process = try #require(app) - try await waitUntil("Parcel graceful quit") { !process.isRunning } - #expect(process.terminationStatus == 0) + let application = try #require(app) + try await waitUntil("Parcel graceful quit") { application.isTerminated } #expect(!FileManager.default.fileExists(atPath: socketURL.path)) } func relaunchApp() async throws { try await quit() - try appLog?.close() - appLog = nil app = nil try await startApp() } func cleanup() async { - if let app { await stopProcess(app) } + if let app { await E2EApplicationLaunch.stop(app) } for fixture in fixtures { await fixture.stop() } - if let appLog { - do { try appLog.close() } catch { Issue.record(error) } - } do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } } private func requireAppRunning() throws { - guard app?.isRunning == true else { + guard let app, !app.isTerminated else { let log = try String(contentsOf: directory.appendingPathComponent("app.log"), encoding: .utf8) throw E2EError(description: "Parcel exited unexpectedly: \(log)") } @@ -848,6 +834,10 @@ enum E2ERunPolicy { static let missingPermission = "Required e2e cannot run: enable build/Parcel.app in System Settings > Privacy & Security > Accessibility. The test runner needs neither Accessibility nor Screen Recording." + static func preflightMessage(trusted: Bool) -> String { + "E2E preflight: build/Parcel.app \(trusted ? "has" : "lacks") Accessibility permission. Real-window scenarios were not run.\n" + } + static func permitsRealScenarios(trusted: Bool, environment: [String: String]) -> Bool { environment["PARCEL_E2E"] == "1" && trusted && environment["PARCEL_E2E_PREFLIGHT_ONLY"] != "1" } @@ -900,14 +890,11 @@ private enum E2EAvailability { trusted = config.accessibility try await session.quit() } - let enabled = try E2ERunPolicy.validate(trusted: trusted, environment: environment) - if !enabled { + if !trusted || environment["PARCEL_E2E_PREFLIGHT_ONLY"] == "1" { try FileHandle.standardError.write( - contentsOf: Data( - "E2E preflight: build/Parcel.app has Accessibility permission. Real-window scenarios were not run.\n" - .utf8)) + contentsOf: Data(E2ERunPolicy.preflightMessage(trusted: trusted).utf8)) } - return enabled + return try E2ERunPolicy.validate(trusted: trusted, environment: environment) } } } -- knotmirror 0.0.1 From a83798e692664eb79af0184d58a2035bc85200f9 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sat, 31 Oct 2026 13:35:13 -0400 Subject: [PATCH 2/4] Include live scenarios in e2e target filters --- Tests/ParcelE2ETests/AppKitTestSuite.swift | 8 +++++++- Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Tests/ParcelE2ETests/AppKitTestSuite.swift b/Tests/ParcelE2ETests/AppKitTestSuite.swift index 319b0d1d..bafdb252 100644 --- a/Tests/ParcelE2ETests/AppKitTestSuite.swift +++ b/Tests/ParcelE2ETests/AppKitTestSuite.swift @@ -1,3 +1,9 @@ import ParcelTestSupport +import Testing -typealias AppKitTestSuite = ParcelTestSupport.AppKitTestSuite +extension ParcelTestSupport.AppKitTestSuite { + // Swift Testing uses the ancestor's module in IDs; the target name keeps target filters complete. + @Suite struct ParcelE2ETests {} +} + +typealias AppKitTestSuite = ParcelTestSupport.AppKitTestSuite.ParcelE2ETests diff --git a/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift b/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift index 4e4b8ea3..6ef832c4 100644 --- a/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift +++ b/Tests/ParcelE2ETests/E2EHarnessRegressionTests.swift @@ -49,6 +49,12 @@ struct E2EHarnessRegressionTests { } } + @Test func sharedAppKitAncestorKeepsTheTargetNameInTestIdentifiers() { + #expect(String(reflecting: AppKitTestSuite.self).contains("ParcelE2ETests")) + #expect(String(reflecting: RealAppEndToEndTests.self).contains("ParcelE2ETests")) + #expect(String(reflecting: AppKitTestSuite.RealAppEndToEndTestsPreflight.self).contains("ParcelE2ETests")) + } + @Test func preflightMessageReportsTheActualGrant() { #expect(E2ERunPolicy.preflightMessage(trusted: false).contains("lacks Accessibility permission")) #expect(E2ERunPolicy.preflightMessage(trusted: true).contains("has Accessibility permission")) -- knotmirror 0.0.1 From 22c5b8bd0986a4b2e4188e004d40d67b25285819 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sat, 31 Oct 2026 14:09:14 -0400 Subject: [PATCH 3/4] Explain locked desktop e2e failures --- Tests/ParcelE2ETests/E2EConsoleSession.swift | 32 ++++++++++++ .../E2EConsoleSessionTests.swift | 50 +++++++++++++++++++ Tests/ParcelE2ETests/ParcelE2ETests.swift | 4 +- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Tests/ParcelE2ETests/E2EConsoleSession.swift create mode 100644 Tests/ParcelE2ETests/E2EConsoleSessionTests.swift diff --git a/Tests/ParcelE2ETests/E2EConsoleSession.swift b/Tests/ParcelE2ETests/E2EConsoleSession.swift new file mode 100644 index 00000000..3c4acc3b --- /dev/null +++ b/Tests/ParcelE2ETests/E2EConsoleSession.swift @@ -0,0 +1,32 @@ +import CoreGraphics +import Foundation + +struct E2EConsoleSession: Decodable { + static let unavailableMessage = + "Required e2e cannot run: sign in, unlock this Mac's screen, and keep the desktop session active before rerunning make e2e." + + let onConsole: Bool + let loginDone: Bool + let screenLocked: Bool? + + private enum CodingKeys: String, CodingKey { + case onConsole = "kCGSSessionOnConsoleKey" + case loginDone = "kCGSessionLoginDoneKey" + case screenLocked = "CGSSessionScreenIsLocked" + } + + static func requireUnlockedConsole() throws { + guard let dictionary = CGSessionCopyCurrentDictionary() else { + throw E2EError(description: unavailableMessage) + } + let data = try PropertyListSerialization.data(fromPropertyList: dictionary, format: .binary, options: 0) + try PropertyListDecoder().decode(Self.self, from: data).requireUnlocked() + } + + func requireUnlocked() throws { + // The lock marker is absent in an unlocked session. + guard onConsole, loginDone, screenLocked != true else { + throw E2EError(description: Self.unavailableMessage) + } + } +} diff --git a/Tests/ParcelE2ETests/E2EConsoleSessionTests.swift b/Tests/ParcelE2ETests/E2EConsoleSessionTests.swift new file mode 100644 index 00000000..8ae51efc --- /dev/null +++ b/Tests/ParcelE2ETests/E2EConsoleSessionTests.swift @@ -0,0 +1,50 @@ +import Foundation +import Testing + +@Suite +struct E2EConsoleSessionTests { + @Test(arguments: [false, true]) + func lockedSessionFailsEvenWhenTheConsoleIsActive(onConsole: Bool) { + let session = E2EConsoleSession(onConsole: onConsole, loginDone: true, screenLocked: true) + do { + try session.requireUnlocked() + Issue.record("Locked console must not permit real-window scenarios") + } catch { #expect(String(describing: error) == E2EConsoleSession.unavailableMessage) } + } + + @Test(arguments: [false, nil]) + func activeUnlockedSessionAcceptsTheOptionalLockMarker(screenLocked: Bool?) throws { + try E2EConsoleSession(onConsole: true, loginDone: true, screenLocked: screenLocked).requireUnlocked() + } + + @Test(arguments: [(false, true), (true, false), (false, false)]) + func inactiveOrLoggedOutSessionIsNotUsable(onConsole: Bool, loginDone: Bool) { + #expect(throws: E2EError.self) { + try E2EConsoleSession(onConsole: onConsole, loginDone: loginDone, screenLocked: false).requireUnlocked() + } + } + + @Test func decodesTheSystemKeysWithoutCoercingMalformedValues() throws { + let active = Data( + """ + + + + kCGSSessionOnConsoleKey + kCGSessionLoginDoneKey + CGSSessionScreenIsLocked + + """.utf8) + let decoder = PropertyListDecoder() + let session = try decoder.decode(E2EConsoleSession.self, from: active) + #expect(session.onConsole) + #expect(session.loginDone) + #expect(session.screenLocked == true) + let malformed = Data( + String(decoding: active, as: UTF8.self).replacingOccurrences(of: "", with: "yes") + .utf8) + #expect(throws: DecodingError.self) { try decoder.decode(E2EConsoleSession.self, from: malformed) } + let missing = Data("".utf8) + #expect(throws: DecodingError.self) { try decoder.decode(E2EConsoleSession.self, from: missing) } + } +} diff --git a/Tests/ParcelE2ETests/ParcelE2ETests.swift b/Tests/ParcelE2ETests/ParcelE2ETests.swift index 6701a5a4..90984c5e 100644 --- a/Tests/ParcelE2ETests/ParcelE2ETests.swift +++ b/Tests/ParcelE2ETests/ParcelE2ETests.swift @@ -894,7 +894,9 @@ private enum E2EAvailability { try FileHandle.standardError.write( contentsOf: Data(E2ERunPolicy.preflightMessage(trusted: trusted).utf8)) } - return try E2ERunPolicy.validate(trusted: trusted, environment: environment) + let enabled = try E2ERunPolicy.validate(trusted: trusted, environment: environment) + if enabled { try E2EConsoleSession.requireUnlockedConsole() } + return enabled } } } -- knotmirror 0.0.1 From f4f4e6a4258886ae755512e539ea837212cd3cea Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sat, 31 Oct 2026 14:14:14 -0400 Subject: [PATCH 4/4] Keep Space cancellation tests suspended until cancelled --- Tests/ParcelEngineTests/SpaceCommandTests.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Tests/ParcelEngineTests/SpaceCommandTests.swift b/Tests/ParcelEngineTests/SpaceCommandTests.swift index 72f21065..059b52c6 100644 --- a/Tests/ParcelEngineTests/SpaceCommandTests.swift +++ b/Tests/ParcelEngineTests/SpaceCommandTests.swift @@ -40,7 +40,13 @@ private final class FakeSpaceWorld: EngineSpaceWorld { onExecute?() if let error { throw error } if suspend { - do { try await Task.sleep(for: .seconds(10)) } catch { + // Suspension must not expire while other tests occupy the main actor. + let (stream, continuation) = AsyncStream.makeStream() + defer { continuation.finish() } + do { + for await _ in stream {} + try Task.checkCancellation() + } catch { cancelled = true throw error } @@ -167,11 +173,11 @@ struct SpaceCommandRoutingTests { let harness = try EngineHarness(spaceWorld: spaces) try await harness.start() let operation = Task { try await harness.engine.performConfigured(.spaceNext) } - for _ in 0..<1000 { - if !spaces.calls.isEmpty { break } - await Task.yield() + await withCheckedContinuation { continuation in + spaces.onExecute = { continuation.resume() } } - #expect(!spaces.calls.isEmpty) + spaces.onExecute = nil + try #require(!spaces.calls.isEmpty) await #expect(throws: IPCError.self) { try await harness.engine.performConfigured(.spaceNext) } await harness.engine.stop() await #expect(throws: CancellationError.self) { try await operation.value } -- knotmirror 0.0.1