Skip to content

fix: use the Flutter SDK Ruflet installed under ~/.ruflet/flutter without the network or --fix - #111

Merged
AdamMusa merged 8 commits into
mainfrom
fix/managed-flutter-sdk-on-disk
Nov 20, 2026
Merged

AdamMusa merged 8 commits into
mainfrom
fix/managed-flutter-sdk-on-disk

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #110

What changed

packages/ruflet/lib/ruflet/cli/flutter_sdk.rb:

  • New installed_managed_flutter_sdk_root. It finds an SDK that an earlier run of ensure_flutter_sdk_downloaded installed, at ~/.ruflet/flutter/<version>/<host>/flutter, and accepts only an executable bin/flutter for the current host.
    • A concrete x.y.z version pin (RUFLET_FLUTTER_VERSION or .fvmrc, e.g. 3.41.2 or 3.41.2@stable) accepts only that exact version. It never swaps in a different installed SDK.
    • Without a concrete pin (template .metadata, the default, a channel name such as stable, or a partial version such as 3.41), the newest installed SDK is used. Unless the template .metadata names another channel, stable releases rank above -pre ones, so a -pre SDK is used only when no stable one is installed. This matches the online lookup, which only uses a channel from .metadata.
  • flutter_tools_via_managed_sdk with auto_install: false (plain ruflet doctor) now uses that installed SDK instead of returning nil. It still downloads nothing and makes no network request.
  • ensure_flutter_sdk_downloaded falls back to the installed SDK when resolve_flutter_release raises (offline) or returns nil (non-200 manifest, or no matching release). If nothing suitable is installed, the old behavior is kept: the same Flutter auto-install failed: ... warning and nil.

Online with auto-install, nothing changes. The manifest still picks the release, the "already installed" check still comes after it, and a release that is not installed is still downloaded. A Flutter on PATH and FVM SDKs are resolved exactly as before, and they still win over the managed SDK.

No app code, ruflet.yaml key or command-line invocation changes.

Behavior changes

Each item below was broken before and is listed here as a bug fix (D6):

  1. Plain ruflet doctor with no system or FVM Flutter, and an SDK under ~/.ruflet/flutter. Before, it printed Flutter: missing and the "Run ruflet doctor --fix" hint and exited 1. That happened right after doctor --fix had installed the SDK. Now it prints Flutter: <version> <channel>, runs flutter doctor with that SDK and returns its status, the same way doctor --fix does. Plain doctor still makes no network request, so it reports the newest installed SDK and does not check whether a newer stable release exists. A later online build may still download a newer release, as it did before.

  2. Commands that need Flutter when the release manifest can't be fetched, with a suitable SDK installed under ~/.ruflet/flutter. This covers build, install, debug, devices, emulators, update and doctor --fix, when offline or when the manifest returns a non-200 response. Before, they printed Flutter auto-install failed: <error> and Flutter is required for ... and exited 1. Now they use the installed SDK. With a concrete x.y.z pin they only do so when that exact version is installed; otherwise they fail exactly as before. A partial pin such as 3.41 uses the newest installed SDK, the same way the online manifest lookup warns and takes the latest stable for it.

    A side effect of the same fallback: for a pinned project offline, with no fvm or dart on PATH, ensure_fvm_available now gets the installed SDK's dart and tries dart pub global activate fvm (output discarded), exactly as it does online. Before, it got nil. If ~/.pub-cache/bin/fvm already exists from an earlier activation, the CLI then also writes .fvmrc (when there is none) into the FVM project dir (the build client dir, the directory of a .fvmrc in the current dir, or ~/.ruflet/fvm_project) and runs fvm install <pin> and fvm use --force <pin> there, as it does online. Before, this case called nothing and exited 1.

No other output changes. The H1 goldens use a Flutter on PATH and are unchanged.

How it was verified

All on the final head, which includes merges of current main (2801ae4). Those merges touch none of the three files this PR changes, and the PR diff against main is unchanged.

  • Regression tests. 11 tests in test/flutter_sdk_test.rb and 1 in test/extra_command_test.rb. In each test, the release manifest fetch and download_file fail the test if they are called, unless the test replaces them. The guards raise Minitest::Assertion, which is not a StandardError, so the offline rescue StandardError cannot swallow them.
    • flutter_tools(auto_install: false) finds the installed SDK.
    • Offline (Errno::ECONNREFUSED) and nil-manifest cases fall back to the installed SDK without the failure warning.
    • Offline with nothing installed still warns Flutter auto-install failed: Errno::ECONNREFUSED and returns nil.
    • An exact pin wins over newer installs, 3.41.2@stable matches 3.41.2, and a pin that is not installed is never replaced.
    • Without a pin, the newest stable SDK for the current host wins, by version order rather than string or directory order. Other hosts and incomplete directories are skipped, and -pre versions rank below stable. With a .metadata channel of beta, the newest -pre SDK wins.
    • Online, a manifest that resolves to a newer release still downloads that release (no fallback).
    • With auto-install off and nothing installed, nothing is created.
    • End to end through command_doctor([]): with an SDK under a temporary HOME and no Flutter on PATH, it exits 0, prints Flutter: 3.41.2 stable and runs flutter doctor with that SDK.
  • Planting the bug back. With main's flutter_sdk.rb and the new tests, 9 tests fail: 4 behavior tests, and 5 helper tests that fail with NoMethodError. The 3 guard tests (online download, offline with nothing installed, nothing created) pass on both versions, which shows those paths are unchanged.
  • Mutations. 15 targeted mutations of flutter_sdk.rb all fail at least one test. One makes plain doctor call ensure_flutter_sdk_downloaded, so it fetches the manifest; it fails 2 tests in flutter_sdk_test.rb and 1 in extra_command_test.rb.
  • End-to-end repro. No flutter, fvm or dart is on PATH. A temporary HOME holds the managed SDK and the real template .metadata, and only the manifest fetch is stubbed. Run on this branch and on main, 14 cases:
    • Changed, as listed above: plain doctor online (0 manifest fetches) and offline goes from exit 1 to exit 0; offline devices and emulators, offline devices with an installed pin from RUFLET_FLUTTER_VERSION or .fvmrc, and devices with a non-200 manifest go from exit 1 to exit 0.
    • Byte-identical to main: online doctor --fix and devices (1 manifest fetch each, no download), offline devices and doctor with a pin that is not installed, online devices with 3.41.2@stable, and an unreadable ~/.ruflet/flutter.
  • packages/ruflet suites. All 22 test files pass, each in its own process, on Ruby 4.0.5, including compat_goldens_test.rb with 322 runs. flutter_sdk_test.rb and extra_command_test.rb also pass with seeds 1, 7, 99 and 4242. CI on this head ran the framework tests on .ruby-version 3.4.5, and they pass: flutter_sdk_test.rb with 22 runs and extra_command_test.rb with 3 runs.
  • H1 goldens. cd packages/ruflet && ruby test/compat/compat.rb --jobs 4 checked 314 goldens, all passing.
  • Merges with open PRs. git merge-tree of this head with each open PR shows no conflict in the files this PR changes. Only feat: warn when the template lacks a control, service or extension the app uses (CRIT-04b) #80 and CLI: cover every command and option, fix what the tests exposed #84 conflict, and each conflicts in exactly the same files when merged with main.

flutter_tools_via_managed_sdk returned nil whenever auto_install was off,
so plain `ruflet doctor` never looked at ~/.ruflet/flutter and reported
"Flutter: missing" right after `ruflet doctor --fix` installed an SDK
there. ensure_flutter_sdk_downloaded fetched the release manifest before
checking the disk, so offline every command failed with "Flutter
auto-install failed" while the SDK was installed.

installed_managed_flutter_sdk_root finds an SDK that an earlier run put
in ~/.ruflet/flutter/<version>/<host>/flutter. It is used without
auto-install, and when the release manifest can't be fetched or
returns nothing. An explicit version pin (RUFLET_FLUTTER_VERSION,
.fvmrc) accepts only that exact version. Otherwise the newest
installed stable SDK is used. Online with auto-install, nothing
changes: the manifest still picks the release and downloads it when
it is missing.

Fixes #110
…d ordering cases

The guards for the release manifest and download_file raised NoMethodError
(flunk on the dummy) or RuntimeError, both StandardErrors that the offline
rescue in ensure_flutter_sdk_downloaded swallows. They now raise
Minitest::Assertion, so plain doctor fetching the manifest fails the tests.

Add tests for an x.y.z@channel pin, a beta channel preferring the newest
-pre SDK, and a newest-stable fixture where string or directory order
would pick a different SDK.
@AdamMusa
AdamMusa merged commit c061df0 into main Nov 20, 2026
10 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.

CLI: the Flutter SDK Ruflet installs under ~/.ruflet/flutter is invisible to plain ruflet doctor, and every command needs the network to find it

1 participant