Skip to content

feat: add design-neutral control core - #81

Merged
AdamMusa merged 1 commit into
codex/engine-initializationfrom
refactor/control-core-foundation
Nov 2, 2026
Merged

AdamMusa merged 1 commit into
codex/engine-initializationfrom
refactor/control-core-foundation

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What

Foundation (F0) of the shared design-neutral core + thin native skins (DECOUPLING_SPEC §2–§4, lead decisions DC-1..DC-9). New files only, no behaviour change: nothing in lib/ uses the core yet; Switch, Checkbox and Radio migrate onto it in the stacked PRs that follow.

Kernel (lib/src/core/, widgets layer only)

File Role
control_spec.dart ControlSpec / PropSpec / EventSpec / MethodSpec (pure data, toJson() for reuse, DC-9): every key Ruby can send, every event and method, and which skins must honor each, with a mandatory reason for single-skin entries.
control_core.dart (+ parts prop_reader.dart, control_events.dart, core_host.dart) One library so Control stays library-private (DC-1). ControlCore<P> (typed props parsed once per build, @protected lifecycle, writeBack, markNeedsBuild, decorate, shared states), FocusableCore (one FocusNode, focus/blur events and methods), PropReader (the only caller of control.getX; debug asserts on undeclared keys or wrong types, CoreReadLog for C6), ControlEvents (the only triggerEvent call site; callbacks are null without a subscription or while disabled unless whileDisabled), CoreHost (the only invoke listener, layout wrapper and props parse; moves its listener when Ruby replaces the Control in place; removes it on unmount).
toggle_label.dart ToggleLabel (one merged semantics node, one tap target, click cursor while enabled) and TileToggleCore (one toggle_inputs ListTile subscription per core, ignored while disabled).
core_semantics.dart, raw_prop.dart, text_or_widget.dart Neutral values/widgets the specced migrations need (accessibility a native widget cannot take, design-bound raw values, text-or-child-control labels).

Contract test (test/architecture/control_core_contract_test.dart)

Driven by test/architecture/core_manifest.dart (empty here; one entry per migration PR):

  • C1 skin isolation (no Control-facing import, extension-on-Control libraries only with a show list, no Control/triggerEvent/updateProperties/invoke-listener/LayoutControl/BaseControl tokens); flutter analyze (fatal warnings) covers the @protected members.
  • C2 core purity via the existing PlatformDependencyGraph: the kernel and every manifest core import no design and reach neither.
  • C3 spec == Ruby KEYWORDS (from the checked-in surface, below), minus framework keys and the keys the chosen layout wrapper applies.
  • C4 skin consumption (each field consumed by every listed skin, or by the shared core for both-skin values, and by no other skin; skin-sourced event callbacks exist and are wired; port methods implemented).
  • C5 lifecycle, C6 completeness, C7 event + semantics parity: widget tests per entry on iOS and Android.
  • C8 legacy ratchet: legacy_renderers.txt (88 design files on the old Control pattern) only shrinks; report-only until the queue drains (DC-6, enforceLegacyRatchet).

The static rules are pure functions in test/support/core_contract.dart, proven with adversarial fixtures; C5–C7 also run against a test-only probe core (test/support/core_probe.dart), so the runners are proven while the manifest is empty.

Snapshot harness and Ruby surface

  • test/support/control_harness.dart, test/support/control_snapshot.dart: JSON snapshots (geometry, exposed semantics, messages sent to Ruby per scripted step, invoke outcomes), rewritten only with --update-goldens. Migration PRs commit them against the legacy renderer first.
  • test/contract/ruflet_control_surface.json: generated by chore: export the control surface for the engine contract ruflet#59 (tools/control_surface.rb, contract v2) from ruflet main @ 816c862f; refresh with ruby tool/sync_ruby_surface.rb --ruby <ruflet checkout> [--check]. Engine CI only reads the copy.

Adaptations of the spec (documented, minimal)

  1. ControlSpec.sharedLayoutKeys (new): keys the core reads while LayoutControl still applies them. The spec's Switch sketch owns width/height, which makes LayoutControl skip sizing entirely and would drop animate_size for sized toggles; the legacy renderers let LayoutControl size and scaled inside. ownedLayoutKeys keeps the spec meaning (wrapper skips them, e.g. a future ListSection margin).
  2. Extra PropTypes stateBorderSide and outlinedBorder (Checkbox border_side/shape), and PropReader.optionalBoolean/has.
  3. textOrWidget returns a neutral TextOrWidget value instead of a Widget, so each skin styles plain-text labels natively while child-control labels keep their own style (exactly the legacy behaviour).
  4. CoreHost throws fix: fail fast on invoke methods no handler claims #59's UnsupportedError text itself for a method its spec does not declare. With exactly one listener per migrated control, nothing else can claim the name, so this is the fail-fast F2 will generalize; F2 (Control.declinedInvoke) switches it to the sentinel once fix: never crash invoke handlers on nil or missing args #52/fix: fail fast on invoke methods no handler claims #59 land. Invoke args are normalized like fix: never crash invoke handlers on nil or missing args #52's invokeArgs (private copy until fix: never crash invoke handlers on nil or missing args #52 merges).
  5. OverlayCore/CoreBuilder/dialog routes and skin ports are not in F0: the spec introduces them with AlertDialog (item 12) and CarouselView; C4 already checks ports via the manifest's portInterface.
  6. C3 ignores the factory-wide common_attributes (flip, transform): every Ruby control accepts them and LayoutControl applies them.

Round 2: QA review changes (all twelve QA mutations now fail the contract test)

QA's mutation run ($SP/qa/contract_mutations.sh, re-run against the rebased Switch tree) now gives 12/12 failing: M4 is caught by C4, M8 by C2b and M12 by C7. Each mutation is also checked into the contract test as a negative fixture (group "QA mutations").

QA item Change
(A) core consumption was inferred from any mention of the field PropSpec.consumer (PropConsumer.skins by default, or PropConsumer.core). C4 now requires every listed skin to reference a skin-consumed field, whatever the core does (M4). A core-consumed field must be referenced by the core, by no skin, and must apply to both skins.
(B) a core subclass could keep and expose the Control New rule C2b: every manifest core and every non-kernel lib/src/core library follows C1's import and token bans (Control, the Control model/extension libraries, the public barrel...). Core class constructors may only forward super. parameters: no other parameters, no initializers, and the parameters are not used in the body. dynamic is banned in skins and cores, which closes the untyped variant (ToggleCore(dynamic c) : qa = c, super(c)). Only the kernel library (control_core.dart + parts) holds a Control.
(C) PropReader.raw() could hand a child Control to a skin Debug assert: a raw value (deep through maps and lists) must not contain a Control. RawProp equality is now deep.
(D) C7 never exercised the skins' native gesture path Manifest entries declare nativeWidgets per skin; the new SnapshotStep.tapNative() taps it with a pointer. C7 fails if the script has no tap native step or if any step could not run (M12).
(E) the one-listener check counted only CoreHost listeners C5 counts every invoke listener on the Control. CoreHost answers a debug-only census method; Control.invokeMethod returns one result per listener (a list for several), and a foreign listener that rejects the name fails the call. This is done without touching models/control.dart, which open PRs #52/#59/#79 edit. In release builds the census name is an ordinary undeclared method.
(F) "declared means fired" was not proven for core events C7 now fails unless the parity script makes the control fire every EventSource.core event on both designs; SnapshotStep.unfocus() drives blur. An event a script truly cannot drive must be listed in unexercisedEvents with a reason.
#52 invokeArgs #52 has not merged, so the private copy stays, with TODO(#52).

The runtime rules now return their problems instead of asserting, so the negative fixtures can prove them: M11 uses a forgetful probe core (C6), M12 a probe whose Material skin inverts the value (C7), and (E) adds a stray and a rejecting listener (C5). M10 mutates the kernel itself; C5 catches it on the real host, as QA confirmed.

Tests

  • test/core/control_core_test.dart (26, incl. the raw() guard): one skin per design; one parse per build with previous props; markNeedsBuild; decorate; layout/base/none wrappers and skipped owned keys; every PropType parser (+ typed child lists); undeclared/wrong-type reads assert; subscribed-only events after the write-back; null callbacks without a subscription or while disabled (whileDisabled kept); undeclared events assert; declared method answered by exactly one listener (scalar result); nil args; undeclared or unhandled methods fail fast with fix: fail fast on invoke methods no handler claims #59's message; in-place control replacement re-binds the listener (old 0 / new 1, invokes and events reach the new instance, same element and core); unmount unregisters and disposes (incl. the FocusNode); focus/blur identical on both designs.
  • test/core/toggle_label_test.dart (8), test/core/core_values_test.dart (5), test/core/control_snapshot_test.dart (4).
  • test/architecture/control_core_contract_test.dart (C1–C8 incl. C2b, adversarial fixtures, probe runners, and the 12 QA mutations as negative fixtures).

team/verify_pr.sh on head 02c2d4b (base 81609d0) with ruflet origin/main (b5fd1694): PASS: engine flutter test +945 all passed, flutter analyze lib test no issues, ruflet_core 153/153 files (687 runs), wire-key audit 0 new findings. (Round 1 was 9fb2161, +834.)

Dependencies

  • Pairs with chore: export the control surface for the engine contract ruflet#59 (generator of the checked-in JSON; not needed to build or test this PR).
  • No open PR touches these paths (gh pr list file check on lib/src/core/, test/architecture/, test/support/, test/contract/, test/core/, tool/). New files only, so it merges cleanly onto any base.

Add the shared control kernel every control will migrate onto: a pure-data
ControlSpec, PropReader as the only reader of wire keys, ControlEvents as the
only event dispatcher, ControlCore/FocusableCore for client state and focus,
and CoreHost as the single owner of a control's invoke listener and layout
keywords (re-bound when Ruby replaces the control in place). ToggleLabel,
TileToggleCore, CoreSemantics, RawProp and TextOrWidget are the neutral
pieces the first migrations share.

The control-core contract test checks every migrated control against rules
C1-C8 (skin isolation, core purity, spec equals Ruby KEYWORDS, skin
consumption, lifecycle, completeness, event and semantics parity, and a
report-only legacy ratchet). The manifest starts empty; the runtime rules run
against a test-only probe core and the static rules against adversarial
fixtures. The JSON snapshot harness and the Ruby control surface copy (with
tool/sync_ruby_surface.rb) support the migration PRs.
@AdamMusa
AdamMusa force-pushed the refactor/control-core-foundation branch from 9fb2161 to 02c2d4b Compare October 29, 2026 00:56
@AdamMusa
AdamMusa merged commit 46ca4b0 into codex/engine-initialization Nov 2, 2026
AdamMusa pushed a commit that referenced this pull request Nov 3, 2026
Follow-up to #81 (design-neutral control core). PropReader resolves every
theme-dependent value against RufletStyleTheme.of(context), and on iOS
that was the root scope the Cupertino app renderer computes once outside
any dialog. The pre-core Cupertino renderers resolved their state maps
against cupertinoStyleTheme(context) at the control, which sees the
CupertinoUserInterfaceLevel.elevated that CupertinoAlertDialog, action
sheets, modal popups and sheets install. So in dark mode a Switch
`thumb_color: {selected: "surface"}` or a Checkbox `fill_color` /
`border_side` / `label_style` inside a Ruby AlertDialog or BottomSheet
became 0xFF000000 instead of the elevated 0xFF1C1C1E.

RufletStyleThemeScope can now carry a design-supplied `localTheme` that
RufletStyleTheme.of consults for the reading context. The Cupertino app
renderer and CupertinoControlTheme install their scope through the new
cupertinoStyleThemeScope, which returns the theme for the reader's own
interface level when it differs from the scope's (each level resolved
once per scope). The kernel and style_theme.dart stay design-neutral, and
Material scopes set no localTheme, so Material is unchanged. Plain colours
read on an elevated surface now get the elevated shade too, so a
control's `active_track_color: "surface"` and `thumb_color` no longer
disagree (before #81 plain colours stayed on the root shade).

elevated_surface_colors_test.dart mounts through the real PlatformApp in
dark mode with one control of every migrated core (Switch, Checkbox,
Radio, Button, IconButton, ListTile, ProgressRing, AppBar) painting
"surface": base shade on the page, elevated in an AlertDialog and a
BottomSheet and under a control theme in a dialog, and the theme surface
in a Material dialog. The dialog and sheet cases fail without the fix
(every core gave 0xFF000000). The harness installs the same scope as the
app renderer. test/architecture: 298/298; dialog, sheet, Cupertino,
snapshot, theme and core widget tests: 1076/1076.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MqfxcsDiEUZngybe9L72JQ
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