Strange runtime error when using StoreKit Test API

We are trying to integrate StoreKit Testing into our unit and UI testing flow on Mac and iOS. The basic idea is bypassing the paywall so that the specific test can do its job without interference.

In our subclass of XCUIApplication, we've overridden the launch method to simulate the purchase of the app's full version:

import XCTest
import StoreKitTest

class OurCustomApp : XCUIApplication
{
	private var _storeKitSession : AnyObject? = nil

	override func launch()
	{
		super.launch()

		do
		{
			_storeKitSession = try SKTestSession(configurationFileNamed: "iap_desktop")
			(_storeKitSession as! SKTestSession).disableDialogs = true
			(_storeKitSession as! SKTestSession).clearTransactions()
			try (_storeKitSession as! SKTestSession).buyProduct(productIdentifier: "<our product identifier>")
		}
		catch
		{
			XCTFail("Can't setup StoreKit test. \(error)")
		}
	}
}

However, we faced a weird runtime issue:

UITests-Runner[53387:25779369] Error in XPC connection when checking Xcode Test app: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.storekitagent was invalidated: failed at lookup with error 159 - Sandbox restriction." UserInfo={NSDebugDescription=The connection to service named com.apple.storekitagent was invalidated: failed at lookup with error 159 - Sandbox restriction.}

We use the proper certificate for StoreKit Testing and follow all the steps from Setting Up StoreKit Testing in Xcode. The problem reproduces on all our machines, including Intel-based and M1 Macs.

We'd appreciate any hints or clues that will help us resolve this issue.

Hi, that's certainly not expected! Could you file a Feedback Report and attach a sysdiagnose from your Mac after reproducing the bug? You can just run the sysdiagnose app from your terminal to collect a sysdiagnose. We'll take a look at what's going wrong and help you get back on track.

Strange runtime error when using StoreKit Test API
 
 
Q