@@ -217,6 +217,38 @@ struct CuaDriverHostCoordinatorTests {
217217 await coordinator . setEnabled ( false )
218218 }
219219
220+ @ Test func `launch without an authoritative pid record never becomes ready` ( ) async throws {
221+ let root = self . shortTemporaryDirectory ( " launch-pidfile-failure " )
222+ let executable = try self . expectedExecutable ( in : root , target : " /bin/sleep " )
223+ defer { try? FileManager . default . removeItem ( at : root ) }
224+ let launcher = CuaProcessLauncherProbe ( )
225+ let coordinator = CuaDriverHostCoordinator (
226+ artifactURL : { executable } ,
227+ applicationSupportURL : { root } ,
228+ bundleIdentifier : { " ai.openclaw.test " } ,
229+ processLauncher : { launch , onTermination in
230+ let socketIndex = try #require ( launch . arguments . firstIndex ( of : " --socket " ) )
231+ let socketPath = try #require ( launch . arguments . indices . contains ( socketIndex + 1 )
232+ ? launch . arguments [ socketIndex + 1 ]
233+ : nil )
234+ let pidFile = URL ( fileURLWithPath : socketPath )
235+ . deletingLastPathComponent ( )
236+ . appendingPathComponent ( " cua.pid " )
237+ try Data ( " incomplete " . utf8 ) . write ( to : pidFile )
238+ return launcher . launch ( launch , onTermination : onTermination )
239+ } ,
240+ readinessProbe : { _ in true } )
241+
242+ await coordinator . setEnabled ( true )
243+
244+ #expect ( coordinator . workerEndpoint == nil )
245+ #expect ( launcher . processes . count == 1 )
246+ #expect ( launcher . processes . allSatisfy { ! $0 . isRunning } )
247+ await coordinator . setEnabled ( false )
248+ let cuaRoot = root . appendingPathComponent ( " OpenClaw/cua " , isDirectory : true )
249+ #expect ( try FileManager . default . contentsOfDirectory ( atPath : cuaRoot . path ) . isEmpty )
250+ }
251+
220252 @ Test func `startup refuses to signal a pid owned by another executable` ( ) async throws {
221253 let root = self . shortTemporaryDirectory ( " startup-pid-reuse " )
222254 let expectedExecutable = try self . expectedExecutable ( in : root , target : " /bin/cat " )
0 commit comments