Repository navigation
refactor: add the Flutter client startup hook seam (WP-00 R3) - #76
Merged
Merged
Conversation
packages/ruflet/test/client_bootstrap_test.rb fixes the lib/ruflet_bootstrap.g.dart every build writes into the Flutter client: with no hooks it is the exact default ruflet-template ships (empty rufletPreRunAppHooks and rufletPostFirstFrameHooks); an unchanged file is not rewritten; hooks from registered providers render in order with one import per library; and a hook the entrypoints could not run (unknown phase, malformed import or function) is rejected.
ruflet-template's entrypoints run two ordered hook lists, one just before runApp and one after the first frame, read from lib/ruflet_bootstrap.g.dart. Ruflet::CLI::ClientBootstrap writes that file on every build, once the entrypoints and the extension selection are final. Later build features add a hook by registering a provider in CLIENT_BOOTSTRAP_HOOK_PROVIDERS instead of editing lib/main*.dart; none is registered yet, so every build writes the empty default the template ships, byte for byte (LF on every platform). H1 goldens: the 60 goldens of builds that reach client preparation gain exactly one file, lib/ruflet_bootstrap.g.dart (new, 949 bytes, empty hook lists); nothing else in any golden changes. The vendored template (e32c873) predates the hooks, so its entrypoints do not import the file and the compiled app is unchanged. Rebuild goldens stay "(no files changed)": the write is idempotent.
Every build used to write lib/ruflet_bootstrap.g.dart into the Flutter client, which changed 60 H1 goldens and added an unused file to client dirs the developer owns (RUFLET_CLIENT_DIR, ./ruflet_client, templates/ruflet_flutter_template). The template entrypoints now declare both hook lists empty themselves between // --RUFLET_BOOTSTRAP_HOOKS_START-- and // --RUFLET_BOOTSTRAP_HOOKS_END-- (AdamMusa/ruflet-template#3), so they build with every gem, released ones included. write_client_bootstrap now: - writes and deletes nothing while no provider adds a hook and nothing under lib/ imports the generated file: every build today; - with hooks, writes them to lib/ruflet_bootstrap.g.dart, imports it from lib/main.self.dart and lib/main.server.dart and replaces the marked block with a pointer. An entrypoint without the block (every released template) gets a warning naming it, and is left alone; - keeps an imported file in step (empty lists without hooks), and removes a generated file nothing imports any more. A file it did not write is never removed; - validates every hook before touching any file, and reads lib/ as bytes, so a non-UTF-8 or unreadable file cannot fail a build. The 60 goldens go back to #73's, byte for byte: compat.rb checks 160/160 against them.
AdamMusa
added a commit
to AdamMusa/ruflet-template
that referenced
this pull request
Nov 8, 2026
Released gems (0.0.19 to 0.0.23) fetch template main at build time and, for a client outside build/client (RUFLET_CLIENT_DIR, ./ruflet_client), refresh lib/main*.dart file by file. They never write lib/ruflet_bootstrap.g.dart, so entrypoints that import it stop compiling there. The entrypoints now declare both hook lists empty themselves, between // --RUFLET_BOOTSTRAP_HOOKS_START-- and // --RUFLET_BOOTSTRAP_HOOKS_END--, next to the RufletBootstrapHook typedef and the runner, and import nothing new. The template no longer ships lib/ruflet_bootstrap.g.dart. Only while a build feature adds hooks does `ruflet build` write that file, import it and empty the marked block (AdamMusa/ruflet#76). The import section is byte-identical to e32c873 again, so the CLI's import edits are unchanged too. The conformance test now checks that the template does not ship the generated file, that the entrypoints import only files the template ships, and that the marked block holds exactly the two empty lists. It fails on e32c873 and on the previous head 8c7e36a.
Keeps this branch stacked on ruflet#73 (WP-00 H1) as it stands now, so the H1 goldens this PR must leave unchanged are #73's current 226.
No build feature registers a hook provider yet, so neither the unit tests nor the H1 goldens could see whether prepare_flutter_client calls write_client_bootstrap at all: deleting the call, moving it before the extension check, or dropping its platform:/self_contained: arguments left every test green. That matters while this branch has to be merged with R1 (split build_command.rb) and R2 (command registry), whose conflict resolutions could drop the call silently. The new tests run the real prepare_flutter_client against the H1 fixture template plus the marked block ruflet-template#3 ships, with only the flutter/dart/pod commands faked (pub get writes the package config the build then verifies). For a server-driven web build and a self-contained iOS build they pin that: * the provider runs once, with this build's config, platform and self_contained; * the generated file and the two routed entrypoints are the only files that differ from the same build without hooks; * the provider runs after the extension selection is applied and verified, sees the pruned entrypoints, and runs before flutter pub get; * a build that stops at the extension check runs no hook and writes nothing; * without a provider the build writes no generated file, warns about nothing and leaves the marked block in place.
…WP-00 R3)
client_bootstrap_imported? built its glob pattern from the client path,
so a RUFLET_CLIENT_DIR or ./ruflet_client under a directory named like
"my app [v2]", "proj{1}" or "a,b{c,d}" matched no Dart file. With hooks,
the entrypoints were routed to lib/ruflet_bootstrap.g.dart, the scan then
found no import, and the file was never written, so the client stopped
compiling. Without hooks, the same miss would have deleted a generated
file an entrypoint still imports.
The client's lib/ is now the glob's base, never part of its pattern. No
build today is affected: no build feature registers a hook provider yet,
and without one the entrypoints never import the file.
Keeps this branch stacked on ruflet#73 (WP-00 H1) as it stands now, so the H1 goldens this PR must leave unchanged are #73's current ones.
With no hooks, write_client_bootstrap wrote lib/ruflet_bootstrap.g.dart whenever a lib file imported a path ending in that name, and overwrote whatever was there (review probes A and B). A build without hooks now writes, edits and deletes nothing unless the file starts with the generated header, which only a build with hooks writes; that file keeps the refresh-while-imported and remove-when-unimported behavior. - A lib/ruflet_bootstrap.g.dart without the header (the developer's own file, a directory, a symlink, an unreadable file) is never overwritten or deleted. A build with hooks warns and leaves it and the entrypoints alone. - Only an import that resolves to this client's lib/ruflet_bootstrap.g.dart counts: relative to the importing file, or package:<the client's pubspec name>/ruflet_bootstrap.g.dart, in either quote style. package:other/... does not. - With hooks, a CRLF entrypoint stays CRLF, and the import goes after a last import that spans lines or ends in a // comment. Tests: probes A and B, the hooks-plus-foreign-file warning, symlinks, import resolution and the pubspec name, unreadable files and dirs (rescue SystemCallError), multi-line and commented last imports, and a CRLF entrypoint.
…F-8 entrypoints (WP-00 R3) The keep-or-delete decision now counts every import, export and part directive and every URI in it (a conditional import's alternatives included), with the same patterns as ruflet-template's conformance test. Before, a lib file that only exported the generated file, or named it as a conditional alternative, saw it deleted by the next build without hooks and stopped compiling. Routing an entrypoint reads and writes bytes and scans a scrubbed copy, so a build with hooks no longer raises ArgumentError on an entrypoint that is not valid UTF-8, and keeps its other bytes. Tests: both review probe cases, the non-UTF-8 entrypoint, a dangling symlinked bootstrap, '/ruflet_bootstrap.g.dart' and 'x:/../' URIs, an entrypoint that imports the file without the block, a missing entrypoint, and an entrypoint that only exports the file. No build adds hooks yet, so no build today reaches any of this.
#75 split build_command.rb into cli/build/ modules and turned prepare_flutter_client's steps into registered contributors. The seam is carried into that layout: - build_command.rb requires client_bootstrap and includes ClientBootstrap next to FlutterSdk, as before. - The write_client_bootstrap call, which ran right after the extension selection was applied and verified, is now the startup_hooks contributor (cli/build/contributors/startup_hooks.rb), registered after :extensions, so it still runs at that point, before assets and before Flutter. - build_contributors_test pins startup_hooks in that place in BUILT_IN and checks that the contributor passes the build on and always continues.
Without hooks, the generated file stays while a directive under lib/ names it. The directive pattern only saw a directive at the start of a line, so `import 'a.dart'; export 'ruflet_bootstrap.g.dart';` or `/* hooks */ export 'ruflet_bootstrap.g.dart';` let the build delete a file that line still needed. A directive now also counts after another directive or a block comment on its line. Text that only looks like one after a semicolon keeps the file too, the safe direction. CLIENT_BOOTSTRAP_DIRECTIVE stays character for character the DIRECTIVE of ruflet-template's conformance test, which changes with it. Tests: the directive tables gain those forms (and `part\tof`, a mid-line `part of`, a block-commented directive that does not count), an entrypoint with the block but no import line gets the import as its first line (plant N19), and no package name never matches 'package:/'. No build adds a hook yet, so no build changes.
This was referenced Nov 20, 2026
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.
Head
36b98ef8containsmaina9b58473(#73 H1 goldens, #74, #75, #70, #83, #88, #77, #86, #71), merged with merge commits (44577a93, thenb0baf549,e624fec9,ad36f12c,003bc899and36b98ef8). Againstmainit changes five files (git diff --stat a9b58473 36b98ef8): the newclient_bootstrap.rb(+363), the newbuild/contributors/startup_hooks.rb(+27),build_command.rb(+4), the newclient_bootstrap_test.rb(+1,245) andbuild_contributors_test.rb(+26 −2). Companion: AdamMusa/ruflet-template#3 (08c4a00).What
WP-00 R3, CLI side:
Ruflet::CLI::ClientBootstrap. Later build features (WP-02/06/08/09) use this seam to add startup hooks to the Flutter client.CLIENT_BOOTSTRAP_HOOK_PROVIDERSis empty and frozen, so no feature adds a hook yet.In #75's layout,
write_client_bootstrapruns as thestartup_hooksbuild contributor. It is registered right after:extensions, so it runs once the extension selection is applied and verified, beforeassetsand beforeflutter pub get. That is the point whereprepare_flutter_clientcalled it before the split. The contributor always continues the build.lib/ruflet_bootstrap.g.dartexists and starts with the generated header. Only a build with hooks writes such a file.lib/names it, and removed once none does.lib/main.self.dartandlib/main.server.dart. It also replaces their marked block (ruflet-template#3) with a pointer comment.//comment.lib/ruflet_bootstrap.g.dartrelative to the importing file, or bepackage:<the client's pubspec name>/ruflet_bootstrap.g.dart, in either quote style.package:other/…,dart:, other schemes and absolute paths never count.import,exportorpartdirective counts (notpart of), through any of its URIs, a conditional import's alternatives included. The directive may start a line, or follow another directive or a block comment on its line. A//comment does not count. Text that only looks like a directive after a semicolon keeps the file too, which is the safe direction. ruflet-template#3's conformance test uses the same two patterns.importdirectives that start a line decide whether an entrypoint still needs the import.lib/that cannot be read. A file that is not valid UTF-8 is scanned with its invalid bytes replaced, so a directive in it still counts. With hooks, an entrypoint that is not valid UTF-8 is routed too, and every byte outside the lines that change is kept.Behavior changes
None. No provider exists, so
ruflet buildwrites, edits and deletes exactly what it did before. The H1 goldens below show this.This round:
startup_hookscontributor at the same point of the build.build_contributors_testpins it inBUILT_INafterextensions, and a new test checks that it passes the client dir, config,platformandself_containedon and continues whateverwrite_client_bootstrapreturns.import 'a.dart'; export 'ruflet_bootstrap.g.dart';or/* hooks */ export 'ruflet_bootstrap.g.dart';lost the file in the next build without hooks. Only a build with hooks can reach this, and none does yet.Evidence
All run 2026-11-19 and 20 on
c3604c40, with Ruby 4.0.5 and Flutter 3.41.2 unless marked.b0baf549to36b98ef8only mergemain:caa4ca95(#83: theruflet_railsandruflet_recordGemfile.lock files, two VM harness tests, a stray0.0.8file),a309af55(#88: four newruflet_coretest files)c444cbd5(#77: the CLI command registry and 56 CLI goldens),9202eb0c(#86: control contract tests and amaterial_control_registry.rbwire-type fix) anda9b58473(#71:ruflet_coreclient state readers and their tests). None of them touches a file this PR changes, and this PR's diff againstmainis byte-identical togit diff dd924eb3 c3604c40.On
36b98ef8: everypackages/ruflettest file on its own: 21 files, 0 failures, 0 errors (client_bootstrap_test39 runs,build_contributors_test10,compat_goldens_test298).compat.rb --jobs 4: 290 goldens, exit 0.ruflet_railsper file underbundle execon an export of the tree: 17 files, 0 failures, Gemfile.lock unchanged. fix: read client-synced control state like event.control.value #71'sclient_state_readers_testandcontrol_value_readers_wire_test: 0 failures. The same set passed on003bc899with Test every control, service and shipped extension against its wire contract #86's eightruflet_coretest files, and one624fec9with Test every public Page method; check client actions against their services #88's three.client_bootstrap_test.rb: 39 runs, 425 assertions, 0 failures, withLANGunset,Canden_US.UTF-8. On Ruby 3.4.5 with minitest 5.25.4 (pinned through a scratch Gemfile): 39 runs, 414 assertions, 0 failures, in all three locales. The gap is the minitest 5/6 helper count difference noted in earlier rounds.build_contributors_test.rb: 10 runs, 64 assertions, 0 failures, in the same three locales on both Rubies.Every
packages/ruflettest file run on its own (ruby -Ilib -Itest <file>,LANGunset): 19 files, 552 runs, 0 failures, 0 errors. The other packages are unchanged againstmain.Plants. 42 changes planted one at a time, each run against both test files; all 42 fail at least one:
true, registered before:extensions, registered after:assets(fails to load), all arguments or onlyself_containeddropped; the directive anchor back at line start, without the after-;case, without the after-*/case, or dropped entirely (so// export …counts);unshift→pushfor an entrypoint without imports (review plant N19);part\tofcounted (N27); a nil package name acceptingpackage:/…(N30);H1. On
c3604c40,compat.rb --jobs 4checks 234 goldens and exits 0, andcompat_goldens_test.rbgives 242 runs, 552 assertions, 0 failures.git diff a9b58473 36b98ef8 -- packages/ruflet/test/compat packages/ruflet/test/compat_goldens_test.rbis empty.H1 with template push new version to rubygem #3 vendored.
compat.rb vendor-template --ref 08c4a00, then--regenerate --jobs 4, onc3604c40and onmaindd924eb3(this PR changes no file undertest/compat): the two sets of 234 goldens are byte-identical (diff -ris empty), and none mentionsruflet_bootstrap.g.dart. Against the committed goldens, 140 differ in 383 lines, the same for both: 227 "files identical" lines, and 156lib/main*.darthash and size lines.Live
ruflet build web. Each run uses a freshruflet newapp. The template is fetched live from a scratch bare repo whosemainis08c4a00, with a freshRUFLET_CACHE_DIR. TheRUFLET_CLIENT_DIRclient starts as a copy ofe32c873.build/clientError:lines;flutter test+7build/clientplatform=web self_contained=false. The file is written and both entrypoints import it.flutter test+7RUFLET_CLIENT_DIRwhoselib/mine.dartisimport 'connection_probe.dart'; export 'ruflet_bootstrap.g.dart';build/clientmain.dart.js8,124,849 B, the same size as this branch without the probe;flutter test+7The probe is a test-only
ruby -rpreload that registers 2 hooks, and it is not part of this PR. The released-gem rows are in ruflet-template#3.CI at
36b98ef8: Build Ruflet Client Prebuilds run 44779432821 (Verify Ruflet Explorer and the Android, iOS Simulator, macOS, Windows, Linux and web builds) and Test Ruflet Explorer Desktop Builds runs 44779432816 and 44779423417 are green. Build Android first failed while Gradle resolved its plugins (Maven Central answered "Resource missing" fororg.jetbrains.kotlin:kotlin-stdlib:2.0.21). This PR changes nothing Android or Gradle reads, and the job passed on every earlier head. Its rerun (attempt 2) passed.Open PRs (
git merge-treeagainst36b98ef8): feat: warn when the template lacks a control, service or extension the app uses (CRIT-04b) #80 conflicts inbuild_command.rb, on the include line next toinclude ClientBootstrap(keep both); it also conflicts withmainincli/commands.rb. fix: resolve path-valued Flutter build flags against the project (CLI-05) #79 and CLI: cover every command and option, fix what the tests exposed #84 already conflict withmain. fix: report bad flags with the command's usage; add ruflet help <command> (CLI-12) #78, fix: carry mruby's method_missing splat-keyword fix (550d10a) on the pinned VM #81, Stop single icon lookups from building the constant-name index #82, Test what every control and service method sends; fix unset values sent as {} and map stack overflows #87, ruflet_server: test every protocol action on both receivers and every codec format; normalize invoke replies like ConnectionProtocol #89 to Register extension packages inside the extensions list, not the import block #91, fix: a raising event handler no longer ends the ruflet_rails session #97 to fix: send default alignment, padding and radius in shapes the renderer reads #100, ruflet_rails: run each WebSocket message in its own Rails executor (fixes dev hang after code edits, stale query cache, leaked DB connections) #102, fix: keep a control's typed or picked value a String in event data #103, ruflet_record: open-ended ranges in where (18.., ..17, ...18) no longer match nothing #107, fix: page.update encodes show_*_icon booleans and leading/trailing icon names like construction #109 and fix: use the Flutter SDK Ruflet installed under ~/.ruflet/flutter without the network or --fix #111 to fix: keep emptied children empty after page.update(col, controls: [...]) #113 merge cleanly.Release coupling
No release order is needed. No build writes anything new until a feature registers a provider. Merging ruflet-template#3 ships it to every user, so the owner merges it (D1).