Skip to content

Test what every control and service method sends; fix unset values sent as {} and map stack overflows - #87

Merged
AdamMusa merged 23 commits into
mainfrom
test/method-contracts
Nov 21, 2026
Merged

AdamMusa merged 23 commits into
mainfrom
test/method-contracts

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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

MethodContractCoverageTest lists every public method that a control, service or shipped extension adds to Ruflet::Control, or replaces in it (flashlight.on). It fails for any method without a spec in test/support/method_contracts/.

For each spec, the generated test:

  1. calls the method on a mounted control;
  2. checks the invoke_control_method payload: control wire id, method name, args;
  3. answers the call the way the client would;
  4. checks that the reply reaches on_result, or that a blocking *_sync method returns it.

Where a method converts an argument, its spec passes a value the conversion changes: a Pathname, URI or Symbol where it calls to_s, a String and a Float where it calls to_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 under also:. 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. Other also: calls cover a window edge the table does not name, geolocator.get_current_position without a configuration, and the top-level nil calls 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 : false and pack, renames each when "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's formats is a constructor prop; no method passes a top-level data: to service_args; Page#invoke already stringifies camera's method name; three are in LocalAuthError.from_error). Two more sets of planted bugs, 21 and 64 (the reviews' coordinate and nil cases, the six helpers' nil branches, the to_patch fix below, and the coordinate edges: longer and one-item Arrays, an object whose to_h gives nil), 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

  • Before: per-service tests under page_*_service_test.rb, mostly checking method names. Nothing failed when a method had no test.
  • After: 256 methods are tested end to end in 296 calls, across 20 services and 42 controls, qrcode_scanner included. 52 methods that only work in Ruby are documented.

Bugs fixed (each with regression tests)

  1. Map coordinates overflowed the stack. MapControl#normalize_coordinates and the DSL's map_coordinates turned nil into nil.to_h ({}), then called themselves on Hash#to_h forever. So map.move_to without destination: always raised SystemStackError, and so did Ruflet.map(initial_center: nil) and any Hash without latitude and longitude.
  2. Unset method arguments reached the client as {}. The args helpers of camera, geolocator, secure storage, audio recorder, the shared service methods and the map control turned nil into {}, both at top level and inside Arrays. camera.lock_capture_orientation() sent { "orientation" => {} }. The renderer passes that to parseDeviceOrientation(String?), which fails. With main's versions of those six files, all 7 invoke_nil_values_test tests fail, and so do the 13 nil calls in the service specs.
  3. Unset props reached the client as {}. Control#serialize_value, which to_patch uses, had the same nil.to_h branch. Ruflet.text("x", tooltip: nil).to_patch sent "tooltip" => {}, while page.update(text, tooltip: nil) sent nil. control_nil_props_test covers it: 3 of its 4 tests fail with main's control.rb, and the fourth pins that other values with to_h still convert.

Behavior changes

Only three kinds of output change: calls that raised, nil method arguments sent as {}, and nil props 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 whose to_h gives coordinates or a prop value, Strings (still passed through), an empty Hash (still {}), a nil Hash value the helpers already left out, and polyline_marker(coordinates: nil) (still []). Tests pin each of these. The client effects below come from template main's handlers (8b08569, the same ruflet_packages as e32c873), which 0.0.23 apps build with. Its Control.get returns the default for null.

  1. A nil method argument is sent as nil, not {}. This is a bug fix: the {} came from nil.to_h, and the handlers read null as "not given".

    • These calls failed on the client and now work:
      • camera.lock_capture_orientation() now locks the current orientation.
      • camera.set_exposure_mode(nil), set_flash_mode(nil) and set_focus_mode(nil) now do nothing.
      • url_launcher.supports_launch_mode(nil) and supports_close_for_launch_mode(nil) now answer for the platform default mode.
      • file_picker.upload(nil) now does nothing.
    • camera.set_focus_point(nil) and set_exposure_point(nil) moved the point to the top-left corner: parseOffset({}) is Offset(0, 0). They now reset it, because parseOffset(null) is null.
    • No client-visible change for camera.set_description(nil), set_exposure_offset(nil) and set_zoom_level(nil) (no-ops either way), or for shared_preferences.set(k, nil) (fails either way, since setString needs a String).
    • A nil inside an Array, or kept inside a Hash, is sent as nil instead 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])).
  2. Map calls that raised SystemStackError now work, with nil meaning "not given".

    • map.move_to(...) without destination:. The keyword defaults to nil, so move_to(zoom: 9) could never be called before. The client passes the missing destination on as dest: null.
    • map.center_on(nil) sends no point. The client's center_on does nothing without one.
    • Ruflet.map(initial_center: nil), ControlFactory.build("map", initial_center: nil), Ruflet.marker(coordinates: nil) and Ruflet.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 nil now means "not given".

  3. Coordinates that cannot be read raise ArgumentError, not SystemStackError or TypeError. That covers an Array shorter than two ([], [1]), a Hash without both coordinates, an object whose to_h gives nil or neither coordinate, and a nil point in a polyline_marker or polygon_marker list. These calls raised on main too; now the error names the bad value at the call that passed it. Because SystemStackError is not a StandardError, a bare rescue now catches these errors.

  4. to_patch sends a nil prop as nil, not {}. That is what page.add sends for a new control, and what a later full patch sends (a parent's new controls list, a view rebuild). Most control classes drop a nil keyword, so the cases are:

    • an explicit nil for a keyword the class keeps: flip: and transform: on any control built by the DSL or ControlFactory; the extra keywords ControlFactory::ATTRIBUTE_OVERRIDES keeps for text and image (tooltip:, visible:, opacity:, width: and the other layout keywords), navigation_rail (scrollable:, pin_leading_to_top:, pin_trailing_to_bottom:), responsive_row and expansion_panel_list (scroll:, auto_scroll:, scroll_interval:) and ruflet_app (assets_dir:); and every prop of map and of a control built with Ruflet::Control.new. A probe that builds every ControlFactory type with each keyword set to nil finds no others: besides flip: and transform:, every prop that sent {} on main is in this list and now sends nil, except audio_recorder's configuration:, which its constructor still turns into {}, as on main;
    • a nil inside an Array or Hash prop of any control (style: { color: nil } now sends "color" => nil);
    • a prop that page.update(control, key: nil) set to nil, when the control is sent again in full.

    On the client, {} was a value: tooltip: {} built a Tooltip with neither message nor richMessage, which Flutter asserts against, and visible: {} made get<bool> throw a TypeError (checked with dart run on the same get body). Template main's handlers for navigation_rail, responsive_row, expansion_panel_list and ruflet_app read none of their keywords above, so those change nothing on a 0.0.23 client. The engine's default branch wraps responsive_row and expansion_panel_list in its scroll surface, where auto_scroll: {} throws the same TypeError (scroll: {} reads as no scroll). Template main stores a null prop as it is (Control.fromMap), and get gives the default for it, as for the page.update that already sent null. This is a bug fix: the {} came from nil.to_h, nil means "not given", and the first render now matches what page.update sends.

Found, not fixed here

  • Template main has no client handler for some methods. These are end_refresh (every scrollable), carousel_view.animate_to_item, draggable_scrollable_sheet.animate_to, and the five local_authentication methods. ruflet-engine's default branch (00d1df3c) has them, from 16c8bd20, 8e33d142 and ac5ad1f3 (Oct 28) and f1d03f3e (Nov 2). Only template main's vendored ruflet_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/ruflet and adds tools/template_surface_revisions.rb. The PR's diff against main is the same as on a937161.

  • One process per file, on Ruby 4.0.5 and on Ruby 3.4.5 (CI's) with minitest 5.25.5 and MT_NO_PLUGINS=1: ruflet_core 210 files (2408 runs), ruflet 27 files (892 runs) and ruflet_server 17 files (227 runs), 0 failing and no file with 0 runs. All ruflet_core files in one process on 4.0.5: 2408 runs, 0 failures, 1 skip (dsl_presented_controls_test wants RUFLET_ENGINE_ROOT).
  • H1 goldens: compat.rb --jobs 4 checked 358 goldens (rc 0, none changed); compat_goldens_test: 366 runs, 0 failures.
  • ruflet_rails (its HTML <map> builds MapControl): bundle exec, exported tree, one process per file: 19 files, 0 failing.
  • Embedded VM, fresh arm64 build of a937161 (framework 0.0.23, mruby 449627d). The VM's inputs (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_gem and the in-process test pass.
    • compat_test and regexp_test stop at the same two failures as before (SystemExit at line 67, partition with a Regexp at line 132). tools and ruby_runtime are identical to main's.
    • A probe of the changed code prints the same in the VM as on CRuby: nil props in to_patch, page.add and a parent's patch, the nil method arguments, nil Hash values, and the coordinate aliases and edges. mruby's nil has to_h too, so the VM sent {} as well.
  • The tests catch the bugs (checked on a937161, whose PR files are the same). With main's lib files, the PR's tests fail: invoke_nil_values_test 7 of 7 and the 13 nil spec calls (main's six helper files), control_nil_props_test 3 of 4 (main's control.rb), and 4 of 10 map tests (main's two map files; 3f48810's map_control.rb fails the initial_center: nil test).
  • Every call the specs made on 3f48810 and on 363c06e is still made and checked.
  • CI on 3fe8617 is green: run 44871780017 (Run framework tests: 254 files, 3527 runs, 0 failures on 3.4.5; Run VM build tests; all six platform builds) and the Explorer desktop runs 44871776260 and 44871780016. Build Android failed once on Gradle not finding kotlin-stdlib:2.0.21 at plugins.gradle.org and passed on rerun (attempt 2).

…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.
#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 []
@AdamMusa
AdamMusa merged commit a668af6 into main Nov 21, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant