Skip to content

feat: warn when the template lacks a control, service or extension the app uses (CRIT-04b) - #80

Merged
AdamMusa merged 16 commits into
mainfrom
feat/template-surface-check
Nov 21, 2026
Merged

AdamMusa merged 16 commits into
mainfrom
feat/template-surface-check

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

WP-00 CRIT-04(b).

#79 has merged. main (f8058191) is merged in with merge commit e77094e5, so the diff against main now shows only this PR's files. The only conflict was extra_command.rb: doctor now takes its exit code from #84's system_exit_code, then applies --strict. Earlier merge commits: 6f629781 (#79's branch, before #79 merged), 3199b905, 88669d87, 89d12dd6 and 781a20ed. This PR's own commits: 4f7e5fa6, 345aa123, b3edbfd6, f25783f9, 58f7c9d0, 383d776d, b82e3500, 626a2420, ec23981e and 3c748db5.

Depends on AdamMusa/ruflet-template#2 (CRIT-04a, prepared and not merged, per D1). #2 is at cd3b8aa0 and contains e793ccef and cdbc2aaf. The revisions table names those two commits, and they exist only on #2:

What

ruflet build, ruflet run and ruflet doctor read two things from the Flutter template:

  • tool/conformance/ruflet_control_surface.json, the wire types it renders;
  • ruflet_packages/, the extension packages it bundles.

They print a warning on stderr when the app calls a control or service the template lacks, or selects a bundled extension it lacks. The warning names the item, the file and line of its first call, and the first ruflet-template revision that has it:

warning: the Flutter template lacks 1 control this app uses:
  form (Form), main.rb:4: needs ruflet-template e793ccef345b or newer
  Template: ~/.ruflet/templates/ruflet_flutter_template (revision c0ffee00c0ff)
  An app built from this template shows "Unknown control" in place of a control it lacks.
  Fetch the latest template with `ruflet doctor --fix`, or pass --strict to fail instead.

The last line says where to get a newer template. ruflet doctor --fix refreshes only the cached template, and each of these takes precedence over it:

  • RUFLET_CLIENT_DIR: "Update the client in RUFLET_CLIENT_DIR from the latest ruflet-template (ruflet doctor --fix does not change it)".
  • RUFLET_TEMPLATE_ROOT: "Update the template in RUFLET_TEMPLATE_ROOT to the latest ruflet-template (…)".
  • A ruflet-template checkout beside this ruflet: "Update the ruflet-template checkout (…)".

The revision in parentheses comes from the checked directory's .ruflet-template-revision file. Without that file it is the installed template's revision: the cached one's, or a checkout's git HEAD. Any other directory, such as a RUFLET_CLIENT_DIR client without that file, gets no revision.

Behavior:

  • Default (D1): warn only. The exit code is unchanged, so a build that succeeds today still succeeds, including against template main.
  • --strict, new on all three commands, makes it an error:
    • build exits 1 after it copies the template into build/client, before Flutter runs or the client is configured.
    • run exits 1 before the server starts.
    • doctor finishes its report, flutter doctor included, then exits 1. If flutter doctor fails, doctor keeps that exit code.
  • Silent when nothing is missing. Nothing is checked for a template without the surface file, or for one whose surface file cannot be read. The check never raises and never fetches anything.
  • Which template is checked:
    • build checks the installed template that build/client is copied from. A custom RUFLET_CLIENT_DIR is checked as its own template.
    • run checks RUFLET_CLIENT_DIR when it names a directory. run --web and --desktop open that client, and build uses it. Otherwise run checks the installed template. Ruflet Explorer and the prebuilt clients are not built from it, so in that case the warning is about the template a ruflet build would use.
    • doctor checks the installed template it reports.

How usage is found.

  • Ripper finds receiverless calls of the names the template lacks: form(...), form do, form key: 1 and a bare form.
  • Names the app defines itself do not count. Besides def, that covers attr, attr_reader, attr_accessor, define_method, alias/alias_method, def_delegator(s), delegate, let/let!/subject, belongs_to/has_one, Struct.new and Data.define, with symbol, quoted-symbol or string names.
  • Comments, strings, symbols, local variables, calls on a receiver and longer names (form_with) do not count.
  • Files read:
    • In a Rails app (config/application.rb and app/views/ruflet/): only app/views/ruflet/**.
    • Otherwise: the project, when it has main.rb, ruflet.yaml, ruflet.yml or services.yaml. The walk skips build, vendor, node_modules, tmp, log, coverage, public, storage, spec, test, dot directories and RubyGems install directories. It reads at most 50,000 directory entries and 5,000 files, each at most 1 MB.
    • run also reads the script it was given, wherever it is.
  • No other Ruby file is read. When the template has every wire type this ruflet knows, no app file is read at all.

Extensions come from the same extensions:/services: selection the build makes. doctor reads ruflet.yaml, ruflet.yml or services.yaml only when the template lacks a bundled package, and it reads them with stderr silenced. Template main lacks ruflet_local_auth, so today doctor does read them.

Minimum revisions. The ruflet gem does not depend on ruflet_core, so the revisions come from a generated table, lib/ruflet/cli/template_surface_revisions.rb. tools/template_surface_revisions.rb builds it from this checkout's registries and the template's history, and has --offline and --check modes. Wire types are dated from 19ac4c9e, the first surface that lists every wire type its renderers handle. 33 wire types map to e793ccef, among them Form, NestedScrollView, the transitions, slivers, Table, Stepper and LocalAuthentication. Packages are dated from 0c02f475. ruflet_local_auth is at cdbc2aaf.

Rework since the review of 626a2420

  • REQUIRED (fix: resolve path-valued Flutter build flags against the project (CLI-05) #79's regression carried in): gone. fix: resolve path-valued Flutter build flags against the project (CLI-05) #79 merged with its fix, and main is merged in, so flutter_tooling.rb, build_path_flags_test.rb and cli_child.rb now equal main's.
  • run --strict checked the installed template even with RUFLET_CLIENT_DIR set (ec23981e). run now checks that client, as build does. The body's "Which template is checked" text is corrected to match. Two new H1 goldens cover it, both with RUFLET_CLIENT_DIR and with the installed template lacking Form:
    • run main.rb --web --strict with a client that renders Form: it serves, exit 0;
    • the same with a client that lacks Form: it names <PROJECT>/my_client and the RUFLET_CLIENT_DIR advice, exit 1.
  • A RUFLET_CLIENT_DIR client was given the app's git HEAD as its revision (3c748db5). Only the cached template and …/templates/ruflet_flutter_template checkouts get a git revision now.
  • The 6 plants that survived now each fail a test:
    • v01: a relative RUFLET_CLIENT_DIR in the advice;
    • v04: lines compared as numbers (9 before 10);
    • v05: doctor reading ruflet.yml;
    • v13: "1 control, 1 service and 1 extension";
    • v17: define_method(:"form");
    • v27: the ruflet.yml project marker.
  • A doctor exit-code test is new. The merge touched that line, and no unit test caught dropping --strict's exit 1.

Behavior changes

Compared with main (f8058191), exactly 24 H1 goldens differ because of this PR. All are additive, per D1 (warn by default):

Invocation main This PR
build/run/doctor where the app calls a control or service the template lacks (form against template main) silent; the control shows "Unknown control" on device the warning on stderr; exit code unchanged
build where a selected bundled extension is missing from the template (services: [biometrics] against template main) build config error: selected Flutter extensions are missing: ruflet_local_auth, exit 1 the same error and exit code, after the warning naming cdbc2aaf
build … --strict --strict forwarded to flutter build (Flutter 3.41.2: Could not find an option named "--strict", exit 64) read by ruflet: exit 1 when something is lacking, otherwise the same build without it
run … --strict, doctor --strict invalid option: --strict, exit 64 read by ruflet, as above
build/run/doctor -h/--help, help build, --help build, run/doctor --bogus-flag — one more line listing --strict

The goldens:

  • build-apk--self-form, run-main.rb-form, doctor-form;
  • build-{apk,ios}--self-biometrics;
  • build-apk--self--strict[-form], build-apk--self--strict-form-explicit-template;
  • run-main.rb--strict[-form], run-main.rb--web--strict-form-with-RUFLET_CLIENT_DIR[-lacking-Form];
  • doctor--strict[-form];
  • {build,run,doctor}--{h,help}, help-build, empty/--help-build;
  • run--bogus-flag and doctor--bogus-flag.

Tests (final head 3c748db5, Homebrew Ruby 4.0.5, GEM_HOME unset)

  • H1. ruby test/compat/compat.rb --jobs 4 checked 358 goldens with 0 failing, on Ruby 4.0.5 and on rbenv 3.4.5.
  • Against main (f8058191).
    • This head's test/compat run with main's lib: "358 goldens, 24 failing", exactly the 24 above.
    • main's own test/compat run with this head's lib: "343 goldens, 12 failing". Each of the 12 only adds lines: the warning, or the one --strict help line.
  • Unit tests. Every packages/ruflet test file passes in its own process: 27 files, 892 runs, 0 failures, 0 errors. That includes test/template_surface_test.rb (50 tests) and compat_goldens_test.rb (366 runs).
  • Planted bugs. The review's 6 surviving plants (v01, v04, v05, v13, v17, v27) are now each caught by template_surface_test.rb. So are 5 new plants on this round's code:
    • run checks the installed template;
    • run_root ignores RUFLET_CLIENT_DIR;
    • run_root skips the directory-exists check;
    • run_root takes a blank value;
    • doctor drops --strict's exit 1.
      The unplanted copy passes.
  • Table. tools/template_surface_revisions.rb --check reports the table current in these cases:
  • Docs. The check reports 19 of the 268 ruby blocks in ruflet_site main (556d737) against template main's surface. Each of the 19 calls one of the 33 wire types that template main lacks.
  • CI on 3c748db5: every job passed, including Build Android and "Verify Ruflet Explorer" (Ruby 3.4.5: template_surface_test 50 runs, compat_goldens_test 366 runs). Publish was skipped.

Not in this PR

Adds test/template_surface_test.rb, red on this commit. An app using
`form` against a template surface that predates it is warned, with the
location of the call and the first ruflet-template revision that renders
Form; --strict makes that an error. Against the new surface nothing is
printed. A template without a surface file, or an unreadable one, is not
checked. Services and bundled extensions are reported the same way.
Usage counts only receiverless method calls (not comments, strings,
symbols, locals, receiver calls or methods the app defines), a Rails app
is read from app/views/ruflet, nothing outside a Ruflet project is read,
and no app file is read when the template has everything.

Adds nine H1 invocations, generated on this code: build, run and doctor
on default_app with and without a main.rb that uses form, and with
--strict. Today none of them warns; `build --strict` is forwarded to
flutter build, and `run --strict` and `doctor --strict` are unknown
flags.
…e app uses (CRIT-04b)

build, run and doctor read the template's
tool/conformance/ruflet_control_surface.json (the wire types it renders)
and its ruflet_packages/ (the extensions it bundles). When the app calls
a control or service the template does not render, or selects a bundled
extension it does not ship, they print a warning on stderr naming it, the
file and line of the first call, and the first ruflet-template revision
that has it. Exit codes are unchanged. --strict (new on all three) makes
it an error: build and run stop with exit 1 before preparing anything,
doctor finishes its report and exits 1.

Nothing is printed when the template has everything the app uses, and a
template without a surface file (older templates) or an unreadable one
is not checked. The check never raises and fetches nothing.

The revisions come from packages/ruflet/lib/ruflet/cli/
template_surface_revisions.rb, generated by
tools/template_surface_revisions.rb from this checkout's registries and
a ruflet-template clone's history (--offline when only the registries
changed). The ruflet gem does not depend on ruflet_core, so the CLI
reads that table rather than the registries. A test fails when the
table is stale.

Usage is found with Ripper: receiverless method calls of the names the
template lacks, minus methods the app defines. Files are read only when
the template lacks something (about 1 ms on an app, 0.3 s on a
2,001-file one against an old template), from app/views/ruflet in a Rails
app, and never outside a Ruflet project.

H1: --strict appears in build, run and doctor help. The biometrics
fixtures, whose build already fails because the pinned template has no
ruflet_local_auth, now get the warning naming the revision first. The
new form fixtures warn, and fail with --strict. Without form, --strict
changes nothing.
…ositives

- Ruflet::CLI resolves download_file and extract_archive to FlutterSdk, as
  on main; TemplateSurfaceCheck is in no command module's ancestors.
- Wire types are dated from 19ac4c9e, the first surface that lists what its
  renderers handle; Lottie, Picker, CodeEditor and the rest of what older
  surfaces leave out are not reported.
- attr_reader, attr_accessor, let, let!, define_method, alias and the other
  definers define names; spec/ and test/ are not read.
- doctor reads the config only when the template lacks a bundled package,
  and quietly.
- Three H1 invocations, generated with main's lib (9f2ca79): an app with
  attr_reader :table plus spec/ and test/ files (build apk --self, run), and
  doctor with a ruflet.yaml that does not parse.
…lse positives

- TemplateSurfaceCheck is called with the command object instead of being
  included in RunCommand, BuildCommand and ExtraCommand. Including it moved
  FlutterSdk below RunCommand in Ruflet::CLI's ancestors, so run --web and
  --desktop, update, rails ruflet:update_all and the Flutter SDK download
  ran RunCommand's download_file and extract_archive (tar -xzf, ditto).
- tools/template_surface_revisions.rb dates wire types from 19ac4c9e (the
  first surface that lists what its renderers handle), so templates from
  0c02f475 to 32cd174 are no longer told they lack Lottie, Rive, Picker and
  the other controls they render. Packages are still dated from 0c02f475,
  and the table lists all of them in EXTENSION_PACKAGES.
- attr*, define_method, alias/alias_method, def_delegator(s), delegate,
  let/let!/subject, belongs_to/has_one, Struct.new and Data.define count as
  definitions; spec/ and test/ are not scanned.
- doctor reads ruflet.yaml/services.yaml only when the template lacks a
  bundled package, with stderr silenced, so it prints nothing new for a
  config it cannot parse.
- The warning says what a lacking template means for any of the three
  commands: an app built from it shows "Unknown control".
…parse

The walk stops after 50,000 directory entries, so a large asset tree cannot
slow build or run. Ripper is required the first time a file may call a name
the template lacks, so loading the CLI costs what it did before the check.
Declared through OptionParser, --strict made -s, --s, --st and the other
abbreviations OptionParser completes mean --strict; on main they are unknown
flags (exit 64), as cli_commands_test pins. run now takes --strict out of
argv before OptionParser runs, and Commands options gain exact: to declare
such a flag; the registry tests leave exact options out of the switches
they expect the parser to define.
…d gems

`ruflet doctor --fix` refreshes only the cached template, but
RUFLET_CLIENT_DIR, RUFLET_TEMPLATE_ROOT and a ruflet-template checkout
beside ruflet take precedence over it. The advice now names that source.

The project walk prunes RubyGems install directories (specifications/
and gems/), such as gems/ruby/3.4.0 after `bundle config set path gems`.

Tests pin what the review found unguarded: run reads the script it was
given from outside the project, MAX_FILES, MAX_FILE_BYTES, the root-prune
guard, Rails detection needing config/application.rb, the recorded client
revision, and doctor's lazy config. The wall-time assertion is replaced
by a parse count.
run --web and --desktop open the client in RUFLET_CLIENT_DIR, and
ruflet build uses it, so the surface check reads that client's surface
instead of the installed template's. Tests pin the six review plants
that survived: a relative RUFLET_CLIENT_DIR in the advice, line numbers
compared as numbers, doctor reading ruflet.yml, the three-kind count
wording, define_method with a quoted symbol, and the ruflet.yml marker.
The surface warning named the git HEAD two directories above the checked
template. For a client in RUFLET_CLIENT_DIR that is the app's repository,
not a template revision. A recorded .ruflet-template-revision still comes
first, and the cached template and checkouts are unchanged.

Also: a doctor exit-code test (--strict exits 1 only after flutter doctor
succeeds), and two H1 goldens for run --web --strict with a
RUFLET_CLIENT_DIR client that renders Form and one that lacks it.
@AdamMusa
AdamMusa merged commit b28cb1c into main Nov 21, 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