Repository navigation
Test what every control and service method sends; fix unset values sent as {} and map stack overflows - #87
Merged
Merged
Conversation
…w the stack
MapControl#normalize_coordinates and the DSL's map_coordinates turned nil
into nil.to_h ({}) and then kept calling themselves on Hash#to_h. So
map.move_to(zoom: 9), whose destination: is optional, raised
SystemStackError, as did Ruflet.map(initial_center: nil) and any Hash
with no latitude and longitude (map.center_on({ x: 1 }),
Ruflet.marker(coordinates: { x: 1 })).
Pass nil, short Arrays and Hashes without coordinates through unchanged.
nil is then dropped from the args like every other unset option.
The args helpers of the camera, geolocator, secure storage and audio
recorder services, the shared service methods and the map control
converted any value with to_h when they could. nil.to_h is {}, so an
unset argument, or a nil inside an Array, reached the client as an
empty map. camera.lock_capture_orientation() sent
{ "orientation" => {} }, which the renderer passes to
parseDeviceOrientation(String?) and fails on.
Keep nil as nil. Five of the six new tests fail without this.
MethodContractCoverageTest lists every public method a control, service or shipped extension adds to Ruflet::Control, or replaces in it (flashlight.on), and fails for any without a spec in test/support/method_contracts. A spec says what the method sends the client: the method name and the args of its invoke_control_method. The generated test calls it on a mounted control and checks the payload, including that it targets the control's wire id. It then answers the call as the client would, and checks the reply reaches on_result (or a blocking *_sync method returns it). Methods that only work in Ruby (Form#validate, the browser context menu's disabled?, dropdown's Material 2 handler aliasing) state why they send nothing and name the test that covers them. 256 methods across 20 services and 42 controls, plus 12 that work only in Ruby.
AdamMusa
force-pushed
the
test/method-contracts
branch
from
November 16, 2026 06:28
6cce7cb to
5722728
Compare
This was referenced Nov 17, 2026
#71 added public readers (field.value, tabs.selected_index and 38 more) to the controls, so MethodContractCoverageTest failed on main once this branch was merged with it: 40 methods had no spec. Each reader returns what the control's props hold and sends nothing, so each gets a local spec naming client_state_readers_test, which covers them.
The earlier fix stopped the stack overflow by passing unreadable
coordinates on unchanged. The client then read them wrongly:
parseLatLng turns {"x" => 1} into LatLng(0, 0) and throws on [1].
On main these inputs already raised (SystemStackError, or TypeError for
[1]), so raise ArgumentError for them instead, at the call that made the
mistake: an Array shorter than two, a Hash without both coordinates, an
object whose to_h gives neither, and a nil point inside a polyline or
polygon list. nil on its own still means not given, and values without
to_h still pass through, as on main.
The secure storage test passed its value straight through, so it never reached normalize_value; only the platform options (web, ios, macos, android, windows) do. Pass nil inside those, so the test fails without the fix.
Most specs passed opaque "sample:x" strings, which every conversion
leaves alone, so a dropped to_i, to_s or Symbol conversion went
unnoticed. The methods that convert their arguments now get values the
conversion changes:
- web_view scroll_to/scroll_by: a String and a Float, sent as Integers;
set_javascript_mode and load_request's method: Symbols, sent as Strings
- map center_on/move_to: [lat, lon] and { lat:, lng: }, sent as
latitude/longitude; animation_duration, sent as duration
- camera: Symbols for the modes and the resolution preset, Hashes with
Symbol keys for the description and point
- clipboard set: an Integer; semantics_service: a Symbol message, rtl: 1
and a Symbol assertiveness
Thirteen planted conversion bugs in these methods now fail the contract
tests.
initial_center: nil was kept as a nil prop, and Control#serialize_value
turns nil into {}, which the client reads as LatLng(0, 0) instead of its
default center. Drop the key, so nil means not given, as for marker.
Object.const_source_location(nil) raises TypeError, so an anonymous control class registered by another test in the same process broke classes_by_type.
The web_view, url_launcher, clipboard, tabs, page_view and local_authentication specs passed Strings, so dropping a to_s changed nothing. They now pass a Pathname, URI or Symbol. Also cover the option handling that no test reached: map's animation_curve -> curve rename, every secure storage platform key, save_file's packed src_bytes, local_authentication's booleans and messages, context_menu's position, interactive_viewer's reset and video's playlist_add keys. A map test pins the String passthrough and to_h conversion main already had.
A sweep that drops each to_s/to_i/to_f/to_sym/!!/pack in the method files found more specs that passed values no conversion changed: map options' Hash keys, window's edge names, the audio recorder's and geolocator's configuration keys, and share_files' nested data bytes. The window and geolocator specs now take the converting value, and a plain test each keeps the case the spec no longer passes (an unknown edge, no configuration).
A spec can now list more calls of its method under also:. The specs that took a converting value keep the call they made before (no options, a plain String) as a second call, so no earlier check is lost. The window edge and geolocator plain tests become also: calls.
The specs that took a Pathname, URI or Symbol, and map's move_to, keep the String or plain call they made before, so each call the specs made on 3f48810 is still made and checked.
Control#serialize_value converted any value with to_h, and nil.to_h is
{}. So Ruflet.text("x", tooltip: nil).to_patch sent "tooltip" => {},
which the client builds into a Tooltip with no message, and visible: nil
sent {} where the client reads a bool. page.update(text, tooltip: nil)
already sent nil. A nil prop, or a nil inside an Array or Hash prop, is
now sent as nil; every other value serializes as before.
…all site - every latitude/longitude key alias, String and Symbol, in center_on, the DSL helpers and a ControlFactory map; a factory map converts [lat, lon]; a Hash with one coordinate raises in the DSL and factory - a nil Hash value is left out by the map, service, geolocator, audio recorder and secure storage helpers, and kept by camera's - upload, shared_preferences.set, url_launcher.supports_*_launch_mode and camera set_* called with nil send nil - polyline_marker and polygon_marker with coordinates: nil send []
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. #86 covers each control's props and events. This PR covers the methods that talk to the client, and fixes the bugs the new tests found.
What's tested
MethodContractCoverageTestlists every public method that a control, service or shipped extension adds toRuflet::Control, or replaces in it (flashlight.on). It fails for any method without a spec intest/support/method_contracts/.For each spec, the generated test:
invoke_control_methodpayload: control wire id, method name, args;on_result, or that a blocking*_syncmethod returns it.Where a method converts an argument, its spec passes a value the conversion changes: a
Pathname,URIor Symbol where it callsto_s, a String and a Float where it callsto_i, Symbol Hash keys,[lat, lon]and{ lat:, lng: }coordinates, truthy non-booleans, and Integer lists where it packs bytes. A spec can list more calls of its method underalso:. The specs that now take a converting value keep their earlier call there, so every call the specs made on 3f48810 is still made and checked. Otheralso:calls cover a window edge the table does not name,geolocator.get_current_positionwithout a configuration, and the top-levelnilcalls that Behavior changes item 1 lists (camera,file_picker.upload,url_launcher.supports_*_launch_mode,shared_preferences.set).A mutation sweep on this head plants one bug at a time in the 30 files that define these methods: it drops each
to_s,to_i,to_f,to_sym,map(&:to_s),!!,? true : falseandpack, renames eachwhen "a" then "b"wire key, and removes each%w[]entry. 92 of the 99 bugs fail a PR test. The other 7 change no method's args (qrcode_scanner'sformatsis a constructor prop; no method passes a top-leveldata:toservice_args;Page#invokealready stringifies camera's method name; three are inLocalAuthError.from_error). Two more sets of planted bugs, 21 and 64 (the reviews' coordinate andnilcases, the six helpers'nilbranches, theto_patchfix below, and the coordinate edges: longer and one-item Arrays, an object whoseto_hgivesnil), all fail a PR test.Methods that only work in Ruby send nothing. Their specs state why and name the test that covers them. Examples:
Form#validate, dropdown's Material 2 handler aliasing, and the 40 client-state readers from #71 (field.value,tabs.selected_index).Coverage
page_*_service_test.rb, mostly checking method names. Nothing failed when a method had no test.qrcode_scannerincluded. 52 methods that only work in Ruby are documented.Bugs fixed (each with regression tests)
MapControl#normalize_coordinatesand the DSL'smap_coordinatesturnednilintonil.to_h({}), then called themselves onHash#to_hforever. Somap.move_towithoutdestination:always raisedSystemStackError, and so didRuflet.map(initial_center: nil)and any Hash without latitude and longitude.{}. The args helpers of camera, geolocator, secure storage, audio recorder, the shared service methods and the map control turnednilinto{}, both at top level and inside Arrays.camera.lock_capture_orientation()sent{ "orientation" => {} }. The renderer passes that toparseDeviceOrientation(String?), which fails. With main's versions of those six files, all 7invoke_nil_values_testtests fail, and so do the 13nilcalls in the service specs.{}.Control#serialize_value, whichto_patchuses, had the samenil.to_hbranch.Ruflet.text("x", tooltip: nil).to_patchsent"tooltip" => {}, whilepage.update(text, tooltip: nil)sentnil.control_nil_props_testcovers it: 3 of its 4 tests fail with main'scontrol.rb, and the fourth pins that other values withto_hstill convert.Behavior changes
Only three kinds of output change: calls that raised,
nilmethod arguments sent as{}, andnilprops sent as{}. Every other input sends what it sent on main. That includes valid coordinates (an Array longer than two still gives its first two items), objects whoseto_hgives coordinates or a prop value, Strings (still passed through), an empty Hash (still{}), anilHash value the helpers already left out, andpolyline_marker(coordinates: nil)(still[]). Tests pin each of these. The client effects below come from template main's handlers (8b08569, the sameruflet_packagesas e32c873), which 0.0.23 apps build with. ItsControl.getreturns the default fornull.A
nilmethod argument is sent asnil, not{}. This is a bug fix: the{}came fromnil.to_h, and the handlers read null as "not given".camera.lock_capture_orientation()now locks the current orientation.camera.set_exposure_mode(nil),set_flash_mode(nil)andset_focus_mode(nil)now do nothing.url_launcher.supports_launch_mode(nil)andsupports_close_for_launch_mode(nil)now answer for the platform default mode.file_picker.upload(nil)now does nothing.camera.set_focus_point(nil)andset_exposure_point(nil)moved the point to the top-left corner:parseOffset({})isOffset(0, 0). They now reset it, becauseparseOffset(null)is null.camera.set_description(nil),set_exposure_offset(nil)andset_zoom_level(nil)(no-ops either way), or forshared_preferences.set(k, nil)(fails either way, sincesetStringneeds a String).nilinside an Array, or kept inside a Hash, is sent asnilinstead of{}. Examples:share_files([nil]),pick_files(allowed_extensions: [nil]), the geolocator and audio recorder configurations, secure storage's platform options (android: { a: [nil] }), camera Hash args (set_focus_point({ x: 1, y: nil })) and map options (zoom_in(offset: [1, nil])).Map calls that raised
SystemStackErrornow work, withnilmeaning "not given".map.move_to(...)withoutdestination:. The keyword defaults tonil, somove_to(zoom: 9)could never be called before. The client passes the missing destination on asdest: null.map.center_on(nil)sends no point. The client'scenter_ondoes nothing without one.Ruflet.map(initial_center: nil),ControlFactory.build("map", initial_center: nil),Ruflet.marker(coordinates: nil)andRuflet.circle_marker(coordinates: nil)leave the prop out, the same as leaving the keyword out, which main already allowed. The map opens at the client's default center.This is a bug fix: the calls crashed in Ruby, and
nilnow means "not given".Coordinates that cannot be read raise
ArgumentError, notSystemStackErrororTypeError. That covers an Array shorter than two ([],[1]), a Hash without both coordinates, an object whoseto_hgivesnilor neither coordinate, and anilpoint in apolyline_markerorpolygon_markerlist. These calls raised on main too; now the error names the bad value at the call that passed it. BecauseSystemStackErroris not aStandardError, a barerescuenow catches these errors.to_patchsends anilprop asnil, not{}. That is whatpage.addsends for a new control, and what a later full patch sends (a parent's newcontrolslist, a view rebuild). Most control classes drop anilkeyword, so the cases are:nilfor a keyword the class keeps:flip:andtransform:on any control built by the DSL orControlFactory; the extra keywordsControlFactory::ATTRIBUTE_OVERRIDESkeeps fortextandimage(tooltip:,visible:,opacity:,width:and the other layout keywords),navigation_rail(scrollable:,pin_leading_to_top:,pin_trailing_to_bottom:),responsive_rowandexpansion_panel_list(scroll:,auto_scroll:,scroll_interval:) andruflet_app(assets_dir:); and every prop ofmapand of a control built withRuflet::Control.new. A probe that builds everyControlFactorytype with each keyword set tonilfinds no others: besidesflip:andtransform:, every prop that sent{}on main is in this list and now sendsnil, exceptaudio_recorder'sconfiguration:, which its constructor still turns into{}, as on main;nilinside an Array or Hash prop of any control (style: { color: nil }now sends"color" => nil);page.update(control, key: nil)set tonil, when the control is sent again in full.On the client,
{}was a value:tooltip: {}built aTooltipwith neithermessagenorrichMessage, which Flutter asserts against, andvisible: {}madeget<bool>throw aTypeError(checked withdart runon the samegetbody). Template main's handlers fornavigation_rail,responsive_row,expansion_panel_listandruflet_appread none of their keywords above, so those change nothing on a 0.0.23 client. The engine's default branch wrapsresponsive_rowandexpansion_panel_listin its scroll surface, whereauto_scroll: {}throws the sameTypeError(scroll: {}reads as no scroll). Template main stores anullprop as it is (Control.fromMap), andgetgives the default for it, as for thepage.updatethat already sentnull. This is a bug fix: the{}came fromnil.to_h,nilmeans "not given", and the first render now matches whatpage.updatesends.Found, not fixed here
end_refresh(every scrollable),carousel_view.animate_to_item,draggable_scrollable_sheet.animate_to, and the fivelocal_authenticationmethods.ruflet-engine's default branch (00d1df3c) has them, from 16c8bd20, 8e33d142 and ac5ad1f3 (Oct 28) and f1d03f3e (Nov 2). Only template main's vendoredruflet_packages, which 0.0.23 apps build with, lacks them. The template re-sync (D1, held for the owner) would bring them.Verified on 3fe8617 (main b28cb1c merged in)
b28cb1c (#80) changes only
packages/rufletand addstools/template_surface_revisions.rb. The PR's diff against main is the same as on a937161.MT_NO_PLUGINS=1:ruflet_core210 files (2408 runs),ruflet27 files (892 runs) andruflet_server17 files (227 runs), 0 failing and no file with 0 runs. Allruflet_corefiles in one process on 4.0.5: 2408 runs, 0 failures, 1 skip (dsl_presented_controls_testwantsRUFLET_ENGINE_ROOT).compat.rb --jobs 4checked 358 goldens (rc 0, none changed);compat_goldens_test: 366 runs, 0 failures.ruflet_rails(its HTML<map>buildsMapControl):bundle exec, exported tree, one process per file: 19 files, 0 failing.ruflet_core,ruflet_server,ruflet_record,ruby_runtime, the harness and the build script) are the same on 3fe8617:client_state_readers,event_client_value,icon_deferral,scoped_helper,ruflet_gem,ruflet_record_gemand the in-process test pass.compat_testandregexp_teststop at the same two failures as before (SystemExitat line 67,partitionwith a Regexp at line 132).toolsandruby_runtimeare identical to main's.nilprops into_patch,page.addand a parent's patch, thenilmethod arguments,nilHash values, and the coordinate aliases and edges. mruby'snilhasto_htoo, so the VM sent{}as well.invoke_nil_values_test7 of 7 and the 13nilspec calls (main's six helper files),control_nil_props_test3 of 4 (main'scontrol.rb), and 4 of 10 map tests (main's two map files; 3f48810'smap_control.rbfails theinitial_center: niltest).kotlin-stdlib:2.0.21at plugins.gradle.org and passed on rerun (attempt 2).