@dvai-bridge/ios 4.0.0 → 4.0.2
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/Package.swift +104 -104
- package/ios/Sources/DVAIBridge/BackendKind.swift +23 -23
- package/ios/Sources/DVAIBridge/BoundServer.swift +46 -46
- package/ios/Sources/DVAIBridge/DVAIBridge.swift +658 -658
- package/ios/Sources/DVAIBridge/DVAIBridgeConfig.swift +86 -86
- package/ios/Sources/DVAIBridge/DVAIBridgeError.swift +33 -33
- package/ios/Sources/DVAIBridge/Internal/BackendSelector.swift +59 -59
- package/ios/Sources/DVAIBridge/Internal/ProgressBroadcaster.swift +84 -84
- package/ios/Sources/DVAIBridge/License/Audience.swift +133 -133
- package/ios/Sources/DVAIBridge/License/Discovery.swift +164 -164
- package/ios/Sources/DVAIBridge/License/LicenseValidator.swift +392 -392
- package/ios/Sources/DVAIBridge/License/PublicKeys.swift +114 -114
- package/ios/Sources/DVAIBridge/License/Types.swift +195 -195
- package/ios/Sources/DVAIBridge/Offload/OffloadConfig.swift +118 -118
- package/ios/Sources/DVAIBridge/ProgressEvent.swift +34 -34
- package/ios/Sources/DVAICoreMLCore/CoreMLBackendError.swift +19 -19
- package/ios/Sources/DVAICoreMLCore/CoreMLHandlers.swift +123 -123
- package/ios/Sources/DVAICoreMLCore/CoreMLPluginState.swift +130 -130
- package/ios/Sources/DVAICoreMLCore/Internal/CoreMLEngine.swift +137 -137
- package/ios/Sources/DVAICoreMLCore/Internal/CoreMLGenerator.swift +108 -108
- package/ios/Sources/DVAICoreMLCore/Internal/CoreMLSampler.swift +96 -96
- package/ios/Sources/DVAICoreMLCore/Internal/CoreMLTokenizer.swift +69 -69
- package/ios/Tests/DVAIBridgeTests/BackendSelectorTests.swift +53 -53
- package/ios/Tests/DVAIBridgeTests/CoreMLEngineTests.swift +18 -18
- package/ios/Tests/DVAIBridgeTests/CoreMLGeneratorShapeTests.swift +11 -11
- package/ios/Tests/DVAIBridgeTests/CoreMLHandlersTests.swift +32 -32
- package/ios/Tests/DVAIBridgeTests/CoreMLPluginStateTests.swift +41 -41
- package/ios/Tests/DVAIBridgeTests/CoreMLSamplerTests.swift +40 -40
- package/ios/Tests/DVAIBridgeTests/CoreMLTokenizerTests.swift +19 -19
- package/ios/Tests/DVAIBridgeTests/DVAIBridgeAPIShapeTests.swift +37 -37
- package/ios/Tests/DVAIBridgeTests/DVAIBridgeConfigTests.swift +52 -52
- package/ios/Tests/DVAIBridgeTests/DVAIBridgeErrorTests.swift +33 -33
- package/ios/Tests/DVAIBridgeTests/LicenseValidatorTests.swift +658 -658
- package/ios/Tests/DVAIBridgeTests/ProgressBroadcasterTests.swift +69 -69
- package/ios/Tests/DVAIBridgeTests/ProgressEventTests.swift +25 -25
- package/ios/Tests/DVAIBridgeTests/ReactiveStateTests.swift +45 -45
- package/ios/Tests/DVAIBridgeTests/RealModelIntegrationTest.swift +385 -359
- package/package.json +3 -4
- package/DVAIBridge.podspec +0 -120
- package/LICENSE +0 -51
- package/README.md +0 -199
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import XCTest
|
|
2
|
-
import Combine
|
|
3
|
-
@testable import DVAIBridge
|
|
4
|
-
|
|
5
|
-
final class ProgressBroadcasterTests: XCTestCase {
|
|
6
|
-
func testCombineSubscriberReceivesEvents() {
|
|
7
|
-
let bcast = ProgressBroadcaster()
|
|
8
|
-
let exp = expectation(description: "received event")
|
|
9
|
-
let cancellable = bcast.publisher.sink { event in
|
|
10
|
-
XCTAssertEqual(event.phase, .ready)
|
|
11
|
-
exp.fulfill()
|
|
12
|
-
}
|
|
13
|
-
bcast.emit(ProgressEvent(phase: .ready))
|
|
14
|
-
wait(for: [exp], timeout: 1)
|
|
15
|
-
cancellable.cancel()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
func testAsyncStreamReceivesEvents() async {
|
|
19
|
-
let bcast = ProgressBroadcaster()
|
|
20
|
-
let stream = bcast.makeStream()
|
|
21
|
-
let task = Task { () -> ProgressEvent? in
|
|
22
|
-
for await event in stream { return event }
|
|
23
|
-
return nil
|
|
24
|
-
}
|
|
25
|
-
bcast.emit(ProgressEvent(phase: .download, bytesReceived: 100))
|
|
26
|
-
let received = await task.value
|
|
27
|
-
XCTAssertEqual(received?.phase, .download)
|
|
28
|
-
XCTAssertEqual(received?.bytesReceived, 100)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func testCallbackReceivesEventsUntilCancelled() {
|
|
32
|
-
let bcast = ProgressBroadcaster()
|
|
33
|
-
var received: [ProgressEvent.Phase] = []
|
|
34
|
-
let token = bcast.addCallback { received.append($0.phase) }
|
|
35
|
-
|
|
36
|
-
bcast.emit(ProgressEvent(phase: .download))
|
|
37
|
-
bcast.emit(ProgressEvent(phase: .ready))
|
|
38
|
-
token.cancel()
|
|
39
|
-
bcast.emit(ProgressEvent(phase: .error, message: "should not see"))
|
|
40
|
-
|
|
41
|
-
XCTAssertEqual(received, [.download, .ready])
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func testAllThreeSurfacesObserveSameEvent() async {
|
|
45
|
-
let bcast = ProgressBroadcaster()
|
|
46
|
-
var combineCount = 0
|
|
47
|
-
var streamCount = 0
|
|
48
|
-
var callbackCount = 0
|
|
49
|
-
|
|
50
|
-
let cancellable = bcast.publisher.sink { _ in combineCount += 1 }
|
|
51
|
-
let stream = bcast.makeStream()
|
|
52
|
-
let task = Task {
|
|
53
|
-
for await _ in stream { streamCount += 1; if streamCount >= 1 { break } }
|
|
54
|
-
}
|
|
55
|
-
let token = bcast.addCallback { _ in callbackCount += 1 }
|
|
56
|
-
|
|
57
|
-
bcast.emit(ProgressEvent(phase: .ready))
|
|
58
|
-
|
|
59
|
-
// Wait for AsyncStream to yield
|
|
60
|
-
_ = await task.value
|
|
61
|
-
|
|
62
|
-
XCTAssertEqual(combineCount, 1)
|
|
63
|
-
XCTAssertEqual(streamCount, 1)
|
|
64
|
-
XCTAssertEqual(callbackCount, 1)
|
|
65
|
-
|
|
66
|
-
cancellable.cancel()
|
|
67
|
-
token.cancel()
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
import XCTest
|
|
2
|
+
import Combine
|
|
3
|
+
@testable import DVAIBridge
|
|
4
|
+
|
|
5
|
+
final class ProgressBroadcasterTests: XCTestCase {
|
|
6
|
+
func testCombineSubscriberReceivesEvents() {
|
|
7
|
+
let bcast = ProgressBroadcaster()
|
|
8
|
+
let exp = expectation(description: "received event")
|
|
9
|
+
let cancellable = bcast.publisher.sink { event in
|
|
10
|
+
XCTAssertEqual(event.phase, .ready)
|
|
11
|
+
exp.fulfill()
|
|
12
|
+
}
|
|
13
|
+
bcast.emit(ProgressEvent(phase: .ready))
|
|
14
|
+
wait(for: [exp], timeout: 1)
|
|
15
|
+
cancellable.cancel()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func testAsyncStreamReceivesEvents() async {
|
|
19
|
+
let bcast = ProgressBroadcaster()
|
|
20
|
+
let stream = bcast.makeStream()
|
|
21
|
+
let task = Task { () -> ProgressEvent? in
|
|
22
|
+
for await event in stream { return event }
|
|
23
|
+
return nil
|
|
24
|
+
}
|
|
25
|
+
bcast.emit(ProgressEvent(phase: .download, bytesReceived: 100))
|
|
26
|
+
let received = await task.value
|
|
27
|
+
XCTAssertEqual(received?.phase, .download)
|
|
28
|
+
XCTAssertEqual(received?.bytesReceived, 100)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func testCallbackReceivesEventsUntilCancelled() {
|
|
32
|
+
let bcast = ProgressBroadcaster()
|
|
33
|
+
var received: [ProgressEvent.Phase] = []
|
|
34
|
+
let token = bcast.addCallback { received.append($0.phase) }
|
|
35
|
+
|
|
36
|
+
bcast.emit(ProgressEvent(phase: .download))
|
|
37
|
+
bcast.emit(ProgressEvent(phase: .ready))
|
|
38
|
+
token.cancel()
|
|
39
|
+
bcast.emit(ProgressEvent(phase: .error, message: "should not see"))
|
|
40
|
+
|
|
41
|
+
XCTAssertEqual(received, [.download, .ready])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func testAllThreeSurfacesObserveSameEvent() async {
|
|
45
|
+
let bcast = ProgressBroadcaster()
|
|
46
|
+
var combineCount = 0
|
|
47
|
+
var streamCount = 0
|
|
48
|
+
var callbackCount = 0
|
|
49
|
+
|
|
50
|
+
let cancellable = bcast.publisher.sink { _ in combineCount += 1 }
|
|
51
|
+
let stream = bcast.makeStream()
|
|
52
|
+
let task = Task {
|
|
53
|
+
for await _ in stream { streamCount += 1; if streamCount >= 1 { break } }
|
|
54
|
+
}
|
|
55
|
+
let token = bcast.addCallback { _ in callbackCount += 1 }
|
|
56
|
+
|
|
57
|
+
bcast.emit(ProgressEvent(phase: .ready))
|
|
58
|
+
|
|
59
|
+
// Wait for AsyncStream to yield
|
|
60
|
+
_ = await task.value
|
|
61
|
+
|
|
62
|
+
XCTAssertEqual(combineCount, 1)
|
|
63
|
+
XCTAssertEqual(streamCount, 1)
|
|
64
|
+
XCTAssertEqual(callbackCount, 1)
|
|
65
|
+
|
|
66
|
+
cancellable.cancel()
|
|
67
|
+
token.cancel()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import XCTest
|
|
2
|
-
@testable import DVAIBridge
|
|
3
|
-
|
|
4
|
-
final class ProgressEventTests: XCTestCase {
|
|
5
|
-
func testCodableRoundTrip() throws {
|
|
6
|
-
let original = ProgressEvent(
|
|
7
|
-
phase: .download,
|
|
8
|
-
bytesReceived: 1024,
|
|
9
|
-
bytesTotal: 4096,
|
|
10
|
-
percent: 25.0,
|
|
11
|
-
message: nil
|
|
12
|
-
)
|
|
13
|
-
let json = try JSONEncoder().encode(original)
|
|
14
|
-
let decoded = try JSONDecoder().decode(ProgressEvent.self, from: json)
|
|
15
|
-
XCTAssertEqual(original, decoded)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
func testPhaseRawValues() {
|
|
19
|
-
XCTAssertEqual(ProgressEvent.Phase.download.rawValue, "download")
|
|
20
|
-
XCTAssertEqual(ProgressEvent.Phase.verify.rawValue, "verify")
|
|
21
|
-
XCTAssertEqual(ProgressEvent.Phase.load.rawValue, "load")
|
|
22
|
-
XCTAssertEqual(ProgressEvent.Phase.ready.rawValue, "ready")
|
|
23
|
-
XCTAssertEqual(ProgressEvent.Phase.error.rawValue, "error")
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import DVAIBridge
|
|
3
|
+
|
|
4
|
+
final class ProgressEventTests: XCTestCase {
|
|
5
|
+
func testCodableRoundTrip() throws {
|
|
6
|
+
let original = ProgressEvent(
|
|
7
|
+
phase: .download,
|
|
8
|
+
bytesReceived: 1024,
|
|
9
|
+
bytesTotal: 4096,
|
|
10
|
+
percent: 25.0,
|
|
11
|
+
message: nil
|
|
12
|
+
)
|
|
13
|
+
let json = try JSONEncoder().encode(original)
|
|
14
|
+
let decoded = try JSONDecoder().decode(ProgressEvent.self, from: json)
|
|
15
|
+
XCTAssertEqual(original, decoded)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func testPhaseRawValues() {
|
|
19
|
+
XCTAssertEqual(ProgressEvent.Phase.download.rawValue, "download")
|
|
20
|
+
XCTAssertEqual(ProgressEvent.Phase.verify.rawValue, "verify")
|
|
21
|
+
XCTAssertEqual(ProgressEvent.Phase.load.rawValue, "load")
|
|
22
|
+
XCTAssertEqual(ProgressEvent.Phase.ready.rawValue, "ready")
|
|
23
|
+
XCTAssertEqual(ProgressEvent.Phase.error.rawValue, "error")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import XCTest
|
|
2
|
-
@testable import DVAIBridge
|
|
3
|
-
|
|
4
|
-
@MainActor
|
|
5
|
-
final class ReactiveStateTests: XCTestCase {
|
|
6
|
-
func testInitialState() {
|
|
7
|
-
let s = DVAIBridgeReactiveState()
|
|
8
|
-
XCTAssertFalse(s.isReady)
|
|
9
|
-
XCTAssertNil(s.baseUrl)
|
|
10
|
-
XCTAssertNil(s.port)
|
|
11
|
-
XCTAssertNil(s.currentBackend)
|
|
12
|
-
XCTAssertNil(s.lastProgress)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
func testDidStartUpdatesObservableProperties() {
|
|
16
|
-
let s = DVAIBridgeReactiveState()
|
|
17
|
-
s.didStart(BoundServer(
|
|
18
|
-
baseUrl: "http://127.0.0.1:38883/v1",
|
|
19
|
-
port: 38883,
|
|
20
|
-
backend: .llama,
|
|
21
|
-
modelId: "x"
|
|
22
|
-
))
|
|
23
|
-
XCTAssertTrue(s.isReady)
|
|
24
|
-
XCTAssertEqual(s.baseUrl, "http://127.0.0.1:38883/v1")
|
|
25
|
-
XCTAssertEqual(s.port, 38883)
|
|
26
|
-
XCTAssertEqual(s.currentBackend, .llama)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
func testDidStopResetsObservableProperties() {
|
|
30
|
-
let s = DVAIBridgeReactiveState()
|
|
31
|
-
s.didStart(BoundServer(baseUrl: "x", port: 1, backend: .llama, modelId: "x"))
|
|
32
|
-
s.didStop()
|
|
33
|
-
XCTAssertFalse(s.isReady)
|
|
34
|
-
XCTAssertNil(s.baseUrl)
|
|
35
|
-
XCTAssertNil(s.port)
|
|
36
|
-
XCTAssertNil(s.currentBackend)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
func testDidReceiveProgressStoresLastEvent() {
|
|
40
|
-
let s = DVAIBridgeReactiveState()
|
|
41
|
-
let event = ProgressEvent(phase: .download, bytesReceived: 100)
|
|
42
|
-
s.didReceiveProgress(event)
|
|
43
|
-
XCTAssertEqual(s.lastProgress, event)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import DVAIBridge
|
|
3
|
+
|
|
4
|
+
@MainActor
|
|
5
|
+
final class ReactiveStateTests: XCTestCase {
|
|
6
|
+
func testInitialState() {
|
|
7
|
+
let s = DVAIBridgeReactiveState()
|
|
8
|
+
XCTAssertFalse(s.isReady)
|
|
9
|
+
XCTAssertNil(s.baseUrl)
|
|
10
|
+
XCTAssertNil(s.port)
|
|
11
|
+
XCTAssertNil(s.currentBackend)
|
|
12
|
+
XCTAssertNil(s.lastProgress)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func testDidStartUpdatesObservableProperties() {
|
|
16
|
+
let s = DVAIBridgeReactiveState()
|
|
17
|
+
s.didStart(BoundServer(
|
|
18
|
+
baseUrl: "http://127.0.0.1:38883/v1",
|
|
19
|
+
port: 38883,
|
|
20
|
+
backend: .llama,
|
|
21
|
+
modelId: "x"
|
|
22
|
+
))
|
|
23
|
+
XCTAssertTrue(s.isReady)
|
|
24
|
+
XCTAssertEqual(s.baseUrl, "http://127.0.0.1:38883/v1")
|
|
25
|
+
XCTAssertEqual(s.port, 38883)
|
|
26
|
+
XCTAssertEqual(s.currentBackend, .llama)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func testDidStopResetsObservableProperties() {
|
|
30
|
+
let s = DVAIBridgeReactiveState()
|
|
31
|
+
s.didStart(BoundServer(baseUrl: "x", port: 1, backend: .llama, modelId: "x"))
|
|
32
|
+
s.didStop()
|
|
33
|
+
XCTAssertFalse(s.isReady)
|
|
34
|
+
XCTAssertNil(s.baseUrl)
|
|
35
|
+
XCTAssertNil(s.port)
|
|
36
|
+
XCTAssertNil(s.currentBackend)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func testDidReceiveProgressStoresLastEvent() {
|
|
40
|
+
let s = DVAIBridgeReactiveState()
|
|
41
|
+
let event = ProgressEvent(phase: .download, bytesReceived: 100)
|
|
42
|
+
s.didReceiveProgress(event)
|
|
43
|
+
XCTAssertEqual(s.lastProgress, event)
|
|
44
|
+
}
|
|
45
|
+
}
|