Merge Yuxi teacher support with classroom discussions
This commit is contained in:
commit
dd96a7b7b4
34 files changed
+2333
-105
No files matched your search
@@ -2,7 +2,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import examples from '../fixtures/teacher-guidance-examples.json';
|
||||
import { TEACHER_BEHAVIOR_PROMPT } from '../../electron/coding-teacher/behavior-prompt';
|
||||
import { compileTeacherContext, estimateTeacherTokens } from '../../electron/coding-teacher/context';
|
||||
import { compileTeacherContext, estimateTeacherTokens, teacherHistoryMessages } from '../../electron/coding-teacher/context';
|
||||
import { consultationDefinition } from '../../electron/coding-teacher/consultation-role';
|
||||
import { applyDiscussionReply, discussionInstructions, editDiscussion, validateDiscussionContext } from '../../electron/coding-teacher/discussion';
|
||||
import { parseTeacherDiscussionReply } from '../../shared/teacher-discussion';
|
||||
@@ -69,19 +69,58 @@ describe('teacher behavior wiring and per-request formats', () => {
|
||||
|
||||
it('leaves the friend persona and enabled teaching material isolated', () => {
|
||||
const friend = consultationDefinition(definition, 'friend');
|
||||
const compiled = compileTeacherContext(friend, source, [], '你觉得呢', []);
|
||||
const compiled = compileTeacherContext(friend, source, [], '你觉得呢', [], undefined, 'question', undefined, true);
|
||||
expect(compiled.messages[0].content).toContain(friend.system_prompt);
|
||||
expect(compiled.messages[0].content).not.toContain(TEACHER_BEHAVIOR_PROMPT);
|
||||
expect(compiled.messages[0].content).not.toContain('启用的教学补充');
|
||||
expect(compiled.messages[0].content).not.toContain('你可以通过只读工具');
|
||||
});
|
||||
|
||||
it('keeps the structured guided-help format authoritative after behavior and cloud supplements', () => {
|
||||
it('keeps the structured guided-help format alongside project read access and teaching guidance', () => {
|
||||
const instructions = discussionInstructions(topic());
|
||||
const compiled = compileTeacherContext(definition, source, [], '我说不清', [], undefined, 'guided-help', instructions);
|
||||
const compiled = compileTeacherContext(definition, source, [], '我说不清', [], undefined, 'guided-help', instructions, true);
|
||||
expect(compiled.messages[0].content).toContain(TEACHER_BEHAVIOR_PROMPT);
|
||||
expect(compiled.messages[0].content).toContain('你可以通过只读工具');
|
||||
expect(compiled.messages[0].content).not.toContain('没有项目读取工具');
|
||||
expect(compiled.messages.at(-2)).toEqual({ role: 'system', content: instructions });
|
||||
expect(compiled.messages.at(-1)?.content).toContain('按本轮界面协议返回');
|
||||
expect(compiled.messages.at(-1)?.content).not.toContain('不返回 JSON');
|
||||
});
|
||||
|
||||
it('budgets readable history without fabricating a student turn for check-ins or losing suggested questions', () => {
|
||||
const saved: TeacherRequest = {
|
||||
id: 'check-in', intent: 'check-in', text: '内部主动触发', response: '刚才的作品有新进展。',
|
||||
references: [], createdAt: 'now', sourceCursor: source.cursor, sourceCapturedAt: 'now',
|
||||
includedSourceMessageIds: [], omittedMessages: 0, status: 'completed',
|
||||
};
|
||||
const history: TeacherRequest[] = [saved, {
|
||||
...saved, id: 'latest', intent: 'suggestions', text: '一起聊什么?',
|
||||
response: '先理解玩家想做什么。' + '需要考虑的作品细节。'.repeat(1200),
|
||||
suggestedQuestions: ['怎样判断这个体验是否有趣?'],
|
||||
}];
|
||||
const original = structuredClone(history);
|
||||
const readable = teacherHistoryMessages(history);
|
||||
expect(readable.map(message => message.id)).toEqual([
|
||||
'teacher:check-in:assistant', 'teacher:latest:user', 'teacher:latest:assistant',
|
||||
]);
|
||||
expect(readable.at(-1)?.text).toContain('怎样判断这个体验是否有趣?');
|
||||
expect(readable.some(message => message.text.includes('内部主动触发'))).toBe(false);
|
||||
|
||||
const instructions = discussionInstructions(topic());
|
||||
const fixed = compileTeacherContext(definition, source, [], '接着刚才的问题聊', [], undefined, 'question', instructions, true);
|
||||
const budget = estimateTeacherTokens(fixed.messages) + 1200;
|
||||
const compiled = compileTeacherContext(definition, source, history, '接着刚才的问题聊', [], budget, 'question', instructions, true);
|
||||
const latest = compiled.messages.find(message => message.content.startsWith('[teacher:latest:assistant]'));
|
||||
expect(latest?.content).toContain('先理解玩家想做什么');
|
||||
expect(latest?.content).toContain('中间内容已省略');
|
||||
expect(latest?.content).toContain('怎样判断这个体验是否有趣?');
|
||||
expect(compiled.omittedMessages).toBe(1);
|
||||
expect(compiled.truncatedMessages).toBeGreaterThan(0);
|
||||
expect(compiled.messages.at(-2)).toEqual({ role: 'system', content: instructions });
|
||||
expect(estimateTeacherTokens(compiled.messages)).toBeLessThanOrEqual(budget);
|
||||
expect(history).toEqual(original);
|
||||
expect(teacherHistoryMessages(history)).toEqual(readable);
|
||||
});
|
||||
});
|
||||
|
||||
describe('representative teaching examples against the real discussion contract', () => {
|
||||
|
||||
Reference in new issue
Block a user