Repository navigation
CLI: cover every command and option, fix what the tests exposed - #84
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 16, 2026 06:24
This was referenced Nov 17, 2026
Merged
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.
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.
Summary
This PR adds tests that run
ruflet's commands and options throughRuflet::CLI.runor theircommand_*handlers, and fixes the bugs those tests found. The branch now includes main at 4ca7634. The fixes were moved onto thecli/build/*split from #75. The command registry from #77/#78 is unchanged.It adds 49 tests:
build_options_test,run_options_testandupdate_options_testare new.extra_command_testhas 13 new tests andnew_command_testhas 4.cli_dispatch_testhas 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.
build appbundlegets the same steps asbuild aab. Flutter callsaabappbundle. Three steps only recognisedaab: the app identity check, the package rename and the stale-output clearing. So an appbundle kept the template'scom.example.ruflet_clientapplication id, even when ruflet.yaml names the app. Google Play does not accept that id.ruflet build appbundle [--self]now runsdart run change_app_package_name:main <id> --androidbeforeflutter build, asaabdoes. Goldens:cli/default_app/build-appbundle--self,cli/services_app/build-appbundle.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.build/app/intermediates/{flutter,assets,compressed_assets,incremental/mergeReleaseAssets}, as an aab rebuild does.appbundleis not renamed toaabanywhere. The log lines, theplatformin.ruflet-runtime.jsonand the--fullbundle cache key are unchanged.A partial Android signing setup now fails the build (exit 0 → 1).
build config error: Android signing is missing ...and built anyway. Gradle then signed with whateverbuild/client/android/key.propertiesan earlier build had left, or with the debug key.Android signing from the RUFLET_ANDROID_* environment is missing ..., or the key.properties path.android/key.propertiesplus one leftoverRUFLET_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.cli/services_app/build-apk-with-partial-signing-env.ruflet install -d IDnow 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":linux,windows,edgeedge)web-serveradb-…idsOther ids map as before.
build_options_test#test_other_device_ids_map_as_beforechecks 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--selfandinstall--d-adb-tls-id-after-apk--self.emulators --create,emulators --deleteandemulators --startwithout--emulatornow answer beforeensure_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.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 nowruflet debug [platform]. The positional argument is a platform, ashelp debugalready said.buildnow listsappbundle: 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.
Ruflet::CLI.bootstrap(path)now returnsruflet new's status. It used to return 0 even when nothing was created, for example when the directory already exists. That case includes everybootstrap(nil)call. Outside the tests, nothing in this repository callsbootstrap.No other golden changed. The regeneration rewrote only the 23 goldens listed above.
compat.rbchecks 320 goldens: 314 from main plus the 6 new ones.Changed with no behavior change
doctor,devices,emulatorsanddebug. These returned$?.exitstatus. Whensystemspawns no child, as a stubbedsystemin a test does,$?still describes the previous child. A helper now takes success fromsystem's own result. On a real system the codes are unchanged: a failed spawn gives 127, a signal gives 1 andexit Ngives N.extra_command_testpass or fail depending on the seed. That includes the existingtest_doctor_fix_uses_host_platform_install_path, which fails at seeds 31100 and 33255, andtest_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:
(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 asruflet <cmd>: <reason>followed by the command's usage, with exit 64, andruflet help <command>lists aliases and options. The tests now assert main's behavior.command_new's own-h/--helpand dashed-name handling.ruflet new --helpandruflet new -xalready stop in the dispatcher (help, or exit 64).new_command_test#test_dashed_words_after_new_are_help_or_usage_errors_not_app_namespins that. A directcommand_newcall behaves as on main.RUFLET_CONFIGresolver. 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_filenow pins that.appbundletoaab. It changed the logs,.ruflet-runtime.jsonand the--fullcache key.Verification
All of this was run on the head, 83fd3f9.
Each test file in its own process. 25
packages/ruflettest 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:
test_appbundle_gets_the_checks_aab_gets,test_install_device_ids_select_the_outputs_to_sync,test_partial_android_signing_fails_the_buildandtest_missing_and_unsupported_targets_fail_with_usage.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_devicesandtest_emulators_usage_errors_do_not_touch_flutter.test_bootstrap_returns_the_scaffold_status.test_help_text,test_help_words_and_no_arguments_print_helpandtest_an_unknown_command_names_the_downcased_word_prints_help_and_exits_1, and cli_usage'stest_build_help_text.Three more fail only at some seeds:
test_debug_maps_platforms_and_options_to_flutter_run,test_emulators_list_start_and_verboseandtest_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_archiveand#download_fileare dead code:FlutterSdk's versions win onRuflet::CLI.NewCommand::RUNTIME_REPO_URL(RUFLET_RUNTIME_REPO_URL) andExtraCommand#resolve_ruby_runtime_rootare never used.RUFLET_CACHE_DIRmoves only the template cache. The client, Flutter SDK, FVM and bootsnap caches stay under~/.ruflet.new_command_test#test_copy_ruflet_client_template_prefers_flutter_templaterunsgit ls-remoteandgit cloneof ruflet-template into$HOME/.ruflet/templateswhen no template is available.update_command_test#test_command_update_downloads_requested_target_for_platformrunsgit ls-remote, plus a clone when$HOMEis empty.$HOME. The first test fails. So do fiveupdate_command_testtests, which make no git call but read the template cached under~/.rufletand 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_permissionsandtest_services_activate_only_their_required_client_extensions.