69 lines
2.7 KiB
Swift
69 lines
2.7 KiB
Swift
import Testing
|
|
import Foundation
|
|
@testable import 康康
|
|
|
|
/// 「记录问诊」(2026-06-28):prompt 红线 + DiaryEntry 标签/录音助手覆盖。
|
|
struct ConsultationTests {
|
|
|
|
// MARK: - Prompt
|
|
|
|
@Test func organizePromptContainsTranscriptAndHardRules() {
|
|
let prompt = ConsultationPrompts.organize(transcript: "上楼梯就喘半个月了医生说做个心电图下周三复查")
|
|
|
|
#expect(prompt.contains("上楼梯就喘半个月了医生说做个心电图下周三复查"))
|
|
// 红线:只转写整理、不自行新增诊断/用药,数值药名时间一字不改
|
|
#expect(prompt.contains("转写整理"))
|
|
#expect(prompt.contains("一字不改"))
|
|
// 结构化小节关键词都在
|
|
#expect(prompt.contains("主诉"))
|
|
#expect(prompt.contains("医生建议"))
|
|
#expect(prompt.contains("复查"))
|
|
// 项目 prompt 规范:禁思考标签
|
|
#expect(prompt.contains("/no_think"))
|
|
}
|
|
|
|
@Test func organizePromptTruncatesLongTranscript() {
|
|
let long = String(repeating: "喘", count: 4000) // 超过上限
|
|
let prompt = ConsultationPrompts.organize(transcript: long)
|
|
|
|
let expectedTail = String(long.prefix(ConsultationPrompts.organizeTranscriptLimit))
|
|
#expect(prompt.contains(expectedTail))
|
|
#expect(!prompt.contains(String(long.prefix(ConsultationPrompts.organizeTranscriptLimit + 2))))
|
|
}
|
|
|
|
// MARK: - DiaryEntry 标签 / 录音助手
|
|
|
|
@Test func consultationTagDrivesClassification() {
|
|
let consult = DiaryEntry(content: "主诉:胸闷", tags: [DiaryEntry.consultationTag])
|
|
#expect(consult.isConsultation)
|
|
#expect(!consult.isMedicationLog)
|
|
|
|
let plain = DiaryEntry(content: "今天还好")
|
|
#expect(!plain.isConsultation)
|
|
|
|
let med = DiaryEntry(content: "缬沙坦 80mg", tags: [DiaryEntry.medicationTag])
|
|
#expect(!med.isConsultation)
|
|
#expect(med.isMedicationLog)
|
|
}
|
|
|
|
@Test func audioAssetPicksAudioMimeOnly() {
|
|
let entry = DiaryEntry(content: "主诉:头晕", tags: [DiaryEntry.consultationTag])
|
|
// 没挂任何 Asset → nil
|
|
#expect(entry.audioAsset == nil)
|
|
// 挂一张图 + 一段录音 → 只认录音
|
|
entry.assets = [
|
|
Asset(relativePath: "a.jpg", mimeType: "image/jpeg"),
|
|
Asset(relativePath: "b.m4a", mimeType: "audio/m4a"),
|
|
]
|
|
#expect(entry.audioAsset?.relativePath == "b.m4a")
|
|
}
|
|
|
|
// MARK: - 时间线归类
|
|
|
|
@Test func consultationDiaryMapsToConsultationKind() {
|
|
let entry = DiaryEntry(content: "主诉:咳嗽\n医生建议:多喝水", tags: [DiaryEntry.consultationTag])
|
|
let timelineEntry = TimelineEntry.from(diary: entry)
|
|
#expect(timelineEntry.kind == .consultation)
|
|
}
|
|
}
|