@@ -126,7 +126,12 @@ struct WasmRunnerTests {
126126 (i64.const 0)))
127127 """
128128 let wasm = try [ UInt8] ( wat2wasm ( wat) )
129- let plugin = try WasmParserPlugin ( manifest: batteryManifest ( ) , moduleBytes: wasm, deadline: . milliseconds( 50 ) )
129+ let plugin = try WasmParserPlugin (
130+ manifest: batteryManifest ( ) ,
131+ moduleBytes: wasm,
132+ deadline: . milliseconds( 50 ) ,
133+ warmupDeadline: . seconds( 2 )
134+ )
130135 let request = ParseRequest ( kind: . characteristic, uuid: . bit16( 0x2A19 ) , payload: Data ( [ 1 ] ) )
131136 #expect( await plugin. parse ( request) == nil )
132137 // Give the timeout task a moment to flip the quarantine flag.
@@ -166,6 +171,42 @@ struct PluginLoaderTests {
166171 #expect( decoded. fields. first? . value == . uint( 88 ) )
167172 }
168173
174+ @Test ( " Bundled Embedded Swift plugin matches the native parser across values " )
175+ func bundledSwiftPluginParity( ) async throws {
176+ let result = PluginLoader . loadBundled ( from: PluginEngineResources . bundle)
177+ let battery = try #require( result. loaded. first {
178+ $0. manifest. identifier == " org.pureswift.plugin.battery-level "
179+ } )
180+ let native = NativeWellKnownCharacteristicParser ( )
181+ var failures = [ UInt8] ( )
182+ for level : UInt8 in [ 0 , 1 , 42 , 99 , 100 , 255 ] {
183+ let request = ParseRequest ( kind: . characteristic, uuid: . bit16( 0x2A19 ) , payload: Data ( [ level] ) )
184+ guard let wasmResult = await battery. plugin. parse ( request) else {
185+ failures. append ( level)
186+ continue
187+ }
188+ let nativeResult = try #require( await native. parse ( request) )
189+ #expect( wasmResult. fields. first? . value == . uint( UInt64 ( level) ) , " level \( level) " )
190+ #expect( wasmResult. fields. first? . value == nativeResult. fields. first? . value, " level \( level) " )
191+ #expect( wasmResult. fields. first? . unit == " % " , " level \( level) " )
192+ }
193+ #expect( failures. isEmpty, " levels returning nil: \( failures) " )
194+ }
195+
196+ @Test ( " Bundled plugin declines a payload it does not recognize " )
197+ func bundledSwiftPluginDeclines( ) async throws {
198+ let result = PluginLoader . loadBundled ( from: PluginEngineResources . bundle)
199+ let battery = try #require( result. loaded. first {
200+ $0. manifest. identifier == " org.pureswift.plugin.battery-level "
201+ } )
202+ // Empty payload: the guest returns 0 ("not mine"), which must surface as nil, not an error.
203+ let empty = ParseRequest ( kind: . characteristic, uuid: . bit16( 0x2A19 ) , payload: Data ( ) )
204+ #expect( await battery. plugin. parse ( empty) == nil )
205+ // Wrong UUID: the plugin checks its own assigned number.
206+ let wrong = ParseRequest ( kind: . characteristic, uuid: . bit16( 0x2A37 ) , payload: Data ( [ 1 ] ) )
207+ #expect( await battery. plugin. parse ( wrong) == nil )
208+ }
209+
169210 @Test ( " A tampered sha256 is rejected " )
170211 func rejectsHashMismatch( ) throws {
171212 let manifestURLs = PluginEngineResources . bundle. urls (
0 commit comments