I’m seeing what looks like a mismatch specifically when running tests via SwiftPM CLI (swift test), and I’m not sure whether this should be tracked as SwiftPM, Swift Testing, or RealityKit.
I don't see anything here that suggests a bug in Swift Testing. While it may be a bug in SwiftPM (I'm not an expert on that part of it) I would start by filing feedback against RealityKit with Apple about it. If it does turn out to be a SwiftPM issue, they can send the bug report along.
Update, six months on: this still reproduces on macOS 27.0 (26A428) and it has escalated from a wrong result to a crash.
Running the same repro package now terminates with SIGSEGV instead of failing the expectation. The faulting frames are all inside RealityKit's USD importer, re-encoding the component it just created:
Foundation JSONWriter.serializeString(_:)
RealityFoundation encodeComponent(_:_:_:)
CoreRE convertToEntityAssetData(...)
CoreRealityIO StageSceneLibraryAssetBuilder::run
Two findings that change the framing of this thread:
It is not SwiftPM-specific. A single Swift file with no package, bundle or test framework crashes the same way: register a Codable component with a String field, write a .usda with a matching RealityKitCustomComponent prim, and call Entity(contentsOf:). It also crashes under xcodebuild test when the raw .usda is in the bundle.
The component instance is uninitialized memory, not a failed decode. Swap the String for a Float and the load succeeds, has is true, and the typed lookup returns -4.170893e+07 rather than the USD value or the Swift default. A String made of arbitrary bytes crashes on first read, which is what the "has == true, typed == nil" symptom on macOS 26 was hiding.
The reason xcodebuild test looked fine in a real project is that Reality Composer Pro compiles .rkassets into a .reality file, which never goes through the USD importer. swift test ships the raw USD instead. Loading the same content compiled with xcrun realitytool compile works under swift test too, so that's a workaround if anyone needs SwiftPM in the meantime.
Filed as FB24852723 with the single-file repro and crash report. @grynspan was right that this belongs with RealityKit rather than SwiftPM or Swift Testing.