Upgrade to Pro — share decks privately, control downloads, hide ads and more …

テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜

テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜

iOSDC Japan 2026 で発表した資料になります。

https://fortee.jp/iosdc-japan-2026/proposal/5b3d99c5-bd13-4a0b-8e5e-c1fa62c2730d

Avatar for Hidemune Takahashi

Hidemune Takahashi

September 12, 2026

More Decks by Hidemune Takahashi

Other Decks in Programming

Transcript

  1. 自己紹介 • h1d3mun3(ヒデムネ) • お仕事 • iOSエンジニア • 普段はタクシーアプリを作っている !!!

    • 趣味はエレキギター" • BOSSのGX-1を買ったら出音が良すぎてびっくり 2
  2. 目次 1. Motivation 2. 隔離macOS VMを作ろう! 3. Claude Codeを動かそう! 4.

    デーモンに会いに行こう! 5. まとめ 6. 参考資料 11
  3. admin@admins-Virtual-Machine workspace-avow % xcodebuild -project Avow.xcodeproj -scheme Avow -destination 'platform=macOS'

    CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" test 〜〜〜中略〜〜〜 Testing started 2026-08-25 22:23:23.975 xcodebuild[1499:6717] IDETestOperationsObserverDebug: Failure collecting logarchive: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.testmanagerd.control was invalidated: Connection init failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.testmanagerd.control was invalidated: Connection init failed at lookup with error 3 No such process.} 2026-08-25 22:23:23.977 xcodebuild[1499:6707] [MT] IDETestOperationsObserverDebug: 0.136 elapsed -- Testing started completed. 2026-08-25 22:23:23.977 xcodebuild[1499:6707] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start 2026-08-25 22:23:23.977 xcodebuild[1499:6707] [MT] IDETestOperationsObserverDebug: 0.136 sec, +0.136 sec -- end Test session results, code coverage, and logs: /Users/admin/Library/Developer/Xcode/DerivedData/Avow-bcpwjhzdopisbhfdmuzjlzybcxfh/Logs/Test/TestAvow-2026.08.25_22-23-23-+0900.xcresult Testing failed: Avow encountered an error (Failed to establish communication with the test runner. (Underlying Error: Couldn’t communicate with a helper application. Try your operation again. If that fails, quit and relaunch the application and try again. The connection to service named com.apple.testmanagerd.control was invalidated: Connection init failed at lookup with error 3 - No such process.)) ** TEST FAILED **
  4. エラーを読み解く NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.testmanagerd.control was

    invalidated: Connection init failed at lookup with error 3 No such process." 33
  5. “Aqua session” はxcodebuildの実行に必須 AppleのDocumentation Archiveからの引用※ SSH経由のリモートログイン(またはLaunch Daemon)か ら `xcodebuild` を実行する場合、ホスト上で適切なセッ

    ション環境が構築されていないと失敗します。 Invoking xcodebuild from a remote login with ssh (or from a launch demon) fails unless the correct session environment is created on the host. 「Aquaセッション」環境は、ユーザーとしてmacOSシステ ムにインタラクティブにログインした際に作成されます。 An “Aqua session” environment is created when you interactively log into your macOS system as a user. ホストシステム上でユーザーが動作している状態であれば、 SSHログイン経由で `xcodebuild` を実行し、あらゆる種類 のテストを行うことが可能です。 Once there is a user running on the host system, running xcodebuild from an ssh login works for all types of tests. 35 https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/08-automation.html
  6. launchctlのセッションとの関連 man launchctlの記述 特定のコンテキストでのみ意味を持つジョブもありま す。 … 関連するセッションには、Aqua(デフォルト)、 Background、LoginWindowがあります。Background エージェントは、GUIへのログインとは無関係に読み込ま れる場合があります。一方、Aquaエージェントは、ユー

    ザーがGUIにログインしたときにのみ読み込まれます。 jobs only make sense in certain contexts. ... Relevant sessions are Aqua (the default), Background and LoginWindow. Background agents may be loaded independently of a GUI login. Aqua agents are loaded only when a user has logged in at the GUI. 36
  7. admin@admins-Virtual-Machine workspace-avow % xcodebuild -project Avow.xcodeproj -scheme Avow -destination 'platform=macOS'

    CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY="" test 〜〜〜中略〜〜〜 Testing started Test suite 'DataAdminServiceTests' started on 'My Mac - Avow (1131)' Test suite 'QuickPanelSelectionTests' started on 'My Mac - Avow (1131)' Test suite 'SwiftDataProjectRepositoryTests' started on 'My Mac - Avow (1131)’ 〜〜〜中略〜〜〜 2026-08-29 22:17:07.143 xcodebuild[966:6252] [MT] IDETestOperationsObserverDebug: 2.172 elapsed -- Testing started completed. 2026-08-29 22:17:07.143 xcodebuild[966:6252] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -start 2026-08-29 22:17:07.143 xcodebuild[966:6252] [MT] IDETestOperationsObserverDebug: 2.172 sec, +2.172 sec -- end Test session results, code coverage, and logs: /Users/admin/Library/Developer/Xcode/DerivedData/Avow-bcpwjhzdopisbhfdmuzjlzybcxfh/Logs/Test/TestAvow-2026.08.29_22-16-44-+0900.xcresult ** TEST SUCCEEDED **
  8. macOSにおける常駐サービス man launchdの記述 launchdの用語において、Daemonとは定義上、す べてのクライアントに対して単一のインスタンスの みが存在するシステム全体のサービスを指します。 一方、Agentはユーザーごとに実行されるサービス です。Daemonは、UIを表示したり、ユーザーのロ グインセッションと直接やり取りしたりするべきで はありません。ユーザーとのやり取りを伴うあらゆ

    る処理は、Agentを介して行う必要があります。 In the launchd lexicon, a daemon is, by definition, a system-wide service of which there is one instance for all clients. An agent is a service that runs on a per-user basis. Daemons should not attempt to display UI or interact directly with a user's login session. Any and all work that involves interacting with a user should be done through agents. 44
  9. testmanagerdがふたつ…. % ls /System/Library/LaunchDaemons | grep -i testmanager com.apple.testmanagerd.plist %

    ls /System/Library/LaunchAgents | grep -i testmanager com.apple.testmanagerd.plist → DaemonにもAgentにもtestmanagerdが存在する # # # 46
  10. 違いをチェック com.apple.testmanagerd.plist (Daemon) com.apple.testmanagerd.plist (Agent) Location /System/Library/LaunchDaemons/ com.apple.testmanagerd.plist /System/Library/LaunchAgents/ com.apple.testmanagerd.plist

    Label com.apple.testmanagerd.remote com.apple.testmanagerd MachServices com.apple.dt.xctestd.remote.runner com.apple.dt.xctestd.remote.target com.apple.dt.xctestd.target com.apple.testmanagerd com.apple.testmanagerd.control Program /usr/libexec/testmanagerd /usr/libexec/testmanagerd LimitLoadToSessionType (なし) [LoginWindow, Aqua] 47
  11. [再掲] エラーを読み解く NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.testmanagerd.control

    was invalidated: Connection init failed at lookup with error 3 No such process." 48
  12. 結論 • xcodebuildが探したもの……. → com.apple.testmanagerd.control • それがいるのは………………… → LaunchAgents •

    Agent がロードされるのは… → LoginWindow / Aqua のみ • macOS VMでは……………….. → ログインしてなかった → Aquaセッションがないのでロードされず、Agentがいなかった
  13. まとめ% • Virtualization Frameworkを利用して、macOS VM環境をMac上に立ち 上げ、Xcodeをインストールして利用可能にすることができた • 隔離環境にClaude Codeを導入し、利用可能な状況にできた •

    xcodebuild testの実行にはAquaもしくはLoginWindowセッションが必須 • macOS VMにGUIログインした結果、Aquaセッションが生まれ、 LaunchAgentsのAgentがロードされ、隔離環境でもxcodebuild testが実 行できた 51
  14. 参考資料 • https://www.github.com/h1d3mun3/augur • man launchctl • man launchd •

    https://developer.apple.com/documentation/foundation/nsxpcconnectioninvalidswift.var • https://developer.apple.com/documentation/xpc • https://developer.apple.com/library/archive/documentation/DeveloperTools/ Conceptual/testing_with_xcode/chapters/08-automation.html 53