GC-UI:前后端分离,前端改用 Flutter(Windows/macOS)
- 新增 GC-UI/:backend(.NET 8 本地 HTTP API + 模型窗口宿主)与 frontend(Flutter 桌面应用) - 前端一套 Dart 代码 + windows/macos 两个原生 runner,共享全部界面逻辑 - 「关于」页新增「源码语言:C#」「前端:Flutter」两行,字段由 /api/about 下发 - 截图脚本覆盖首页/下载/设置/关于/外壳,需要真实后端时用 runAsync 等待请求 - README 补充平台选型理由、接口列表与截图用法
This commit is contained in:
1 parent
2f3a8682c9
commit
9ca99a1fe1
68 files changed
+7400
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gc_ui/api_client.dart';
|
||||
|
||||
/// 前后端契约联调测试。
|
||||
///
|
||||
/// 需要 GC-UI 后端正在运行(`dotnet run --project GC-UI/backend/GC.UI.Server`)。
|
||||
/// 后端没起时整组跳过,不会让 CI 变红。
|
||||
///
|
||||
/// 注意:flutter_test 默认把所有 HTTP 请求拦成 400,这里显式放开真实网络。
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
HttpOverrides.global = null;
|
||||
});
|
||||
|
||||
final api = GcApi(
|
||||
baseUrl: const String.fromEnvironment(
|
||||
'GC_UI_BASE_URL',
|
||||
defaultValue: 'http://127.0.0.1:17890',
|
||||
),
|
||||
);
|
||||
|
||||
Future<bool> backendUp() async {
|
||||
try {
|
||||
await api.health();
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
test('health / settings / models / sources / jobs 都能解析', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
final health = await api.health();
|
||||
expect(health.ok, isTrue);
|
||||
expect(health.version, isNotEmpty);
|
||||
expect(health.platform, isNotEmpty);
|
||||
|
||||
final settings = await api.settings();
|
||||
expect(settings.modelRoot, isNotEmpty);
|
||||
expect(settings.dataRoot, isNotEmpty);
|
||||
expect(settings.renderFps, greaterThan(0));
|
||||
expect(settings.memoryMb, greaterThan(0));
|
||||
expect(settings.languages, isNotEmpty);
|
||||
expect(settings.sources, isNotEmpty);
|
||||
|
||||
final models = await api.models();
|
||||
for (final model in models) {
|
||||
expect(model.id, isNotEmpty);
|
||||
expect(model.name, isNotEmpty);
|
||||
}
|
||||
|
||||
final sources = await api.sources();
|
||||
expect(sources, isNotEmpty);
|
||||
expect(sources.first.id, isNotEmpty);
|
||||
|
||||
final jobs = await api.jobs();
|
||||
expect(jobs, isA<List<JobInfo>>());
|
||||
});
|
||||
|
||||
test('设置补丁能写回并读出一致', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
final before = await api.settings();
|
||||
final updated = await api.saveSettings(
|
||||
SettingsPatch(renderFps: before.renderFps == 60 ? 90 : 60),
|
||||
);
|
||||
expect(updated.renderFps, before.renderFps == 60 ? 90 : 60);
|
||||
|
||||
final restored = await api.saveSettings(
|
||||
SettingsPatch(renderFps: before.renderFps),
|
||||
);
|
||||
expect(restored.renderFps, before.renderFps);
|
||||
});
|
||||
|
||||
test('越界路径被后端拒绝', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
await expectLater(
|
||||
api.openFolder('/etc'),
|
||||
throwsA(isA<ApiException>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user