feat(app): configure and safely switch multi-address servers

This commit is contained in:
2026-10-24 03:04:53 +01:00
parent 47cfb31e7d
commit b499da304d
38 changed files with 1764 additions and 65 deletions
@@ -0,0 +1,78 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/data/chat_create_prompt_store.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart';
import 'package:pipelines_app/features/settings/settings_store.dart';
import 'package:pipelines_app/features/attention/runtime/attention_store.dart';
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
void main() {
setUp(() => SharedPreferences.setMockInitialValues({}));
test(
'server-local drafts, read marks, workspace and alerts stay isolated',
() async {
const homeDrafts = SharedPreferencesChatDraftStore(serverId: 'home');
const workDrafts = SharedPreferencesChatDraftStore(serverId: 'work');
await homeDrafts.write('same-session-id', 'private home draft');
expect(await workDrafts.read('same-session-id'), '');
const homePrompts = SharedPreferencesChatCreatePromptStore(
serverId: 'home',
);
const workPrompts = SharedPreferencesChatCreatePromptStore(
serverId: 'work',
);
await homePrompts.write('opencode', '/same-path', (
send: true,
text: 'private instructions',
));
expect(await workPrompts.read('opencode', '/same-path'), isNull);
await workDrafts.write('same-session-id', 'work draft');
expect(await homeDrafts.read('same-session-id'), 'private home draft');
const homeLocal = SharedPreferencesChatSessionLocalStore(
serverId: 'home',
);
const workLocal = SharedPreferencesChatSessionLocalStore(
serverId: 'work',
);
await homeLocal.save(const ChatSessionLocal(hidden: ['same-session-id']));
expect((await workLocal.load()).hidden, isEmpty);
const homeSettings = SharedPreferencesSettingsStore(serverId: 'home');
const workSettings = SharedPreferencesSettingsStore(serverId: 'work');
await homeSettings.saveWorkspace('/home-project');
expect((await workSettings.load()).workspace, '');
const homeAttention = SharedPreferencesAttentionStore(serverId: 'home');
const workAttention = SharedPreferencesAttentionStore(serverId: 'work');
await homeAttention.write('home dismissals');
expect(await workAttention.read(), isNull);
const homeNotifications = SharedPreferencesNotificationStore(
serverId: 'home',
);
const workNotifications = SharedPreferencesNotificationStore(
serverId: 'work',
);
await homeNotifications.write('home ledger');
expect(await workNotifications.read(), isNull);
},
);
test(
'migrated original server retains legacy local data; new servers do not',
() async {
await const SharedPreferencesChatDraftStore().write(
's',
'existing draft',
);
final old = SharedPreferencesChatDraftStore(
serverId: serverStorageScope('legacy-server'),
);
expect(await old.read('s'), 'existing draft');
expect(
await const SharedPreferencesChatDraftStore(serverId: 'new').read('s'),
'',
);
},
);
}