Compare commits
11
Commits
v0.1.3
..
38ca180cf7
No files matched your search
+36
-124
@@ -22,12 +22,6 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
class _Model implements ModelAdapter {
|
class _Model implements ModelAdapter {
|
||||||
final requests = <ModelRequest>[];
|
final requests = <ModelRequest>[];
|
||||||
final streams = <StreamController<ModelEvent>>[];
|
final streams = <StreamController<ModelEvent>>[];
|
||||||
final _requestWaiters = <int, Completer<void>>{};
|
|
||||||
|
|
||||||
Future<void> waitForRequests(int count) {
|
|
||||||
if (requests.length >= count) return Future<void>.value();
|
|
||||||
return _requestWaiters.putIfAbsent(count, Completer<void>.new).future;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<ModelEvent> stream(
|
Stream<ModelEvent> stream(
|
||||||
@@ -37,9 +31,6 @@ class _Model implements ModelAdapter {
|
|||||||
requests.add(request);
|
requests.add(request);
|
||||||
final stream = StreamController<ModelEvent>();
|
final stream = StreamController<ModelEvent>();
|
||||||
streams.add(stream);
|
streams.add(stream);
|
||||||
for (final count in _requestWaiters.keys.toList()) {
|
|
||||||
if (requests.length >= count) _requestWaiters.remove(count)!.complete();
|
|
||||||
}
|
|
||||||
unawaited(cancellation.whenCancelled.then((_) => stream.close()));
|
unawaited(cancellation.whenCancelled.then((_) => stream.close()));
|
||||||
return stream.stream;
|
return stream.stream;
|
||||||
}
|
}
|
||||||
@@ -91,46 +82,12 @@ class _DelayedRestoreConversation extends AgentConversationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _waitForRequests(
|
Future<void> _until(bool Function() check) async {
|
||||||
ProviderContainer container,
|
for (var attempt = 0; attempt < 1000; attempt++) {
|
||||||
ChatControllerProvider provider,
|
if (check()) return;
|
||||||
_Model model,
|
await Future<void>.delayed(const Duration(milliseconds: 1));
|
||||||
int count,
|
|
||||||
) async {
|
|
||||||
if (model.requests.length >= count) return;
|
|
||||||
final settled = Completer<void>();
|
|
||||||
void onState(ChatState state) {
|
|
||||||
if (!state.busy && model.requests.length < count && !settled.isCompleted) {
|
|
||||||
settled.completeError(
|
|
||||||
TestFailure('Send settled before model request $count: ${state.error}'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final subscription = container.listen(provider, (_, state) => onState(state));
|
|
||||||
onState(container.read(provider));
|
|
||||||
try {
|
|
||||||
await Future.any([model.waitForRequests(count), settled.future]);
|
|
||||||
} finally {
|
|
||||||
subscription.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _waitForState(
|
|
||||||
ProviderContainer container,
|
|
||||||
ChatControllerProvider provider,
|
|
||||||
bool Function(ChatState) check,
|
|
||||||
) async {
|
|
||||||
if (check(container.read(provider))) return;
|
|
||||||
final ready = Completer<void>();
|
|
||||||
final subscription = container.listen(provider, (_, state) {
|
|
||||||
if (check(state) && !ready.isCompleted) ready.complete();
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await ready.future;
|
|
||||||
} finally {
|
|
||||||
subscription.close();
|
|
||||||
}
|
}
|
||||||
|
fail('Expected state was not reached');
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -138,7 +95,6 @@ void main() {
|
|||||||
late Directory conversationsRoot;
|
late Directory conversationsRoot;
|
||||||
late ConversationRepository conversationRepository;
|
late ConversationRepository conversationRepository;
|
||||||
late ProviderContainer container;
|
late ProviderContainer container;
|
||||||
late AgentConversationRegistry registry;
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
model = _Model();
|
model = _Model();
|
||||||
conversationsRoot = await Directory.systemTemp.createTemp('chat-test-');
|
conversationsRoot = await Directory.systemTemp.createTemp('chat-test-');
|
||||||
@@ -175,11 +131,8 @@ void main() {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
registry = container.read(agentConversationRegistryProvider);
|
|
||||||
});
|
});
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
// Disposal initiates cancellation, but files remain open until the run settles.
|
|
||||||
await registry.cancelAll();
|
|
||||||
container.dispose();
|
container.dispose();
|
||||||
await conversationsRoot.delete(recursive: true);
|
await conversationsRoot.delete(recursive: true);
|
||||||
});
|
});
|
||||||
@@ -438,12 +391,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
await tester.tap(find.byTooltip('发送消息'));
|
await tester.tap(find.byTooltip('发送消息'));
|
||||||
await _waitForRequests(
|
await _until(() => model.requests.isNotEmpty);
|
||||||
container,
|
|
||||||
chatControllerProvider('lib'),
|
|
||||||
model,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(model.requests.single.messages.single.text, '测试发送');
|
expect(model.requests.single.messages.single.text, '测试发送');
|
||||||
@@ -513,10 +461,11 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
model.streams.single.add(const TextDelta('正在生成的内容'));
|
model.streams.single.add(const TextDelta('正在生成的内容'));
|
||||||
await _waitForState(
|
await _until(
|
||||||
container,
|
() => container
|
||||||
chatControllerProvider('lib'),
|
.read(chatControllerProvider('lib'))
|
||||||
(state) => state.partialResponse.isNotEmpty,
|
.partialResponse
|
||||||
|
.isNotEmpty,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -524,11 +473,7 @@ void main() {
|
|||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
await tester.tap(find.byTooltip('停止回复'));
|
await tester.tap(find.byTooltip('停止回复'));
|
||||||
await container.read(chatControllerProvider('lib').notifier).stop();
|
await container.read(chatControllerProvider('lib').notifier).stop();
|
||||||
await _waitForState(
|
await _until(() => !container.read(chatControllerProvider('lib')).busy);
|
||||||
container,
|
|
||||||
chatControllerProvider('lib'),
|
|
||||||
(state) => !state.busy,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('回复已中断'), findsOneWidget);
|
expect(find.text('回复已中断'), findsOneWidget);
|
||||||
@@ -569,11 +514,7 @@ void main() {
|
|||||||
addTearDown(subscription.close);
|
addTearDown(subscription.close);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.runAsync(
|
await tester.runAsync(
|
||||||
() => _waitForState(
|
() => _until(() => isolated.read(provider).messages.length == 2),
|
||||||
isolated,
|
|
||||||
provider,
|
|
||||||
(state) => state.messages.length == 2,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
final controller = isolated.read(provider.notifier);
|
final controller = isolated.read(provider.notifier);
|
||||||
expect(isolated.read(provider).messages.last.elapsedMs, 23000);
|
expect(isolated.read(provider).messages.last.elapsedMs, 23000);
|
||||||
@@ -680,12 +621,7 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
await tester.tap(find.byTooltip('发送消息'));
|
await tester.tap(find.byTooltip('发送消息'));
|
||||||
await _waitForRequests(
|
await _until(() => model.streams.isNotEmpty);
|
||||||
container,
|
|
||||||
chatControllerProvider('project'),
|
|
||||||
model,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.byKey(const Key('test-project-selector')), findsNothing);
|
expect(find.byKey(const Key('test-project-selector')), findsNothing);
|
||||||
@@ -693,10 +629,8 @@ void main() {
|
|||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
model.streams.single.add(ModelResponse(text: '已经开始'));
|
model.streams.single.add(ModelResponse(text: '已经开始'));
|
||||||
await model.streams.single.close();
|
await model.streams.single.close();
|
||||||
await _waitForState(
|
await _until(
|
||||||
container,
|
() => !container.read(chatControllerProvider('project')).busy,
|
||||||
chatControllerProvider('project'),
|
|
||||||
(state) => !state.busy,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -763,12 +697,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||||
await _waitForRequests(
|
await _until(() => model.requests.isNotEmpty);
|
||||||
container,
|
|
||||||
chatControllerProvider('lib'),
|
|
||||||
model,
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(
|
expect(
|
||||||
@@ -780,11 +709,7 @@ void main() {
|
|||||||
await tester.runAsync(() async {
|
await tester.runAsync(() async {
|
||||||
model.streams.single.add(ModelResponse(text: 'ok'));
|
model.streams.single.add(ModelResponse(text: 'ok'));
|
||||||
await model.streams.single.close();
|
await model.streams.single.close();
|
||||||
await _waitForState(
|
await _until(() => !container.read(chatControllerProvider('lib')).busy);
|
||||||
container,
|
|
||||||
chatControllerProvider('lib'),
|
|
||||||
(state) => !state.busy,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
@@ -800,15 +725,11 @@ void main() {
|
|||||||
addTearDown(subscription.close);
|
addTearDown(subscription.close);
|
||||||
final controller = container.read(provider.notifier);
|
final controller = container.read(provider.notifier);
|
||||||
final sending = controller.send('你好', timelineId: 'first');
|
final sending = controller.send('你好', timelineId: 'first');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
await controller.send('重复', timelineId: 'first');
|
await controller.send('重复', timelineId: 'first');
|
||||||
expect(model.requests, hasLength(1));
|
expect(model.requests, hasLength(1));
|
||||||
model.streams[0].add(const TextDelta('你好呀'));
|
model.streams[0].add(const TextDelta('你好呀'));
|
||||||
await _waitForState(
|
await _until(() => container.read(provider).partialResponse == '你好呀');
|
||||||
container,
|
|
||||||
provider,
|
|
||||||
(state) => state.partialResponse == '你好呀',
|
|
||||||
);
|
|
||||||
expect(container.read(provider).busy, isTrue);
|
expect(container.read(provider).busy, isTrue);
|
||||||
model.streams[0].add(ModelResponse(text: '你好呀!'));
|
model.streams[0].add(ModelResponse(text: '你好呀!'));
|
||||||
await model.streams[0].close();
|
await model.streams[0].close();
|
||||||
@@ -817,7 +738,7 @@ void main() {
|
|||||||
expect(container.read(provider).partialResponse, isEmpty);
|
expect(container.read(provider).partialResponse, isEmpty);
|
||||||
|
|
||||||
final second = controller.send('接着说', timelineId: 'second');
|
final second = controller.send('接着说', timelineId: 'second');
|
||||||
await _waitForRequests(container, provider, model, 2);
|
await _until(() => model.requests.length == 2);
|
||||||
expect(model.requests[1].messages.map((m) => m.text), [
|
expect(model.requests[1].messages.map((m) => m.text), [
|
||||||
'你好',
|
'你好',
|
||||||
'你好呀!',
|
'你好呀!',
|
||||||
@@ -837,7 +758,7 @@ void main() {
|
|||||||
final other = container
|
final other = container
|
||||||
.read(otherProvider.notifier)
|
.read(otherProvider.notifier)
|
||||||
.send('新会话', timelineId: 'timeline');
|
.send('新会话', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, otherProvider, model, 3);
|
await _until(() => model.requests.length == 3);
|
||||||
expect(model.requests.last.messages.map((m) => m.text), ['新会话']);
|
expect(model.requests.last.messages.map((m) => m.text), ['新会话']);
|
||||||
model.streams[2].add(ModelResponse(text: '新回答'));
|
model.streams[2].add(ModelResponse(text: '新回答'));
|
||||||
await model.streams[2].close();
|
await model.streams[2].close();
|
||||||
@@ -852,20 +773,16 @@ void main() {
|
|||||||
addTearDown(subscription.close);
|
addTearDown(subscription.close);
|
||||||
final controller = container.read(provider.notifier);
|
final controller = container.read(provider.notifier);
|
||||||
final sending = controller.send('开始', timelineId: 'timeline');
|
final sending = controller.send('开始', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
model.streams[0].add(const TextDelta('部分回复'));
|
model.streams[0].add(const TextDelta('部分回复'));
|
||||||
await _waitForState(
|
await _until(() => container.read(provider).partialResponse.isNotEmpty);
|
||||||
container,
|
|
||||||
provider,
|
|
||||||
(state) => state.partialResponse.isNotEmpty,
|
|
||||||
);
|
|
||||||
controller.stop();
|
controller.stop();
|
||||||
await sending;
|
await sending;
|
||||||
expect(container.read(provider).busy, isFalse);
|
expect(container.read(provider).busy, isFalse);
|
||||||
expect(container.read(provider).messages.last.text, '部分回复');
|
expect(container.read(provider).messages.last.text, '部分回复');
|
||||||
expect(container.read(provider).messages.last.interrupted, isTrue);
|
expect(container.read(provider).messages.last.interrupted, isTrue);
|
||||||
final next = controller.send('再来', timelineId: 'timeline');
|
final next = controller.send('再来', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 2);
|
await _until(() => model.streams.length == 2);
|
||||||
model.streams[1].add(ModelResponse(text: '完成'));
|
model.streams[1].add(ModelResponse(text: '完成'));
|
||||||
await model.streams[1].close();
|
await model.streams[1].close();
|
||||||
await next;
|
await next;
|
||||||
@@ -888,14 +805,14 @@ void main() {
|
|||||||
final first = container
|
final first = container
|
||||||
.read(firstProvider.notifier)
|
.read(firstProvider.notifier)
|
||||||
.send('第一条', timelineId: 'timeline');
|
.send('第一条', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, firstProvider, model, 1);
|
await _until(() => model.streams.length == 1);
|
||||||
model.streams[0].add(ModelResponse(text: '第一答'));
|
model.streams[0].add(ModelResponse(text: '第一答'));
|
||||||
await model.streams[0].close();
|
await model.streams[0].close();
|
||||||
await first;
|
await first;
|
||||||
final second = container
|
final second = container
|
||||||
.read(secondProvider.notifier)
|
.read(secondProvider.notifier)
|
||||||
.send('第二条', timelineId: 'timeline');
|
.send('第二条', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, secondProvider, model, 2);
|
await _until(() => model.streams.length == 2);
|
||||||
expect(model.requests[1].messages.map((message) => message.text), ['第二条']);
|
expect(model.requests[1].messages.map((message) => message.text), ['第二条']);
|
||||||
model.streams[1].add(ModelResponse(text: '第二答'));
|
model.streams[1].add(ModelResponse(text: '第二答'));
|
||||||
await model.streams[1].close();
|
await model.streams[1].close();
|
||||||
@@ -918,7 +835,7 @@ void main() {
|
|||||||
final first = container
|
final first = container
|
||||||
.read(provider.notifier)
|
.read(provider.notifier)
|
||||||
.send('保留这段对话', timelineId: 'timeline');
|
.send('保留这段对话', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
model.streams.single.add(ModelResponse(text: '已经保存'));
|
model.streams.single.add(ModelResponse(text: '已经保存'));
|
||||||
await model.streams.single.close();
|
await model.streams.single.close();
|
||||||
await first;
|
await first;
|
||||||
@@ -960,18 +877,13 @@ void main() {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
registry = container.read(agentConversationRegistryProvider);
|
|
||||||
final restoredProvider = chatControllerProvider(
|
final restoredProvider = chatControllerProvider(
|
||||||
'project',
|
'project',
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
);
|
);
|
||||||
subscription = container.listen(restoredProvider, (_, _) {});
|
subscription = container.listen(restoredProvider, (_, _) {});
|
||||||
addTearDown(subscription.close);
|
addTearDown(subscription.close);
|
||||||
await _waitForState(
|
await _until(() => container.read(restoredProvider).messages.length == 2);
|
||||||
container,
|
|
||||||
restoredProvider,
|
|
||||||
(state) => state.messages.length == 2,
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
container
|
container
|
||||||
.read(restoredProvider)
|
.read(restoredProvider)
|
||||||
@@ -983,7 +895,7 @@ void main() {
|
|||||||
final continued = container
|
final continued = container
|
||||||
.read(restoredProvider.notifier)
|
.read(restoredProvider.notifier)
|
||||||
.send('继续', timelineId: 'timeline');
|
.send('继续', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, restoredProvider, model, 2);
|
await _until(() => model.requests.length == 2);
|
||||||
expect(model.requests.last.messages.map((message) => message.text), [
|
expect(model.requests.last.messages.map((message) => message.text), [
|
||||||
'保留这段对话',
|
'保留这段对话',
|
||||||
'已经保存',
|
'已经保存',
|
||||||
@@ -1037,7 +949,7 @@ void main() {
|
|||||||
final first = switchingContainer
|
final first = switchingContainer
|
||||||
.read(provider.notifier)
|
.read(provider.notifier)
|
||||||
.send('旧会话', timelineId: 'timeline');
|
.send('旧会话', timelineId: 'timeline');
|
||||||
await _waitForRequests(switchingContainer, provider, firstModel, 1);
|
await _until(() => firstModel.streams.isNotEmpty);
|
||||||
firstModel.streams.single.add(ModelResponse(text: '旧回答'));
|
firstModel.streams.single.add(ModelResponse(text: '旧回答'));
|
||||||
await firstModel.streams.single.close();
|
await firstModel.streams.single.close();
|
||||||
await first;
|
await first;
|
||||||
@@ -1052,7 +964,7 @@ void main() {
|
|||||||
final second = switchingContainer
|
final second = switchingContainer
|
||||||
.read(provider.notifier)
|
.read(provider.notifier)
|
||||||
.send('继续会话', timelineId: 'timeline');
|
.send('继续会话', timelineId: 'timeline');
|
||||||
await _waitForRequests(switchingContainer, provider, firstModel, 2);
|
await _until(() => firstModel.streams.length == 2);
|
||||||
expect(firstModel.requests.last.messages.map((message) => message.text), [
|
expect(firstModel.requests.last.messages.map((message) => message.text), [
|
||||||
'旧会话',
|
'旧会话',
|
||||||
'旧回答',
|
'旧回答',
|
||||||
@@ -1092,7 +1004,7 @@ void main() {
|
|||||||
final sending = container
|
final sending = container
|
||||||
.read(provider.notifier)
|
.read(provider.notifier)
|
||||||
.send('hello', timelineId: 'timeline');
|
.send('hello', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
model.streams.single.addError(entry.key);
|
model.streams.single.addError(entry.key);
|
||||||
await model.streams.single.close();
|
await model.streams.single.close();
|
||||||
await sending;
|
await sending;
|
||||||
@@ -1106,7 +1018,7 @@ void main() {
|
|||||||
addTearDown(subscription.close);
|
addTearDown(subscription.close);
|
||||||
final controller = container.read(provider.notifier);
|
final controller = container.read(provider.notifier);
|
||||||
final sending = controller.send('开始', timelineId: 'timeline');
|
final sending = controller.send('开始', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
model.streams[0].addError(StateError('sensitive remote payload'));
|
model.streams[0].addError(StateError('sensitive remote payload'));
|
||||||
await model.streams[0].close();
|
await model.streams[0].close();
|
||||||
await sending;
|
await sending;
|
||||||
@@ -1120,7 +1032,7 @@ void main() {
|
|||||||
['开始'],
|
['开始'],
|
||||||
);
|
);
|
||||||
final next = controller.send('重试', timelineId: 'timeline');
|
final next = controller.send('重试', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 2);
|
await _until(() => model.streams.length == 2);
|
||||||
model.streams[1].add(ModelResponse(text: '成功'));
|
model.streams[1].add(ModelResponse(text: '成功'));
|
||||||
await model.streams[1].close();
|
await model.streams[1].close();
|
||||||
await next;
|
await next;
|
||||||
@@ -1136,7 +1048,7 @@ void main() {
|
|||||||
await early;
|
await early;
|
||||||
expect(container.read(provider).busy, isFalse);
|
expect(container.read(provider).busy, isFalse);
|
||||||
final later = controller.send('再次开始', timelineId: 'timeline');
|
final later = controller.send('再次开始', timelineId: 'timeline');
|
||||||
await _waitForRequests(container, provider, model, 1);
|
await _until(() => model.streams.isNotEmpty);
|
||||||
subscription.close();
|
subscription.close();
|
||||||
container.dispose();
|
container.dispose();
|
||||||
await later;
|
await later;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import tempfile
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from read_dependencies import ROOT, validate_pins
|
from read_dependencies import ROOT, validate_pins
|
||||||
from release_transport import SERVER, attachment_url, request
|
from release_transport import SERVER, request
|
||||||
|
|
||||||
|
|
||||||
def verify_archive(data, pins):
|
def verify_archive(data, pins):
|
||||||
@@ -94,7 +94,10 @@ def release_archive(pins):
|
|||||||
assets = [asset for asset in release['assets'] if asset['name'] == core['artifact']['file']]
|
assets = [asset for asset in release['assets'] if asset['name'] == core['artifact']['file']]
|
||||||
if len(assets) != 1:
|
if len(assets) != 1:
|
||||||
raise ValueError('Expected exactly one Core release source archive.')
|
raise ValueError('Expected exactly one Core release source archive.')
|
||||||
return request(attachment_url(assets[0]))
|
url = assets[0]['browser_download_url']
|
||||||
|
if not url.startswith(SERVER + '/'):
|
||||||
|
raise ValueError('Unexpected Core release download origin.')
|
||||||
|
return request(url)
|
||||||
|
|
||||||
|
|
||||||
def prepare(pins, root=ROOT):
|
def prepare(pins, root=ROOT):
|
||||||
|
|||||||
@@ -8,22 +8,10 @@ from unittest.mock import patch
|
|||||||
import unittest
|
import unittest
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from prepare_dependencies import extract_archive, prepare, release_archive, verify_archive
|
from prepare_dependencies import extract_archive, prepare, verify_archive
|
||||||
|
|
||||||
|
|
||||||
class CoreSourceDependencyTests(unittest.TestCase):
|
class CoreSourceDependencyTests(unittest.TestCase):
|
||||||
def test_local_gitea_response_links_use_verified_public_origin(self):
|
|
||||||
_, pins = self.bundle()
|
|
||||||
asset = {'name': pins['core']['artifact']['file'],
|
|
||||||
'browser_download_url': 'http://git.orangraph.com/lingjhf/cutdex_core/releases/download/v0.0.1/cutdex-core-0.0.1.zip'}
|
|
||||||
release = {'tag_name': 'v0.0.1', 'draft': False, 'prerelease': False, 'assets': [asset]}
|
|
||||||
with patch('prepare_dependencies.request', side_effect=[release, b'archive']) as send:
|
|
||||||
self.assertEqual(release_archive(pins), b'archive')
|
|
||||||
self.assertEqual(send.call_args.args[0], asset['browser_download_url'].replace('http:', 'https:'))
|
|
||||||
asset['browser_download_url'] = 'https://untrusted.example/archive.zip'
|
|
||||||
with patch('prepare_dependencies.request', return_value=release), self.assertRaises(ValueError):
|
|
||||||
release_archive(pins)
|
|
||||||
|
|
||||||
def bundle(self, extra=None):
|
def bundle(self, extra=None):
|
||||||
prefix = 'cutdex-core-0.0.1/'
|
prefix = 'cutdex-core-0.0.1/'
|
||||||
native = {'version': '0.0.1', 'source_commit': 'b' * 40, 'path': 'native_flutter',
|
native = {'version': '0.0.1', 'source_commit': 'b' * 40, 'path': 'native_flutter',
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ ws2_32 ucrtbase version
|
|||||||
'''.split())
|
'''.split())
|
||||||
SYSTEM_DLLS = {name + '.dll' for name in SYSTEM_DLLS}
|
SYSTEM_DLLS = {name + '.dll' for name in SYSTEM_DLLS}
|
||||||
REQUIRED = (
|
REQUIRED = (
|
||||||
'cutdex.exe', 'flutter_windows.dll', 'cutdex_native_flutter_plugin.dll',
|
'cutdex.exe', 'flutter_windows.dll', 'cutdex_runtime_plugin.dll',
|
||||||
'deskup_plugin.dll', 'velopack_libc.dll',
|
'deskup_plugin.dll', 'velopack_libc.dll',
|
||||||
'cutdex_windows_ffi.dll', 'sqlite3.dll', 'data/app.so', 'data/icudtl.dat',
|
'cutdex_windows_ffi.dll', 'sqlite3.dll', 'data/app.so', 'data/icudtl.dat',
|
||||||
'processing/bin/cutdex-processing-worker.exe',
|
'processing/bin/cutdex-processing-worker.exe',
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ class DependencyGateTest(unittest.TestCase):
|
|||||||
with self.assertRaisesRegex(ValueError, 'data/app.so'):
|
with self.assertRaisesRegex(ValueError, 'data/app.so'):
|
||||||
audit(self.root, lambda p: [])
|
audit(self.root, lambda p: [])
|
||||||
|
|
||||||
def test_native_flutter_plugin_is_required_after_migration(self):
|
|
||||||
(self.root / 'cutdex_native_flutter_plugin.dll').unlink()
|
|
||||||
(self.root / 'cutdex_runtime_plugin.dll').touch()
|
|
||||||
with self.assertRaisesRegex(ValueError, 'cutdex_native_flutter_plugin.dll'):
|
|
||||||
audit(self.root, lambda p: [], require_processing=False)
|
|
||||||
|
|
||||||
def test_jvm_is_not_assumed_to_be_a_system_dependency(self):
|
def test_jvm_is_not_assumed_to_be_a_system_dependency(self):
|
||||||
with self.assertRaisesRegex(ValueError, 'jvm.dll'):
|
with self.assertRaisesRegex(ValueError, 'jvm.dll'):
|
||||||
audit(self.root, lambda p: ['jvm.dll'] if p.name == 'cutdex.exe' else [])
|
audit(self.root, lambda p: ['jvm.dll'] if p.name == 'cutdex.exe' else [])
|
||||||
|
|||||||
Reference in new issue
Block a user