merge(app): land native-endpoint-boot (run 155)

This commit is contained in:
2026-10-22 23:10:43 +01:00
2 changed files with 123 additions and 5 deletions
+37 -5
View File
@@ -4,17 +4,49 @@ import 'package:flutter/widgets.dart';
import 'app_url_strategy.dart';
import 'pipelines_app.dart';
import 'server_endpoint.dart';
import '../features/settings/settings_store.dart';
/// Native builds must supply their server explicitly; there is no baked host.
const configuredServerUrl = String.fromEnvironment('PIPELINES_SERVER_URL');
/// Resolves the endpoint for this launch and starts the normal composition.
void runPipelinesApp({Uri? base, String configured = configuredServerUrl}) {
useAppUrlStrategy();
final server = ServerEndpoint.resolve(
/// Resolves the launch endpoint, loading the last saved native endpoint only
/// when no build-time endpoint was supplied.
Future<ServerEndpoint> resolveLaunchServer({
Uri? base,
String configured = configuredServerUrl,
bool web = kIsWeb,
SettingsStore? settingsStore,
}) async {
WidgetsFlutterBinding.ensureInitialized();
var endpoint = configured;
if (!web && endpoint.trim().isEmpty) {
try {
endpoint =
(await (settingsStore ?? const SharedPreferencesSettingsStore())
.load())
.serverUrl;
} catch (_) {
endpoint = '';
}
}
return ServerEndpoint.resolve(
base: base ?? Uri.base,
web: kIsWeb,
web: web,
configured: endpoint,
);
}
/// Resolves the endpoint for this launch and starts the normal composition.
Future<void> runPipelinesApp({
Uri? base,
String configured = configuredServerUrl,
SettingsStore? settingsStore,
}) async {
useAppUrlStrategy();
final server = await resolveLaunchServer(
base: base,
configured: configured,
settingsStore: settingsStore,
);
runApp(PipelinesApp(server: server));
}
+86
View File
@@ -0,0 +1,86 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/bootstrap.dart';
import 'package:pipelines_app/features/settings/settings_store.dart';
class _TestSettingsStore implements SettingsStore {
_TestSettingsStore(this.value, {this.fail = false});
final String value;
final bool fail;
int loads = 0;
@override
Future<SettingsValues> load() async {
loads++;
if (fail) throw StateError('unavailable');
return SettingsValues(serverUrl: value);
}
@override
Future<bool> saveServerUrl(String value) async => true;
@override
Future<bool> saveWorkspace(String value) async => true;
}
void main() {
const nativeBase = 'http://127.0.0.1:8096/';
test(
'uses saved endpoint natively only when build configuration is blank',
() async {
final store = _TestSettingsStore('wss://saved.example.test');
final saved = await resolveLaunchServer(
base: Uri.parse(nativeBase),
configured: '',
web: false,
settingsStore: store,
);
expect(saved.uri, Uri.parse('wss://saved.example.test/connect'));
expect(store.loads, 1);
final configured = await resolveLaunchServer(
base: Uri.parse(nativeBase),
configured: 'ws://build.example.test',
web: false,
settingsStore: store,
);
expect(configured.uri, Uri.parse('ws://build.example.test/connect'));
expect(store.loads, 1);
},
);
test(
'blank or failed settings load leaves native configuration required',
() async {
for (final store in [
_TestSettingsStore(''),
_TestSettingsStore('', fail: true),
]) {
final server = await resolveLaunchServer(
base: Uri.parse(nativeBase),
configured: '',
web: false,
settingsStore: store,
);
expect(server.requiresConfiguration, isTrue);
expect(server.uri, isNull);
}
},
);
test(
'web infers same-origin endpoint without loading native settings',
() async {
final store = _TestSettingsStore('wss://saved.example.test');
final server = await resolveLaunchServer(
base: Uri.parse('https://web.example.test/runs'),
configured: '',
web: true,
settingsStore: store,
);
expect(server.uri, Uri.parse('wss://web.example.test/connect'));
expect(store.loads, 0);
},
);
}