feat(garage_updates): an auto updater for garage apps
Asks Garage for the newest release of a project, downloads it with resume, checks the sha256, installs it beside the old one and restarts into it. Splash on garage_ui, a native stub and a first time installer for windows, bundle swap on mac, the system installer on android. No-op on web. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHotisA4hV2xmuZsHTksFX
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
444933b004
commit
d3b232f0ee
@@ -0,0 +1,145 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
import "package:garage_updates/core.dart";
|
||||
|
||||
import "support/fake_install.dart";
|
||||
import "support/fake_server.dart";
|
||||
|
||||
// the rule: a copy the updater didnt put there is left completly alone. no
|
||||
// check, no download, nothing swapped, one line on the console.
|
||||
|
||||
void main() {
|
||||
group("detecting", () {
|
||||
test("this very test run is not an install", () {
|
||||
// flutter_tester off the jit, exactly the dev case
|
||||
final found = detectInstall();
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, isNotNull);
|
||||
});
|
||||
|
||||
test("a debug build is never an install, wherever it sits", () {
|
||||
final fake = FakeWindowsInstall.create();
|
||||
addTearDown(fake.dispose);
|
||||
|
||||
final found = detectInstall(executable: fake.exe.path, platform: "windows", product: false);
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, contains("release build"));
|
||||
|
||||
// the same place as a release build is one
|
||||
expect(detectInstall(executable: fake.exe.path, platform: "windows", product: true).installer, isNotNull);
|
||||
});
|
||||
|
||||
test("flutter run on windows", () {
|
||||
final found = detectInstall(
|
||||
executable: r"C:\src\app\build\windows\x64\runner\Debug\app.exe",
|
||||
platform: "windows",
|
||||
product: true,
|
||||
);
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, contains("app-<build>"));
|
||||
});
|
||||
|
||||
test("a release exe run out of the build folder on windows", () {
|
||||
final tmp = Directory.systemTemp.createTempSync("gu_dev_");
|
||||
addTearDown(() => tmp.deleteSync(recursive: true));
|
||||
final release = Directory("${tmp.path}/build/windows/x64/runner/Release")..createSync(recursive: true);
|
||||
|
||||
final found = detectInstall(executable: "${release.path}/app.exe", platform: "windows", product: true);
|
||||
expect(found.installer, isNull);
|
||||
});
|
||||
|
||||
test("dart run / a bare binary on the mac", () {
|
||||
final found = detectInstall(
|
||||
executable: "/opt/homebrew/Cellar/dart/3.8.1/libexec/bin/dart",
|
||||
platform: "macos",
|
||||
product: true,
|
||||
environment: const {"HOME": "/Users/someone"},
|
||||
);
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, contains("app bundle"));
|
||||
});
|
||||
|
||||
test("flutter run on the mac", () {
|
||||
final found = detectInstall(
|
||||
executable: "/Users/someone/app/build/macos/Build/Products/Debug/App.app/Contents/MacOS/App",
|
||||
platform: "macos",
|
||||
product: true,
|
||||
environment: const {"HOME": "/Users/someone"},
|
||||
);
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, contains("build folder"));
|
||||
});
|
||||
|
||||
test("a platform core has no installer for", () {
|
||||
final found = detectInstall(executable: "/usr/bin/app", platform: "linux", product: true);
|
||||
expect(found.installer, isNull);
|
||||
expect(found.reason, contains("linux"));
|
||||
});
|
||||
});
|
||||
|
||||
group("an engine with no install", () {
|
||||
late FakeServer server;
|
||||
late UpdateEngine engine;
|
||||
final exits = <int>[];
|
||||
|
||||
setUp(() async {
|
||||
exits.clear();
|
||||
server = await FakeServer.start(noise(1024));
|
||||
server.updateBody = {"status": "required", "minimum_build": 99, "latest": server.release().toJson()};
|
||||
engine = UpdateEngine(
|
||||
project: "proj_1",
|
||||
build: 12,
|
||||
notInstalledReason: "this isn't a release build",
|
||||
client: UpdateClient(project: "proj_1", apiBase: server.base, httpClient: HttpClient()),
|
||||
downloader: Downloader(httpClient: HttpClient(), retries: 0),
|
||||
arch: "arm64",
|
||||
exitProcess: exits.add,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
engine.close();
|
||||
await server.close();
|
||||
});
|
||||
|
||||
test("says why once, and never asks the server", () async {
|
||||
expect(engine.installed, isFalse);
|
||||
expect(engine.notInstalledReason, "this isn't a release build");
|
||||
|
||||
final lines = await printsOf(() async {
|
||||
expect((await engine.check()).status, UpdateStatus.unknown);
|
||||
expect((await engine.check()).hasUpdate, isFalse);
|
||||
expect(engine.reportIfNotInstalled(), isFalse);
|
||||
});
|
||||
|
||||
expect(lines, ["[garage_updates] not updating this copy: this isn't a release build"]);
|
||||
expect(server.log, isEmpty);
|
||||
});
|
||||
|
||||
test("wont download, install or restart", () async {
|
||||
final release = server.release();
|
||||
final notInstalled = throwsA(isA<UpdateError>().having((e) => e.code, "code", "not_installed"));
|
||||
|
||||
await expectLater(engine.download(release), notInstalled);
|
||||
await expectLater(engine.install(release), notInstalled);
|
||||
await expectLater(engine.restart(), notInstalled);
|
||||
|
||||
expect(server.log, isEmpty);
|
||||
expect(exits, isEmpty);
|
||||
});
|
||||
|
||||
test("counting starts and markHealthy are quiet no-ops", () async {
|
||||
expect(await engine.noteStart(), isFalse);
|
||||
await engine.markHealthy();
|
||||
expect(await engine.isDownloaded(server.release()), isFalse);
|
||||
});
|
||||
|
||||
test("detect() off a test run gives exactly this engine", () {
|
||||
final e = UpdateEngine.detect(project: "proj_1", build: 12);
|
||||
addTearDown(e.close);
|
||||
expect(e.installed, isFalse);
|
||||
expect(e.installer, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user