build: prepare Flutter management center for agent integration
This commit is contained in:
1 parent
05d4d5fea6
commit
e91fa0235c
34 files changed
+3481
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ads_manager/data/manager_repository.dart';
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
final repo = ManagerRepository(stdout.writeln);
|
||||
try {
|
||||
await repo.init();
|
||||
final devices = await repo.devices();
|
||||
stdout.writeln(
|
||||
'API devices: ${devices.map((d) => "${d.id} busy=${d.busy}").join(", ")}',
|
||||
);
|
||||
final nodes = await repo.get('v2/nodes') as Map<String, dynamic>;
|
||||
stdout.writeln('Relay nodes: ${(nodes["nodes"] as List<dynamic>).length}');
|
||||
stdout.writeln(await repo.run(repo.settings.adb, ['devices', '-l']));
|
||||
if (!args.contains('--connect')) {
|
||||
return;
|
||||
}
|
||||
final device = devices.where((d) => !d.busy).firstOrNull;
|
||||
if (device == null) {
|
||||
stdout.writeln('SKIP: no idle device');
|
||||
return;
|
||||
}
|
||||
final s = await repo.connect(device.id);
|
||||
for (var i = 0; i < 20 && !s.ready && !s.exited; i++) {
|
||||
await Future<void>.delayed(const Duration(seconds: 3));
|
||||
await repo.monitor();
|
||||
}
|
||||
if (!s.ready) {
|
||||
throw StateError('ADB not ready: ${s.state}');
|
||||
}
|
||||
stdout.writeln(
|
||||
'Remote model: ${await repo.run(s.adb, ['-s', s.endpoint, 'shell', 'getprop', 'ro.product.model'])}',
|
||||
);
|
||||
if (args.contains('--screen')) {
|
||||
await repo.screen(s);
|
||||
await Future<void>.delayed(const Duration(seconds: 8));
|
||||
if (s.screen == null) {
|
||||
throw StateError('scrcpy exited early');
|
||||
}
|
||||
stdout.writeln('scrcpy process alive: ${s.screen!.pid}');
|
||||
}
|
||||
stdout.writeln('LIVE PASS');
|
||||
} finally {
|
||||
await repo.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:ads_manager/data/manager_repository.dart';
|
||||
import 'package:ads_manager/ui/manager_model.dart';
|
||||
import 'package:ads_manager/ui/manager_view.dart';
|
||||
|
||||
void main() {
|
||||
test('API URL preserves deployment prefix and rejects insecure schemes', () {
|
||||
final s = Settings()..server = 'wss://example.com/ads/';
|
||||
expect(
|
||||
s.uri('v1/devices').toString(),
|
||||
'https://example.com/ads/v1/devices',
|
||||
);
|
||||
s.server = 'ws://example.com';
|
||||
expect(() => s.uri('v1/devices'), throwsFormatException);
|
||||
});
|
||||
test(
|
||||
'agent credentials are rejected; client secret is not persisted',
|
||||
() async {
|
||||
final dir = await Directory.systemTemp.createTemp('ads-flutter-test');
|
||||
try {
|
||||
final file = File('${dir.path}/client.env');
|
||||
final repo = ManagerRepository((_) {});
|
||||
repo.settings.credential = file.path;
|
||||
await file.writeAsString('ADS_AGENT_TOKEN=${'a' * 32}');
|
||||
await expectLater(repo.importCredential(), throwsFormatException);
|
||||
await file.writeAsString('ADS_CLIENT_TOKEN=${'b' * 32}');
|
||||
await repo.importCredential();
|
||||
expect(repo.token, 'b' * 32);
|
||||
expect(repo.settings.toJson().toString(), isNot(contains('b' * 32)));
|
||||
} finally {
|
||||
await dir.delete(recursive: true);
|
||||
}
|
||||
},
|
||||
);
|
||||
for (final width in [920.0, 1280.0]) {
|
||||
testWidgets('device status, search and navigation at $width px', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = Size(width, 820);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final m = ManagerModel();
|
||||
m.devices = [
|
||||
const Device('test-phone', false),
|
||||
const Device('busy-phone', true),
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ManagerView(model: m, onQuit: () async {}),
|
||||
),
|
||||
);
|
||||
expect(find.text('test-phone'), findsOneWidget);
|
||||
expect(find.text('其他客户端占用'), findsOneWidget);
|
||||
await tester.enterText(find.byType(TextField), 'test');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('busy-phone'), findsNothing);
|
||||
await tester.tap(find.text('连接配置'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('保存配置'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
m.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user