Repository navigation
ruflet_server: test every protocol action on both receivers and every codec format; normalize invoke replies like ConnectionProtocol - #89
Merged
Conversation
Ruflet::ConnectionProtocol (ruflet_rails and other host adapters) normalizes the client's invoke_control_method reply with Protocol.normalize_invoke_method_result_payload. Ruflet::Server, which `ruflet run` starts, has its own receiver and passed the payload through as is. So a reply spelled callId/value, as older clients send it, reached its on_result under Rails but was silently dropped by the standalone server. Normalize it the same way.
…c's formats ProtocolActionContractTest sends every Protocol action, legacy JSON spellings included, through Ruflet::Server and through a Ruflet::ConnectionProtocol host. It checks each gives the client the same result: - register: the reply, the route and client details, and the app's controls published; - control events: the handler runs, with event data, including eventTarget/eventName payloads; - update_control: props applied; - invoke replies: delivered; - python_output: ignored; - page updates: sent as patch_control; - an app that raises on register: session_crashed. It also fails if an action is added to Protocol::ACTIONS without a test here. WireCodecContractTest covers every MessagePack format the codec writes or reads, at each size boundary (fixint to int64/uint64, f32/f64, fixstr to str32, bin8 to bin32, arrays and maps to 32-bit sizes, and the three Flet extension types as ext8/16/32 and fixext). For each it checks the marker byte, the round trip and, when the msgpack gem is installed, agreement with it in both directions.
This was referenced Nov 17, 2026
The comments called callId/value the spelling older clients send. No shipped client has sent it: the engine's InvokeMethodResponseBody and the template's client write control_id/call_id/result/error. The fix makes Ruflet::Server treat a reply the way ConnectionProtocol already does; say that instead.
… action The invoke contract test sent only successful replies, so dropping the reply's error in Protocol.normalize_invoke_method_result_payload passed every test. Send the engine's error reply too, to on_result and to invoke_sync, which must raise it, and invoke_sync's success reply. The coverage guard compared Protocol::ACTIONS with a hand-written list, so naming an action there without a test passed it. Each test now records the action it covers, and the guard checks every action has one on both receivers.
wire_codec_contract_test skips its checks against the msgpack gem when the gem is missing, and CI never installed it, so 45 of them skipped. Install it (test-only; no Ruflet package depends on it).
Ruflet::Server used to index such a reply directly, which raised TypeError inside Page#handle_invoke_method_result and logged "invoke callback error". Normalized, it is ignored silently, as ConnectionProtocol already did, and the pending call stays pending.
…and the 16-bit size limits The contract test now sends the callId and value aliases separately and a reply carrying both result and value, the eventData key and the target and eventTarget ids, and maps, arrays and bins of 65535 entries. Warnings are checked without the RUFLET_DEBUG trace, so the suite passes with RUFLET_DEBUG=1, and python_output on Ruflet::Server must log nothing.
This was referenced Nov 20, 2026
The alias contract test now sends a reply carrying call_id and a different callId, and one with call_id nil and callId set. The compatibility test is renamed to say it sends callId, and its comment says what the standalone server did before: it ignored the reply, and on_result got the timeout error once the call's timeout passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the release-readiness test pass. This PR covers
ruflet_server.What's tested
ProtocolActionContractTestsends everyProtocol::ACTIONSentry, legacy JSON spellings included, through both receivers:Ruflet::Server, the standalone serverruflet runstarts;Ruflet::ConnectionProtocolhost, the loopruflet_railsincludes.It asserts the client gets the same result from either:
register_client,registerWebClientcontrol_event,pageEventFromWebtarget/name/dataandeventTarget/eventName/eventDatapayloadsupdate_control,updateControlPropsid,targetoreventTargetinvoke_control_methodon_result;invoke_syncreturns the result or raises the error; thecallIdandvaluealiases are delivered, each alone, together, andcallIdwith a nilcall_id;call_idwins overcallIdandresultovervalue; a reply that is not a map is ignored, logs nothing, and the call stays pendingpython_outputpatch_control(outbound)page.updatesends it to the control's idsession_crashed(outbound)Each test records the action it covers.
test_every_action_has_a_test_on_both_receiversfails if aProtocol::ACTIONSentry has no test on either receiver. It checks that a test exists, not what the test asserts. Log checks ignore theincoming action=lineRUFLET_DEBUG=1adds, so the suite also passes with it set.WireCodecContractTestcovers every MessagePack format the codec writes or reads, on both sides of each size limit:For each format it checks the spec's marker byte and the round trip. When the
msgpackgem is installed, it also checks agreement with that gem in both directions; without the gem those checks skip. A new test-only step inbuild-ruflet-client.ymlinstallsmsgpack1.8.5 so they run in CI. No Ruflet package depends on it.Coverage:
ruflet_servergoes from 64 to 227 tests, and the codec from 9 cases to 142. On main,form_wire_test.rbandevent_client_value_wire_test.rbdriveregister_client,update_controlandcontrol_eventthroughRuflet::Server#handle_message(the second also through aConnectionProtocolhost), andconnection_protocol_test.rbsendspython_outputand a crashing register to aConnectionProtocolhost. Noruflet_servertest sends the legacy spellings or an invoke reply through either receiver, orpython_outputor a crashing register throughRuflet::Server. (Outsideruflet_server,ruflet_rails/test/protocol_endpoint_test.rband the H1rails_endpointgoldens also driveregister_clientandcontrol_eventthroughConnectionProtocol.)Fix
Ruflet::Server#on_invoke_control_methodpassed the client's reply through unchanged.ConnectionProtocolnormalizes it withProtocol.normalize_invoke_method_result_payload, and now the standalone server does too. The regression test,test_standalone_server_accepts_a_callId_and_value_invoke_replyinprotocol_compatibility_test.rb, fails without the fix.The first commit's message says older clients send
callId/value. That is wrong (see below); the code comments now say so.Behavior changes
Both come from the fix in
Ruflet::Server#on_invoke_control_method.ruflet_server/libis also compiled into the embedded VM (ruby_runtime/vm/mrbgems/ruflet-framework/mrbgem.rake), so embedded apps get them at the next VM rebuild. Replies in the engine's shape behave exactly as before (see Verified).The standalone server now applies the normalizer's two aliases, as
ConnectionProtocol(ruflet_rails) already did.callIdis read whencall_idis missing, nil or false.valueis read when the reply has noresultkey. OnRuflet::Server, forpage.invoke(..., on_result:)andinvoke_sync:callId+valueon_resultgot(nil, "execution expired")once the call's timeout passed (10 s by default; it never ran withtimeout: nil);invoke_syncraisedTimeout::Erroron_result(v, nil)at once;invoke_syncreturns vcallId+result/error, orcall_idnil or false +callIdcall_idcall_id+value, noresultkeyon_result(nil, nil);invoke_syncreturned nilon_result(v, nil);invoke_syncreturns vresultandvaluestill usesresult; one with bothcall_idandcallIdusescall_id.InvokeMethodResponseBody#toMapwritescontrol_id/call_id/result/error; the file is the same blob in ruflet-enginecodex/engine-initialization(98e41857, and f44e7df7 before it) and template main (8b085697)._onInvokeMethodinruflet_backend.dartis the only place either sends an invoke reply. Those replies always carrycall_idand aresultkey, so neither alias can fire for them.git log --all -G"[\"']callId[\"'] *[:=]" -- '*.dart'finds nothing in ruflet-engine, ruflet-template or ruflet. Ruflet's history includes the former bundledruflet_client.A reply that is an array, integer, float or
trueno longer logsinvoke callback error: .... Before,Page#handle_invoke_method_resultindexed it with"call_id". That raisedTypeError(array, integer) orNoMethodError(float,true) internally, and the error was rescued and logged.on_resultgets(nil, "execution expired"). Only the log line is gone.ConnectionProtocol.nilandfalse(whichhandle_messageturns into{}), strings and extension values were ignored silently before and still are.Verified on 71b1c6a (includes main 06c6e28)
ruflet_server, one process per file: 17 files, 227 runs, 0 failures, 0 skips on Ruby 4.0.5 (msgpack 1.8.5), on 3.4.5 (msgpack 1.8.7), and on 4.0.5 withRUFLET_DEBUG=1. Main: 15 files, 64 runs.ruflet_serverfiles ran 227 runs, 0 skips;wire_codec_contract_testran 133 runs, 0 skips.compat.rb --jobs 4checked 320 goldens, exit 0.compat_goldens_testran 328 runs, 0 failures.callIdpreferred overcall_id,callIdread only when thecall_idkey is absent,valuepreferred overresult, the normalizer droppingerror, theeventData,targetandeventTargetfallbacks dropped,python_outputraising onRuflet::Server(which only logs it), each 16-bit map, array and bin limit lowered to 65534, a newProtocol::ACTIONSentry with no test, andinvoke_syncignoring the error.page.invokewith notimeout:and one reply each. On main'sRuflet::Server,callId+value,callId+result, andcallIdwithcall_idnil or false each got(nil, "execution expired")at 10.1 s; withtimeout: nilon_resultnever ran;invoke_sync(timeout: 2)raisedTimeout::Error. On this head each is delivered at once.ConnectionProtocolgives this head's results on both. An array reply withtimeout: 2got the timeout error at 2.1 s on both receivers, before and after.Ruflet::Server#handle_messageon main and on this head with 33 reply shapes. 25 gave the same result on both, including every engine shape: success, error,false, a nested map with ext types, extra keys, a duplicate reply, andinvoke_syncsuccess, error and empty error. The 8 that differ are the alias rows in Behavior change 1. On main, the 5 shapes with an array, integer, float ortruepayload loggedinvoke callback error; on this head none do (Behavior change 2).embedded_mrubyharness (framework 0.0.21,--preload) with this head'son_invoke_control_methodloaded, engine replies give the same results as without it;callId+value,call_id+value, andcallIdwithcall_idnil or false are delivered; the array reply no longer logs. mrbc compilesserver.rb,connection_protocol.rbandprotocol.rb.control_id/call_id/result/error, and this PR touches onlyruflet_serverand a CI test step.