How to correctly resolve URL bookmarks for use in Simulator UI tests?

To make UI testing easier and faster, I usually create URL bookmarks during normal app usage in the Simulator so that they can be instantly resolved on app launch during UI tests. For example, one of my apps allows browsing selected folders and stores bookmarks so they can be quickly opened again on following app launches, and instead of selecting the test folder each time at the beginning of the UI test, I select it once during normal app usage so that it's available immediately during the UI test.

This usually works fine, but every now and then the UI tests fail because the tested app isn't able to resolve the stored bookmark. I don't know why this happens, but usually opening and closing the app again in the Simulator and re-running the UI tests solves the issue.

The problem now is that I've just tried to setup some new UI tests for Apple Vision Pro Simulator and I'm never able to resolve bookmarks. So I created a sample project that reproduces the issue, and curiously enough the bookmarks don't even resolve when using an iPad Simulator (which usually works fine with my regular UI tests).

What am I doing wrong? This can be reproduced with a default iOS project, embedding the default storyboard view controller in a navigation view controller, and this code:

import UIKit

class ViewController: UIViewController, UIDocumentPickerDelegate {

    override func viewDidLoad() {
        navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .add, primaryAction: UIAction(handler: { _ in
            let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
            picker.delegate = self
            self.present(picker, animated: true)
        }))
        if let bookmark = UserDefaults.standard.data(forKey: "bookmark") {
            readBookmark(bookmark)
        }
    }
    
    func readBookmark(_ bookmark: Data) {
        do {
            let label = UILabel(frame: CGRect(x: 100, y: 100, width: 600, height: 100))
            label.numberOfLines = 0
            var stale = false
            let url = try URL(resolvingBookmarkData: bookmark, bookmarkDataIsStale: &stale)
            if !url.startAccessingSecurityScopedResource() {
                fatalError()
            }
            label.text = url.path
            view.addSubview(label)
        } catch {
            fatalError(error.localizedDescription)
        }
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        do {
            let url = urls[0]
            if !url.startAccessingSecurityScopedResource() {
                fatalError()
            }
            let bookmark = try url.bookmarkData()
            UserDefaults.standard.set(bookmark, forKey: "bookmark")
            readBookmark(bookmark)
        } catch {
            fatalError(error.localizedDescription)
        }
    }

}

And a default UI test, which always crashes because of the fatalError() in the catch clause of readBookmark(_:):

final class problemUITests: XCTestCase {

    @MainActor
    func testExample() throws {
        let app = XCUIApplication()
        app.launch()
    }
}
How to correctly resolve URL bookmarks for use in Simulator UI tests?
 
 
Q