forked from hangshuo652/aurak
feat: support choice+open dual question generation with judgment anchors
- Add judgment and followupHints fields to QuestionBankItem entity - Rewrite generateQuestions prompt for 3:7 choice:open ratio - Extract parseGeneratedQuestion function with type-aware parsing - Add 29 unit tests: 14 prompt content + 15 parse logic - Total: 97 tests passing (59 baseline + 38 new)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { QuestionBankItem, QuestionType, QuestionDifficulty, QuestionDimension, QuestionBankItemStatus } from './question-bank-item.entity';
|
||||
|
||||
describe('QuestionBankItem entity', () => {
|
||||
describe('existing fields', () => {
|
||||
it('should create an instance with default questionType', () => {
|
||||
const item = new QuestionBankItem();
|
||||
expect(item.questionType).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should set and get basic fields', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.questionText = '【场景】你在编写代码... 【问题】请描述你会如何处理';
|
||||
item.questionType = QuestionType.SHORT_ANSWER;
|
||||
item.options = null;
|
||||
item.correctAnswer = null;
|
||||
item.keyPoints = ['规范文档化', '源头统一'];
|
||||
item.difficulty = QuestionDifficulty.STANDARD;
|
||||
item.dimension = QuestionDimension.PROMPT;
|
||||
item.basis = '知识库原文依据';
|
||||
item.status = QuestionBankItemStatus.PENDING_REVIEW;
|
||||
|
||||
expect(item.questionText).toBe('【场景】你在编写代码... 【问题】请描述你会如何处理');
|
||||
expect(item.questionType).toBe(QuestionType.SHORT_ANSWER);
|
||||
expect(item.options).toBeNull();
|
||||
expect(item.correctAnswer).toBeNull();
|
||||
expect(item.keyPoints).toEqual(['规范文档化', '源头统一']);
|
||||
expect(item.difficulty).toBe(QuestionDifficulty.STANDARD);
|
||||
expect(item.dimension).toBe(QuestionDimension.PROMPT);
|
||||
expect(item.basis).toBe('知识库原文依据');
|
||||
expect(item.status).toBe(QuestionBankItemStatus.PENDING_REVIEW);
|
||||
});
|
||||
});
|
||||
|
||||
describe('judgment field', () => {
|
||||
it('should accept judgment text for choice question', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.judgment = 'B正确,因为提供了具体约束和角色设定。A错误在于过于笼统。C错误在于过度细节但缺乏核心约束。D错误在于错误建议。';
|
||||
expect(item.judgment).toBe('B正确,因为提供了具体约束和角色设定。A错误在于过于笼统。C错误在于过度细节但缺乏核心约束。D错误在于错误建议。');
|
||||
});
|
||||
|
||||
it('should accept judgment text for open question', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.judgment = '关键考点:会话管理——长对话导致上下文窗口膨胀 通过标准:说出"让AI总结之前内容+开新窗口"即通过';
|
||||
expect(item.judgment).toContain('通过标准');
|
||||
expect(item.judgment).toContain('会话管理');
|
||||
});
|
||||
|
||||
it('should allow null judgment', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.judgment = null;
|
||||
expect(item.judgment).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('followupHints field', () => {
|
||||
it('should accept array of followup hints', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.followupHints = [
|
||||
'如果只回答"开新窗口"没说怎么带上前情:追问"开新窗口后之前讨论的结论不就丢了吗?怎么把有用信息带过去?"',
|
||||
'如果内容不完整:追问"还有没有更好的办法?"',
|
||||
];
|
||||
expect(item.followupHints).toHaveLength(2);
|
||||
expect(item.followupHints[0]).toContain('开新窗口');
|
||||
expect(item.followupHints[1]).toContain('更好的办法');
|
||||
});
|
||||
|
||||
it('should accept single followup hint', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.followupHints = ['追问如何保留之前结论'];
|
||||
expect(item.followupHints).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should accept empty array', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.followupHints = [];
|
||||
expect(item.followupHints).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should allow null followupHints', () => {
|
||||
const item = new QuestionBankItem();
|
||||
item.followupHints = null;
|
||||
expect(item.followupHints).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -86,6 +86,12 @@ export class QuestionBankItem {
|
||||
@Column({ type: 'text', nullable: true })
|
||||
basis: string | null;
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
judgment: string | null;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true, name: 'followup_hints' })
|
||||
followupHints: string[] | null;
|
||||
|
||||
@Column({ name: 'created_by', nullable: true, type: 'text' })
|
||||
createdBy: string | null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user