Skip to content

Test every control, service and shipped extension against its wire contract - #86

Merged
AdamMusa merged 8 commits into
mainfrom
test/control-contracts
Nov 20, 2026
Merged

AdamMusa merged 8 commits into
mainfrom
test/control-contracts

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Part of the release-readiness test pass. This PR adds a wire-contract test for every control, service and shipped extension in ruflet_core. Invoke methods, Page APIs, ruflet_server, ruflet_rails and ruflet_record follow in separate PRs.

What's tested

ControlContractCoverageTest enumerates every name ControlFactory resolves, plus the extensions Ruflet ships. That covers CLASS_MAP, which merges RufletControls, PlatformControlContracts and RufletServices. The test fails for any class without a spec in test/support/control_contracts/. Its exceptions list is empty.

Each spec states the wire type, every alias the factory registers, the props the control can't be built without, and any prop or event sent under a different key. From that, each class gets three generated tests:

Test Asserts
test_<type>_wire_type_and_names _c; each alias builds the same class and wire type; TYPE_MAP agrees for an untyped Ruflet::Control; the Ruflet.* helper builds it
test_<type>_props_serialize_under_ruby_keys each prop, set on its own, reaches the patch under its Ruby wire key
test_<type>_events_attach_and_dispatch each on_* flags the event on the wire, and the handler runs once with the control when the client sends the event to the mounted control

Props and events come from ControlFactory.constructor_keywords. That is the class's KEYWORDS, or its constructor's keyword parameters when it has no KEYWORDS constant (40 classes, for example badge, banner, divider and tab; 12 more have neither and are open-schema). A keyword added later is tested without editing the spec.

Open-schema classes. 51 classes have no constructor keywords and pass any prop through: video, web_view, map with its layers, markers and attributions, the three ads, lottie, rive, code_editor, the six color pickers, data_table2/data_row2/data_column2, and every chart class plus chart_axis and chart_axis_label. For these:

  • the spec lists under props: and events: the names the engine's renderer reads (ruflet-engine codex/engine-initialization f44e7df). That is 458 props and 77 events over 50 classes. map_layer lists none, because the engine has no MapLayer renderer;
  • each is also checked with one prop and one event that no renderer reads;
  • the coverage test fails for an open-schema spec with no props: (map_layer is the one listed exception).

The lists are copied from the engine source. A rename in the engine does not fail here.

Coverage

  • Before: 126 hand-written compatibility test files (680 tests), each covering a subset of one control's props. Nothing failed when a control had no test.
  • After: 263 classes under 459 names, with 7,216 props and 782 events. Of those, 6,707 props and 654 events come from constructor keywords, 458 and 77 are listed for open-schema classes, and 51 of each are the probes. By family: 107 Material, 24 Cupertino, 80 shared, 25 platform contracts, 26 services and 1 extension.

The renames the specs record are the deliberate ones: dropdown_m2's Material 2 spellings (DropdownControl::MATERIAL2_RENAMES), cupertino_switch's *_thumb_image → *_thumb_image_src, and the service registry's _services.

Behavior changes

ControlRegistry::TYPE_MAP still held old Flet wire names. Ruflet::Control.new(type: ...) for these six types therefore sent a different _c from the class-built control. The fix is its own commit (d0158cc). Its regression test, test/untyped_control_wire_type_test.rb, fails 6 of 6 on main.

type: _c on main _c now
windowdragarea windowDragArea WindowDragArea
datarow r DataRow
datacell c DataCell
datacolumn c DataColumn
option dropdownoption Option
dropdownoption dropdownoption DropdownOption

The underscore spellings change the same way, because Control#wire_type looks up TYPE_MAP[type.delete("_")]: window_drag_area, data_row, data_cell, data_column and dropdown_option.

  • windowdragarea now renders. The engine matches only "WindowDragArea" (ruflet_core_extension.dart). For windowDragArea it showed "Unknown control" (control_widget.dart:40).
  • For the other five, only _c changes. DataTable and Dropdown read rows, cells, columns and options by slot without checking _c, so these rendered before and render the same now.
  • Only untyped Ruflet::Control instances change. Controls built by the factory, the Ruflet.* helpers or the DSL use the class's WIRE and do not change. The factory builds an untyped Control only for a name it does not register, so an unregistered spelling that strips to one of these keys changes too: ControlFactory.build("window_dragarea") sends WindowDragArea (main: windowDragArea). No code in packages/ passes such a name itself; app code that passes one to the factory, through the DSL or ruflet_rails, gets the new _c.

The commit message of d0158cc calls the old names "a type no current client renders". That is true only of windowDragArea. The test's comment is corrected in b4ec646; history is not rewritten.

Verified on 3074b71 (main caa4ca9 merged in)

  • ruflet_core, one process per file: 198 files, 1887 runs, 0 failures, 1 skip, on Ruby 4.0.5 and on 3.4.5 (CI's). All files in one process on 4.0.5: 1887 runs, 0 failures, 1 skip. The skip is dsl_presented_controls_test, which needs RUFLET_ENGINE_ROOT. That file is unchanged.
  • ruflet_server: 13 files, 49 runs, 0 failures.
  • H1: ruby test/compat/compat.rb --jobs 4 checked 234 goldens, exit 0. compat_goldens_test.rb: 242 runs, 0 failures.
  • With main's material_control_registry.rb planted, untyped_control_wire_type_test.rb fails 6 of 6.
  • Planted bugs, each against an archive of this head:
    • VideoControl drops every prop and handler: 2 failures. The same bug passed on the previous head 7bcd125.
    • Video drops only volume: 1 failure.
    • Video gets a KEYWORDS schema that lacks volume: 1 failure.
    • The shared base of the 14 map layer, marker and attribution classes drops every prop: 28 failures.
    • The ads drop their on_* handlers: 3 failures.
    • Map stops normalizing initial_center: 1 failure.
  • Embedded VM: an arm64 scratch build from this PR's sources (mruby 449627d), run with this head's harness tests.
    • Pass: icon_deferral, scoped_helper, ruflet_gem, ruflet_record_gem, and the in-process page exchange.
    • In the VM, Ruflet::Control.new(type:) sends the class's wire type for all six types above.
    • Fail: compat_test at line 67 (mruby has no SystemExit) and regexp_test at line 132 (OnigRegexp passed to String#partition). Neither touches anything this PR changes.

Gate: final head 465a92d (main c444cbd merged in, #77 and #88)

The merge touches nothing the PR changed. git diff c444cbd5 465a92d6 equals git diff caa4ca95 3074b71b.

  • ruflet_core, one process per file: 201 files, 2006 runs, 0 failures, 1 skip (dsl_presented_controls_test), on Ruby 4.0.5 and 3.4.5. Run on fbc9869f (main a309af5 merged in), whose ruflet_core and ruflet_server trees are identical to 465a92d.
  • ruflet_server: 13 files, 49 runs, 0 failures (same tree).
  • packages/ruflet, one process per file on 465a92d: 20 files, 606 runs, 0 failures.
  • H1 on 465a92d: compat.rb --jobs 4 checked 290 goldens, exit 0. compat_goldens_test.rb: 298 runs, 0 failures.
  • The underscore and factory-fallback rows above: probed on main a309af5 and on the merged head.

No template or CLI change, so apps built with published gems that fetch template main are unaffected. No files from #82 are touched.

…area controls

ControlRegistry::TYPE_MAP still held the names older Flet clients used:
"c" for DataCell and DataColumn, "r" for DataRow, "windowDragArea" and
"dropdownoption". A control built as Ruflet::Control.new(type: "datarow")
takes its wire type from that map, so it sent a type no current client
renders, while ControlFactory.build sent "DataRow" from the class's WIRE.

Make the six entries agree with their classes.
ControlContractCoverageTest enumerates every name ControlFactory resolves
(CLASS_MAP: controls, platform contracts and services) plus the extensions
Ruflet ships, and fails for any class without a spec in
test/support/control_contracts. Its exceptions list is empty.

Each spec states the wire type, every registered alias, the props the
control cannot be built without and any prop or event sent under another
key. From it, the family test files generate three tests per class:

- the wire type (`_c`), that every alias builds the same class and type,
  that TYPE_MAP agrees for an untyped Ruflet::Control, and that the
  Ruflet.* helper builds it;
- that each KEYWORDS prop, set on its own, reaches the patch under its
  Ruby wire key;
- that each on_* keyword flags the event on the wire and that the handler
  runs once, with the control, when the client sends the event for the
  mounted control.

Props and events come from the class's KEYWORDS, so a keyword added
later is tested without editing the spec.

263 classes (107 Material, 24 Cupertino, 80 shared, 25 platform
contracts, 26 services, 1 extension) under 459 names: 6,707 props
and 654 events.
The comment claimed no current client rendered the old names. Only
"windowDragArea" failed to render (the engine matches "WindowDragArea"
only and shows "Unknown control" otherwise). DataTable and Dropdown read
their rows, cells, columns and options by slot without checking the
type, so for the other five only `_c` changes.
51 classes (video, web_view, map and its layers, the ads, charts, color
pickers, data_table2, lottie, rive, code_editor) have no constructor
keywords and pass any prop through, so their props and events tests
checked nothing: VideoControl could drop every prop and still pass.

Specs can now list props: and events: to test besides the constructor
keywords. Each open-schema Material spec lists the names the engine's
renderer for it reads (ruflet-engine codex/engine-initialization
f44e7df): 458 props and 77 events. Every open-schema class is also
checked with one prop and one event no renderer reads, and the coverage
test requires props: for every open-schema spec except map_layer, which
has no engine renderer.

Also describe where the props come from correctly: the constructor
keywords, i.e. KEYWORDS or, without that constant, the constructor's
keyword parameters.
@AdamMusa
AdamMusa merged commit 9202eb0 into main Nov 20, 2026
12 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