Batch 5: remove silent desktop gateway fallback

This commit is contained in:
Haitao Pan 2026-03-29 16:48:45 +08:00
parent 9542dc3768
commit f16a07cc6c
3 changed files with 48 additions and 3 deletions

View File

@ -301,7 +301,6 @@ extension AppControllerDesktopSettingsRuntime on AppController {
final runtime = GatewayRuntime(
store: temporaryStore,
identityStore: DeviceIdentityStore(temporaryStore),
sessionClient: GoGatewayRuntimeDesktopClient(),
);
await runtime.initialize();
try {

View File

@ -26,10 +26,13 @@ class GatewayRuntime extends ChangeNotifier with GatewayRuntimeHelpersInternal {
required SecureConfigStore store,
required DeviceIdentityStore identityStore,
GatewayRuntimeSessionClient? sessionClient,
bool allowDirectSocketFallbackOnSessionClientFailure = false,
String runtimeId = '',
}) : storeInternal = store,
identityStoreInternal = identityStore,
sessionClientInternal = sessionClient,
allowDirectSocketFallbackOnSessionClientFailureInternal =
allowDirectSocketFallbackOnSessionClientFailure,
runtimeIdInternal = runtimeId.trim().isNotEmpty
? runtimeId.trim()
: randomIdInternal();
@ -37,6 +40,7 @@ class GatewayRuntime extends ChangeNotifier with GatewayRuntimeHelpersInternal {
final SecureConfigStore storeInternal;
final DeviceIdentityStore identityStoreInternal;
final GatewayRuntimeSessionClient? sessionClientInternal;
final bool allowDirectSocketFallbackOnSessionClientFailureInternal;
final String runtimeIdInternal;
final StreamController<GatewayPushEvent> eventsInternal =
StreamController<GatewayPushEvent>.broadcast();
@ -292,7 +296,8 @@ class GatewayRuntime extends ChangeNotifier with GatewayRuntimeHelpersInternal {
notifyListeners();
return;
} on GatewayRuntimeException catch (error) {
if (_shouldFallbackToDirectRuntimeInternal(error)) {
if (allowDirectSocketFallbackOnSessionClientFailureInternal &&
_shouldFallbackToDirectRuntimeInternal(error)) {
appendLogInternal(
this,
'warn',

View File

@ -225,7 +225,7 @@ void main() {
);
test(
'GatewayRuntime falls back to direct websocket when go-core bridge is unavailable',
'GatewayRuntime does not silently fall back to direct websocket when go-core bridge is unavailable',
() async {
SharedPreferences.setMockInitialValues(<String, Object>{});
final store = createIsolatedTestStore();
@ -243,6 +243,47 @@ void main() {
addTearDown(runtime.dispose);
addTearDown(server.close);
await runtime.initialize();
await expectLater(
() => runtime.connectProfile(
GatewayConnectionProfile.defaults().copyWith(
mode: RuntimeConnectionMode.local,
host: '127.0.0.1',
port: server.port,
tls: false,
useSetupCode: false,
),
authTokenOverride: 'shared-token-from-form',
),
throwsA(isA<GatewayRuntimeException>()),
);
expect(server.connectAuth, isNull);
expect(runtime.snapshot.status, RuntimeConnectionStatus.error);
expect(runtime.snapshot.lastErrorCode, 'GO_GATEWAY_RUNTIME_ENDPOINT_MISSING');
},
);
test(
'GatewayRuntime can explicitly fall back to direct websocket when enabled',
() async {
SharedPreferences.setMockInitialValues(<String, Object>{});
final store = createIsolatedTestStore();
final runtime = GatewayRuntime(
store: store,
identityStore: DeviceIdentityStore(store),
sessionClient: _FakeGatewayRuntimeSessionClient(
connectError: GatewayRuntimeException(
'go bridge unavailable',
code: 'GO_GATEWAY_RUNTIME_ENDPOINT_MISSING',
),
),
allowDirectSocketFallbackOnSessionClientFailure: true,
);
final server = await FakeGatewayRuntimeServerInternal.start();
addTearDown(runtime.dispose);
addTearDown(server.close);
await runtime.initialize();
await runtime.connectProfile(
GatewayConnectionProfile.defaults().copyWith(