feat(followup-audio): confirm role corrections and reextract cached transcripts

This commit is contained in:
2026-10-12 12:24:34 +08:00
parent 2dfec801e7
commit 9e3aa9fc61
15 changed files with 660 additions and 16 deletions
+43
View File
@@ -38,6 +38,7 @@ function setupPanel(overrides = {}, propsPatch = {}, options = {}) {
followupAudioUploadChunk: async (id, index, blob) => { calls.push(['chunk', id, index, blob.size]); return { index, received: true } },
followupAudioUploadComplete: async id => { calls.push(['complete', id]); return { upload_id: id, duration_seconds: 10, sha256: 'test' } },
followupAudioCreate: async payload => { calls.push(['create', payload]); return { task_id: 2, status: 'queued' } },
followupAudioReextract: async payload => { calls.push(['reextract', payload]); return task(payload.id, { status: 'queued', version: payload.version + 1, items: [], extraction_revision: 1, extraction_channel_roles: payload.channel_roles }) },
followupAudioDelete: async payload => { calls.push(['delete', payload]); return { id: payload.id, status: 'deleted', version: payload.version + 1 } },
followupAudioRetry: async id => { calls.push(['retry', id]); return { id, status: 'queued' } },
...overrides
@@ -2008,3 +2009,45 @@ test('close and unmount abort pending capabilities and prevent any late state re
} finally { f.dispose() }
}
})
const roleConflictTask = (extra={}) => stereoTask({items:[], channel_roles:'left_service',extraction_channel_roles:'left_service',extraction_revision:0,can_reextract:true,reextract_block_reason:'',role_check:{conflict:true,suggested_roles:'right_service',message:'合成角色冲突',evidence:[{channel:1,start_ms:0,end_ms:15000,text:'我是测试医院的医疗助理'}]},...extra})
test('role correction requires explicit confirmation and submits versioned roles without uploading or applying',async()=>{
let current=roleConflictTask();const confirmations=[]
const f=setupPanel({followupAudioDetail:async()=>current,followupAudioLists:async()=>({items:[current]}),followupAudioReextract:async p=>{f.calls.push(['reextract',p]);current=roleConflictTask({status:'queued',version:2,extraction_revision:1,extraction_channel_roles:p.channel_roles,channel_roles:p.channel_roles,can_reextract:false,role_check:{conflict:false,suggested_roles:'unconfirmed',message:'',evidence:[]}});return current}}, {}, {confirm:async(message)=>{confirmations.push(message)}})
await settle();await f.panel.openTask(1);assert.equal(f.panel.reextractTarget.value,'right_service');await f.panel.reextractWithRoles()
assert.deepEqual(f.calls.find(c=>c[0]==='reextract')[1],{id:1,version:1,channel_roles:'right_service'});assert.match(confirmations[0],/右客服/);assert.match(confirmations[0],/不重复语音识别/)
assert.equal(f.panel.detail.value.status,'queued');assert.equal(f.panel.detail.value.extraction_revision,1);assert.equal(f.calls.some(c=>['apply','create','session','chunk'].includes(c[0])),false);f.dispose()
})
test('role proposal never mutates manual roles or sends re-extraction until confirmed',async()=>{
const f=setupPanel({followupAudioDetail:async()=>roleConflictTask()}, {}, {confirm:async()=>{throw new Error('cancel')}});await settle();await f.panel.openTask(1)
assert.equal(f.panel.savedChannelRoles.value,'left_service');assert.equal(f.panel.channelRoles.value,'left_service');assert.equal(f.calls.some(c=>c[0]==='reextract'),false)
await f.panel.reextractWithRoles();assert.equal(f.calls.some(c=>c[0]==='reextract'),false);assert.equal(f.panel.detail.value.status,'review');assert.equal(f.panel.mutation.value,'');f.dispose()
})
test('re-extraction blocks dirty, readonly, unavailable, same-role and processing contexts',async()=>{
const f=setupPanel({followupAudioDetail:async()=>roleConflictTask()});await settle();await f.panel.openTask(1)
f.panel.reviewRef.value={hasUnsavedChanges:()=>true};await f.panel.reextractWithRoles();assert.equal(f.calls.some(c=>c[0]==='reextract'),false)
f.panel.reviewRef.value=null;f.props.viewOnly=true;await f.panel.reextractWithRoles();f.props.viewOnly=false
for(const patch of [{can_reextract:false},{status:'running'},{status:'applied'},{role_check:{conflict:false,suggested_roles:'left_service',evidence:[],message:''}}]){f.panel.installDetail(roleConflictTask(patch),false);await f.panel.reextractWithRoles()}
assert.equal(f.calls.some(c=>c[0]==='reextract'),false);f.dispose()
})
test('re-extraction confirmation and late results are fenced across patient changes',async()=>{
const answer=deferred();const f=setupPanel({followupAudioDetail:async()=>roleConflictTask()}, {}, {confirm:()=>answer.promise});await settle();await f.panel.openTask(1)
const pending=f.panel.reextractWithRoles();f.props.diagnosisId=20;await settle();answer.resolve();await pending;assert.equal(f.calls.some(c=>c[0]==='reextract'),false);f.dispose()
const response=deferred();const g=setupPanel({followupAudioDetail:async id=>roleConflictTask({id}),followupAudioReextract:async p=>{g.calls.push(['reextract',p]);return response.promise}});await settle();await g.panel.openTask(1)
const work=g.panel.reextractWithRoles();await settle();await g.panel.reextractWithRoles();assert.equal(g.calls.filter(c=>c[0]==='reextract').length,1);g.props.diagnosisId=30;await settle();await g.panel.openTask(2);response.resolve(roleConflictTask({status:'queued',version:2}));await work;assert.equal(g.panel.selectedId.value,2);assert.equal(g.panel.detail.value.id,2);g.dispose()
})
test('explicitly corrected review roles take priority over the advisory suggestion',async()=>{
const f=setupPanel({followupAudioDetail:async()=>roleConflictTask({channel_roles:'right_service',role_check:{conflict:false,suggested_roles:'unconfirmed',message:'',evidence:[]}})});await settle();await f.panel.openTask(1);assert.equal(f.panel.reextractTarget.value,'right_service');f.dispose()
const calls=[];const api=loadTs(path.join(root,'src/api/followupAudio.ts'),()=>({default:{post:async(config,options)=>{calls.push({config,options});return {code:1,data:roleConflictTask({status:'queued'})}}}}));await api.followupAudioReextract({id:1,version:1,channel_roles:'right_service'});assert.equal(calls[0].config.url,'/tcm.followupAudio/reextract');assert.equal(calls[0].options.isOpenRetry,false)
})
test('duplicate diagnosis suggestions are blocked clearly without losing distinct daily measurements',()=>{
const fields={diagnosis:[{key:'symptoms',label:'症状',type:'text'},{key:'remark',label:'备注',type:'text'}]}
const a=item({id:'a',kind:'diagnosis',values:{symptoms:'口干'}}),b=item({id:'b',kind:'diagnosis',values:{symptoms:'睡眠中断'}})
assert.match(state.reviewBatchIssue([a,b],fields),/症状存在多条选中建议/)
assert.equal(state.reviewBatchIssue([a,{...b,selected:false}],fields),'')
assert.equal(state.reviewBatchIssue([item(),item({id:'another',record_time:'12:00'})],fields),'')
assert.equal(a.values.symptoms,'口干');assert.equal(b.values.symptoms,'睡眠中断')
})