fbf04d90db
Port the Oracle off the Python g4f container onto on-device providers: Chromium HTTP via Cronet, a shared cookie session, IterList retry, hosted OpenAI-compat aggregators, and same-origin WebView fallbacks instead of CORS fetch.
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:words999/g4f/http_util.dart';
|
|
import 'package:words999/g4f/sse.dart';
|
|
|
|
void main() {
|
|
test('splitSseLines reassembles lines split across chunks', () async {
|
|
final lines = await splitSseLines(Stream.fromIterable([
|
|
'data: {"message":"Hel',
|
|
'lo"}\n',
|
|
'data: {"message":"!"}\n',
|
|
'data: [DONE]\n',
|
|
])).toList();
|
|
expect(lines, [
|
|
'data: {"message":"Hello"}',
|
|
'data: {"message":"!"}',
|
|
'data: [DONE]',
|
|
]);
|
|
});
|
|
|
|
test('extractSseContent reads OpenAI deltas and Duck messages', () {
|
|
expect(
|
|
extractSseContent('{"choices":[{"delta":{"content":"Привет"}}]}'),
|
|
'Привет',
|
|
);
|
|
expect(
|
|
extractSseContent('{"message":"знак","action":"success"}'),
|
|
'знак',
|
|
);
|
|
expect(extractSseContent('[DONE]'), isNull);
|
|
});
|
|
|
|
test('extractOpenAiMessage reads a non-stream body', () {
|
|
const body =
|
|
'{"choices":[{"message":{"role":"assistant","content":"OK"}}]}';
|
|
expect(extractOpenAiMessage(body), 'OK');
|
|
});
|
|
|
|
test('looksLikeGarbage detects WAF and error pages', () {
|
|
expect(looksLikeGarbage('<!DOCTYPE html><html>'), isTrue);
|
|
expect(looksLikeGarbage('Just a moment...'), isTrue);
|
|
expect(looksLikeGarbage('Оракул видит знак ВЕТЕР'), isFalse);
|
|
expect(looksLikeModelOutput('OK'), isFalse);
|
|
expect(looksLikeModelOutput('{}'), isFalse);
|
|
expect(looksLikeGarbage('No cake credits'), isTrue);
|
|
expect(looksLikeModelOutput('Оракул видит знак ВЕТЕР'), isTrue);
|
|
});
|
|
}
|