@h1r-ai/croche-react-native 0.5.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +90 -451
- package/THIRD-PARTY-NOTICES +906 -14
- package/android/build.gradle +6 -1
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +126 -0
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +106 -0
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +217 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +48 -824
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +68 -0
- package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +64 -41
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +64 -0
- package/android/src/test/java/dev/croche/reactnative/BlobFilesTest.kt +107 -0
- package/android/src/test/java/dev/croche/reactnative/ImageAdapterWireTest.kt +70 -0
- package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +44 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +19 -32
- package/android/src/test/java/dev/croche/reactnative/ProjectHandlerStagesTest.kt +32 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectRecoveryTest.kt +12 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectTimeZoneTest.kt +11 -15
- package/android/src/test/java/dev/croche/reactnative/StorageVersionWireTest.kt +37 -0
- package/android/src/test/java/dev/croche/reactnative/VerificationDispatchTest.kt +24 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +10 -8
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +55 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +1 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageInput.kt +15 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapOrientation.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapPalCodec.kt +66 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidAssetPal.kt +30 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreFactory.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +116 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidMainDispatcher.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidS2Pal.kt +14 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStateStore.kt +216 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +108 -0
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +8 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Adapters.kt +75 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +31 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +25 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +121 -103
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +89 -103
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +20 -360
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +136 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Decision.kt +170 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +23 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +26 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/EncodedImageCodec.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +715 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +9 -322
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +16 -28
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeEvent.kt +59 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeHandleOwner.kt +118 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +10 -74
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +294 -37
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +127 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StateStore.kt +90 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +88 -24
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +5723 -3088
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +96 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundOsRegistration.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundSink.kt +37 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreDefinitionCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +30 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +41 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +127 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ImageAdapterHost.kt +28 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +70 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStateStore.kt +125 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +64 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativeCoreInitialization.kt +21 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +60 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PalCallbacks.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PlainToolJson.kt +56 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +43 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StateStoreContract.kt +103 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StorageVersionContract.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +100 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/BlobFiles.kt +157 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/InstancePayloadPurge.kt +79 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/VersionedKeyFiles.kt +71 -0
- package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
- package/croche-react-native.podspec +1 -0
- package/dist/package.json +1 -0
- package/dist/react-native/src/NativeCrocheRuntime.d.ts +16 -0
- package/dist/react-native/src/NativeCrocheRuntime.js +2 -0
- package/dist/react-native/src/core-native.d.ts +6 -0
- package/dist/react-native/src/core-native.js +316 -0
- package/dist/react-native/src/core-wire.d.ts +55 -0
- package/dist/react-native/src/core-wire.js +1 -0
- package/dist/react-native/src/native-module.d.ts +8 -0
- package/dist/react-native/src/native-module.js +53 -0
- package/dist/rn-shared-build.json +16 -0
- package/dist/runtime/src/adapters.d.ts +8 -0
- package/dist/runtime/src/adapters.js +29 -0
- package/dist/runtime/src/agent.d.ts +91 -0
- package/dist/runtime/src/agent.js +137 -0
- package/dist/runtime/src/app-api.d.ts +572 -0
- package/dist/runtime/src/app-api.js +1 -0
- package/dist/runtime/src/cancel.d.ts +9 -0
- package/dist/runtime/src/cancel.js +27 -0
- package/dist/runtime/src/core/foreground.d.ts +3 -0
- package/dist/runtime/src/core/foreground.js +40 -0
- package/dist/runtime/src/core/port.d.ts +247 -0
- package/dist/runtime/src/core/port.js +1 -0
- package/dist/runtime/src/core/wasm-owner.d.ts +32 -0
- package/dist/runtime/src/core/wasm-owner.js +237 -0
- package/dist/runtime/src/core/wasm.d.ts +1 -0
- package/dist/runtime/src/core/wasm.js +2 -0
- package/dist/runtime/src/croche.d.ts +97 -0
- package/dist/runtime/src/croche.js +172 -0
- package/dist/runtime/src/errors.d.ts +33 -0
- package/dist/runtime/src/errors.js +63 -0
- package/dist/runtime/src/events.d.ts +5 -0
- package/dist/runtime/src/events.js +31 -0
- package/dist/runtime/src/generated/app-stream.d.ts +328 -0
- package/dist/runtime/src/generated/app-stream.js +127 -0
- package/dist/runtime/src/image-input.d.ts +5 -0
- package/dist/runtime/src/image-input.js +60 -0
- package/dist/runtime/src/index.d.ts +6 -0
- package/dist/runtime/src/index.js +5 -0
- package/dist/runtime/src/index.native.d.ts +1 -0
- package/dist/runtime/src/index.native.js +2 -0
- package/dist/runtime/src/json.d.ts +13 -0
- package/dist/runtime/src/json.js +120 -0
- package/dist/runtime/src/native-adapter.d.ts +3 -0
- package/dist/runtime/src/native-adapter.js +30 -0
- package/dist/runtime/src/pal/host.d.ts +5 -0
- package/dist/runtime/src/pal/host.js +60 -0
- package/dist/runtime/src/pal/platform.d.ts +21 -0
- package/dist/runtime/src/pal/platform.js +7 -0
- package/dist/runtime/src/pal/state-store-lock.d.ts +8 -0
- package/dist/runtime/src/pal/state-store-lock.js +2 -0
- package/dist/runtime/src/pal/state-store.d.ts +66 -0
- package/dist/runtime/src/pal/state-store.js +1 -0
- package/dist/runtime/src/pal/storage-version-contract.d.ts +19 -0
- package/dist/runtime/src/pal/storage-version-contract.js +68 -0
- package/dist/runtime/src/pal/transactional-storage.d.ts +3 -0
- package/dist/runtime/src/pal/transactional-storage.js +124 -0
- package/dist/runtime/src/rn-entry.d.ts +1 -0
- package/dist/runtime/src/rn-entry.js +4 -0
- package/dist/runtime/src/run-tool.d.ts +33 -0
- package/dist/runtime/src/run-tool.js +7 -0
- package/dist/runtime/src/tools.d.ts +35 -0
- package/dist/runtime/src/tools.js +94 -0
- package/ios/CoreAgentTransport.swift +14 -0
- package/ios/CoreDeliveryTransport.swift +58 -0
- package/ios/CoreNativePal.swift +98 -0
- package/ios/CorePlatformTransport.swift +44 -0
- package/ios/CoreWireDispatch.swift +122 -0
- package/ios/CoreWireSupport.swift +286 -0
- package/ios/CrocheRuntimeBridge.swift +34 -994
- package/ios/ProjectPal.swift +49 -0
- package/ios/RNCrocheRuntime.mm +18 -201
- package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
- package/ios/vendor/CrocheRuntimeSDK/BlobFiles.swift +124 -0
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +60 -0
- package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
- package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
- package/ios/vendor/CrocheRuntimeSDK/EncodedImages.swift +85 -0
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +26 -157
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +672 -0
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +34 -371
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
- package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
- package/ios/vendor/CrocheRuntimeSDK/InstancePayloadPurge.swift +88 -0
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +30 -14
- package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +1 -155
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +33 -59
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +289 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +302 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStateStore.swift +253 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +281 -0
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +4 -269
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +24 -461
- package/ios/vendor/CrocheRuntimeSDK/RuntimeHTTPAdapter.swift +42 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Adapters.swift +110 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +248 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Allowance.swift +20 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +170 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +313 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Decision.swift +146 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +37 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1HandleOwner.swift +58 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +346 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +89 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +165 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +100 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +278 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Verification.swift +27 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StateStoreContract.swift +189 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StorageVersionContract.swift +68 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +23 -269
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +163 -116
- package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +4712 -2469
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +899 -608
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +899 -608
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
- package/package.json +18 -8
- package/scripts/README.md +11 -0
- package/scripts/build-shared.mjs +46 -0
- package/scripts/build.mjs +11 -0
- package/scripts/check-swift-vendor-modules.sh +15 -0
- package/scripts/vendor-native.sh +8 -6
- package/src/NativeCrocheRuntime.ts +12 -159
- package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +0 -25
- package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +0 -17
- package/android/src/main/java/dev/croche/reactnative/ProjectTimeZone.kt +0 -14
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/CrocheProjectRecordProvider.kt +0 -32
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +0 -146
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +0 -110
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +0 -178
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +0 -173
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +0 -25
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +0 -87
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +0 -181
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +0 -227
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +0 -59
- package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +0 -453
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +0 -38
- package/src/index.ts +0 -664
- package/src/project-types.ts +0 -35
- package/src/project.ts +0 -434
- package/src/protocol.ts +0 -28
- package/src/types.ts +0 -9
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import com.google.gson.*
|
|
4
|
+
import dev.croche.ffi.*
|
|
5
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
6
|
+
|
|
7
|
+
internal class NativePal(private val storage: CoreStoragePal, private val host: HostPal, private val emit: (String) -> Unit) {
|
|
8
|
+
private val http = ConcurrentHashMap<String, CancelToken>()
|
|
9
|
+
private val httpLock = Any()
|
|
10
|
+
private val cancelledBeforeStart = mutableSetOf<String>()
|
|
11
|
+
private fun ByteArray.numbers() = map { it.toInt() and 255 }
|
|
12
|
+
fun call(method: String, a: JsonArray): Any? = when (method) {
|
|
13
|
+
"listState" -> {
|
|
14
|
+
require(a.size() == 2)
|
|
15
|
+
val page = storage.listState(a.text(0), stateListOptions(a[1]))
|
|
16
|
+
mapOf("entries" to page.entries.map { mapOf("key" to it.key, "value" to it.value) }, "nextCursor" to page.nextCursor)
|
|
17
|
+
}
|
|
18
|
+
"commit" -> {
|
|
19
|
+
val guard = a[1].asJsonObject
|
|
20
|
+
val condition = CoreStateCondition(stateRequiredString(guard.get("key")), p1Nullable(guard.get("version")))
|
|
21
|
+
when (val result = storage.commitState(stateOps(a[0].asJsonArray), condition)) {
|
|
22
|
+
is CoreStateCommit.Committed -> mapOf("type" to "committed", "version" to result.version)
|
|
23
|
+
CoreStateCommit.Conflict -> mapOf("type" to "conflict")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
"readVersioned" -> storage.readVersioned(p1Nullable(a.getOrNull(0)) ?: throw CoreStorageFailure.Failure("Missing storage key")).let { mapOf("value" to it.value, "version" to it.version) }
|
|
27
|
+
"writeIf" -> {
|
|
28
|
+
require(a.size() == 3)
|
|
29
|
+
when (val result = storage.writeIf(p1Nullable(a[0]) ?: throw CoreStorageFailure.Failure("Missing storage key"), p1Nullable(a[1]), p1Nullable(a[2]))) {
|
|
30
|
+
is CoreWriteOutcome.Written -> mapOf("type" to "written", "version" to result.version)
|
|
31
|
+
is CoreWriteOutcome.Conflict -> mapOf("type" to "conflict", "version" to result.version)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
"read" -> storage.read(a.text(0)); "write" -> storage.write(a.text(0), a.text(1)).let { null }
|
|
35
|
+
"remove" -> storage.remove(a.text(0)).let { null }; "list" -> storage.list(a.text(0))
|
|
36
|
+
"lock" -> if (storage.lock(a.text(0)) == PalLockOutcome.ACQUIRED) "acquired" else "held"
|
|
37
|
+
"unlock" -> storage.unlock(a.text(0)).let { null }
|
|
38
|
+
"readSecret" -> storage.readSecret(a.text(0)); "writeSecret" -> storage.writeSecret(a.text(0), a.text(1)).let { null }
|
|
39
|
+
"removeSecret" -> storage.removeSecret(a.text(0)).let { null }
|
|
40
|
+
"purgeInstance" -> storage.purgeInstance(a.text(0), a.getOrNull(1)?.let(::p1Nullable)).let { null }
|
|
41
|
+
"platformFacts" -> host.platformFacts().let { f -> mapOf("targetKind" to when (f.targetKind) { PalTargetKind.IOS_DEVICE -> "ios-device"; PalTargetKind.IOS_SIMULATOR -> "ios-simulator"; PalTargetKind.ANDROID -> "android"; PalTargetKind.OTHER -> "other" }, "debuggable" to f.debuggable, "locale" to f.locale, "attestationPlatform" to f.attestationPlatform).filterValues { it != null } }
|
|
42
|
+
"readAsset" -> host.readAsset(a.text(0))?.numbers()
|
|
43
|
+
"resolve" -> host.resolve(a.text(0), CancelToken())
|
|
44
|
+
"readImage" -> host.readImage(PalImageReadRequest(PalImageReadSource.Local(a.text(0)), a[1].asLong.toULong()), CancelToken()).numbers()
|
|
45
|
+
"cancelHttp" -> {
|
|
46
|
+
val id = a.text(0)
|
|
47
|
+
val token = synchronized(httpLock) { http[id].also { if (it == null) cancelledBeforeStart.add(id) } }
|
|
48
|
+
token?.cancel(); null
|
|
49
|
+
}
|
|
50
|
+
"http" -> {
|
|
51
|
+
val id = a.text(0); val p = a[1].asJsonObject; val token = CancelToken()
|
|
52
|
+
val cancelled = synchronized(httpLock) { http[id] = token; cancelledBeforeStart.remove(id) }
|
|
53
|
+
if (cancelled) token.cancel()
|
|
54
|
+
try {
|
|
55
|
+
val request = PalHttpRequest(p.get("connectTo")?.takeUnless { it.isJsonNull }?.asString, p.get("url").asString, p.get("method").asString,
|
|
56
|
+
p.getAsJsonArray("headers").map { PalHeader(it.asJsonArray.text(0), it.asJsonArray.text(1)) },
|
|
57
|
+
p.get("body")?.takeUnless { it.isJsonNull }?.asString, p.get("timeoutMs").asLong.toULong(), p.get("responseMode").asString, p.get("maxResponseBytes").asLong.toULong())
|
|
58
|
+
host.http(request, object : HttpSink(NoHandle) {
|
|
59
|
+
override fun head(status: UShort, headers: List<PalHeader>) { emit(json(mapOf("id" to id, "type" to "head", "status" to status.toInt(), "headers" to headers.map { listOf(it.name, it.value) }))) }
|
|
60
|
+
override fun chunk(bytes: ByteArray): Boolean { emit(json(mapOf("id" to id, "type" to "chunk", "bytes" to bytes.numbers()))); return true }
|
|
61
|
+
}, token)
|
|
62
|
+
null
|
|
63
|
+
} finally { synchronized(httpLock) { http.remove(id) } }
|
|
64
|
+
}
|
|
65
|
+
else -> error("Unknown native PAL method")
|
|
66
|
+
}
|
|
67
|
+
private fun JsonArray.getOrNull(i: Int): JsonElement? = if (size() > i) get(i) else null
|
|
68
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import dev.croche.ffi.HostPal
|
|
4
|
+
import dev.croche.ffi.HostStreamPlatform
|
|
5
|
+
|
|
6
|
+
/** One OS registrar: S7 owns WorkManager registration and schedule timing. */
|
|
7
|
+
internal fun rnHostPal(host: HostPal): HostPal = object : HostPal by host {
|
|
8
|
+
override fun streamPlatform() = HostStreamPlatform.REACT_NATIVE
|
|
9
|
+
}
|
|
@@ -1,49 +1,72 @@
|
|
|
1
1
|
package dev.croche.reactnative
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import dev.croche.CrocheException
|
|
5
|
-
import dev.croche.ffi.CoreRuntimeInterface
|
|
6
|
-
import dev.croche.ffi.EventListener
|
|
3
|
+
import dev.croche.ffi.*
|
|
7
4
|
import org.junit.Assert.*
|
|
8
5
|
import org.junit.Test
|
|
9
|
-
import java.lang.reflect.Proxy
|
|
10
6
|
|
|
11
7
|
class AgentMemoryTest {
|
|
12
|
-
@Test fun
|
|
13
|
-
val
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
val
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} as CoreRuntimeInterface
|
|
27
|
-
val args = JsonParser.parseString("{\"id\":\"m1\",\"on\":true}").asJsonObject
|
|
28
|
-
val changes = mutableListOf<String>()
|
|
29
|
-
assertEquals("[{\"id\":\"m1\"}]", agentMemory(core, "list", args, changes::add))
|
|
30
|
-
assertEquals("{\"enabled\":true,\"items\":[]}", agentMemory(core, "export", args, changes::add))
|
|
31
|
-
for (op in listOf("delete", "clear", "enabled")) assertEquals("{\"deferred\":true}", agentMemory(core, op, args, changes::add))
|
|
32
|
-
assertEquals("null", agentMemory(core, "observe", args, changes::add))
|
|
33
|
-
// Don't enter UniFFI's thread attach hook from a pure JVM test; assert the listener is installed.
|
|
34
|
-
assertNotNull(observer)
|
|
35
|
-
assertEquals(listOf("memoryList", "memoryExport", "memoryDelete", "memoryClear", "memorySetEnabled", "setMemoryObserver"), calls.map { it.first })
|
|
36
|
-
assertEquals(listOf("m1"), calls.first { it.first == "memoryDelete" }.second)
|
|
37
|
-
assertEquals(listOf(true), calls.first { it.first == "memorySetEnabled" }.second)
|
|
38
|
-
args.addProperty("on", false)
|
|
39
|
-
agentMemory(core, "observe", args, changes::add)
|
|
40
|
-
assertNull(observer)
|
|
41
|
-
try { agentMemory(core, "set", args, changes::add); fail("set must be refused") }
|
|
42
|
-
catch (error: CrocheException) { assertEquals("invalid_memory", error.code); assertTrue(error.message!!.contains("memory.set")) }
|
|
43
|
-
closed = true
|
|
44
|
-
for (op in listOf("list", "delete", "clear", "enabled", "export", "observe")) {
|
|
45
|
-
try { agentMemory(core, op, args, changes::add); fail("closed $op must be refused") }
|
|
46
|
-
catch (error: CrocheException) { assertEquals("closed", error.code) }
|
|
47
|
-
}
|
|
8
|
+
@Test fun decisionDispatchForwardsJsonOptionsAndTokenAndPreservesCoreError() {
|
|
9
|
+
val agent = MemoryAgentFake()
|
|
10
|
+
val bridge = CoreDispatch({ error("No new host") }, { error("No platform storage") }) { error("No event") }
|
|
11
|
+
val id = bridge.handles.hold(agent)
|
|
12
|
+
val cancel = CancelToken(NoHandle)
|
|
13
|
+
val token = bridge.handles.hold(cancel)
|
|
14
|
+
val input = """{"state":{"raw":[null,false,0]}}"""
|
|
15
|
+
val arguments = com.google.gson.JsonArray().apply { add(input); add(com.google.gson.JsonNull.INSTANCE); add(token) }
|
|
16
|
+
assertEquals("""{"id":"decision"}""", bridge.call(id, "decide", arguments))
|
|
17
|
+
assertEquals(listOf("decide" to listOf(input, null, cancel)), agent.calls)
|
|
18
|
+
assertSame(cancel, agent.calls.single().second[2])
|
|
19
|
+
agent.closed = true
|
|
20
|
+
try { bridge.call(id, "decide", arguments); fail("Core refusal") }
|
|
21
|
+
catch (error: CoreApiException.Failure) { assertEquals("closed", error.code); assertEquals("Agent is closed", error.detail) }
|
|
48
22
|
}
|
|
23
|
+
@Test fun memoryIsTheS1AgentHandleAndErrorsPassThrough() {
|
|
24
|
+
val agent = MemoryAgentFake()
|
|
25
|
+
val bridge = CoreDispatch({ error("Memory must not open a new host") }, { error("Memory must not request platform storage") }) { error("Memory must not emit a legacy observer event") }
|
|
26
|
+
val id = bridge.handles.hold(agent)
|
|
27
|
+
assertEquals("{\"items\":[{\"id\":\"m1\"}]}", bridge.call(id, "memoryList", args("[]")))
|
|
28
|
+
assertNull(bridge.call(id, "memoryDelete", args("[\"m1\"]")))
|
|
29
|
+
assertNull(bridge.call(id, "memoryClear", args("[]")))
|
|
30
|
+
assertNull(bridge.call(id, "memoryEnabled", args("[true]")))
|
|
31
|
+
assertEquals(listOf("memoryList","memoryDelete","memoryClear","memoryEnabled"), agent.calls.map { it.first })
|
|
32
|
+
assertEquals(listOf("m1"), agent.calls[1].second)
|
|
33
|
+
assertEquals(listOf(true), agent.calls[3].second)
|
|
34
|
+
agent.closed = true
|
|
35
|
+
try { bridge.call(id, "memoryList", args("[]")); fail("closed agent must refuse") }
|
|
36
|
+
catch (error: CoreApiException.Failure) { assertEquals("closed", error.code); assertEquals("Agent is closed", error.detail) }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// A concrete implementation preserves checked Core exceptions without JVM Proxy wrapping.
|
|
41
|
+
private class MemoryAgentFake : CoreAgentInterface {
|
|
42
|
+
val calls = mutableListOf<Pair<String, List<Any?>>>()
|
|
43
|
+
var closed = false
|
|
44
|
+
private fun record(name: String, args: List<Any?> = emptyList()) {
|
|
45
|
+
if (closed) throw CoreApiException.Failure("closed", "Agent is closed", "closed", null, null)
|
|
46
|
+
calls += name to args
|
|
47
|
+
}
|
|
48
|
+
override fun `cancel`(`inputId`: kotlin.String?) = error("Unexpected cancel")
|
|
49
|
+
override fun `clearHistory`(`optionsJson`: kotlin.String?) = error("Unexpected clearHistory")
|
|
50
|
+
override fun `decide`(`inputJson`: kotlin.String, `optionsJson`: kotlin.String?, `cancel`: CancelToken?): kotlin.String {
|
|
51
|
+
record("decide", listOf(inputJson, optionsJson, cancel)); return """{"id":"decision"}"""
|
|
52
|
+
}
|
|
53
|
+
override fun `id`(): kotlin.String = error("Unexpected id")
|
|
54
|
+
override fun `instance`(): kotlin.String? = error("Unexpected instance")
|
|
55
|
+
override fun attachment(id: String): String = error("Unexpected image")
|
|
56
|
+
override fun listAttachments(optionsJson: String?): String = error("Unexpected listAttachments")
|
|
57
|
+
override fun copyAttachment(sourceJson: String): String = error("Unexpected copyAttachment")
|
|
58
|
+
override fun deleteAttachment(id: String): Unit = error("Unexpected deleteAttachment")
|
|
59
|
+
override fun releaseAttachment(id: String): Unit = error("Unexpected releaseAttachment")
|
|
60
|
+
override fun `memoryClear`() { record("memoryClear") }
|
|
61
|
+
override fun `memoryDelete`(`id`: kotlin.String) { record("memoryDelete", listOf(id)) }
|
|
62
|
+
override fun `memoryEnabled`(`on`: kotlin.Boolean) { record("memoryEnabled", listOf(on)) }
|
|
63
|
+
override fun `memoryList`(`optionsJson`: kotlin.String?): kotlin.String { record("memoryList"); return "{\"items\":[{\"id\":\"m1\"}]}" }
|
|
64
|
+
override fun `request`(`inputJson`: kotlin.String, `images`: List<CoreAttachmentInput>, `optionsJson`: kotlin.String?, `cancel`: CancelToken?): kotlin.String = error("Unexpected request")
|
|
65
|
+
override fun `resetTools`() = error("Unexpected resetTools")
|
|
66
|
+
override fun `resetWiki`() = error("Unexpected resetWiki")
|
|
67
|
+
override fun `send`(`inputJson`: kotlin.String, `images`: List<CoreAttachmentInput>, `optionsJson`: kotlin.String?, `cancel`: CancelToken?): kotlin.String = error("Unexpected send")
|
|
68
|
+
override fun `setTools`(`scopeJson`: kotlin.String) = error("Unexpected setTools")
|
|
69
|
+
override fun `setWiki`(`scopeJson`: kotlin.String) = error("Unexpected setWiki")
|
|
70
|
+
override fun `shutdown`() = error("Unexpected shutdown")
|
|
71
|
+
override fun `subscribe`(`selectionJson`: kotlin.String, `eventSink`: CoreEventSink): CoreSubscription = error("Unexpected subscribe")
|
|
49
72
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import dev.croche.ffi.*
|
|
4
|
+
import org.junit.Assert.*
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class BackgroundDelegationTest {
|
|
8
|
+
@Test fun backgroundRegistrationAndTimingHaveOnlyTheS7Owner() {
|
|
9
|
+
val wake = CoreBackgroundWake(NoHandle)
|
|
10
|
+
val calls = mutableListOf<String>()
|
|
11
|
+
val refusal = CorePalException.Failure("capability_unsupported", "not installed")
|
|
12
|
+
val base = BackgroundHostFake(wake, calls, refusal)
|
|
13
|
+
val rn = rnHostPal(base)
|
|
14
|
+
try { rn.registerBackground("from-core", wake); fail("silent Ok") }
|
|
15
|
+
catch (actual: CorePalException.Failure) { assertSame(refusal, actual) }
|
|
16
|
+
rn.schedule("opaque schedule")
|
|
17
|
+
assertEquals(listOf("registerBackground", "schedule"), calls)
|
|
18
|
+
assertEquals(HostStreamPlatform.REACT_NATIVE, rn.streamPlatform())
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Throw the actual checked PAL error from a concrete method, never a Proxy handler.
|
|
23
|
+
private class BackgroundHostFake(
|
|
24
|
+
private val expectedWake: CoreBackgroundWake,
|
|
25
|
+
private val calls: MutableList<String>,
|
|
26
|
+
private val refusal: CorePalException.Failure,
|
|
27
|
+
) : HostPal {
|
|
28
|
+
override fun blobOperation(operation: String, key: String, cursor: String?, bytes: ByteArray?): PalBlobReply = error("Unexpected blob operation")
|
|
29
|
+
override fun `streamPlatform`(): HostStreamPlatform = error("Unexpected streamPlatform")
|
|
30
|
+
override fun imageSupport(): String? = error("Unexpected imageSupport")
|
|
31
|
+
override fun imageOperation(operation: String, bytes: ByteArray, optionsJson: String, cancel: CancelToken): PalImageReply = error("Unexpected imageOperation")
|
|
32
|
+
override fun `readImage`(`request`: PalImageReadRequest, `cancel`: CancelToken): kotlin.ByteArray = error("Unexpected readImage")
|
|
33
|
+
override fun `releaseImage`(`capture`: kotlin.String) = error("Unexpected releaseImage")
|
|
34
|
+
override fun `http`(`request`: PalHttpRequest, `sink`: HttpSink, `cancel`: CancelToken) = error("Unexpected http")
|
|
35
|
+
override fun `resolve`(`host`: kotlin.String, `cancel`: CancelToken): List<kotlin.String> = error("Unexpected resolve")
|
|
36
|
+
override fun `platformFacts`(): PalPlatformFacts = error("Unexpected platformFacts")
|
|
37
|
+
override fun `readAsset`(`path`: kotlin.String): kotlin.ByteArray? = error("Unexpected readAsset")
|
|
38
|
+
override fun `list`(`prefix`: kotlin.String): List<kotlin.String> = error("Unexpected list")
|
|
39
|
+
override fun `read`(`key`: kotlin.String): kotlin.String? = error("Unexpected read")
|
|
40
|
+
override fun `write`(`key`: kotlin.String, `value`: kotlin.String) = error("Unexpected write")
|
|
41
|
+
override fun `readSecret`(`key`: kotlin.String): kotlin.String? = error("Unexpected readSecret")
|
|
42
|
+
override fun `writeSecret`(`key`: kotlin.String, `value`: kotlin.String) = error("Unexpected writeSecret")
|
|
43
|
+
override fun `remove`(`key`: kotlin.String) = error("Unexpected remove")
|
|
44
|
+
override fun purgeInstance(prefix: String) = error("Unexpected purgeInstance")
|
|
45
|
+
override fun `removeSecret`(`key`: kotlin.String) = error("Unexpected removeSecret")
|
|
46
|
+
override fun `lock`(`key`: kotlin.String): PalLockOutcome = error("Unexpected lock")
|
|
47
|
+
override fun `unlock`(`key`: kotlin.String) = error("Unexpected unlock")
|
|
48
|
+
override fun `storeIdentity`(): kotlin.String = error("Unexpected storeIdentity")
|
|
49
|
+
override fun `tool`(`invocation`: kotlin.String, `cancel`: CancelToken): ToolOutput = error("Unexpected tool")
|
|
50
|
+
override fun `attest`(`request`: kotlin.String, `timeoutMs`: kotlin.ULong): kotlin.String = error("Unexpected attest")
|
|
51
|
+
override fun `nowMs`(): kotlin.Double = error("Unexpected nowMs")
|
|
52
|
+
override fun `utcOffsetMinutes`(`atMs`: kotlin.Double): kotlin.Long = error("Unexpected utcOffsetMinutes")
|
|
53
|
+
override fun `random`(): kotlin.String = error("Unexpected random")
|
|
54
|
+
override fun `wake`(`atMs`: kotlin.Double?) = error("Unexpected wake")
|
|
55
|
+
override fun `schedule`(`entries`: kotlin.String) {
|
|
56
|
+
calls += "schedule"
|
|
57
|
+
assertEquals("opaque schedule", entries)
|
|
58
|
+
}
|
|
59
|
+
override fun `registerBackground`(`identifier`: kotlin.String, `wake`: CoreBackgroundWake) {
|
|
60
|
+
calls += "registerBackground"
|
|
61
|
+
assertEquals("from-core", identifier); assertSame(expectedWake, wake)
|
|
62
|
+
throw refusal
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import dev.croche.s7.pal.BlobFiles
|
|
4
|
+
import dev.croche.ffi.FfiException
|
|
5
|
+
import java.io.File
|
|
6
|
+
import java.nio.file.Files
|
|
7
|
+
import org.junit.Assert.assertArrayEquals
|
|
8
|
+
import org.junit.Assert.assertEquals
|
|
9
|
+
import org.junit.Assert.assertFalse
|
|
10
|
+
import org.junit.Assert.assertNotNull
|
|
11
|
+
import org.junit.Assert.assertNull
|
|
12
|
+
import org.junit.Assert.assertThrows
|
|
13
|
+
import org.junit.Assert.assertTrue
|
|
14
|
+
import org.junit.Rule
|
|
15
|
+
import org.junit.Test
|
|
16
|
+
import org.junit.rules.TemporaryFolder
|
|
17
|
+
|
|
18
|
+
class BlobFilesTest {
|
|
19
|
+
@get:Rule val temp = TemporaryFolder()
|
|
20
|
+
|
|
21
|
+
@Test fun blobFailureRetainsTheLocalCause() {
|
|
22
|
+
val store = BlobFiles(temp.newFolder()) {}
|
|
23
|
+
val failure = assertThrows(FfiException.Failure::class.java) {
|
|
24
|
+
store.operation("get", "../invalid", null, null)
|
|
25
|
+
}
|
|
26
|
+
assertEquals("storage_error", failure.code)
|
|
27
|
+
assertEquals("Blob operation failed", failure.detail)
|
|
28
|
+
assertTrue(failure.cause is IllegalArgumentException)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test fun rawObjectsReopenAndPageWithinTheirPrefix() {
|
|
32
|
+
val directory = temp.newFolder()
|
|
33
|
+
val store = BlobFiles(directory) {}
|
|
34
|
+
val prefix = "project/user/agent/~default/files/"
|
|
35
|
+
val other = "project/user/agent/named/files/other"
|
|
36
|
+
val data = byteArrayOf(0, -1, -128, 11)
|
|
37
|
+
val keys = (0..1000).map { prefix + it.toString().padStart(4, '0') }
|
|
38
|
+
val first = keys.first()
|
|
39
|
+
assertNull(store.get(first))
|
|
40
|
+
store.put(other, data)
|
|
41
|
+
store.put(first, data)
|
|
42
|
+
assertArrayEquals(data, File(directory, "blobs/$first/object").readBytes())
|
|
43
|
+
for (key in keys.drop(1).asReversed()) store.put(key, byteArrayOf(1))
|
|
44
|
+
|
|
45
|
+
val reopened = BlobFiles(directory) {}
|
|
46
|
+
assertArrayEquals(data, reopened.get(first))
|
|
47
|
+
assertEquals(listOf(BlobFiles.Entry(first, data.size.toLong())), reopened.list(first, null).entries)
|
|
48
|
+
val page = reopened.list(prefix, null)
|
|
49
|
+
assertEquals(keys.take(1000), page.entries.map { it.key })
|
|
50
|
+
assertNotNull(page.nextCursor)
|
|
51
|
+
val tail = reopened.list(prefix, page.nextCursor)
|
|
52
|
+
assertEquals(listOf(BlobFiles.Entry(keys.last(), 1)), tail.entries)
|
|
53
|
+
assertNull(tail.nextCursor)
|
|
54
|
+
|
|
55
|
+
reopened.delete(first)
|
|
56
|
+
reopened.delete(first)
|
|
57
|
+
assertNull(reopened.get(first))
|
|
58
|
+
assertTrue(reopened.list(first, null).entries.isEmpty())
|
|
59
|
+
keys.drop(1).forEach(reopened::delete)
|
|
60
|
+
|
|
61
|
+
val staged = File(directory, "blobs/${prefix}unpublished/.tmp-crash")
|
|
62
|
+
Files.createDirectories(staged.parentFile.toPath())
|
|
63
|
+
staged.writeBytes(data)
|
|
64
|
+
reopened.purgeStaging(prefix)
|
|
65
|
+
assertTrue(!staged.exists())
|
|
66
|
+
assertTrue(File(directory, "blobs/$prefix").isDirectory)
|
|
67
|
+
assertTrue(reopened.list(prefix, null).entries.isEmpty())
|
|
68
|
+
assertArrayEquals(data, reopened.get(other))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test fun stagingPurgeRemovesOnlyRegularCrashFiles() {
|
|
72
|
+
val directory = temp.newFolder()
|
|
73
|
+
val store = BlobFiles(directory) {}
|
|
74
|
+
val key = "owner/files/record/live"
|
|
75
|
+
val owner = File(directory, "blobs/owner/files")
|
|
76
|
+
val staged = File(owner, "record/live/.tmp-crash")
|
|
77
|
+
val unrelated = File(owner, "notes")
|
|
78
|
+
val foreign = File(owner, "!foreign/.tmp-foreign")
|
|
79
|
+
val outside = temp.newFolder()
|
|
80
|
+
val target = File(outside, ".tmp-target")
|
|
81
|
+
val sibling = File(directory, "blobs/sibling/.tmp-sibling")
|
|
82
|
+
val bytes = byteArrayOf(0, -1, -128)
|
|
83
|
+
store.put(key, bytes)
|
|
84
|
+
Files.createDirectory(foreign.parentFile.toPath())
|
|
85
|
+
Files.createDirectory(sibling.parentFile.toPath())
|
|
86
|
+
for (path in listOf(staged, unrelated, foreign, target, sibling)) path.writeBytes(bytes)
|
|
87
|
+
val link = File(owner, ".tmp-link").toPath()
|
|
88
|
+
val linkedDir = File(owner, "linked").toPath()
|
|
89
|
+
val linksSupported = File.separatorChar != '\\'
|
|
90
|
+
if (linksSupported) {
|
|
91
|
+
Files.createSymbolicLink(link, target.toPath())
|
|
92
|
+
Files.createSymbolicLink(linkedDir, outside.toPath())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
store.purgeStaging("owner/files/")
|
|
96
|
+
assertArrayEquals("unrelated file survives", bytes, unrelated.readBytes())
|
|
97
|
+
assertArrayEquals(bytes, store.get(key))
|
|
98
|
+
assertFalse("selected temp disappears", staged.exists())
|
|
99
|
+
assertArrayEquals(bytes, foreign.readBytes())
|
|
100
|
+
assertArrayEquals(bytes, sibling.readBytes())
|
|
101
|
+
assertArrayEquals(bytes, target.readBytes())
|
|
102
|
+
if (linksSupported) {
|
|
103
|
+
assertEquals(target.toPath(), Files.readSymbolicLink(link))
|
|
104
|
+
assertEquals(outside.toPath(), Files.readSymbolicLink(linkedDir))
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import com.google.gson.JsonNull
|
|
4
|
+
import com.google.gson.JsonParser
|
|
5
|
+
import dev.croche.ffi.HostPal
|
|
6
|
+
import dev.croche.s7.pal.BlobFiles
|
|
7
|
+
import java.nio.file.Files
|
|
8
|
+
import java.lang.reflect.Proxy
|
|
9
|
+
import org.junit.Assert.assertArrayEquals
|
|
10
|
+
import org.junit.Assert.assertEquals
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
|
|
13
|
+
class ImageAdapterWireTest {
|
|
14
|
+
@Test fun supportIsAnObjectAtTheFactoryBoundaryAndAllOtherEffectsStayNative() {
|
|
15
|
+
val support = JsonParser.parseString("""{"inputMediaTypes":["image/jpeg"],"outputMediaTypes":["image/png"]}""")
|
|
16
|
+
val options = "{}"
|
|
17
|
+
assertEquals(options, forwardedOpen(options, support = support))
|
|
18
|
+
assertEquals(options, forwardedOpen(options, support = JsonNull.INSTANCE))
|
|
19
|
+
}
|
|
20
|
+
@Test fun defaultBlobCallbacksReachTheNativeFileStore() {
|
|
21
|
+
val directory = Files.createTempDirectory("rn-default-blobs").toFile()
|
|
22
|
+
try {
|
|
23
|
+
val store = BlobFiles(directory) {}
|
|
24
|
+
val base = Proxy.newProxyInstance(HostPal::class.java.classLoader, arrayOf(HostPal::class.java)) { _, method, args ->
|
|
25
|
+
check(method.name == "blobOperation")
|
|
26
|
+
store.operation(args[0] as String, args[1] as String, args[2] as String?, args[3] as ByteArray?)
|
|
27
|
+
} as HostPal
|
|
28
|
+
val host = CallbackHost(base, "host-blob", null, CoreCallbacks { error("Unexpected JS callback") },
|
|
29
|
+
CoreHandles(), customBlobs = false)
|
|
30
|
+
val bytes = byteArrayOf(0, -1, -128)
|
|
31
|
+
host.blobOperation("put", "test/blob", null, bytes)
|
|
32
|
+
assertArrayEquals(bytes, directory.resolve("blobs/test/blob/object").readBytes())
|
|
33
|
+
} finally {
|
|
34
|
+
directory.deleteRecursively()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test fun selectedBlobCallbacksPassBytesAndOpaqueCursor() {
|
|
39
|
+
val base = Proxy.newProxyInstance(HostPal::class.java.classLoader, arrayOf(HostPal::class.java)) { _, method, _ ->
|
|
40
|
+
error("Unexpected native host operation: ${method.name}")
|
|
41
|
+
} as HostPal
|
|
42
|
+
lateinit var callbacks: CoreCallbacks
|
|
43
|
+
callbacks = CoreCallbacks { raw ->
|
|
44
|
+
val packet = JsonParser.parseString(raw).asJsonObject
|
|
45
|
+
assertEquals("blob", packet["type"].asString)
|
|
46
|
+
assertEquals("host-blob", packet["host"].asString)
|
|
47
|
+
val response = when (packet["operation"].asString) {
|
|
48
|
+
"put" -> {
|
|
49
|
+
assertEquals(listOf(0, 255, 128), packet.getAsJsonArray("bytes").map { it.asInt })
|
|
50
|
+
"""{"value":{}}"""
|
|
51
|
+
}
|
|
52
|
+
"get" -> """{"value":{"bytes":[0,255,128]}}"""
|
|
53
|
+
"list" -> {
|
|
54
|
+
assertEquals("opaque", packet["cursor"].asString)
|
|
55
|
+
"""{"value":{"entries":[{"key":"p/a","size":3}],"nextCursor":"continue"}}"""
|
|
56
|
+
}
|
|
57
|
+
else -> error("Unexpected blob callback")
|
|
58
|
+
}
|
|
59
|
+
callbacks.reply(packet["call"].asString, response)
|
|
60
|
+
}
|
|
61
|
+
val host = CallbackHost(base, "host-blob", null, callbacks, CoreHandles(), customBlobs = true)
|
|
62
|
+
val bytes = byteArrayOf(0, -1, -128)
|
|
63
|
+
host.blobOperation("put", "p/a", null, bytes)
|
|
64
|
+
assertArrayEquals(bytes, host.blobOperation("get", "p/a", null, null).bytes)
|
|
65
|
+
val page = host.blobOperation("list", "p/", "opaque", null)
|
|
66
|
+
assertEquals("p/a", page.entries.single().key)
|
|
67
|
+
assertEquals(3uL, page.entries.single().size)
|
|
68
|
+
assertEquals("continue", page.nextCursor)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import com.google.gson.JsonArray
|
|
4
|
+
import com.google.gson.JsonElement
|
|
5
|
+
import com.google.gson.JsonParser
|
|
6
|
+
import dev.croche.ffi.HostPal
|
|
7
|
+
import dev.croche.ffi.HostStreamPlatform
|
|
8
|
+
import java.lang.reflect.Proxy
|
|
9
|
+
import kotlinx.coroutines.runBlocking
|
|
10
|
+
import org.junit.Assert.*
|
|
11
|
+
|
|
12
|
+
/** Capture the actual RN open boundary before the native factory; no native library or network. */
|
|
13
|
+
internal fun forwardedOpen(options: String, recovery: String? = null, support: JsonElement? = null): String {
|
|
14
|
+
class Captured : RuntimeException()
|
|
15
|
+
var observed: String? = null
|
|
16
|
+
var factReads = 0
|
|
17
|
+
val host = Proxy.newProxyInstance(HostPal::class.java.classLoader, arrayOf(HostPal::class.java)) { _, method, _ ->
|
|
18
|
+
when (method.name) {
|
|
19
|
+
"streamPlatform" -> { factReads++; HostStreamPlatform.REACT_NATIVE }
|
|
20
|
+
else -> error("Open forwarding must not run a host effect: ${method.name}")
|
|
21
|
+
}
|
|
22
|
+
} as HostPal
|
|
23
|
+
val bridge = CoreDispatch({ host }, { error("Open must use its storage argument") },
|
|
24
|
+
openFactory = { json, registrations, storage, actualHost, actualRecovery ->
|
|
25
|
+
observed = json
|
|
26
|
+
assertEquals(recovery, actualRecovery)
|
|
27
|
+
assertTrue(registrations.isEmpty())
|
|
28
|
+
assertTrue(storage is CallbackStorage)
|
|
29
|
+
assertEquals(0, factReads)
|
|
30
|
+
assertTrue(actualHost is CallbackHost)
|
|
31
|
+
assertEquals(HostStreamPlatform.REACT_NATIVE, actualHost.streamPlatform())
|
|
32
|
+
assertEquals(1, factReads)
|
|
33
|
+
assertEquals(support?.takeUnless { it.isJsonNull },
|
|
34
|
+
actualHost.imageSupport()?.let(JsonParser::parseString))
|
|
35
|
+
throw Captured()
|
|
36
|
+
}, emit = { error("Open forwarding must not emit an event") })
|
|
37
|
+
val arguments = JsonArray().apply {
|
|
38
|
+
add(options); add(JsonArray()); add("storage"); add("host"); add(recovery)
|
|
39
|
+
if (support != null) add(support)
|
|
40
|
+
}
|
|
41
|
+
try { runBlocking { bridge.open(arguments) }; fail("Capture must interrupt the native factory") }
|
|
42
|
+
catch (_: Captured) { }
|
|
43
|
+
return requireNotNull(observed) { "The real RN open path did not call the factory" }
|
|
44
|
+
}
|
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
package dev.croche.reactnative
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import dev.croche.RuntimeCancellation
|
|
7
|
-
import org.junit.Assert.assertEquals
|
|
8
|
-
import org.junit.Assert.assertFalse
|
|
9
|
-
import org.junit.Assert.assertNull
|
|
3
|
+
import dev.croche.ffi.*
|
|
4
|
+
import java.lang.reflect.Proxy
|
|
5
|
+
import org.junit.Assert.*
|
|
10
6
|
import org.junit.Test
|
|
11
7
|
|
|
12
|
-
/**
|
|
13
|
-
* exactly when the bridge has an attestor. Core's side (it then attests at register) is the
|
|
14
|
-
* driver gate `project_a_host_naming_its_attestation_platform_attests_each_agent_at_register`. */
|
|
8
|
+
/** Attestation availability is a PAL fact; RN never derives it from app options. */
|
|
15
9
|
class ProjectAttestationTest {
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
private fun host(facts: PalPlatformFacts): HostPal {
|
|
11
|
+
val base = Proxy.newProxyInstance(HostPal::class.java.classLoader, arrayOf(HostPal::class.java)) { _, method, _ ->
|
|
12
|
+
check(method.name == "platformFacts") { "Unexpected effect ${method.name}" }
|
|
13
|
+
facts
|
|
14
|
+
} as HostPal
|
|
15
|
+
return rnHostPal(base)
|
|
19
16
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@Test fun aCloudProjectNumberGivesAnAttestorAndCoreHearsItsPlatform() {
|
|
25
|
-
val host = host(""","android":{"cloudProjectNumber":123}""")
|
|
26
|
-
assertEquals("android-play-integrity", host.get("attestationPlatform").asString)
|
|
27
|
-
assertEquals("pk_fixture", host.get("projectKey").asString)
|
|
17
|
+
@Test fun availableAttestorFactReachesCoreUnchanged() {
|
|
18
|
+
val facts = PalPlatformFacts(PalTargetKind.ANDROID, false, "ko-KR", "android-play-integrity")
|
|
19
|
+
assertSame("platform facts unchanged", facts, host(facts).platformFacts())
|
|
28
20
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
assertNull(projectAttestor(options(extra)) { Fake() })
|
|
33
|
-
assertFalse(extra, host(extra).has("attestationPlatform"))
|
|
34
|
-
}
|
|
21
|
+
@Test fun absentAttestorFactStaysAbsentWithoutSdkDefaults() {
|
|
22
|
+
val facts = PalPlatformFacts(PalTargetKind.OTHER, null, null, null)
|
|
23
|
+
assertSame("platform facts unchanged", facts, host(facts).platformFacts())
|
|
35
24
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
projectHost(options, projectAttestor(options) { Fake() })
|
|
40
|
-
assertFalse(options.getAsJsonObject("host").has("attestationPlatform"))
|
|
25
|
+
@Test fun factsAreNotInjectedIntoTheOptions() {
|
|
26
|
+
val options = """{"projectKey":"pk_fixture","future":{"value":"unchanged"}}"""
|
|
27
|
+
assertEquals("opaque options", options, forwardedOpen(options))
|
|
41
28
|
}
|
|
42
29
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import java.util.concurrent.CountDownLatch
|
|
4
|
+
import org.junit.Assert.*
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
/** The SDK retains opaque callback references, not its own per-instance handler registry. */
|
|
8
|
+
class ProjectHandlerStagesTest {
|
|
9
|
+
@Test fun concurrentTransportOwnersKeepTheirOwnReferencesAndCleanup() {
|
|
10
|
+
val handles = CoreHandles()
|
|
11
|
+
val start = CountDownLatch(1)
|
|
12
|
+
val values = listOf(Any(), Any())
|
|
13
|
+
val ids = arrayOfNulls<String>(2)
|
|
14
|
+
val workers = values.mapIndexed { i, value -> Thread { start.await(); ids[i] = handles.hold(value) }.also { it.start() } }
|
|
15
|
+
start.countDown(); workers.forEach { it.join() }
|
|
16
|
+
assertNotEquals("transport handles do not alias", ids[0], ids[1])
|
|
17
|
+
assertSame("transport owner unchanged", values[0], handles.value(ids[0]!!))
|
|
18
|
+
assertSame("transport owner unchanged", values[1], handles.value(ids[1]!!))
|
|
19
|
+
handles.forget(ids[0]!!)
|
|
20
|
+
assertSame("transport owner unchanged", values[1], handles.value(ids[1]!!))
|
|
21
|
+
try { handles.value(ids[0]!!); fail("Retired handle must be absent") } catch (_: IllegalStateException) { }
|
|
22
|
+
}
|
|
23
|
+
@Test fun agentLabelsAndMaintenanceNamesAreOpaqueValues() {
|
|
24
|
+
val handles = CoreHandles()
|
|
25
|
+
val names = listOf("default", "other", "[\"도우미\",\"thread/one\"]", "[\"\$gc\",\"pass\"]")
|
|
26
|
+
val ids = names.map(handles::hold)
|
|
27
|
+
assertEquals("transport handles do not alias", names.size, ids.toSet().size)
|
|
28
|
+
ids.zip(names).forEach { (id, value) -> assertEquals("transport owner unchanged", value, handles.value(id)) }
|
|
29
|
+
handles.clear()
|
|
30
|
+
for (id in ids) try { handles.value(id); fail("Cleared handle must be absent") } catch (_: IllegalStateException) { }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
package dev.croche.reactnative
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Test
|
|
5
|
+
|
|
6
|
+
class ProjectRecoveryTest {
|
|
7
|
+
@Test fun recoveryJsonIsASeparateUnchangedNativeArgument() {
|
|
8
|
+
for (mode in listOf("{\"recover\":\"delete\"}", "{}", "{\"recover\":\"invalid\"}")) {
|
|
9
|
+
assertEquals("{\"wholeOptions\":true}", forwardedOpen("{\"wholeOptions\":true}", mode))
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
package dev.croche.reactnative
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import dev.croche.CrocheException
|
|
5
|
-
import org.junit.Assert.*
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
6
4
|
import org.junit.Test
|
|
7
5
|
|
|
6
|
+
/** Core owns defaults/validation. The RN open transport preserves each input literally. */
|
|
8
7
|
class ProjectTimeZoneTest {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
assertEquals(-600, projectZone(options("""{"timeZone":"Pacific/Honolulu"}"""))!!.getOffset(0) / 60_000)
|
|
8
|
+
@Test fun explicitZoneReachesCoreUnchanged() {
|
|
9
|
+
val options = """{"projectKey":"pk_fixture","timeZone":"Pacific/Honolulu"}"""
|
|
10
|
+
assertEquals("opaque options", options, forwardedOpen(options))
|
|
13
11
|
}
|
|
14
|
-
@Test fun
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
@Test fun absentAndNullReachCoreWithoutADeviceDefault() {
|
|
13
|
+
for (options in listOf("""{"projectKey":"pk_fixture"}""", """{"projectKey":"pk_fixture","timeZone":null}"""))
|
|
14
|
+
assertEquals("opaque options", options, forwardedOpen(options))
|
|
17
15
|
}
|
|
18
|
-
@Test fun
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
catch (error: CrocheException) { assertEquals("invalid_configuration", error.code) }
|
|
22
|
-
}
|
|
16
|
+
@Test fun invalidZoneAndNonStringReachCoresValidatorUnchanged() {
|
|
17
|
+
for (options in listOf("""{"projectKey":"pk_fixture","timeZone":"Not/AZone"}""", """{"projectKey":"pk_fixture","timeZone":42}"""))
|
|
18
|
+
assertEquals("opaque options", options, forwardedOpen(options))
|
|
23
19
|
}
|
|
24
20
|
}
|