mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
fix(app): reserved bundled module ids, existing-data warning, clipboard cleared on hide, fields reset per screen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0024438706
commit
ada391a88e
11 files changed
+404
-95
No files matched your search
+100
-1
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -337,4 +336,104 @@ void main() {
|
||||
expect(b.moduleRequests.last.$2['op'], 'suspend');
|
||||
expect(app.modules.macroVersion, greaterThan(before));
|
||||
});
|
||||
|
||||
testWidgets('a file cannot pose as a bundled module', (tester) async {
|
||||
final b = MemoryBackend()..inspectResult = vault();
|
||||
pickModuleFile = () async => Uint8List(4);
|
||||
await pump(tester, b, route: const SettingsRoute(), height: 3000);
|
||||
await tester.tap(find.byKey(const ValueKey('module-install-file')));
|
||||
await settle(tester);
|
||||
expect(
|
||||
find.textContaining('reserved for modules included'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Install Secrets 0.1.0?'), findsNothing);
|
||||
expect(b.installedModules, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('installing over existing data warns in the consent dialog', (
|
||||
tester,
|
||||
) async {
|
||||
final m = vault();
|
||||
final b = MemoryBackend()
|
||||
..inspectResult = ModuleDto(
|
||||
id: 'acme.notes',
|
||||
name: 'Notes',
|
||||
version: '1',
|
||||
description: '',
|
||||
author: 'Acme',
|
||||
permissions: const ['storage'],
|
||||
views: const [],
|
||||
macros: const [],
|
||||
enabled: true,
|
||||
size: m.size,
|
||||
)
|
||||
..moduleData.add('acme.notes');
|
||||
pickModuleFile = () async => Uint8List(4);
|
||||
await pump(tester, b, route: const SettingsRoute(), height: 3000);
|
||||
await tester.tap(find.byKey(const ValueKey('module-install-file')));
|
||||
await settle(tester);
|
||||
expect(find.text('Install Notes 1?'), findsOneWidget);
|
||||
expect(find.textContaining('already holds data'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('suspending clears a copied secret from the clipboard', (
|
||||
tester,
|
||||
) async {
|
||||
final writes = mockClipboard(tester);
|
||||
final b = MemoryBackend();
|
||||
b.installedModules['synapse.secrets'] = vault();
|
||||
final app = await pump(tester, b);
|
||||
await app.modules.applyEffects({
|
||||
'effects': [
|
||||
{
|
||||
'copy': {'text': 'hunter2', 'clear_after_ms': 30000},
|
||||
},
|
||||
],
|
||||
});
|
||||
await app.modules.suspend();
|
||||
expect(writes, ['hunter2', '']);
|
||||
// The pending timer was cancelled: nothing more happens later.
|
||||
await tester.pump(const Duration(seconds: 31));
|
||||
expect(writes, ['hunter2', '']);
|
||||
});
|
||||
|
||||
testWidgets('fields start empty on a new screen even with a reused id', (
|
||||
tester,
|
||||
) async {
|
||||
final b = MemoryBackend();
|
||||
b.installedModules['synapse.secrets'] = vault();
|
||||
var screen = 'edit';
|
||||
b.moduleHandlers['synapse.secrets'] = (req) {
|
||||
if (req['op'] == 'event') screen = 'locked';
|
||||
return {
|
||||
'ui': {
|
||||
'type': 'column',
|
||||
'key': screen,
|
||||
'children': [
|
||||
{
|
||||
'type': 'field',
|
||||
'id': 'password',
|
||||
'label': screen == 'edit' ? 'Password' : 'Master password',
|
||||
'value': '',
|
||||
'secret': true,
|
||||
},
|
||||
{'type': 'button', 'label': 'Go', 'action': 'go'},
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
await pump(
|
||||
tester,
|
||||
b,
|
||||
route: const ModuleRoute('synapse.secrets', 'vault', title: 'Secrets'),
|
||||
);
|
||||
await tester.enterText(find.widgetWithText(TextField, 'Password'), 'typed');
|
||||
await tester.tap(find.text('Go'));
|
||||
await settle(tester);
|
||||
final field = tester.widget<TextField>(
|
||||
find.widgetWithText(TextField, 'Master password'),
|
||||
);
|
||||
expect(field.controller!.text, '');
|
||||
});
|
||||
}
|
||||
@@ -73,6 +73,11 @@ class MemoryBackend implements GraphBackend {
|
||||
@override
|
||||
Future<void> stopModule(String id) async => stoppedModules.add(id);
|
||||
|
||||
/// Module ids with data in the graph.
|
||||
final moduleData = <String>{};
|
||||
@override
|
||||
Future<bool> moduleHasData(String id) async => moduleData.contains(id);
|
||||
|
||||
static ModuleDto withEnabled(ModuleDto m, bool enabled) => ModuleDto(
|
||||
id: m.id,
|
||||
name: m.name,
|
||||
|
||||
Reference in new issue
Block a user