fix: AI 复习变式请求字段与校验一致;转写后删除不保留的录音
- generateReviewVariant 的指令要求 stimulus/answer/acceptedAnswers 等字段, 而 decodeGeneratedReviewVariant 只接受 schemaVersion、variantId、 targetItemId、prompt、expectedAnswer 五个字段,导致 AI 变式始终校验失败。 现在指令只要求这五个字段,并补充了请求与解码一致性的测试。 - finishVoiceInput(keepAudio: false) 转写完成(或页面已关闭)后删除音频, 补练页和测评页的语音输入不再在本机残留录音文件。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:kouyu_english/core/ai_service.dart';
|
||||
import 'package:kouyu_english/core/generated_content.dart';
|
||||
import 'package:kouyu_english/core/models.dart';
|
||||
|
||||
void main() {
|
||||
const valid = '''{
|
||||
@@ -35,6 +41,54 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'review variant request asks for exactly the fields it accepts',
|
||||
() async {
|
||||
AiService.instance.setFallbackApiKey('test-key');
|
||||
final prompts = <String>[];
|
||||
final variant = await http.runWithClient(
|
||||
() => AiService.instance.generateReviewVariant(
|
||||
provider: AiProviderType.openAi,
|
||||
endpoint: 'https://example.test/v1',
|
||||
model: 'test-model',
|
||||
targetItemId: 'A0-P12',
|
||||
basePrompt: '请用英语说你来自哪里。',
|
||||
),
|
||||
() => MockClient((request) async {
|
||||
final body = jsonDecode(request.body) as Map<String, dynamic>;
|
||||
final messages = body['messages'] as List<dynamic>;
|
||||
prompts.add((messages.single as Map<String, dynamic>)['content']);
|
||||
return http.Response(
|
||||
jsonEncode({
|
||||
'choices': [
|
||||
{
|
||||
'message': {'content': valid},
|
||||
},
|
||||
],
|
||||
}),
|
||||
200,
|
||||
headers: {'content-type': 'application/json; charset=utf-8'},
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
expect(variant, isNotNull);
|
||||
expect(prompts, hasLength(1));
|
||||
for (final field in [
|
||||
'schemaVersion',
|
||||
'variantId',
|
||||
'targetItemId',
|
||||
'prompt',
|
||||
'expectedAnswer',
|
||||
]) {
|
||||
expect(prompts.single, contains(field));
|
||||
}
|
||||
for (final field in ['stimulus', 'acceptedAnswers', 'forbiddenPhrases']) {
|
||||
expect(prompts.single, isNot(contains(field)));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const writing = '''{
|
||||
"schemaVersion":"writing-feedback-1",
|
||||
"lessonId":"a0-06",
|
||||
|
||||
Reference in New Issue
Block a user