Skip to content

CLI: cover every command and option, fix what the tests exposed - #84

Merged
AdamMusa merged 7 commits into
mainfrom
test/cli-coverage
Nov 21, 2026
Merged

AdamMusa merged 7 commits into
mainfrom
test/cli-coverage

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR adds tests that run ruflet's commands and options through Ruflet::CLI.run or their command_* handlers, and fixes the bugs those tests found. The branch now includes main at 4ca7634. The fixes were moved onto the cli/build/* split from #75. The command registry from #77/#78 is unchanged.

It adds 49 tests:

  • build_options_test, run_options_test and update_options_test are new.
  • extra_command_test has 13 new tests and new_command_test has 4.
  • cli_dispatch_test has 1 new test.

It also adds 6 H1 corpus entries.

Behavior changes

Every item below changes what an existing invocation does, and each one fixes a bug. An H1 golden pins each item: either an existing golden regenerated here, or a new one.

  1. build appbundle gets the same steps as build aab. Flutter calls aab appbundle. Three steps only recognised aab: the app identity check, the package rename and the stale-output clearing. So an appbundle kept the template's com.example.ruflet_client application id, even when ruflet.yaml names the app. Google Play does not accept that id.

    • ruflet build appbundle [--self] now runs dart run change_app_package_name:main <id> --android before flutter build, as aab does. Goldens: cli/default_app/build-appbundle--self, cli/services_app/build-appbundle.
    • If app.package_name or app.organization is missing, an appbundle build now fails with build config error: ruflet.yaml must define ... (exit 0 → 1). apk, android, aab and ios builds already failed this way. New golden: cli/rails_app/rake-ruflet_build_appbundle. rake ruflet:build[appbundle] was the only Rails mobile target that still built without these keys.
    • A rebuild clears build/app/intermediates/{flutter,assets,compressed_assets,incremental/mergeReleaseAssets}, as an aab rebuild does.
    • appbundle is not renamed to aab anywhere. The log lines, the platform in .ruflet-runtime.json and the --full bundle cache key are unchanged.
  2. A partial Android signing setup now fails the build (exit 0 → 1).

    • Before, it printed build config error: Android signing is missing ... and built anyway. Gradle then signed with whatever build/client/android/key.properties an earlier build had left, or with the debug key.
    • Now the build stops before it writes anything else, as other build config errors do.
    • The first line now names the source: Android signing from the RUFLET_ANDROID_* environment is missing ..., or the key.properties path.
    • This also covers a complete android/key.properties plus one leftover RUFLET_ANDROID_* variable. Once any of those variables is set, the environment replaces key.properties, so that build now fails until the variable is unset or the set is completed.
    • New golden: cli/services_app/build-apk-with-partial-signing-env.
  3. ruflet install -d ID now picks the right outputs for six kinds of id. Before, each of these synced the wrong platform's outputs and failed with "Could not find built app outputs":

    id synced before now
    linux, windows, edge Android its own platform (web for edge)
    web-server the host's web
    40-hex iPhone UDIDs (pre-2018 devices) Android iOS
    wireless-debugging adb-… ids iOS on a Mac Android

    Other ids map as before. build_options_test#test_other_device_ids_map_as_before checks a sample of them against the rule this PR replaces. New goldens (exit 1 → 0): cli/default_app/install--d-linux, install--d-windows, install--d-40-hex-udid-after-ios--self and install--d-adb-tls-id-after-apk--self.

  4. emulators --create, emulators --delete and emulators --start without --emulator now answer before ensure_flutter!. On a machine without Flutter, that call can install an SDK or exit. The message and exit status (1) are unchanged. With Flutter installed, the output is the same: the existing goldens for these commands did not change.

  5. The help text had three wrong statements, now fixed. refactor: dispatch ruflet commands through a command registry (WP-00 R2) #77 and fix: report bad flags with the command's usage; add ruflet help <command> (CLI-12) #78 kept this text byte-identical, and these are the only edits to it:

    • ruflet debug [scriptname|path] is now ruflet debug [platform]. The positional argument is a platform, as help debug already said.
    • build now lists appbundle: in the top-level help, help build, the build usage error and the missing-target usage line.
    • --self Self-contained lite build (default profile) is now --self Self-contained build; lite profile unless --full. The default build is server-driven, not --self.

    This regenerates 21 help goldens:

    • cli/empty/: no-arguments, help, --help, -h, -h-uppercase, help-uppercase, help--h, help--help, help-bogus, help-dash, help-end-of-options, --help-end-of-options, --help-build, bogus-command, bogus-command-mixed-case and empty-command.
    • cli/default_app/: help-build, build--help, build--h and build-without-target.
    • cli/rails_app/rake-ruflet_build_--help.

    The only lines that change in them are the three statements above.

  6. Ruflet::CLI.bootstrap(path) now returns ruflet new's status. It used to return 0 even when nothing was created, for example when the directory already exists. That case includes every bootstrap(nil) call. Outside the tests, nothing in this repository calls bootstrap.

No other golden changed. The regeneration rewrote only the 23 goldens listed above. compat.rb checks 320 goldens: 314 from main plus the 6 new ones.

Changed with no behavior change

  • Exit codes of doctor, devices, emulators and debug. These returned $?.exitstatus. When system spawns no child, as a stubbed system in a test does, $? still describes the previous child. A helper now takes success from system's own result. On a real system the codes are unchanged: a failed spawn gives 127, a signal gives 1 and exit N gives N.
    • On main's lib, this makes extra_command_test pass or fail depending on the seed. That includes the existing test_doctor_fix_uses_host_platform_install_path, which fails at seeds 31100 and 33255, and test_doctor_without_fix_reports_the_flutter_sdk_doctor_fix_installed, which fails at seeds 1 and 2.

Dropped since the last review

These were either already on main or fixed nothing:

  • The dispatcher's own usage error (exit 1) and the rewritten help heredoc with (also: ...) columns and option lists. On main, refactor: dispatch ruflet commands through a command registry (WP-00 R2) #77/fix: report bad flags with the command's usage; add ruflet help <command> (CLI-12) #78 already report a bad flag as ruflet <cmd>: <reason> followed by the command's usage, with exit 64, and ruflet help <command> lists aliases and options. The tests now assert main's behavior.
  • command_new's own -h/--help and dashed-name handling. ruflet new --help and ruflet new -x already stop in the dispatcher (help, or exit 64). new_command_test#test_dashed_words_after_new_are_help_or_usage_errors_not_app_names pins that. A direct command_new call behaves as on main.
  • The shared RUFLET_CONFIG resolver. Asset configuration and config loading already resolve to the same directory in every case, so it fixed nothing. build_options_test#test_assets_ruflet_yml_declares_are_configured_when_ruflet_config_names_a_missing_file now pins that.
  • Renaming appbundle to aab. It changed the logs, .ruflet-runtime.json and the --full cache key.

Verification

All of this was run on the head, 83fd3f9.

  • Each test file in its own process. 25 packages/ruflet test files on Ruby 4.0.5 (GEM_HOME unset) and on Ruby 3.4.5 (MT_NO_PLUGINS=1, minitest 5.25.5): 0 failures on both.

  • All test files except the goldens in one process, with seeds 1, 2, 3, 31100 and 33255: 437 runs, 0 failures for each seed.

  • H1 goldens. ruby test/compat/compat.rb --jobs 4: checked 320 goldens, 0 failing. ruby -Ilib -Itest test/compat_goldens_test.rb: 328 runs, 0 failures.

  • The new tests against main's lib (4ca7634). These fail at all five seeds:

    • build_options: test_appbundle_gets_the_checks_aab_gets, test_install_device_ids_select_the_outputs_to_sync, test_partial_android_signing_fails_the_build and test_missing_and_unsupported_targets_fail_with_usage.
    • extra_command: test_a_failed_system_call_never_reports_a_stale_success, test_exit_codes_follow_system_not_a_stale_last_status, test_devices_passes_its_arguments_to_flutter_devices and test_emulators_usage_errors_do_not_touch_flutter.
    • cli_dispatch: test_bootstrap_returns_the_scaffold_status.
    • The help-text assertions: cli_dispatch's test_help_text, test_help_words_and_no_arguments_print_help and test_an_unknown_command_names_the_downcased_word_prints_help_and_exits_1, and cli_usage's test_build_help_text.

    Three more fail only at some seeds: test_debug_maps_platforms_and_options_to_flutter_run, test_emulators_list_start_and_verbose and test_doctor_without_fix_reports_a_healthy_setup.

  • Planted bugs. I planted 28 single-line bugs, one per fix, and ran each against 13 CLI test files, one process per file. All 28 were caught. The unplanted copy passes.

Not fixed (found while writing the tests)

  • RunCommand#extract_archive and #download_file are dead code: FlutterSdk's versions win on Ruflet::CLI.
  • NewCommand::RUNTIME_REPO_URL (RUFLET_RUNTIME_REPO_URL) and ExtraCommand#resolve_ruby_runtime_root are never used.
  • RUFLET_CACHE_DIR moves only the template cache. The client, Flutter SDK, FVM and bootsnap caches stay under ~/.ruflet.
  • Two existing tests reach GitHub. The tests this PR adds make no git or network calls.
    • new_command_test#test_copy_ruflet_client_template_prefers_flutter_template runs git ls-remote and git clone of ruflet-template into $HOME/.ruflet/templates when no template is available.
    • update_command_test#test_command_update_downloads_requested_target_for_platform runs git ls-remote, plus a clone when $HOME is empty.
    • I ran the suite with a git that always fails and an empty $HOME. The first test fails. So do five update_command_test tests, which make no git call but read the template cached under ~/.ruflet and fail without it: test_prepare_flutter_client_runs_pod_install_for_ios, test_prepare_flutter_client_server_mode_removes_ruby_runtime_dependency_and_override, test_prepare_flutter_client_stops_when_pod_install_fails, test_qrcode_scanner_adds_extension_and_camera_permissions and test_services_activate_only_their_required_client_extensions.

Found by driving every command and option through Ruflet::CLI.run and the
command_* entry points:

- doctor, devices, emulators and debug returned $?.exitstatus. $? still
  describes the previous child when system spawned none, which made
  extra_command_test#test_doctor_fix_uses_host_platform_install_path pass
  or fail by seed. The exit code now follows system's own result.
- An unknown flag or bad value (`run --port abc`, `update --platform`)
  raised OptionParser errors with a backtrace. Ruflet::CLI.run reports
  them as usage errors and exits 1.
- emulators ran ensure_flutter!, which may install an SDK or exit, before
  parsing; --create, --delete and --start without --emulator now answer
  without it.
- `ruflet new --help` scaffolded a directory named "--help"; dashed names
  are now options (-h/--help print usage, anything else is an error).
- Ruflet::CLI.bootstrap always returned 0, even when nothing was created.
- `build appbundle` skipped the app-identity check, package-name rewrite
  and stale-asset clearing, which only recognize "aab"; it is normalized
  to aab like ipa is to ios.
- A partial Android signing setup printed "build config error" and built
  anyway, with whatever key.properties an earlier build left. It now
  fails the build.
- `install -d linux` and `-d windows` synced Android outputs, as did a
  40-hex iPhone UDID; adb-tls wireless ids were treated as iOS on macOS.
  Named desktop/web devices are matched first.
- Config loading and asset configuration resolved RUFLET_CONFIG /
  ruflet.yaml / ruflet.yml separately and disagreed when RUFLET_CONFIG
  named a missing file.
- Help documented `debug [scriptname|path]` (the positional is a platform),
  called --self the "default profile" (the default is server-driven), and
  omitted appbundle, the aliases, and the debug/install/emulators/update
  options.

New tests: cli_dispatch_test.rb, build_options_test.rb, and additions to
extra_command_test.rb and new_command_test.rb. 15 of them fail on the
previous code, as does the existing doctor test once a sibling test leaves
a failing $?.
update: every target and flag (web/desktop/all/check, --web, --desktop,
--check, --force, --platform), unsupported hosts and platforms, unknown
targets and failed downloads. run: option parsing, script resolution, the
child environment (target, port, assets, web client), the busy-port banner
and the failure paths. No bugs found here; these lock the behaviour in.
@AdamMusa
AdamMusa marked this pull request as ready for review November 16, 2026 06:24
Port the build fixes onto the cli/build/* split (#75) and keep #77/#78's
command registry: usage errors stay main's (exit 64), and the dispatcher,
help heredoc and new-command checks this branch had are dropped in favour
of main's. appbundle now gets aab's identity check, package rename and
stale-output clearing without being renamed to aab.
…ldens

New corpus entries record what each fix changes: install -d linux,
-d windows, a 40-hex iPhone UDID and a wireless adb id; a partial
RUFLET_ANDROID_* setup; rake ruflet:build[appbundle]. The regenerated
goldens are the help text's three corrected statements and appbundle's
package rename.
A flunk inside define_singleton_method runs with the runner as self, so
it raised NoMethodError instead of failing the test (and a rescue in the
command could have swallowed it). Call the test's flunk.
Only the ids the fix names change platform: linux, windows, edge,
web-server, adb-* and 40-hex UDIDs. Pin that every other id maps as the
replaced rule did.
@AdamMusa
AdamMusa merged commit 06c6e28 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